Mercurial > emacs
annotate lisp/indent.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 | 213978acbc1e |
| children | 96adb71c61ec |
| rev | line source |
|---|---|
|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
1 ;;; indent.el --- indentation commands for Emacs |
|
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
2 |
| 845 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
| 4 | |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
5 ;; Maintainer: FSF |
| 263 | 6 |
| 7 ;; This file is part of GNU Emacs. | |
| 8 | |
| 9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 10 ;; 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:
732
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
| 263 | 12 ;; any later version. |
| 13 | |
| 14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 ;; GNU General Public License for more details. | |
| 18 | |
| 19 ;; You should have received a copy of the GNU General Public License | |
| 20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 22 | |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
23 ;;; Code: |
| 263 | 24 |
| 269 | 25 (defvar indent-line-function 'indent-to-left-margin "\ |
| 26 Function to indent current line.");Now in loaddefs.el | |
| 263 | 27 |
| 28 (defun indent-according-to-mode () | |
| 29 "Indent line in proper way for current major mode." | |
| 30 (interactive) | |
| 31 (funcall indent-line-function)) | |
| 32 | |
| 33 (defun indent-for-tab-command () | |
| 34 "Indent line in proper way for current major mode." | |
| 35 (interactive) | |
| 36 (if (eq indent-line-function 'indent-to-left-margin) | |
| 37 (insert-tab) | |
| 38 (funcall indent-line-function))) | |
| 39 | |
| 40 (defun insert-tab () | |
| 41 (if abbrev-mode | |
| 42 (expand-abbrev)) | |
| 43 (if indent-tabs-mode | |
| 44 (insert ?\t) | |
| 45 (indent-to (* tab-width (1+ (/ (current-column) tab-width)))))) | |
| 46 | |
| 47 (defun indent-rigidly (start end arg) | |
| 48 "Indent all lines starting in the region sideways by ARG columns. | |
| 49 Called from a program, takes three arguments, START, END and ARG." | |
| 50 (interactive "r\np") | |
| 51 (save-excursion | |
| 52 (goto-char end) | |
| 53 (setq end (point-marker)) | |
| 54 (goto-char start) | |
| 55 (or (bolp) (forward-line 1)) | |
| 56 (while (< (point) end) | |
| 57 (let ((indent (current-indentation))) | |
| 58 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
| 59 (or (eolp) | |
| 60 (indent-to (max 0 (+ indent arg)) 0))) | |
| 61 (forward-line 1)) | |
| 62 (move-marker end nil))) | |
| 63 | |
| 64 ;; This is the default indent-line-function, | |
| 65 ;; used in Fundamental Mode, Text Mode, etc. | |
| 66 (defun indent-to-left-margin () | |
| 67 (or (= (current-indentation) left-margin) | |
| 68 (let (epos) | |
| 69 (save-excursion | |
| 70 (beginning-of-line) | |
| 71 (delete-region (point) | |
| 72 (progn (skip-chars-forward " \t") | |
| 73 (point))) | |
| 74 (indent-to left-margin) | |
| 75 (setq epos (point))) | |
| 76 (if (< (point) epos) | |
| 77 (goto-char epos))))) | |
| 78 | |
| 79 (defvar indent-region-function nil | |
| 80 "Function which is short cut to indent each line in region with TAB. | |
| 81 A value of nil means really perform TAB on each line.") | |
| 82 | |
| 83 (defun indent-region (start end arg) | |
| 84 "Indent each nonblank line in the region. | |
| 85 With no argument, indent each line with TAB. | |
| 86 \(If there is a fill prefix, make each line start with the fill prefix.) | |
| 87 With argument COLUMN, indent each line to that column. | |
| 88 Called from a program, takes three args: START, END and COLUMN." | |
| 89 (interactive "r\nP") | |
| 90 (if (null arg) | |
| 91 (if fill-prefix | |
| 92 (save-excursion | |
| 93 (goto-char end) | |
| 94 (setq end (point-marker)) | |
| 95 (goto-char start) | |
| 96 (let ((regexp (regexp-quote fill-prefix))) | |
| 97 (while (< (point) end) | |
| 98 (or (looking-at regexp) | |
| 99 (insert fill-prefix)) | |
| 100 (forward-line 1)))) | |
| 101 (if indent-region-function | |
| 102 (funcall indent-region-function start end) | |
| 103 (save-excursion | |
| 104 (goto-char end) | |
| 105 (setq end (point-marker)) | |
| 106 (goto-char start) | |
| 107 (or (bolp) (forward-line 1)) | |
| 108 (while (< (point) end) | |
| 109 (funcall indent-line-function) | |
| 110 (forward-line 1)) | |
| 111 (move-marker end nil)))) | |
| 112 (setq arg (prefix-numeric-value arg)) | |
| 113 (save-excursion | |
| 114 (goto-char end) | |
| 115 (setq end (point-marker)) | |
| 116 (goto-char start) | |
| 117 (or (bolp) (forward-line 1)) | |
| 118 (while (< (point) end) | |
| 119 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
| 120 (or (eolp) | |
| 121 (indent-to arg 0)) | |
| 122 (forward-line 1)) | |
| 123 (move-marker end nil)))) | |
| 124 | |
| 125 (defun indent-relative-maybe () | |
| 126 "Indent a new line like previous nonblank line." | |
| 127 (interactive) | |
| 128 (indent-relative t)) | |
| 129 | |
| 130 (defun indent-relative (&optional unindented-ok) | |
| 131 "Space out to under next indent point in previous nonblank line. | |
| 132 An indent point is a non-whitespace character following whitespace. | |
| 133 If the previous nonblank line has no indent points beyond the | |
| 134 column point starts at, `tab-to-tab-stop' is done instead." | |
| 135 (interactive "P") | |
| 136 (if abbrev-mode (expand-abbrev)) | |
| 137 (let ((start-column (current-column)) | |
| 138 indent) | |
| 139 (save-excursion | |
| 140 (beginning-of-line) | |
| 141 (if (re-search-backward "^[^\n]" nil t) | |
| 142 (let ((end (save-excursion (forward-line 1) (point)))) | |
| 143 (move-to-column start-column) | |
| 144 ;; Is start-column inside a tab on this line? | |
| 145 (if (> (current-column) start-column) | |
| 146 (backward-char 1)) | |
| 147 (or (looking-at "[ \t]") | |
| 148 unindented-ok | |
| 149 (skip-chars-forward "^ \t" end)) | |
| 150 (skip-chars-forward " \t" end) | |
| 151 (or (= (point) end) (setq indent (current-column)))))) | |
| 152 (if indent | |
| 153 (let ((opoint (point-marker))) | |
| 154 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | |
| 155 (indent-to indent 0) | |
| 156 (if (> opoint (point)) | |
| 157 (goto-char opoint)) | |
| 158 (move-marker opoint nil)) | |
| 159 (tab-to-tab-stop)))) | |
| 160 | |
| 161 (defvar tab-stop-list | |
| 162 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120) | |
| 163 "*List of tab stop positions used by `tab-to-tab-stops'.") | |
| 164 | |
| 165 (defvar edit-tab-stops-map nil "Keymap used in `edit-tab-stops'.") | |
| 166 (if edit-tab-stops-map | |
| 167 nil | |
| 168 (setq edit-tab-stops-map (make-sparse-keymap)) | |
| 169 (define-key edit-tab-stops-map "\C-x\C-s" 'edit-tab-stops-note-changes) | |
| 170 (define-key edit-tab-stops-map "\C-c\C-c" 'edit-tab-stops-note-changes)) | |
| 171 | |
| 172 (defvar edit-tab-stops-buffer nil | |
| 173 "Buffer whose tab stops are being edited--in case | |
| 174 the variable `tab-stop-list' is local in that buffer.") | |
| 175 | |
| 176 (defun edit-tab-stops () | |
| 177 "Edit the tab stops used by `tab-to-tab-stop'. | |
| 178 Creates a buffer *Tab Stops* containing text describing the tab stops. | |
| 179 A colon indicates a column where there is a tab stop. | |
| 180 You can add or remove colons and then do \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes] to make changes take effect." | |
| 181 (interactive) | |
| 182 (setq edit-tab-stops-buffer (current-buffer)) | |
| 183 (switch-to-buffer (get-buffer-create "*Tab Stops*")) | |
| 184 (use-local-map edit-tab-stops-map) | |
| 185 (make-local-variable 'indent-tabs-mode) | |
| 186 (setq indent-tabs-mode nil) | |
| 187 (overwrite-mode 1) | |
| 188 (setq truncate-lines t) | |
| 189 (erase-buffer) | |
| 190 (let ((tabs tab-stop-list)) | |
| 191 (while tabs | |
| 192 (indent-to (car tabs) 0) | |
| 193 (insert ?:) | |
| 194 (setq tabs (cdr tabs)))) | |
| 195 (let ((count 0)) | |
| 196 (insert ?\n) | |
| 197 (while (< count 8) | |
| 198 (insert (+ count ?0)) | |
| 199 (insert " ") | |
| 200 (setq count (1+ count))) | |
| 201 (insert ?\n) | |
| 202 (while (> count 0) | |
| 203 (insert "0123456789") | |
| 204 (setq count (1- count)))) | |
| 205 (insert "\nTo install changes, type C-c C-c") | |
| 206 (goto-char (point-min))) | |
| 207 | |
| 208 (defun edit-tab-stops-note-changes () | |
| 209 "Put edited tab stops into effect." | |
| 210 (interactive) | |
| 211 (let (tabs) | |
| 212 (save-excursion | |
| 213 (goto-char 1) | |
| 214 (end-of-line) | |
| 215 (while (search-backward ":" nil t) | |
| 216 (setq tabs (cons (current-column) tabs)))) | |
| 217 (bury-buffer (prog1 (current-buffer) | |
| 218 (switch-to-buffer edit-tab-stops-buffer))) | |
| 219 (setq tab-stop-list tabs)) | |
| 220 (message "Tab stops installed")) | |
| 221 | |
| 222 (defun tab-to-tab-stop () | |
| 223 "Insert spaces or tabs to next defined tab-stop column. | |
| 224 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
| 225 Use \\[edit-tab-stops] to edit them interactively." | |
| 226 (interactive) | |
| 227 (if abbrev-mode (expand-abbrev)) | |
| 228 (let ((tabs tab-stop-list)) | |
| 229 (while (and tabs (>= (current-column) (car tabs))) | |
| 230 (setq tabs (cdr tabs))) | |
| 231 (if tabs | |
| 232 (indent-to (car tabs)) | |
| 233 (insert ?\ )))) | |
| 234 | |
| 235 (defun move-to-tab-stop () | |
| 236 "Move point to next defined tab-stop column. | |
| 237 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
| 238 Use \\[edit-tab-stops] to edit them interactively." | |
| 239 (interactive) | |
| 240 (let ((tabs tab-stop-list)) | |
| 241 (while (and tabs (>= (current-column) (car tabs))) | |
| 242 (setq tabs (cdr tabs))) | |
| 243 (if tabs | |
| 244 (move-to-column (car tabs) t)))) | |
| 245 | |
| 246 (define-key global-map "\t" 'indent-for-tab-command) | |
| 247 (define-key esc-map "\034" 'indent-region) | |
| 248 (define-key ctl-x-map "\t" 'indent-rigidly) | |
| 249 (define-key esc-map "i" 'tab-to-tab-stop) | |
|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
250 |
|
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
251 ;;; indent.el ends here |
