Mercurial > emacs
annotate lisp/emacs-lisp/lisp-mode.el @ 12686:8a11e11d3365
(tpu-version): New version.
(tpu-help-keypad-map): New help text.
(tpu-backward-line): Only move to BOL if not already there.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 27 Jul 1995 07:37:12 +0000 |
parents | 66b3d052d4fe |
children | c50826e44362 |
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) | |
12682
66b3d052d4fe
(shared-lisp-mode-map): Don't bind TAB, just set indent-line-function.
Richard M. Stallman <rms@gnu.org>
parents:
12352
diff
changeset
|
117 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify)) |
213 | 118 |
119 (defvar emacs-lisp-mode-map () | |
120 "Keymap for Emacs Lisp mode. | |
12682
66b3d052d4fe
(shared-lisp-mode-map): Don't bind TAB, just set indent-line-function.
Richard M. Stallman <rms@gnu.org>
parents:
12352
diff
changeset
|
121 All commands in `shared-lisp-mode-map' are inherited by this map.") |
213 | 122 |
123 (if emacs-lisp-mode-map | |
124 () | |
12035
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
125 (let ((map (make-sparse-keymap "Emacs-Lisp"))) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
126 (setq emacs-lisp-mode-map |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
127 (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
|
128 (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
|
129 (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
|
130 (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
|
131 (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
|
132 (cons "Emacs-Lisp" map)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
133 (define-key map [edebug-defun] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
134 '("Instrument Function for Debugging" . edebug-defun)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
135 (define-key map [byte-recompile] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
136 '("Byte-recompile Directory..." . byte-recompile-directory)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
137 (define-key map [byte-compile] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
138 '("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
|
139 (define-key map [separator-eval] '("--")) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
140 (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
|
141 (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
|
142 (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
|
143 (define-key map [separator-format] '("--")) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
144 (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
|
145 (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
|
146 (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
|
147 (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
|
148 (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
|
149 (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
|
150 |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
151 (defun emacs-lisp-byte-compile () |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
152 "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
|
153 (interactive) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
154 (if buffer-file-name |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
155 (byte-compile-file buffer-file-name) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
156 (error "The buffer must be saved in a file first."))) |
213 | 157 |
158 (defun emacs-lisp-mode () | |
159 "Major mode for editing Lisp code to run in Emacs. | |
160 Commands: | |
161 Delete converts tabs to spaces as it moves back. | |
162 Blank lines separate paragraphs. Semicolons start comments. | |
163 \\{emacs-lisp-mode-map} | |
164 Entry to this mode calls the value of `emacs-lisp-mode-hook' | |
165 if that value is non-nil." | |
166 (interactive) | |
167 (kill-all-local-variables) | |
168 (use-local-map emacs-lisp-mode-map) | |
169 (set-syntax-table emacs-lisp-mode-syntax-table) | |
170 (setq major-mode 'emacs-lisp-mode) | |
171 (setq mode-name "Emacs-Lisp") | |
172 (lisp-mode-variables nil) | |
173 (run-hooks 'emacs-lisp-mode-hook)) | |
174 | |
175 (defvar lisp-mode-map () | |
176 "Keymap for ordinary Lisp mode. | |
177 All commands in `shared-lisp-mode-map' are inherited by this map.") | |
178 | |
179 (if lisp-mode-map | |
180 () | |
181 (setq lisp-mode-map | |
182 (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
|
183 (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
|
184 (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)) |
213 | 185 |
186 (defun lisp-mode () | |
187 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp. | |
188 Commands: | |
189 Delete converts tabs to spaces as it moves back. | |
190 Blank lines separate paragraphs. Semicolons start comments. | |
191 \\{lisp-mode-map} | |
192 Note that `run-lisp' may be used either to start an inferior Lisp job | |
193 or to switch back to an existing one. | |
194 | |
195 Entry to this mode calls the value of `lisp-mode-hook' | |
196 if that value is non-nil." | |
197 (interactive) | |
198 (kill-all-local-variables) | |
199 (use-local-map lisp-mode-map) | |
200 (setq major-mode 'lisp-mode) | |
201 (setq mode-name "Lisp") | |
202 (lisp-mode-variables t) | |
203 (set-syntax-table lisp-mode-syntax-table) | |
204 (run-hooks 'lisp-mode-hook)) | |
205 | |
206 ;; 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
|
207 (defun lisp-eval-defun nil |
213 | 208 "Send the current defun to the Lisp process made by \\[run-lisp]." |
209 (interactive) | |
210 (error "Process lisp does not exist")) | |
211 | |
212 (defvar lisp-interaction-mode-map () | |
213 "Keymap for Lisp Interaction moe. | |
214 All commands in `shared-lisp-mode-map' are inherited by this map.") | |
215 | |
216 (if lisp-interaction-mode-map | |
217 () | |
218 (setq lisp-interaction-mode-map | |
219 (nconc (make-sparse-keymap) shared-lisp-mode-map)) | |
220 (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
|
221 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol) |
213 | 222 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp)) |
223 | |
224 (defun lisp-interaction-mode () | |
225 "Major mode for typing and evaluating Lisp forms. | |
226 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression | |
227 before point, and prints its value into the buffer, advancing point. | |
228 | |
229 Commands: | |
230 Delete converts tabs to spaces as it moves back. | |
231 Paragraphs are separated only by blank lines. | |
232 Semicolons start comments. | |
233 \\{lisp-interaction-mode-map} | |
234 Entry to this mode calls the value of `lisp-interaction-mode-hook' | |
235 if that value is non-nil." | |
236 (interactive) | |
237 (kill-all-local-variables) | |
238 (use-local-map lisp-interaction-mode-map) | |
239 (setq major-mode 'lisp-interaction-mode) | |
240 (setq mode-name "Lisp Interaction") | |
241 (set-syntax-table emacs-lisp-mode-syntax-table) | |
242 (lisp-mode-variables nil) | |
243 (run-hooks 'lisp-interaction-mode-hook)) | |
244 | |
248 | 245 (defun eval-print-last-sexp () |
213 | 246 "Evaluate sexp before point; print value into current buffer." |
248 | 247 (interactive) |
422 | 248 (let ((standard-output (current-buffer))) |
249 (terpri) | |
250 (eval-last-sexp t) | |
251 (terpri))) | |
213 | 252 |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
253 (defun eval-last-sexp (eval-last-sexp-arg-internal) |
213 | 254 "Evaluate sexp before point; print value in minibuffer. |
255 With argument, print output into current buffer." | |
256 (interactive "P") | |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
257 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)) |
1163 | 258 (opoint (point))) |
249 | 259 (prin1 (let ((stab (syntax-table))) |
260 (eval (unwind-protect | |
261 (save-excursion | |
262 (set-syntax-table emacs-lisp-mode-syntax-table) | |
263 (forward-sexp -1) | |
1163 | 264 (save-restriction |
265 (narrow-to-region (point-min) opoint) | |
266 (read (current-buffer)))) | |
249 | 267 (set-syntax-table stab))))))) |
213 | 268 |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
269 (defun eval-defun (eval-defun-arg-internal) |
248 | 270 "Evaluate defun that point is in or before. |
271 Print value in minibuffer. | |
272 With argument, insert value in current buffer after the defun." | |
213 | 273 (interactive "P") |
10968
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
274 (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
|
275 (form (save-excursion |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
276 (end-of-defun) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
277 (beginning-of-defun) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
278 (read (current-buffer))))) |
12352
e6b42a6ea8e6
(eval-defun): Don't change defvar to defconst
Richard M. Stallman <rms@gnu.org>
parents:
12218
diff
changeset
|
279 (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
|
280 (cdr-safe (cdr-safe form))) |
10968
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
281 (setq form (cons 'defconst (cdr form)))) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
282 (prin1 (eval form)))) |
213 | 283 |
284 (defun lisp-comment-indent () | |
285 (if (looking-at "\\s<\\s<\\s<") | |
286 (current-column) | |
287 (if (looking-at "\\s<\\s<") | |
288 (let ((tem (calculate-lisp-indent))) | |
289 (if (listp tem) (car tem) tem)) | |
290 (skip-chars-backward " \t") | |
291 (max (if (bolp) 0 (1+ (current-column))) | |
292 comment-column)))) | |
293 | |
294 (defconst lisp-indent-offset nil "") | |
295 (defconst lisp-indent-function 'lisp-indent-function "") | |
296 | |
297 (defun lisp-indent-line (&optional whole-exp) | |
298 "Indent current line as Lisp code. | |
299 With argument, indent any additional lines of the same expression | |
300 rigidly along with this one." | |
301 (interactive "P") | |
302 (let ((indent (calculate-lisp-indent)) shift-amt beg end | |
303 (pos (- (point-max) (point)))) | |
304 (beginning-of-line) | |
305 (setq beg (point)) | |
306 (skip-chars-forward " \t") | |
307 (if (looking-at "\\s<\\s<\\s<") | |
308 ;; Don't alter indentation of a ;;; comment line. | |
677
7a9b4ea68565
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
659
diff
changeset
|
309 (goto-char (- (point-max) pos)) |
213 | 310 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<"))) |
311 ;; Single-semicolon comment lines should be indented | |
312 ;; as comment lines, not as code. | |
313 (progn (indent-for-comment) (forward-char -1)) | |
314 (if (listp indent) (setq indent (car indent))) | |
315 (setq shift-amt (- indent (current-column))) | |
316 (if (zerop shift-amt) | |
317 nil | |
318 (delete-region beg (point)) | |
319 (indent-to indent))) | |
320 ;; If initial point was within line's indentation, | |
321 ;; position after the indentation. Else stay at same point in text. | |
322 (if (> (- (point-max) pos) (point)) | |
323 (goto-char (- (point-max) pos))) | |
324 ;; If desired, shift remaining lines of expression the same amount. | |
325 (and whole-exp (not (zerop shift-amt)) | |
326 (save-excursion | |
327 (goto-char beg) | |
328 (forward-sexp 1) | |
329 (setq end (point)) | |
330 (goto-char beg) | |
331 (forward-line 1) | |
332 (setq beg (point)) | |
333 (> end beg)) | |
334 (indent-code-rigidly beg end shift-amt))))) | |
335 | |
9424
738999b0296f
Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
9423
diff
changeset
|
336 (defvar calculate-lisp-indent-last-sexp) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
337 |
213 | 338 (defun calculate-lisp-indent (&optional parse-start) |
339 "Return appropriate indentation for current line as Lisp code. | |
340 In usual case returns an integer: the column to indent to. | |
341 Can instead return a list, whose car is the column to indent to. | |
342 This means that following lines at the same level of indentation | |
343 should not necessarily be indented the same way. | |
344 The second element of the list is the buffer position | |
345 of the start of the containing expression." | |
346 (save-excursion | |
347 (beginning-of-line) | |
348 (let ((indent-point (point)) | |
349 state paren-depth | |
350 ;; setting this to a number inhibits calling hook | |
351 (desired-indent nil) | |
352 (retry t) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
353 calculate-lisp-indent-last-sexp containing-sexp) |
213 | 354 (if parse-start |
355 (goto-char parse-start) | |
356 (beginning-of-defun)) | |
357 ;; Find outermost containing sexp | |
358 (while (< (point) indent-point) | |
359 (setq state (parse-partial-sexp (point) indent-point 0))) | |
360 ;; Find innermost containing sexp | |
361 (while (and retry | |
362 state | |
363 (> (setq paren-depth (elt state 0)) 0)) | |
364 (setq retry nil) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
365 (setq calculate-lisp-indent-last-sexp (elt state 2)) |
213 | 366 (setq containing-sexp (elt state 1)) |
367 ;; Position following last unclosed open. | |
368 (goto-char (1+ containing-sexp)) | |
369 ;; Is there a complete sexp since then? | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
370 (if (and calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
371 (> calculate-lisp-indent-last-sexp (point))) |
213 | 372 ;; 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
|
373 (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
|
374 indent-point 0))) |
213 | 375 (if (setq retry (car (cdr peek))) (setq state peek))))) |
376 (if retry | |
377 nil | |
378 ;; Innermost containing sexp found | |
379 (goto-char (1+ containing-sexp)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
380 (if (not calculate-lisp-indent-last-sexp) |
213 | 381 ;; indent-point immediately follows open paren. |
382 ;; Don't call hook. | |
383 (setq desired-indent (current-column)) | |
384 ;; 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
|
385 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
213 | 386 (cond ((looking-at "\\s(") |
387 ;; First element of containing sexp is a list. | |
388 ;; Indent under that list. | |
389 ) | |
390 ((> (save-excursion (forward-line 1) (point)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
391 calculate-lisp-indent-last-sexp) |
213 | 392 ;; This is the first line to start within the containing sexp. |
393 ;; It's almost certainly a function call. | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
394 (if (= (point) calculate-lisp-indent-last-sexp) |
213 | 395 ;; Containing sexp has nothing before this line |
396 ;; except the first element. Indent under that element. | |
397 nil | |
398 ;; Skip the first element, find start of second (the first | |
399 ;; argument of the function call) and indent under. | |
400 (progn (forward-sexp 1) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
401 (parse-partial-sexp (point) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
402 calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
403 0 t))) |
213 | 404 (backward-prefix-chars)) |
405 (t | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
406 ;; Indent beneath first sexp on same line as |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
407 ;; calculate-lisp-indent-last-sexp. Again, it's |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
408 ;; almost certainly a function call. |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
409 (goto-char calculate-lisp-indent-last-sexp) |
213 | 410 (beginning-of-line) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
411 (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
|
412 0 t) |
213 | 413 (backward-prefix-chars))))) |
414 ;; 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
|
415 ;; Call indentation hook except when overridden by lisp-indent-offset |
213 | 416 ;; or if the desired indentation has already been computed. |
417 (let ((normal-indent (current-column))) | |
418 (cond ((elt state 3) | |
419 ;; Inside a string, don't change indentation. | |
420 (goto-char indent-point) | |
421 (skip-chars-forward " \t") | |
422 (current-column)) | |
423 ((and (integerp lisp-indent-offset) containing-sexp) | |
424 ;; Indent by constant offset | |
425 (goto-char containing-sexp) | |
426 (+ (current-column) lisp-indent-offset)) | |
427 (desired-indent) | |
428 ((and (boundp 'lisp-indent-function) | |
429 lisp-indent-function | |
430 (not retry)) | |
431 (or (funcall lisp-indent-function indent-point state) | |
432 normal-indent)) | |
433 (t | |
214 | 434 normal-indent)))))) |
213 | 435 |
436 (defun lisp-indent-function (indent-point state) | |
437 (let ((normal-indent (current-column))) | |
438 (goto-char (1+ (elt state 1))) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
439 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
213 | 440 (if (and (elt state 2) |
441 (not (looking-at "\\sw\\|\\s_"))) | |
442 ;; car of form doesn't seem to be a a symbol | |
443 (progn | |
444 (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
|
445 calculate-lisp-indent-last-sexp)) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
446 (progn (goto-char calculate-lisp-indent-last-sexp) |
213 | 447 (beginning-of-line) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
448 (parse-partial-sexp (point) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
449 calculate-lisp-indent-last-sexp 0 t))) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
450 ;; 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
|
451 ;; 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
|
452 ;; 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
|
453 ;; inside the innermost containing sexp. |
213 | 454 (backward-prefix-chars) |
455 (current-column)) | |
456 (let ((function (buffer-substring (point) | |
457 (progn (forward-sexp 1) (point)))) | |
458 method) | |
3638
45169f86d3a4
(lisp-indent-function): Look for either
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
459 (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
|
460 (get (intern-soft function) 'lisp-indent-hook))) |
213 | 461 (cond ((or (eq method 'defun) |
462 (and (null method) | |
463 (> (length function) 3) | |
464 (string-match "\\`def" function))) | |
465 (lisp-indent-defform state indent-point)) | |
466 ((integerp method) | |
467 (lisp-indent-specform method state | |
468 indent-point normal-indent)) | |
469 (method | |
470 (funcall method state indent-point))))))) | |
471 | |
2933
420dfaaacfc5
(lisp-body-indent): Add doc.
Richard M. Stallman <rms@gnu.org>
parents:
2450
diff
changeset
|
472 (defconst lisp-body-indent 2 |
420dfaaacfc5
(lisp-body-indent): Add doc.
Richard M. Stallman <rms@gnu.org>
parents:
2450
diff
changeset
|
473 "Number of columns to indent the second line of a `(def...)' form.") |
213 | 474 |
475 (defun lisp-indent-specform (count state indent-point normal-indent) | |
476 (let ((containing-form-start (elt state 1)) | |
477 (i count) | |
478 body-indent containing-form-column) | |
479 ;; Move to the start of containing form, calculate indentation | |
480 ;; to use for non-distinguished forms (> count), and move past the | |
481 ;; function symbol. lisp-indent-function guarantees that there is at | |
482 ;; least one word or symbol character following open paren of containing | |
483 ;; form. | |
484 (goto-char containing-form-start) | |
485 (setq containing-form-column (current-column)) | |
486 (setq body-indent (+ lisp-body-indent containing-form-column)) | |
487 (forward-char 1) | |
488 (forward-sexp 1) | |
489 ;; Now find the start of the last form. | |
490 (parse-partial-sexp (point) indent-point 1 t) | |
491 (while (and (< (point) indent-point) | |
492 (condition-case () | |
493 (progn | |
494 (setq count (1- count)) | |
495 (forward-sexp 1) | |
496 (parse-partial-sexp (point) indent-point 1 t)) | |
497 (error nil)))) | |
498 ;; Point is sitting on first character of last (or count) sexp. | |
499 (if (> count 0) | |
500 ;; A distinguished form. If it is the first or second form use double | |
501 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound | |
502 ;; to 2 (the default), this just happens to work the same with if as | |
503 ;; the older code, but it makes unwind-protect, condition-case, | |
504 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older, | |
505 ;; less hacked, behavior can be obtained by replacing below with | |
506 ;; (list normal-indent containing-form-start). | |
507 (if (<= (- i count) 1) | |
508 (list (+ containing-form-column (* 2 lisp-body-indent)) | |
509 containing-form-start) | |
510 (list normal-indent containing-form-start)) | |
511 ;; A non-distinguished form. Use body-indent if there are no | |
512 ;; distinguished forms and this is the first undistinguished form, | |
513 ;; or if this is the first undistinguished form and the preceding | |
514 ;; distinguished form has indentation at least as great as body-indent. | |
515 (if (or (and (= i 0) (= count 0)) | |
516 (and (= count 0) (<= body-indent normal-indent))) | |
517 body-indent | |
518 normal-indent)))) | |
519 | |
520 (defun lisp-indent-defform (state indent-point) | |
521 (goto-char (car (cdr state))) | |
522 (forward-line 1) | |
523 (if (> (point) (car (cdr (cdr state)))) | |
524 (progn | |
525 (goto-char (car (cdr state))) | |
526 (+ lisp-body-indent (current-column))))) | |
527 | |
528 | |
529 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented | |
530 ;; like defun if the first form is placed on the next line, otherwise | |
531 ;; it is indented like any other form (i.e. forms line up under first). | |
532 | |
533 (put 'lambda 'lisp-indent-function 'defun) | |
534 (put 'autoload 'lisp-indent-function 'defun) | |
535 (put 'progn 'lisp-indent-function 0) | |
536 (put 'prog1 'lisp-indent-function 1) | |
537 (put 'prog2 'lisp-indent-function 2) | |
538 (put 'save-excursion 'lisp-indent-function 0) | |
539 (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
|
540 (put 'save-selected-window 'lisp-indent-function 0) |
213 | 541 (put 'save-restriction 'lisp-indent-function 0) |
1163 | 542 (put 'save-match-data 'lisp-indent-function 0) |
213 | 543 (put 'let 'lisp-indent-function 1) |
544 (put 'let* 'lisp-indent-function 1) | |
545 (put 'while 'lisp-indent-function 1) | |
546 (put 'if 'lisp-indent-function 2) | |
547 (put 'catch 'lisp-indent-function 1) | |
548 (put 'condition-case 'lisp-indent-function 2) | |
549 (put 'unwind-protect 'lisp-indent-function 1) | |
550 (put 'with-output-to-temp-buffer 'lisp-indent-function 1) | |
551 | |
552 (defun indent-sexp (&optional endpos) | |
553 "Indent each line of the list starting just after point. | |
554 If optional arg ENDPOS is given, indent each line, stopping when | |
555 ENDPOS is encountered." | |
556 (interactive) | |
727 | 557 (let ((indent-stack (list nil)) |
558 (next-depth 0) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
559 ;; 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
|
560 ;; 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
|
561 ;; 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
|
562 ;; 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
|
563 ;; 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
|
564 (starting-point (if endpos nil (point))) |
727 | 565 (last-point (point)) |
566 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
|
567 (or endpos |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
568 ;; 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
|
569 (save-excursion (forward-sexp 1))) |
213 | 570 (save-excursion |
571 (setq outer-loop-done nil) | |
572 (while (if endpos (< (point) endpos) | |
573 (not outer-loop-done)) | |
574 (setq last-depth next-depth | |
575 inner-loop-done nil) | |
576 ;; Parse this line so we can learn the state | |
577 ;; to indent the next line. | |
578 ;; This inner loop goes through only once | |
579 ;; unless a line ends inside a string. | |
580 (while (and (not inner-loop-done) | |
581 (not (setq outer-loop-done (eobp)))) | |
582 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) | |
583 nil nil state)) | |
584 (setq next-depth (car state)) | |
585 ;; If the line contains a comment other than the sort | |
586 ;; that is indented like code, | |
587 ;; indent it now with indent-for-comment. | |
588 ;; Comments indented like code are right already. | |
589 ;; In any case clear the in-comment flag in the state | |
590 ;; because parse-partial-sexp never sees the newlines. | |
591 (if (car (nthcdr 4 state)) | |
592 (progn (indent-for-comment) | |
593 (end-of-line) | |
594 (setcar (nthcdr 4 state) nil))) | |
595 ;; If this line ends inside a string, | |
596 ;; go straight to next line, remaining within the inner loop, | |
597 ;; and turn off the \-flag. | |
598 (if (car (nthcdr 3 state)) | |
599 (progn | |
600 (forward-line 1) | |
601 (setcar (nthcdr 5 state) nil)) | |
602 (setq inner-loop-done t))) | |
603 (and endpos | |
727 | 604 (<= next-depth 0) |
605 (progn | |
606 (setq indent-stack (append indent-stack | |
607 (make-list (- next-depth) nil)) | |
608 last-depth (- last-depth next-depth) | |
609 next-depth 0))) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
610 (or outer-loop-done endpos |
213 | 611 (setq outer-loop-done (<= next-depth 0))) |
612 (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
|
613 (forward-line 1) |
213 | 614 (while (> last-depth next-depth) |
615 (setq indent-stack (cdr indent-stack) | |
616 last-depth (1- last-depth))) | |
617 (while (< last-depth next-depth) | |
618 (setq indent-stack (cons nil indent-stack) | |
619 last-depth (1+ last-depth))) | |
620 ;; Now go to the next line and indent it according | |
621 ;; to what we learned from parsing the previous one. | |
622 (forward-line 1) | |
623 (setq bol (point)) | |
624 (skip-chars-forward " \t") | |
625 ;; But not if the line is blank, or just a comment | |
626 ;; (except for double-semi comments; indent them as usual). | |
627 (if (or (eobp) (looking-at "\\s<\\|\n")) | |
628 nil | |
629 (if (and (car indent-stack) | |
630 (>= (car indent-stack) 0)) | |
631 (setq this-indent (car indent-stack)) | |
632 (let ((val (calculate-lisp-indent | |
633 (if (car indent-stack) (- (car indent-stack)) | |
727 | 634 starting-point)))) |
213 | 635 (if (integerp val) |
636 (setcar indent-stack | |
637 (setq this-indent val)) | |
638 (setcar indent-stack (- (car (cdr val)))) | |
639 (setq this-indent (car val))))) | |
640 (if (/= (current-column) this-indent) | |
641 (progn (delete-region bol (point)) | |
642 (indent-to this-indent))))) | |
643 (or outer-loop-done | |
644 (setq outer-loop-done (= (point) last-point)) | |
645 (setq last-point (point))))))) | |
646 | |
647 ;; Indent every line whose first char is between START and END inclusive. | |
648 (defun lisp-indent-region (start end) | |
649 (save-excursion | |
650 (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
|
651 (goto-char start) |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
652 (and (bolp) (not (eolp)) |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
653 (lisp-indent-line)) |
213 | 654 (indent-sexp endmark) |
655 (set-marker endmark nil)))) | |
656 | |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
657 ;;;; Lisp paragraph filling commands. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
658 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
659 (defun lisp-fill-paragraph (&optional justify) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
660 "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
|
661 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
|
662 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
|
663 and initial semicolons." |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
664 (interactive "P") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
665 (let ( |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
666 ;; 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
|
667 has-comment |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
668 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
669 ;; 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
|
670 comment-fill-prefix |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
671 ) |
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 ;; 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
|
674 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
675 (beginning-of-line) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
676 (cond |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
677 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
678 ;; 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
|
679 ((looking-at "[ \t]*;[; \t]*") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
680 (setq has-comment t |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
681 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
|
682 (match-end 0)))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
683 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
684 ;; 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
|
685 ;; 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
|
686 ;; character. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
687 ((progn |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
688 (while (not (looking-at ";\\|$")) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
689 (skip-chars-forward "^;\n\"\\\\?") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
690 (cond |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
691 ((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
|
692 ((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
|
693 (looking-at ";+[\t ]*")) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
694 (setq has-comment t) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
695 (setq comment-fill-prefix |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
696 (concat (make-string (current-column) ? ) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
697 (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
|
698 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
699 (if (not has-comment) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
700 (fill-paragraph justify) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
701 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
702 ;; 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
|
703 (save-restriction |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
704 (narrow-to-region |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
705 ;; 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
|
706 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
707 (while (and (zerop (forward-line -1)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
708 (looking-at "^[ \t]*;"))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
709 ;; 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
|
710 (or (looking-at "^[ \t]*;") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
711 (forward-line 1)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
712 (point)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
713 ;; 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
|
714 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
715 (while (progn (forward-line 1) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
716 (looking-at "^[ \t]*;"))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
717 (point))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
718 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
719 ;; 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
|
720 (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
|
721 (paragraph-separate (concat paragraph-start "\\|^[ \t;]*$")) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
722 (fill-prefix comment-fill-prefix)) |
10629
2c9bdcab7052
(lisp-fill-paragraph): Return t.
Richard M. Stallman <rms@gnu.org>
parents:
10628
diff
changeset
|
723 (fill-paragraph justify)))) |
2c9bdcab7052
(lisp-fill-paragraph): Return t.
Richard M. Stallman <rms@gnu.org>
parents:
10628
diff
changeset
|
724 t)) |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
725 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
726 |
213 | 727 (defun indent-code-rigidly (start end arg &optional nochange-regexp) |
728 "Indent all lines of code, starting in the region, sideways by ARG columns. | |
729 Does not affect lines starting inside comments or strings, assuming that | |
730 the start of the region is not inside them. | |
731 | |
732 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP. | |
733 The last is a regexp which, if matched at the beginning of a line, | |
734 means don't indent that line." | |
735 (interactive "r\np") | |
736 (let (state) | |
737 (save-excursion | |
738 (goto-char end) | |
739 (setq end (point-marker)) | |
740 (goto-char start) | |
741 (or (bolp) | |
742 (setq state (parse-partial-sexp (point) | |
743 (progn | |
744 (forward-line 1) (point)) | |
745 nil nil state))) | |
746 (while (< (point) end) | |
747 (or (car (nthcdr 3 state)) | |
748 (and nochange-regexp | |
749 (looking-at nochange-regexp)) | |
750 ;; If line does not start in string, indent it | |
751 (let ((indent (current-indentation))) | |
752 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
753 (or (eolp) | |
754 (indent-to (max 0 (+ indent arg)) 0)))) | |
755 (setq state (parse-partial-sexp (point) | |
756 (progn | |
757 (forward-line 1) (point)) | |
758 nil nil state)))))) | |
584 | 759 |
760 (provide 'lisp-mode) | |
761 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
762 ;;; lisp-mode.el ends here |