Mercurial > emacs
annotate lisp/electric.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 | 5beb9d2bc959 |
| children | 04fb1d3d6992 |
| rev | line source |
|---|---|
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; electric.el --- window maker and Command loop for `electric' modes. |
|
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
| 845 | 3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. |
| 4 | |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
5 ;; Author: K. Shane Hartman |
|
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
6 ;; Maintainer: FSF |
|
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: extensions |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
8 |
| 35 | 9 ;; This file is part of GNU Emacs. |
| 10 | |
| 11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 12 ;; 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:
778
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
| 35 | 14 ;; any later version. |
| 15 | |
| 16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 ;; GNU General Public License for more details. | |
| 20 | |
| 21 ;; You should have received a copy of the GNU General Public License | |
| 22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 24 | |
| 25 | |
| 584 | 26 ; zaaaaaaap |
| 35 | 27 |
| 28 ;; perhaps this should be in subr.el... | |
| 29 (defun shrink-window-if-larger-than-buffer (window) | |
| 30 (save-excursion | |
| 31 (set-buffer (window-buffer window)) | |
| 32 (let ((w (selected-window)) ;save-window-excursion can't win | |
| 33 (buffer-file-name buffer-file-name) | |
| 34 (p (point)) | |
| 35 (n 0) | |
| 36 (window-min-height 0) | |
| 37 (buffer-read-only nil) | |
| 38 (modified (buffer-modified-p)) | |
| 39 (buffer (current-buffer))) | |
| 40 (unwind-protect | |
| 41 (progn | |
| 42 (select-window window) | |
| 43 (goto-char (point-min)) | |
| 44 (while (pos-visible-in-window-p (point-max)) | |
| 45 ;; defeat file locking... don't try this at home, kids! | |
| 46 (setq buffer-file-name nil) | |
| 47 (insert ?\n) (setq n (1+ n))) | |
| 48 (if (> n 0) (shrink-window (1- n)))) | |
| 49 (delete-region (point-min) (point)) | |
| 50 (set-buffer-modified-p modified) | |
| 51 (goto-char p) | |
| 52 (select-window w) | |
| 53 ;; Make sure we unbind buffer-read-only | |
| 54 ;; with the proper current buffer. | |
| 55 (set-buffer buffer))))) | |
| 56 | |
| 57 ;; This loop is the guts for non-standard modes which retain control | |
| 58 ;; until some event occurs. It is a `do-forever', the only way out is to | |
| 59 ;; throw. It assumes that you have set up the keymap, window, and | |
| 60 ;; everything else: all it does is read commands and execute them - | |
| 61 ;; providing error messages should one occur (if there is no loop | |
| 62 ;; function - which see). The required argument is a tag which should | |
| 63 ;; expect a value of nil if the user decides to punt. The | |
| 64 ;; second argument is a prompt string (defaults to "->"). Given third | |
| 65 ;; argument non-nil, it INHIBITS quitting unless the user types C-g at | |
| 66 ;; toplevel. This is so user can do things like C-u C-g and not get | |
| 67 ;; thrown out. Fourth argument, if non-nil, should be a function of two | |
| 68 ;; arguments which is called after every command is executed. The fifth | |
| 69 ;; argument, if provided, is the state variable for the function. If the | |
| 70 ;; loop-function gets an error, the loop will abort WITHOUT throwing | |
| 71 ;; (moral: use unwind-protect around call to this function for any | |
| 72 ;; critical stuff). The second argument for the loop function is the | |
| 73 ;; conditions for any error that occurred or nil if none. | |
| 74 | |
| 75 (defun Electric-command-loop (return-tag | |
| 76 &optional prompt inhibit-quit | |
| 77 loop-function loop-state) | |
| 78 (if (not prompt) (setq prompt "->")) | |
| 79 (let (cmd (err nil)) | |
| 80 (while t | |
| 81 (setq cmd (read-key-sequence (if (stringp prompt) | |
| 82 prompt (funcall prompt)))) | |
| 83 (setq last-command-char (aref cmd (1- (length cmd))) | |
| 84 this-command (key-binding cmd) | |
| 85 cmd this-command) | |
| 86 (if (or (prog1 quit-flag (setq quit-flag nil)) | |
| 87 (= last-input-char ?\C-g)) | |
|
1609
5beb9d2bc959
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
845
diff
changeset
|
88 (progn (setq unread-command-event nil |
| 35 | 89 prefix-arg nil) |
| 90 ;; If it wasn't cancelling a prefix character, then quit. | |
| 91 (if (or (= (length (this-command-keys)) 1) | |
| 92 (not inhibit-quit)) ; safety | |
| 93 (progn (ding) | |
| 94 (message "Quit") | |
| 95 (throw return-tag nil)) | |
| 96 (setq cmd nil)))) | |
| 97 (setq current-prefix-arg prefix-arg) | |
| 98 (if cmd | |
| 99 (condition-case conditions | |
| 100 (progn (command-execute cmd) | |
|
703
e2780d9a814c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
662
diff
changeset
|
101 (setq last-command this-command) |
| 35 | 102 (if (or (prog1 quit-flag (setq quit-flag nil)) |
| 103 (= last-input-char ?\C-g)) | |
|
1609
5beb9d2bc959
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
845
diff
changeset
|
104 (progn (setq unread-command-event nil) |
| 35 | 105 (if (not inhibit-quit) |
| 106 (progn (ding) | |
| 107 (message "Quit") | |
| 108 (throw return-tag nil)) | |
| 109 (ding))))) | |
| 110 (buffer-read-only (if loop-function | |
| 111 (setq err conditions) | |
| 112 (ding) | |
| 113 (message "Buffer is read-only") | |
| 114 (sit-for 2))) | |
| 115 (beginning-of-buffer (if loop-function | |
| 116 (setq err conditions) | |
| 117 (ding) | |
| 118 (message "Beginning of Buffer") | |
| 119 (sit-for 2))) | |
| 120 (end-of-buffer (if loop-function | |
| 121 (setq err conditions) | |
| 122 (ding) | |
| 123 (message "End of Buffer") | |
| 124 (sit-for 2))) | |
| 125 (error (if loop-function | |
| 126 (setq err conditions) | |
| 127 (ding) | |
| 128 (message "Error: %s" | |
| 129 (if (eq (car conditions) 'error) | |
| 130 (car (cdr conditions)) | |
| 131 (prin1-to-string conditions))) | |
| 132 (sit-for 2)))) | |
| 133 (ding)) | |
| 134 (if loop-function (funcall loop-function loop-state err)))) | |
| 135 (ding) | |
| 136 (throw return-tag nil)) | |
| 137 | |
| 138 ;; This function is like pop-to-buffer, sort of. | |
| 139 ;; The algorithm is | |
| 140 ;; If there is a window displaying buffer | |
| 141 ;; Select it | |
| 142 ;; Else if there is only one window | |
| 143 ;; Split it, selecting the window on the bottom with height being | |
| 144 ;; the lesser of max-height (if non-nil) and the number of lines in | |
| 145 ;; the buffer to be displayed subject to window-min-height constraint. | |
| 146 ;; Else | |
| 147 ;; Switch to buffer in the current window. | |
| 148 ;; | |
| 149 ;; Then if max-height is nil, and not all of the lines in the buffer | |
| 778 | 150 ;; are displayed, grab the whole frame. |
| 35 | 151 ;; |
| 152 ;; Returns selected window on buffer positioned at point-min. | |
| 153 | |
| 154 (defun Electric-pop-up-window (buffer &optional max-height) | |
| 155 (let* ((win (or (get-buffer-window buffer) (selected-window))) | |
| 156 (buf (get-buffer buffer)) | |
| 157 (one-window (one-window-p t)) | |
| 158 (pop-up-windows t) | |
| 159 (target-height) | |
| 160 (lines)) | |
| 161 (if (not buf) | |
| 162 (error "Buffer %s does not exist" buffer) | |
| 163 (save-excursion | |
| 164 (set-buffer buf) | |
| 165 (setq lines (count-lines (point-min) (point-max))) | |
| 166 (setq target-height | |
| 167 (min (max (if max-height (min max-height (1+ lines)) (1+ lines)) | |
| 168 window-min-height) | |
| 169 (save-window-excursion | |
| 170 (delete-other-windows) | |
| 171 (1- (window-height (selected-window))))))) | |
| 172 (cond ((and (eq (window-buffer win) buf)) | |
| 173 (select-window win)) | |
| 174 (one-window | |
| 175 (goto-char (window-start win)) | |
| 176 (pop-to-buffer buffer) | |
| 177 (setq win (selected-window)) | |
| 178 (enlarge-window (- target-height (window-height win)))) | |
| 179 (t | |
| 180 (switch-to-buffer buf))) | |
| 181 (if (and (not max-height) | |
| 182 (> target-height (window-height (selected-window)))) | |
| 183 (progn (goto-char (window-start win)) | |
| 184 (enlarge-window (- target-height (window-height win))))) | |
| 185 (goto-char (point-min)) | |
| 186 win))) | |
| 584 | 187 |
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
188 (provide 'electric) |
|
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
189 |
|
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
190 ; electric.el ends here |
