Mercurial > emacs
annotate lisp/emacs-lisp/lisp-mode.el @ 12530:c2b2449231c2
[HAVE_X11XTR6]: Include locale.h
(x_term_init) [HAVE_X11XTR6]: Set LC_NUMERIC and LC_TIME back to C.
(note_mouse_movement): Set mouse_moved in the x_display_info.
(XTmouse_position, x_scroll_bar_note_movement): Likewise.
(x_scroll_bar_report_motion): Likewise.
(x_draw_box, x_display_box_cursor, x_display_bar_cursor):
New args x, y. Don't use curs_x or curs_y here. Callers changed.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Mon, 17 Jul 1995 22:12:45 +0000 |
parents | e6b42a6ea8e6 |
children | 66b3d052d4fe |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
20674ae6bf52
*** 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:
727
diff
changeset
|
5 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: lisp, languages |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
7 |
213 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; 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:
727
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
213 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
24 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
25 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
26 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
27 ;; This mode is documented in the Emacs manual |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
28 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
29 ;;; Code: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
30 |
213 | 31 (defvar lisp-mode-syntax-table nil "") |
32 (defvar emacs-lisp-mode-syntax-table nil "") | |
33 (defvar lisp-mode-abbrev-table nil "") | |
34 | |
35 (if (not emacs-lisp-mode-syntax-table) | |
36 (let ((i 0)) | |
37 (setq emacs-lisp-mode-syntax-table (make-syntax-table)) | |
38 (while (< i ?0) | |
39 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
40 (setq i (1+ i))) | |
41 (setq i (1+ ?9)) | |
42 (while (< i ?A) | |
43 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
44 (setq i (1+ i))) | |
45 (setq i (1+ ?Z)) | |
46 (while (< i ?a) | |
47 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
48 (setq i (1+ i))) | |
49 (setq i (1+ ?z)) | |
50 (while (< i 128) | |
51 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
52 (setq i (1+ i))) | |
53 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) | |
54 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) | |
55 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table) | |
8325
2c8b3c988b10
(emacs-lisp-mode-syntax-table): Give RET the same syntax as newline.
Richard M. Stallman <rms@gnu.org>
parents:
7301
diff
changeset
|
56 ;; Give CR the same syntax as newline, for selective-display. |
2c8b3c988b10
(emacs-lisp-mode-syntax-table): Give RET the same syntax as newline.
Richard M. Stallman <rms@gnu.org>
parents:
7301
diff
changeset
|
57 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table) |
213 | 58 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table) |
59 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table) | |
60 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table) | |
61 (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table) | |
62 ;; Used to be singlequote; changed for flonums. | |
63 (modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table) | |
64 (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table) | |
65 (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table) | |
66 (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table) | |
67 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table) | |
68 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table) | |
69 (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table) | |
70 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table))) | |
71 | |
285 | 72 (if (not lisp-mode-syntax-table) |
73 (progn (setq lisp-mode-syntax-table | |
74 (copy-syntax-table emacs-lisp-mode-syntax-table)) | |
75 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table) | |
76 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table) | |
77 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table))) | |
78 | |
213 | 79 (define-abbrev-table 'lisp-mode-abbrev-table ()) |
80 | |
81 (defun lisp-mode-variables (lisp-syntax) | |
82 (cond (lisp-syntax | |
83 (set-syntax-table lisp-mode-syntax-table))) | |
84 (setq local-abbrev-table lisp-mode-abbrev-table) | |
85 (make-local-variable 'paragraph-start) | |
86 (setq paragraph-start (concat "^$\\|" page-delimiter)) | |
87 (make-local-variable 'paragraph-separate) | |
88 (setq paragraph-separate paragraph-start) | |
89 (make-local-variable 'paragraph-ignore-fill-prefix) | |
90 (setq paragraph-ignore-fill-prefix t) | |
10628
04591bafb562
(shared-lisp-mode-map): Don't bind M-q.
Richard M. Stallman <rms@gnu.org>
parents:
10594
diff
changeset
|
91 (make-local-variable 'fill-paragraph-function) |
04591bafb562
(shared-lisp-mode-map): Don't bind M-q.
Richard M. Stallman <rms@gnu.org>
parents:
10594
diff
changeset
|
92 (setq fill-paragraph-function 'lisp-fill-paragraph) |
213 | 93 (make-local-variable 'indent-line-function) |
94 (setq indent-line-function 'lisp-indent-line) | |
95 (make-local-variable 'indent-region-function) | |
96 (setq indent-region-function 'lisp-indent-region) | |
97 (make-local-variable 'parse-sexp-ignore-comments) | |
98 (setq parse-sexp-ignore-comments t) | |
6076
4f76564fc2cd
(lisp-mode-variables): Set outline-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
5103
diff
changeset
|
99 (make-local-variable 'outline-regexp) |
7301
edad1db699ab
(lisp-mode-variables): Added missing backslash to outline-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
7170
diff
changeset
|
100 (setq outline-regexp ";;; \\|(....") |
213 | 101 (make-local-variable 'comment-start) |
102 (setq comment-start ";") | |
103 (make-local-variable 'comment-start-skip) | |
7170
3b452d97f111
(lisp-mode-variables): Undo previous change.
Karl Heuer <kwzh@gnu.org>
parents:
7079
diff
changeset
|
104 (setq comment-start-skip ";+ *") |
213 | 105 (make-local-variable 'comment-column) |
106 (setq comment-column 40) | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
107 (make-local-variable 'comment-indent-function) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
108 (setq comment-indent-function 'lisp-comment-indent)) |
213 | 109 |
110 (defvar shared-lisp-mode-map () | |
111 "Keymap for commands shared by all sorts of Lisp modes.") | |
112 | |
113 (if shared-lisp-mode-map | |
114 () | |
115 (setq shared-lisp-mode-map (make-sparse-keymap)) | |
116 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) | |
117 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify) | |
118 (define-key shared-lisp-mode-map "\t" 'lisp-indent-line)) | |
119 | |
120 (defvar emacs-lisp-mode-map () | |
121 "Keymap for Emacs Lisp mode. | |
122 All commands in shared-lisp-mode-map are inherited by this map.") | |
123 | |
124 (if emacs-lisp-mode-map | |
125 () | |
12035
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
126 (let ((map (make-sparse-keymap "Emacs-Lisp"))) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
127 (setq emacs-lisp-mode-map |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
128 (nconc (make-sparse-keymap) shared-lisp-mode-map)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
129 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
130 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
131 (define-key emacs-lisp-mode-map [menu-bar] (make-sparse-keymap)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
132 (define-key emacs-lisp-mode-map [menu-bar emacs-lisp] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
133 (cons "Emacs-Lisp" map)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
134 (define-key map [edebug-defun] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
135 '("Instrument Function for Debugging" . edebug-defun)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
136 (define-key map [byte-recompile] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
137 '("Byte-recompile Directory..." . byte-recompile-directory)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
138 (define-key map [byte-compile] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
139 '("Byte-compile This File" . emacs-lisp-byte-compile)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
140 (define-key map [separator-eval] '("--")) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
141 (define-key map [eval-buffer] '("Evaluate Buffer" . eval-current-buffer)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
142 (define-key map [eval-region] '("Evaluate Region" . eval-region)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
143 (define-key map [eval-sexp] '("Evaluate Last S-expression" . eval-last-sexp)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
144 (define-key map [separator-format] '("--")) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
145 (define-key map [comment-region] '("Comment Out Region" . comment-region)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
146 (define-key map [indent-region] '("Indent Region" . indent-region)) |
12218
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
147 (define-key map [indent-line] '("Indent Line" . lisp-indent-line)) |
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
148 (put 'eval-region 'menu-enable 'mark-active) |
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
149 (put 'comment-region 'menu-enable 'mark-active) |
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
150 (put 'indent-region 'menu-enable 'mark-active))) |
12035
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
151 |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
152 (defun emacs-lisp-byte-compile () |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
153 "Byte compile the file containing the current buffer." |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
154 (interactive) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
155 (if buffer-file-name |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
156 (byte-compile-file buffer-file-name) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
157 (error "The buffer must be saved in a file first."))) |
213 | 158 |
159 (defun emacs-lisp-mode () | |
160 "Major mode for editing Lisp code to run in Emacs. | |
161 Commands: | |
162 Delete converts tabs to spaces as it moves back. | |
163 Blank lines separate paragraphs. Semicolons start comments. | |
164 \\{emacs-lisp-mode-map} | |
165 Entry to this mode calls the value of `emacs-lisp-mode-hook' | |
166 if that value is non-nil." | |
167 (interactive) | |
168 (kill-all-local-variables) | |
169 (use-local-map emacs-lisp-mode-map) | |
170 (set-syntax-table emacs-lisp-mode-syntax-table) | |
171 (setq major-mode 'emacs-lisp-mode) | |
172 (setq mode-name "Emacs-Lisp") | |
173 (lisp-mode-variables nil) | |
174 (run-hooks 'emacs-lisp-mode-hook)) | |
175 | |
176 (defvar lisp-mode-map () | |
177 "Keymap for ordinary Lisp mode. | |
178 All commands in `shared-lisp-mode-map' are inherited by this map.") | |
179 | |
180 (if lisp-mode-map | |
181 () | |
182 (setq lisp-mode-map | |
183 (nconc (make-sparse-keymap) shared-lisp-mode-map)) | |
5103
40b068fb4c37
(lisp-eval-defun): Renamed from lisp-send-defun.
Richard M. Stallman <rms@gnu.org>
parents:
3638
diff
changeset
|
184 (define-key lisp-mode-map "\e\C-x" 'lisp-eval-defun) |
40b068fb4c37
(lisp-eval-defun): Renamed from lisp-send-defun.
Richard M. Stallman <rms@gnu.org>
parents:
3638
diff
changeset
|
185 (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)) |
213 | 186 |
187 (defun lisp-mode () | |
188 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp. | |
189 Commands: | |
190 Delete converts tabs to spaces as it moves back. | |
191 Blank lines separate paragraphs. Semicolons start comments. | |
192 \\{lisp-mode-map} | |
193 Note that `run-lisp' may be used either to start an inferior Lisp job | |
194 or to switch back to an existing one. | |
195 | |
196 Entry to this mode calls the value of `lisp-mode-hook' | |
197 if that value is non-nil." | |
198 (interactive) | |
199 (kill-all-local-variables) | |
200 (use-local-map lisp-mode-map) | |
201 (setq major-mode 'lisp-mode) | |
202 (setq mode-name "Lisp") | |
203 (lisp-mode-variables t) | |
204 (set-syntax-table lisp-mode-syntax-table) | |
205 (run-hooks 'lisp-mode-hook)) | |
206 | |
207 ;; This will do unless shell.el is loaded. | |
5103
40b068fb4c37
(lisp-eval-defun): Renamed from lisp-send-defun.
Richard M. Stallman <rms@gnu.org>
parents:
3638
diff
changeset
|
208 (defun lisp-eval-defun nil |
213 | 209 "Send the current defun to the Lisp process made by \\[run-lisp]." |
210 (interactive) | |
211 (error "Process lisp does not exist")) | |
212 | |
213 (defvar lisp-interaction-mode-map () | |
214 "Keymap for Lisp Interaction moe. | |
215 All commands in `shared-lisp-mode-map' are inherited by this map.") | |
216 | |
217 (if lisp-interaction-mode-map | |
218 () | |
219 (setq lisp-interaction-mode-map | |
220 (nconc (make-sparse-keymap) shared-lisp-mode-map)) | |
221 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun) | |
878
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
222 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol) |
213 | 223 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp)) |
224 | |
225 (defun lisp-interaction-mode () | |
226 "Major mode for typing and evaluating Lisp forms. | |
227 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression | |
228 before point, and prints its value into the buffer, advancing point. | |
229 | |
230 Commands: | |
231 Delete converts tabs to spaces as it moves back. | |
232 Paragraphs are separated only by blank lines. | |
233 Semicolons start comments. | |
234 \\{lisp-interaction-mode-map} | |
235 Entry to this mode calls the value of `lisp-interaction-mode-hook' | |
236 if that value is non-nil." | |
237 (interactive) | |
238 (kill-all-local-variables) | |
239 (use-local-map lisp-interaction-mode-map) | |
240 (setq major-mode 'lisp-interaction-mode) | |
241 (setq mode-name "Lisp Interaction") | |
242 (set-syntax-table emacs-lisp-mode-syntax-table) | |
243 (lisp-mode-variables nil) | |
244 (run-hooks 'lisp-interaction-mode-hook)) | |
245 | |
248 | 246 (defun eval-print-last-sexp () |
213 | 247 "Evaluate sexp before point; print value into current buffer." |
248 | 248 (interactive) |
422 | 249 (let ((standard-output (current-buffer))) |
250 (terpri) | |
251 (eval-last-sexp t) | |
252 (terpri))) | |
213 | 253 |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
254 (defun eval-last-sexp (eval-last-sexp-arg-internal) |
213 | 255 "Evaluate sexp before point; print value in minibuffer. |
256 With argument, print output into current buffer." | |
257 (interactive "P") | |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
258 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)) |
1163 | 259 (opoint (point))) |
249 | 260 (prin1 (let ((stab (syntax-table))) |
261 (eval (unwind-protect | |
262 (save-excursion | |
263 (set-syntax-table emacs-lisp-mode-syntax-table) | |
264 (forward-sexp -1) | |
1163 | 265 (save-restriction |
266 (narrow-to-region (point-min) opoint) | |
267 (read (current-buffer)))) | |
249 | 268 (set-syntax-table stab))))))) |
213 | 269 |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
270 (defun eval-defun (eval-defun-arg-internal) |
248 | 271 "Evaluate defun that point is in or before. |
272 Print value in minibuffer. | |
273 With argument, insert value in current buffer after the defun." | |
213 | 274 (interactive "P") |
10968
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
275 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
276 (form (save-excursion |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
277 (end-of-defun) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
278 (beginning-of-defun) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
279 (read (current-buffer))))) |
12352
e6b42a6ea8e6
(eval-defun): Don't change defvar to defconst
Richard M. Stallman <rms@gnu.org>
parents:
12218
diff
changeset
|
280 (if (and (eq (car form) 'defvar) |
e6b42a6ea8e6
(eval-defun): Don't change defvar to defconst
Richard M. Stallman <rms@gnu.org>
parents:
12218
diff
changeset
|
281 (cdr-safe (cdr-safe form))) |
10968
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
282 (setq form (cons 'defconst (cdr form)))) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
283 (prin1 (eval form)))) |
213 | 284 |
285 (defun lisp-comment-indent () | |
286 (if (looking-at "\\s<\\s<\\s<") | |
287 (current-column) | |
288 (if (looking-at "\\s<\\s<") | |
289 (let ((tem (calculate-lisp-indent))) | |
290 (if (listp tem) (car tem) tem)) | |
291 (skip-chars-backward " \t") | |
292 (max (if (bolp) 0 (1+ (current-column))) | |
293 comment-column)))) | |
294 | |
295 (defconst lisp-indent-offset nil "") | |
296 (defconst lisp-indent-function 'lisp-indent-function "") | |
297 | |
298 (defun lisp-indent-line (&optional whole-exp) | |
299 "Indent current line as Lisp code. | |
300 With argument, indent any additional lines of the same expression | |
301 rigidly along with this one." | |
302 (interactive "P") | |
303 (let ((indent (calculate-lisp-indent)) shift-amt beg end | |
304 (pos (- (point-max) (point)))) | |
305 (beginning-of-line) | |
306 (setq beg (point)) | |
307 (skip-chars-forward " \t") | |
308 (if (looking-at "\\s<\\s<\\s<") | |
309 ;; Don't alter indentation of a ;;; comment line. | |
677
7a9b4ea68565
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
659
diff
changeset
|
310 (goto-char (- (point-max) pos)) |
213 | 311 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<"))) |
312 ;; Single-semicolon comment lines should be indented | |
313 ;; as comment lines, not as code. | |
314 (progn (indent-for-comment) (forward-char -1)) | |
315 (if (listp indent) (setq indent (car indent))) | |
316 (setq shift-amt (- indent (current-column))) | |
317 (if (zerop shift-amt) | |
318 nil | |
319 (delete-region beg (point)) | |
320 (indent-to indent))) | |
321 ;; If initial point was within line's indentation, | |
322 ;; position after the indentation. Else stay at same point in text. | |
323 (if (> (- (point-max) pos) (point)) | |
324 (goto-char (- (point-max) pos))) | |
325 ;; If desired, shift remaining lines of expression the same amount. | |
326 (and whole-exp (not (zerop shift-amt)) | |
327 (save-excursion | |
328 (goto-char beg) | |
329 (forward-sexp 1) | |
330 (setq end (point)) | |
331 (goto-char beg) | |
332 (forward-line 1) | |
333 (setq beg (point)) | |
334 (> end beg)) | |
335 (indent-code-rigidly beg end shift-amt))))) | |
336 | |
9424
738999b0296f
Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
9423
diff
changeset
|
337 (defvar calculate-lisp-indent-last-sexp) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
338 |
213 | 339 (defun calculate-lisp-indent (&optional parse-start) |
340 "Return appropriate indentation for current line as Lisp code. | |
341 In usual case returns an integer: the column to indent to. | |
342 Can instead return a list, whose car is the column to indent to. | |
343 This means that following lines at the same level of indentation | |
344 should not necessarily be indented the same way. | |
345 The second element of the list is the buffer position | |
346 of the start of the containing expression." | |
347 (save-excursion | |
348 (beginning-of-line) | |
349 (let ((indent-point (point)) | |
350 state paren-depth | |
351 ;; setting this to a number inhibits calling hook | |
352 (desired-indent nil) | |
353 (retry t) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
354 calculate-lisp-indent-last-sexp containing-sexp) |
213 | 355 (if parse-start |
356 (goto-char parse-start) | |
357 (beginning-of-defun)) | |
358 ;; Find outermost containing sexp | |
359 (while (< (point) indent-point) | |
360 (setq state (parse-partial-sexp (point) indent-point 0))) | |
361 ;; Find innermost containing sexp | |
362 (while (and retry | |
363 state | |
364 (> (setq paren-depth (elt state 0)) 0)) | |
365 (setq retry nil) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
366 (setq calculate-lisp-indent-last-sexp (elt state 2)) |
213 | 367 (setq containing-sexp (elt state 1)) |
368 ;; Position following last unclosed open. | |
369 (goto-char (1+ containing-sexp)) | |
370 ;; Is there a complete sexp since then? | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
371 (if (and calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
372 (> calculate-lisp-indent-last-sexp (point))) |
213 | 373 ;; Yes, but is there a containing sexp after that? |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
374 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
375 indent-point 0))) |
213 | 376 (if (setq retry (car (cdr peek))) (setq state peek))))) |
377 (if retry | |
378 nil | |
379 ;; Innermost containing sexp found | |
380 (goto-char (1+ containing-sexp)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
381 (if (not calculate-lisp-indent-last-sexp) |
213 | 382 ;; indent-point immediately follows open paren. |
383 ;; Don't call hook. | |
384 (setq desired-indent (current-column)) | |
385 ;; Find the start of first element of containing sexp. | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
386 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
213 | 387 (cond ((looking-at "\\s(") |
388 ;; First element of containing sexp is a list. | |
389 ;; Indent under that list. | |
390 ) | |
391 ((> (save-excursion (forward-line 1) (point)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
392 calculate-lisp-indent-last-sexp) |
213 | 393 ;; This is the first line to start within the containing sexp. |
394 ;; It's almost certainly a function call. | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
395 (if (= (point) calculate-lisp-indent-last-sexp) |
213 | 396 ;; Containing sexp has nothing before this line |
397 ;; except the first element. Indent under that element. | |
398 nil | |
399 ;; Skip the first element, find start of second (the first | |
400 ;; argument of the function call) and indent under. | |
401 (progn (forward-sexp 1) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
402 (parse-partial-sexp (point) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
403 calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
404 0 t))) |
213 | 405 (backward-prefix-chars)) |
406 (t | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
407 ;; Indent beneath first sexp on same line as |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
408 ;; calculate-lisp-indent-last-sexp. Again, it's |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
409 ;; almost certainly a function call. |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
410 (goto-char calculate-lisp-indent-last-sexp) |
213 | 411 (beginning-of-line) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
412 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
413 0 t) |
213 | 414 (backward-prefix-chars))))) |
415 ;; Point is at the point to indent under unless we are inside a string. | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3241
diff
changeset
|
416 ;; Call indentation hook except when overridden by lisp-indent-offset |
213 | 417 ;; or if the desired indentation has already been computed. |
418 (let ((normal-indent (current-column))) | |
419 (cond ((elt state 3) | |
420 ;; Inside a string, don't change indentation. | |
421 (goto-char indent-point) | |
422 (skip-chars-forward " \t") | |
423 (current-column)) | |
424 ((and (integerp lisp-indent-offset) containing-sexp) | |
425 ;; Indent by constant offset | |
426 (goto-char containing-sexp) | |
427 (+ (current-column) lisp-indent-offset)) | |
428 (desired-indent) | |
429 ((and (boundp 'lisp-indent-function) | |
430 lisp-indent-function | |
431 (not retry)) | |
432 (or (funcall lisp-indent-function indent-point state) | |
433 normal-indent)) | |
434 (t | |
214 | 435 normal-indent)))))) |
213 | 436 |
437 (defun lisp-indent-function (indent-point state) | |
438 (let ((normal-indent (current-column))) | |
439 (goto-char (1+ (elt state 1))) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
440 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
213 | 441 (if (and (elt state 2) |
442 (not (looking-at "\\sw\\|\\s_"))) | |
443 ;; car of form doesn't seem to be a a symbol | |
444 (progn | |
445 (if (not (> (save-excursion (forward-line 1) (point)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
446 calculate-lisp-indent-last-sexp)) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
447 (progn (goto-char calculate-lisp-indent-last-sexp) |
213 | 448 (beginning-of-line) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
449 (parse-partial-sexp (point) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
450 calculate-lisp-indent-last-sexp 0 t))) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
451 ;; Indent under the list or under the first sexp on the same |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
452 ;; line as calculate-lisp-indent-last-sexp. Note that first |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
453 ;; thing on that line has to be complete sexp since we are |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
454 ;; inside the innermost containing sexp. |
213 | 455 (backward-prefix-chars) |
456 (current-column)) | |
457 (let ((function (buffer-substring (point) | |
458 (progn (forward-sexp 1) (point)))) | |
459 method) | |
3638
45169f86d3a4
(lisp-indent-function): Look for either
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
460 (setq method (or (get (intern-soft function) 'lisp-indent-function) |
45169f86d3a4
(lisp-indent-function): Look for either
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
461 (get (intern-soft function) 'lisp-indent-hook))) |
213 | 462 (cond ((or (eq method 'defun) |
463 (and (null method) | |
464 (> (length function) 3) | |
465 (string-match "\\`def" function))) | |
466 (lisp-indent-defform state indent-point)) | |
467 ((integerp method) | |
468 (lisp-indent-specform method state | |
469 indent-point normal-indent)) | |
470 (method | |
471 (funcall method state indent-point))))))) | |
472 | |
2933
420dfaaacfc5
(lisp-body-indent): Add doc.
Richard M. Stallman <rms@gnu.org>
parents:
2450
diff
changeset
|
473 (defconst lisp-body-indent 2 |
420dfaaacfc5
(lisp-body-indent): Add doc.
Richard M. Stallman <rms@gnu.org>
parents:
2450
diff
changeset
|
474 "Number of columns to indent the second line of a `(def...)' form.") |
213 | 475 |
476 (defun lisp-indent-specform (count state indent-point normal-indent) | |
477 (let ((containing-form-start (elt state 1)) | |
478 (i count) | |
479 body-indent containing-form-column) | |
480 ;; Move to the start of containing form, calculate indentation | |
481 ;; to use for non-distinguished forms (> count), and move past the | |
482 ;; function symbol. lisp-indent-function guarantees that there is at | |
483 ;; least one word or symbol character following open paren of containing | |
484 ;; form. | |
485 (goto-char containing-form-start) | |
486 (setq containing-form-column (current-column)) | |
487 (setq body-indent (+ lisp-body-indent containing-form-column)) | |
488 (forward-char 1) | |
489 (forward-sexp 1) | |
490 ;; Now find the start of the last form. | |
491 (parse-partial-sexp (point) indent-point 1 t) | |
492 (while (and (< (point) indent-point) | |
493 (condition-case () | |
494 (progn | |
495 (setq count (1- count)) | |
496 (forward-sexp 1) | |
497 (parse-partial-sexp (point) indent-point 1 t)) | |
498 (error nil)))) | |
499 ;; Point is sitting on first character of last (or count) sexp. | |
500 (if (> count 0) | |
501 ;; A distinguished form. If it is the first or second form use double | |
502 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound | |
503 ;; to 2 (the default), this just happens to work the same with if as | |
504 ;; the older code, but it makes unwind-protect, condition-case, | |
505 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older, | |
506 ;; less hacked, behavior can be obtained by replacing below with | |
507 ;; (list normal-indent containing-form-start). | |
508 (if (<= (- i count) 1) | |
509 (list (+ containing-form-column (* 2 lisp-body-indent)) | |
510 containing-form-start) | |
511 (list normal-indent containing-form-start)) | |
512 ;; A non-distinguished form. Use body-indent if there are no | |
513 ;; distinguished forms and this is the first undistinguished form, | |
514 ;; or if this is the first undistinguished form and the preceding | |
515 ;; distinguished form has indentation at least as great as body-indent. | |
516 (if (or (and (= i 0) (= count 0)) | |
517 (and (= count 0) (<= body-indent normal-indent))) | |
518 body-indent | |
519 normal-indent)))) | |
520 | |
521 (defun lisp-indent-defform (state indent-point) | |
522 (goto-char (car (cdr state))) | |
523 (forward-line 1) | |
524 (if (> (point) (car (cdr (cdr state)))) | |
525 (progn | |
526 (goto-char (car (cdr state))) | |
527 (+ lisp-body-indent (current-column))))) | |
528 | |
529 | |
530 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented | |
531 ;; like defun if the first form is placed on the next line, otherwise | |
532 ;; it is indented like any other form (i.e. forms line up under first). | |
533 | |
534 (put 'lambda 'lisp-indent-function 'defun) | |
535 (put 'autoload 'lisp-indent-function 'defun) | |
536 (put 'progn 'lisp-indent-function 0) | |
537 (put 'prog1 'lisp-indent-function 1) | |
538 (put 'prog2 'lisp-indent-function 2) | |
539 (put 'save-excursion 'lisp-indent-function 0) | |
540 (put 'save-window-excursion 'lisp-indent-function 0) | |
12218
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
541 (put 'save-selected-window 'lisp-indent-function 0) |
213 | 542 (put 'save-restriction 'lisp-indent-function 0) |
1163 | 543 (put 'save-match-data 'lisp-indent-function 0) |
213 | 544 (put 'let 'lisp-indent-function 1) |
545 (put 'let* 'lisp-indent-function 1) | |
546 (put 'while 'lisp-indent-function 1) | |
547 (put 'if 'lisp-indent-function 2) | |
548 (put 'catch 'lisp-indent-function 1) | |
549 (put 'condition-case 'lisp-indent-function 2) | |
550 (put 'unwind-protect 'lisp-indent-function 1) | |
551 (put 'with-output-to-temp-buffer 'lisp-indent-function 1) | |
552 | |
553 (defun indent-sexp (&optional endpos) | |
554 "Indent each line of the list starting just after point. | |
555 If optional arg ENDPOS is given, indent each line, stopping when | |
556 ENDPOS is encountered." | |
557 (interactive) | |
727 | 558 (let ((indent-stack (list nil)) |
559 (next-depth 0) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
560 ;; If ENDPOS is non-nil, use nil as STARTING-POINT |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
561 ;; so that calculate-lisp-indent will find the beginning of |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
562 ;; the defun we are in. |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
563 ;; If ENDPOS is nil, it is safe not to scan before point |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
564 ;; since every line we indent is more deeply nested than point is. |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
565 (starting-point (if endpos nil (point))) |
727 | 566 (last-point (point)) |
567 last-depth bol outer-loop-done inner-loop-done state this-indent) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
568 (or endpos |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
569 ;; Get error now if we don't have a complete sexp after point. |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
570 (save-excursion (forward-sexp 1))) |
213 | 571 (save-excursion |
572 (setq outer-loop-done nil) | |
573 (while (if endpos (< (point) endpos) | |
574 (not outer-loop-done)) | |
575 (setq last-depth next-depth | |
576 inner-loop-done nil) | |
577 ;; Parse this line so we can learn the state | |
578 ;; to indent the next line. | |
579 ;; This inner loop goes through only once | |
580 ;; unless a line ends inside a string. | |
581 (while (and (not inner-loop-done) | |
582 (not (setq outer-loop-done (eobp)))) | |
583 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) | |
584 nil nil state)) | |
585 (setq next-depth (car state)) | |
586 ;; If the line contains a comment other than the sort | |
587 ;; that is indented like code, | |
588 ;; indent it now with indent-for-comment. | |
589 ;; Comments indented like code are right already. | |
590 ;; In any case clear the in-comment flag in the state | |
591 ;; because parse-partial-sexp never sees the newlines. | |
592 (if (car (nthcdr 4 state)) | |
593 (progn (indent-for-comment) | |
594 (end-of-line) | |
595 (setcar (nthcdr 4 state) nil))) | |
596 ;; If this line ends inside a string, | |
597 ;; go straight to next line, remaining within the inner loop, | |
598 ;; and turn off the \-flag. | |
599 (if (car (nthcdr 3 state)) | |
600 (progn | |
601 (forward-line 1) | |
602 (setcar (nthcdr 5 state) nil)) | |
603 (setq inner-loop-done t))) | |
604 (and endpos | |
727 | 605 (<= next-depth 0) |
606 (progn | |
607 (setq indent-stack (append indent-stack | |
608 (make-list (- next-depth) nil)) | |
609 last-depth (- last-depth next-depth) | |
610 next-depth 0))) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
611 (or outer-loop-done endpos |
213 | 612 (setq outer-loop-done (<= next-depth 0))) |
613 (if outer-loop-done | |
3241
6c9b5f6dca70
(indent-sexp): Even if outer-loop-done is t, still move down one line.
Richard M. Stallman <rms@gnu.org>
parents:
2933
diff
changeset
|
614 (forward-line 1) |
213 | 615 (while (> last-depth next-depth) |
616 (setq indent-stack (cdr indent-stack) | |
617 last-depth (1- last-depth))) | |
618 (while (< last-depth next-depth) | |
619 (setq indent-stack (cons nil indent-stack) | |
620 last-depth (1+ last-depth))) | |
621 ;; Now go to the next line and indent it according | |
622 ;; to what we learned from parsing the previous one. | |
623 (forward-line 1) | |
624 (setq bol (point)) | |
625 (skip-chars-forward " \t") | |
626 ;; But not if the line is blank, or just a comment | |
627 ;; (except for double-semi comments; indent them as usual). | |
628 (if (or (eobp) (looking-at "\\s<\\|\n")) | |
629 nil | |
630 (if (and (car indent-stack) | |
631 (>= (car indent-stack) 0)) | |
632 (setq this-indent (car indent-stack)) | |
633 (let ((val (calculate-lisp-indent | |
634 (if (car indent-stack) (- (car indent-stack)) | |
727 | 635 starting-point)))) |
213 | 636 (if (integerp val) |
637 (setcar indent-stack | |
638 (setq this-indent val)) | |
639 (setcar indent-stack (- (car (cdr val)))) | |
640 (setq this-indent (car val))))) | |
641 (if (/= (current-column) this-indent) | |
642 (progn (delete-region bol (point)) | |
643 (indent-to this-indent))))) | |
644 (or outer-loop-done | |
645 (setq outer-loop-done (= (point) last-point)) | |
646 (setq last-point (point))))))) | |
647 | |
648 ;; Indent every line whose first char is between START and END inclusive. | |
649 (defun lisp-indent-region (start end) | |
650 (save-excursion | |
651 (let ((endmark (copy-marker end))) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
652 (goto-char start) |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
653 (and (bolp) (not (eolp)) |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
654 (lisp-indent-line)) |
213 | 655 (indent-sexp endmark) |
656 (set-marker endmark nil)))) | |
657 | |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
658 ;;;; Lisp paragraph filling commands. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
659 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
660 (defun lisp-fill-paragraph (&optional justify) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
661 "Like \\[fill-paragraph], but handle Emacs Lisp comments. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
662 If any of the current line is a comment, fill the comment or the |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
663 paragraph of it that point is in, preserving the comment's indentation |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
664 and initial semicolons." |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
665 (interactive "P") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
666 (let ( |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
667 ;; Non-nil if the current line contains a comment. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
668 has-comment |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
669 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
670 ;; If has-comment, the appropriate fill-prefix for the comment. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
671 comment-fill-prefix |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
672 ) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
673 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
674 ;; Figure out what kind of comment we are looking at. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
675 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
676 (beginning-of-line) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
677 (cond |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
678 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
679 ;; A line with nothing but a comment on it? |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
680 ((looking-at "[ \t]*;[; \t]*") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
681 (setq has-comment t |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
682 comment-fill-prefix (buffer-substring (match-beginning 0) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
683 (match-end 0)))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
684 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
685 ;; A line with some code, followed by a comment? Remember that the |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
686 ;; semi which starts the comment shouldn't be part of a string or |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
687 ;; character. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
688 ((progn |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
689 (while (not (looking-at ";\\|$")) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
690 (skip-chars-forward "^;\n\"\\\\?") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
691 (cond |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
692 ((eq (char-after (point)) ?\\) (forward-char 2)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
693 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1)))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
694 (looking-at ";+[\t ]*")) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
695 (setq has-comment t) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
696 (setq comment-fill-prefix |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
697 (concat (make-string (current-column) ? ) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
698 (buffer-substring (match-beginning 0) (match-end 0))))))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
699 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
700 (if (not has-comment) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
701 (fill-paragraph justify) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
702 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
703 ;; Narrow to include only the comment, and then fill the region. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
704 (save-restriction |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
705 (narrow-to-region |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
706 ;; Find the first line we should include in the region to fill. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
707 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
708 (while (and (zerop (forward-line -1)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
709 (looking-at "^[ \t]*;"))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
710 ;; We may have gone to far. Go forward again. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
711 (or (looking-at "^[ \t]*;") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
712 (forward-line 1)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
713 (point)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
714 ;; Find the beginning of the first line past the region to fill. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
715 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
716 (while (progn (forward-line 1) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
717 (looking-at "^[ \t]*;"))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
718 (point))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
719 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
720 ;; Lines with only semicolons on them can be paragraph boundaries. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
721 (let ((paragraph-start (concat paragraph-start "\\|^[ \t;]*$")) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
722 (paragraph-separate (concat paragraph-start "\\|^[ \t;]*$")) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
723 (fill-prefix comment-fill-prefix)) |
10629
2c9bdcab7052
(lisp-fill-paragraph): Return t.
Richard M. Stallman <rms@gnu.org>
parents:
10628
diff
changeset
|
724 (fill-paragraph justify)))) |
2c9bdcab7052
(lisp-fill-paragraph): Return t.
Richard M. Stallman <rms@gnu.org>
parents:
10628
diff
changeset
|
725 t)) |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
726 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
727 |
213 | 728 (defun indent-code-rigidly (start end arg &optional nochange-regexp) |
729 "Indent all lines of code, starting in the region, sideways by ARG columns. | |
730 Does not affect lines starting inside comments or strings, assuming that | |
731 the start of the region is not inside them. | |
732 | |
733 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP. | |
734 The last is a regexp which, if matched at the beginning of a line, | |
735 means don't indent that line." | |
736 (interactive "r\np") | |
737 (let (state) | |
738 (save-excursion | |
739 (goto-char end) | |
740 (setq end (point-marker)) | |
741 (goto-char start) | |
742 (or (bolp) | |
743 (setq state (parse-partial-sexp (point) | |
744 (progn | |
745 (forward-line 1) (point)) | |
746 nil nil state))) | |
747 (while (< (point) end) | |
748 (or (car (nthcdr 3 state)) | |
749 (and nochange-regexp | |
750 (looking-at nochange-regexp)) | |
751 ;; If line does not start in string, indent it | |
752 (let ((indent (current-indentation))) | |
753 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
754 (or (eolp) | |
755 (indent-to (max 0 (+ indent arg)) 0)))) | |
756 (setq state (parse-partial-sexp (point) | |
757 (progn | |
758 (forward-line 1) (point)) | |
759 nil nil state)))))) | |
584 | 760 |
761 (provide 'lisp-mode) | |
762 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
763 ;;; lisp-mode.el ends here |