Mercurial > emacs
annotate lisp/map-ynp.el @ 1717:aa7d6d57504b
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Thu, 24 Dec 1992 06:17:18 +0000 |
| parents | 46528118f75d |
| children | 04fb1d3d6992 |
| rev | line source |
|---|---|
|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
1 ;;; map-ynp.el --- General-purpose boolean question-asker. |
|
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
2 |
|
840
113281b361ec
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;;; Copyright (C) 1991, 1992 Free Software Foundation, Inc. |
|
113281b361ec
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> |
|
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: lisp, extensions |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
7 |
| 304 | 8 ;;; This program is free software; you can redistribute it and/or modify |
| 9 ;;; it under the terms of the GNU General Public License as published by | |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
10 ;;; the Free Software Foundation; either version 2, or (at your option) |
| 304 | 11 ;;; any later version. |
| 12 ;;; | |
| 13 ;;; This program is distributed in the hope that it will be useful, | |
| 14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 ;;; GNU General Public License for more details. | |
| 17 ;;; | |
| 18 ;;; A copy of the GNU General Public License can be obtained from this | |
| 19 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from | |
| 20 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | |
| 21 ;;; 02139, USA. | |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
22 |
|
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
23 ;;; Commentary: |
|
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
24 |
| 304 | 25 ;;; map-y-or-n-p is a general-purpose question-asking function. |
| 26 ;;; It asks a series of y/n questions (a la y-or-n-p), and decides to | |
| 27 ;;; applies an action to each element of a list based on the answer. | |
| 28 ;;; The nice thing is that you also get some other possible answers | |
| 29 ;;; to use, reminiscent of query-replace: ! to answer y to all remaining | |
| 30 ;;; questions; ESC or q to answer n to all remaining questions; . to answer | |
| 31 ;;; y once and then n for the remainder; and you can get help with C-h. | |
| 32 | |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
33 ;;; Code: |
|
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
34 |
| 304 | 35 ;;;###autoload |
| 891 | 36 (defun map-y-or-n-p (prompter actor list &optional help action-alist) |
| 304 | 37 "Ask a series of boolean questions. |
| 891 | 38 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST. |
| 304 | 39 |
| 40 LIST is a list of objects, or a function of no arguments to return the next | |
| 41 object or nil. | |
| 42 | |
| 580 | 43 If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not |
| 572 | 44 a string, PROMPTER is a function of one arg (an object from LIST), which |
| 45 returns a string to be used as the prompt for that object. If the return | |
| 46 value is not a string, it is eval'd to get the answer; it may be nil to | |
| 47 ignore the object, t to act on the object without asking the user, or a | |
| 48 form to do a more complex prompt. | |
| 49 | |
| 304 | 50 ACTOR is a function of one arg (an object from LIST), |
| 51 which gets called with each object that the user answers `yes' for. | |
| 52 | |
| 53 If HELP is given, it is a list (OBJECT OBJECTS ACTION), | |
| 54 where OBJECT is a string giving the singular noun for an elt of LIST; | |
| 55 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive | |
| 56 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\). | |
| 57 | |
| 58 At the prompts, the user may enter y, Y, or SPC to act on that object; | |
| 59 n, N, or DEL to skip that object; ! to act on all following objects; | |
| 60 ESC or q to exit (skip all following objects); . (period) to act on the | |
| 61 current object and then exit; or \\[help-command] to get help. | |
| 62 | |
| 891 | 63 If ACTION-ALIST is given, it is an alist (KEY FUNCTION HELP) of extra keys |
| 64 that will be accepted. KEY is a character; FUNCTION is a function of one | |
| 65 arg (an object from LIST); HELP is a string. When the user hits KEY, | |
| 66 FUNCTION is called. If it returns non-nil, the object is considered | |
| 67 \"acted upon\", and the next object from LIST is processed. If it returns | |
| 68 nil, the prompt is repeated for the same object. | |
| 69 | |
| 304 | 70 Returns the number of actions taken." |
| 474 | 71 (let* ((old-help-form help-form) |
| 891 | 72 (help-form (let ((object (if help (nth 0 help) "object")) |
| 73 (objects (if help (nth 1 help) "objects")) | |
| 74 (action (if help (nth 2 help) "act on"))) | |
| 75 (concat (format "Type SPC or `y' to %s the current %s; | |
| 76 DEL or `n' to skip the current %s; | |
| 77 ! to %s all remaining %s; | |
| 78 ESC or `q' to exit;\n" | |
| 79 action object object action objects) | |
|
1235
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
80 (mapconcat (function |
|
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
81 (lambda (elt) |
|
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
82 (format "%c to %s" |
|
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
83 (nth 0 elt) |
|
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
84 (nth 2 elt)))) |
| 891 | 85 action-alist |
| 86 ";\n") | |
| 87 (if action-alist ";\n") | |
| 88 (format "or . (period) to %s \ | |
| 89 the current %s and exit." | |
| 90 action object)))) | |
| 91 (user-keys (if action-alist | |
|
1235
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
92 (concat (mapconcat (function |
|
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
93 (lambda (elt) |
|
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
94 (key-description |
|
a9e3ec19b7d7
Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents:
911
diff
changeset
|
95 (char-to-string (car elt))))) |
| 891 | 96 action-alist ", ") |
| 97 " ") | |
| 98 "")) | |
| 474 | 99 (actions 0) |
| 891 | 100 prompt char elt tail |
| 474 | 101 (next (if (or (symbolp list) |
| 102 (subrp list) | |
| 103 (compiled-function-p list) | |
| 104 (and (consp list) | |
| 105 (eq (car list) 'lambda))) | |
| 106 (function (lambda () | |
| 107 (setq elt (funcall list)))) | |
| 108 (function (lambda () | |
| 109 (if list | |
| 110 (progn | |
| 111 (setq elt (car list) | |
| 112 list (cdr list)) | |
| 113 t) | |
| 114 nil)))))) | |
| 304 | 115 (if (stringp prompter) |
| 116 (setq prompter (` (lambda (object) | |
| 117 (format (, prompter) object))))) | |
| 415 | 118 (while (funcall next) |
| 304 | 119 (setq prompt (funcall prompter elt)) |
| 120 (if (stringp prompt) | |
| 121 (progn | |
| 122 ;; Prompt the user about this object. | |
| 123 (let ((cursor-in-echo-area t)) | |
|
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
891
diff
changeset
|
124 (message "%s(y, n, !, ., q, %sor %s) " |
| 891 | 125 prompt user-keys |
| 126 (key-description (char-to-string help-char))) | |
| 304 | 127 (setq char (read-char))) |
| 128 (cond ((or (= ?q char) | |
| 129 (= ?\e char)) | |
| 130 (setq next (function (lambda () nil)))) | |
| 131 ((or (= ?y char) | |
| 132 (= ?Y char) | |
| 133 (= ? char)) | |
| 134 ;; Act on the object. | |
| 135 (let ((help-form old-help-form)) | |
| 136 (funcall actor elt)) | |
| 137 (setq actions (1+ actions))) | |
| 138 ((or (= ?n char) | |
| 139 (= ?N char) | |
| 140 (= ?\^? char)) | |
| 141 ;; Skip the object. | |
| 142 ) | |
| 143 ((= ?. char) | |
| 144 ;; Act on the object and then exit. | |
| 145 (funcall actor elt) | |
| 146 (setq actions (1+ actions) | |
| 147 next (function (lambda () nil)))) | |
| 148 ((= ?! char) | |
| 319 | 149 ;; Act on this and all following objects. |
| 150 (if (eval (funcall prompter elt)) | |
| 151 (progn | |
| 152 (funcall actor elt) | |
| 153 (setq actions (1+ actions)))) | |
| 474 | 154 (while (funcall next) |
| 319 | 155 (if (eval (funcall prompter elt)) |
| 304 | 156 (progn |
| 157 (funcall actor elt) | |
| 308 | 158 (setq actions (1+ actions)))))) |
| 304 | 159 ((= ?? char) |
|
1616
46528118f75d
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1235
diff
changeset
|
160 (setq unread-command-event help-char) |
| 319 | 161 (setq next (` (lambda () |
| 162 (setq next '(, next)) | |
| 163 '(, elt))))) | |
| 891 | 164 ((setq tail (assq char action-alist)) |
| 165 ;; A user-defined key. | |
| 166 (if (funcall (nth 1 tail) elt) ;Call its function. | |
| 167 ;; The function has eaten this object. | |
| 168 (setq actions (1+ actions)) | |
| 169 ;; Regurgitated; try again. | |
| 170 (setq next (` (lambda () | |
| 171 (setq next '(, next)) | |
| 172 '(, elt)))))) | |
| 304 | 173 (t |
| 174 ;; Random char. | |
| 175 (message "Type %s for help." | |
| 176 (key-description (char-to-string help-char))) | |
| 177 (beep) | |
| 178 (sit-for 1) | |
| 319 | 179 (setq next (` (lambda () |
| 180 (setq next '(, next)) | |
| 181 '(, elt))))))) | |
| 304 | 182 (if (eval prompt) |
| 183 (progn | |
| 319 | 184 (funcall actor elt) |
| 185 (setq actions (1+ actions)))))) | |
| 304 | 186 ;; Clear the last prompt from the minibuffer. |
| 187 (message "") | |
| 188 ;; Return the number of actions that were taken. | |
| 189 actions)) | |
|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
190 |
|
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
191 ;;; map-ynp.el ends here |
