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