0
|
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands.
|
|
2
|
2
|
3 ;; Copyright (C) 1985, 1996 Free Software Foundation, Inc.
|
0
|
4 ;; Copyright (C) 1995 Tinker Systems
|
|
5
|
|
6 ;; Maintainer: FSF
|
|
7 ;; Keywords: lisp, languages
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
0
|
25
|
2
|
26 ;;; Synched up with: FSF 19.34 (but starting to diverge).
|
0
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; The base major mode for editing Lisp code (used also for Emacs Lisp).
|
|
31 ;; This mode is documented in the Emacs manual
|
|
32
|
|
33 ;;; Code:
|
|
34
|
|
35 (defvar lisp-mode-syntax-table nil "")
|
|
36 (defvar emacs-lisp-mode-syntax-table nil "")
|
|
37 (defvar lisp-mode-abbrev-table nil "")
|
|
38
|
2
|
39 ;; XEmacs change
|
0
|
40 (defvar lisp-interaction-mode-popup-menu
|
|
41 (purecopy '("Lisp Interaction Menu"
|
|
42 ["Evaluate Last S-expression" eval-last-sexp t]
|
|
43 ["Evaluate Entire Buffer" eval-current-buffer t]
|
|
44 ["Evaluate Region" eval-region (region-exists-p)]
|
|
45 "---"
|
|
46 ["Evaluate This Defun" eval-defun t]
|
|
47 ;; FSF says "Instrument Function for Debugging"
|
|
48 ["Debug This Defun" edebug-defun t]
|
|
49 "---"
|
|
50 ["Trace a Function" trace-function-background t]
|
|
51 ["Untrace All Functions" untrace-all (fboundp 'untrace-all)]
|
|
52 "---"
|
|
53 ["Comment Out Region" comment-region (region-exists-p)]
|
|
54 ["Indent Region" indent-region (region-exists-p)]
|
|
55 ["Indent Line" lisp-indent-line t]
|
|
56 "---"
|
|
57 ["Debug On Error" (setq debug-on-error (not debug-on-error))
|
|
58 :style toggle :selected debug-on-error]
|
|
59 ["Debug On Quit" (setq debug-on-quit (not debug-on-quit))
|
|
60 :style toggle :selected debug-on-quit]
|
|
61 )))
|
|
62
|
|
63 (defvar emacs-lisp-mode-popup-menu
|
|
64 (purecopy
|
|
65 (nconc
|
|
66 '("Emacs-Lisp Menu"
|
|
67 ["Byte-compile This File" emacs-lisp-byte-compile t]
|
|
68 ["Byte-recompile Directory..." byte-recompile-directory t]
|
|
69 "---")
|
|
70 (cdr lisp-interaction-mode-popup-menu))))
|
|
71
|
|
72 ;Don't have a menubar entry in Lisp Interaction mode. Otherwise, the
|
|
73 ;*scratch* buffer has a Lisp menubar item! Very confusing.
|
|
74 ;(defvar lisp-interaction-mode-menubar-menu
|
|
75 ; (purecopy (cons "Lisp" (cdr lisp-interaction-mode-popup-menu))))
|
|
76
|
|
77 (defvar emacs-lisp-mode-menubar-menu
|
|
78 (purecopy (cons "Lisp" (cdr emacs-lisp-mode-popup-menu))))
|
|
79
|
|
80 (if (not emacs-lisp-mode-syntax-table)
|
|
81 (let ((i 0))
|
|
82 (setq emacs-lisp-mode-syntax-table (make-syntax-table))
|
|
83 (while (< i ?0)
|
|
84 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
|
|
85 (setq i (1+ i)))
|
|
86 (setq i (1+ ?9))
|
|
87 (while (< i ?A)
|
|
88 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
|
|
89 (setq i (1+ i)))
|
|
90 (setq i (1+ ?Z))
|
|
91 (while (< i ?a)
|
|
92 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
|
|
93 (setq i (1+ i)))
|
|
94 (setq i (1+ ?z))
|
|
95 (while (< i 128)
|
|
96 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
|
|
97 (setq i (1+ i)))
|
|
98 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table)
|
|
99 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table)
|
|
100 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table)
|
|
101 ;; Give CR the same syntax as newline, for selective-display.
|
|
102 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table)
|
2
|
103 ;; XEmacs change
|
0
|
104 ;; Treat ^L as whitespace.
|
|
105 (modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table)
|
|
106 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table)
|
|
107 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table)
|
|
108 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table)
|
|
109 (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table)
|
|
110 ;; Used to be singlequote; changed for flonums.
|
|
111 (modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table)
|
|
112 (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table)
|
|
113 (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table)
|
|
114 (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table)
|
|
115 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table)
|
|
116 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table)
|
|
117 (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table)
|
|
118 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table)))
|
|
119
|
|
120 (if (not lisp-mode-syntax-table)
|
|
121 (progn (setq lisp-mode-syntax-table
|
|
122 (copy-syntax-table emacs-lisp-mode-syntax-table))
|
2
|
123 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table)
|
0
|
124 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table)
|
2
|
125 ;; XEmacs changes
|
0
|
126 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table)
|
|
127 ;;
|
|
128 ;; If emacs was compiled with NEW_SYNTAX, then do
|
|
129 ;; CL's #| |# block comments.
|
|
130 (if (= 8 (length (parse-partial-sexp (point) (point))))
|
|
131 (progn
|
|
132 (modify-syntax-entry ?# "' 58" lisp-mode-syntax-table)
|
|
133 (modify-syntax-entry ?| ". 67" lisp-mode-syntax-table))
|
2
|
134 ;; else, old style
|
|
135 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table))))
|
0
|
136
|
|
137 (define-abbrev-table 'lisp-mode-abbrev-table ())
|
|
138
|
|
139 ;(defvar lisp-imenu-generic-expression
|
|
140 ; '(
|
|
141 ; (nil
|
|
142 ; "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
|
|
143 ; ("Variables"
|
|
144 ; "^\\s-*(def\\(var\\|const\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
|
|
145 ; ("Types"
|
|
146 ; "^\\s-*(def\\(type\\|struct\\|class\\|ine-condition\\)\\s-+\\([-A-Za-z0-9+]+\\)"
|
|
147 ; 2))
|
|
148 ;
|
|
149 ; "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
|
|
150
|
|
151 (defun lisp-mode-variables (lisp-syntax)
|
2
|
152 (cond (lisp-syntax
|
|
153 (set-syntax-table lisp-mode-syntax-table)))
|
0
|
154 (setq local-abbrev-table lisp-mode-abbrev-table)
|
|
155 (make-local-variable 'paragraph-start)
|
|
156 (setq paragraph-start (concat page-delimiter "\\|$" ))
|
|
157 (make-local-variable 'paragraph-separate)
|
|
158 (setq paragraph-separate paragraph-start)
|
|
159 (make-local-variable 'paragraph-ignore-fill-prefix)
|
|
160 (setq paragraph-ignore-fill-prefix t)
|
|
161 (make-local-variable 'fill-paragraph-function)
|
|
162 (setq fill-paragraph-function 'lisp-fill-paragraph)
|
2
|
163 ;; Adaptive fill mode gets in the way of auto-fill,
|
|
164 ;; and should make no difference for explicit fill
|
|
165 ;; because lisp-fill-paragraph should do the job.
|
|
166 (make-local-variable 'adaptive-fill-mode)
|
|
167 (setq adaptive-fill-mode nil)
|
0
|
168 (make-local-variable 'indent-line-function)
|
|
169 (setq indent-line-function 'lisp-indent-line)
|
|
170 (make-local-variable 'indent-region-function)
|
|
171 (setq indent-region-function 'lisp-indent-region)
|
|
172 (make-local-variable 'parse-sexp-ignore-comments)
|
|
173 (setq parse-sexp-ignore-comments t)
|
|
174 (make-local-variable 'outline-regexp)
|
|
175 (setq outline-regexp ";;; \\|(....")
|
2
|
176 (make-local-variable 'comment-start)
|
|
177 (setq comment-start ";")
|
|
178 ;; XEmacs change
|
0
|
179 (set (make-local-variable 'block-comment-start) ";;")
|
|
180 (make-local-variable 'comment-start-skip)
|
2
|
181 ;; Look within the line for a ; following an even number of backslashes
|
|
182 ;; after either a non-backslash or the line beginning.
|
|
183 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
|
0
|
184 (make-local-variable 'comment-column)
|
|
185 (setq comment-column 40)
|
|
186 (make-local-variable 'comment-indent-function)
|
|
187 (setq comment-indent-function 'lisp-comment-indent)
|
2
|
188 ;; XEmacs changes
|
0
|
189 ; (make-local-variable 'imenu-generic-expression)
|
|
190 ; (setq imenu-generic-expression lisp-imenu-generic-expression)
|
|
191 (set (make-local-variable 'dabbrev-case-fold-search) nil)
|
|
192 (set (make-local-variable 'dabbrev-case-replace) nil)
|
|
193 )
|
|
194
|
|
195
|
|
196 (defvar shared-lisp-mode-map ()
|
|
197 "Keymap for commands shared by all sorts of Lisp modes.")
|
|
198
|
|
199 (if shared-lisp-mode-map
|
|
200 ()
|
|
201 (setq shared-lisp-mode-map (make-sparse-keymap))
|
2
|
202 ;; XEmacs changes
|
0
|
203 (set-keymap-name shared-lisp-mode-map 'shared-lisp-mode-map)
|
2
|
204 (define-key shared-lisp-mode-map "\M-;" 'lisp-indent-for-comment)
|
0
|
205 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp)
|
2
|
206 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify))
|
0
|
207
|
|
208 (defvar emacs-lisp-mode-map ()
|
|
209 "Keymap for Emacs Lisp mode.
|
|
210 All commands in `shared-lisp-mode-map' are inherited by this map.")
|
|
211
|
|
212 (if emacs-lisp-mode-map
|
|
213 ()
|
2
|
214 ;; XEmacs: Ignore FSF nconc stuff
|
0
|
215 (setq emacs-lisp-mode-map (make-sparse-keymap))
|
|
216 (set-keymap-name emacs-lisp-mode-map 'emacs-lisp-mode-map)
|
|
217 (set-keymap-parents emacs-lisp-mode-map (list shared-lisp-mode-map))
|
|
218 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
|
2
|
219 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
|
|
220 ;; XEmacs: Not sure what the FSF menu bindings are. I hope XEmacs
|
|
221 ;; doesn't need them.
|
|
222 )
|
0
|
223
|
|
224 (defun emacs-lisp-byte-compile ()
|
|
225 "Byte compile the file containing the current buffer."
|
|
226 (interactive)
|
|
227 (if buffer-file-name
|
2
|
228 ;; XEmacs change. Force buffer save first
|
0
|
229 (progn
|
|
230 (save-buffer)
|
|
231 (byte-compile-file buffer-file-name))
|
|
232 (error "The buffer must be saved in a file first.")))
|
|
233
|
2
|
234 (defun emacs-lisp-byte-compile-and-load ()
|
|
235 "Byte-compile the current file (if it has changed), then load compiled code."
|
|
236 (interactive)
|
|
237 (or buffer-file-name
|
|
238 (error "The buffer must be saved in a file first"))
|
|
239 (require 'bytecomp)
|
|
240 ;; Recompile if file or buffer has changed since last compilation.
|
|
241 (if (and (buffer-modified-p)
|
|
242 (y-or-n-p (format "save buffer %s first? " (buffer-name))))
|
|
243 (save-buffer))
|
|
244 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name)))
|
|
245 (if (file-newer-than-file-p compiled-file-name buffer-file-name)
|
|
246 (load-file compiled-file-name)
|
|
247 (byte-compile-file buffer-file-name t))))
|
|
248
|
0
|
249 (defun emacs-lisp-mode ()
|
|
250 "Major mode for editing Lisp code to run in Emacs.
|
|
251 Commands:
|
|
252 Delete converts tabs to spaces as it moves back.
|
|
253 Blank lines separate paragraphs. Semicolons start comments.
|
|
254 \\{emacs-lisp-mode-map}
|
|
255 Entry to this mode calls the value of `emacs-lisp-mode-hook'
|
|
256 if that value is non-nil."
|
|
257 (interactive)
|
|
258 (kill-all-local-variables)
|
|
259 (use-local-map emacs-lisp-mode-map)
|
|
260 (set-syntax-table emacs-lisp-mode-syntax-table)
|
2
|
261 ;; XEmacs changes
|
0
|
262 (setq major-mode 'emacs-lisp-mode
|
|
263 mode-popup-menu emacs-lisp-mode-popup-menu
|
|
264 mode-name "Emacs-Lisp")
|
|
265 (if (and (featurep 'menubar)
|
|
266 current-menubar)
|
|
267 (progn
|
|
268 ;; make a local copy of the menubar, so our modes don't
|
|
269 ;; change the global menubar
|
|
270 (set-buffer-menubar current-menubar)
|
|
271 (add-submenu nil emacs-lisp-mode-menubar-menu)))
|
|
272 (lisp-mode-variables nil)
|
|
273 (run-hooks 'emacs-lisp-mode-hook))
|
|
274
|
|
275 (defvar lisp-mode-map ()
|
|
276 "Keymap for ordinary Lisp mode.
|
|
277 All commands in `shared-lisp-mode-map' are inherited by this map.")
|
|
278
|
|
279 (if lisp-mode-map
|
|
280 ()
|
2
|
281 ;; XEmacs changes
|
0
|
282 (setq lisp-mode-map (make-sparse-keymap))
|
|
283 (set-keymap-name lisp-mode-map 'lisp-mode-map)
|
|
284 (set-keymap-parents lisp-mode-map (list shared-lisp-mode-map))
|
|
285 (define-key lisp-mode-map "\e\C-x" 'lisp-send-defun)
|
|
286 ;; gag, no. use ilisp. -jwz
|
|
287 ;; (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)
|
|
288 )
|
|
289
|
|
290 (defun lisp-mode ()
|
|
291 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
|
|
292 Commands:
|
|
293 Delete converts tabs to spaces as it moves back.
|
|
294 Blank lines separate paragraphs. Semicolons start comments.
|
|
295 \\{lisp-mode-map}
|
|
296 Note that `run-lisp' may be used either to start an inferior Lisp job
|
|
297 or to switch back to an existing one.
|
|
298
|
|
299 Entry to this mode calls the value of `lisp-mode-hook'
|
|
300 if that value is non-nil."
|
|
301 (interactive)
|
|
302 (kill-all-local-variables)
|
|
303 (use-local-map lisp-mode-map)
|
|
304 (setq major-mode 'lisp-mode)
|
|
305 (setq mode-name "Lisp")
|
|
306 (lisp-mode-variables t)
|
|
307 (set-syntax-table lisp-mode-syntax-table)
|
|
308 (run-hooks 'lisp-mode-hook))
|
|
309
|
|
310 ;; This will do unless shell.el is loaded.
|
2
|
311 ;; XEmacs change
|
0
|
312 (defun lisp-send-defun ()
|
|
313 "Send the current defun to the Lisp process made by \\[run-lisp]."
|
|
314 (interactive)
|
|
315 (error "Process lisp does not exist"))
|
|
316
|
|
317 ;; XEmacs change: emacs-lisp-mode-map is a more appropriate parent.
|
2
|
318 (defvar lisp-interaction-mode-map ()
|
0
|
319 "Keymap for Lisp Interaction moe.
|
2
|
320 All commands in `shared-lisp-mode-map' are inherited by this map.")
|
0
|
321
|
|
322 (if lisp-interaction-mode-map
|
|
323 ()
|
2
|
324 ;; XEmacs set keymap our way
|
0
|
325 (setq lisp-interaction-mode-map (make-sparse-keymap))
|
|
326 (set-keymap-name lisp-interaction-mode-map 'lisp-interaction-mode-map)
|
|
327 (set-keymap-parents lisp-interaction-mode-map (list emacs-lisp-mode-map))
|
|
328 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun)
|
|
329 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol)
|
|
330 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))
|
|
331
|
|
332 (defun lisp-interaction-mode ()
|
|
333 "Major mode for typing and evaluating Lisp forms.
|
|
334 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression
|
|
335 before point, and prints its value into the buffer, advancing point.
|
|
336
|
|
337 Commands:
|
|
338 Delete converts tabs to spaces as it moves back.
|
2
|
339 Paragraphs are separated only by blank lines.
|
|
340 Semicolons start comments.
|
0
|
341 \\{lisp-interaction-mode-map}
|
|
342 Entry to this mode calls the value of `lisp-interaction-mode-hook'
|
|
343 if that value is non-nil."
|
|
344 (interactive)
|
|
345 (kill-all-local-variables)
|
|
346 (use-local-map lisp-interaction-mode-map)
|
2
|
347 (setq major-mode 'lisp-interaction-mode)
|
|
348 (setq mode-name "Lisp Interaction")
|
|
349 ;; XEmacs change
|
|
350 (setq mode-popup-menu lisp-interaction-mode-popup-menu)
|
0
|
351 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
352 (lisp-mode-variables nil)
|
|
353 (run-hooks 'lisp-interaction-mode-hook))
|
|
354
|
|
355 (defun eval-print-last-sexp ()
|
|
356 "Evaluate sexp before point; print value into current buffer."
|
|
357 (interactive)
|
|
358 (let ((standard-output (current-buffer)))
|
|
359 (terpri)
|
|
360 (eval-last-sexp t)
|
|
361 (terpri)))
|
|
362
|
2
|
363 ;; XEmacs change
|
0
|
364 (defun eval-interactive (expr)
|
|
365 "Like `eval' except that it transforms defvars to defconsts."
|
|
366 ;; by Stig@hackvan.com
|
|
367 (if (and (consp expr)
|
|
368 (eq (car expr) 'defvar)
|
|
369 (> (length expr) 2))
|
|
370 (progn (eval (cons 'defconst (cdr expr)))
|
|
371 (message "defvar treated as defconst")
|
|
372 (sit-for 1)
|
|
373 (message ""))
|
|
374 (eval expr)))
|
|
375
|
2
|
376 (defun eval-last-sexp (eval-last-sexp-arg-internal)
|
0
|
377 "Evaluate sexp before point; print value in minibuffer.
|
|
378 With argument, print output into current buffer."
|
|
379 (interactive "P")
|
|
380 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))
|
|
381 (opoint (point)))
|
|
382 (prin1 (let ((stab (syntax-table)))
|
2
|
383 ;; XEmacs change use eval-interactive not eval
|
0
|
384 (eval-interactive (unwind-protect
|
|
385 (save-excursion
|
|
386 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
387 (forward-sexp -1)
|
|
388 (save-restriction
|
|
389 (narrow-to-region (point-min) opoint)
|
|
390 (read (current-buffer))))
|
|
391 (set-syntax-table stab)))))))
|
|
392
|
2
|
393 (defun eval-defun (eval-defun-arg-internal)
|
0
|
394 "Evaluate defun that point is in or before.
|
|
395 Print value in minibuffer.
|
|
396 With argument, insert value in current buffer after the defun."
|
|
397 (interactive "P")
|
2
|
398 ;; XEmacs: FSF version works, so use it
|
|
399 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t))
|
|
400 (form (save-excursion
|
|
401 (end-of-defun)
|
|
402 (beginning-of-defun)
|
|
403 (read (current-buffer)))))
|
|
404 (if (and (eq (car form) 'defvar)
|
|
405 (cdr-safe (cdr-safe form)))
|
|
406 (setq form (cons 'defconst (cdr form))))
|
|
407 (prin1 (eval form))))
|
0
|
408
|
|
409 (defun lisp-comment-indent ()
|
|
410 (if (looking-at "\\s<\\s<\\s<")
|
|
411 (current-column)
|
|
412 (if (looking-at "\\s<\\s<")
|
|
413 (let ((tem (calculate-lisp-indent)))
|
|
414 (if (listp tem) (car tem) tem))
|
|
415 (skip-chars-backward " \t")
|
|
416 (max (if (bolp) 0 (1+ (current-column)))
|
|
417 comment-column))))
|
|
418
|
2
|
419 ;; XEmacs change
|
0
|
420 (defun lisp-indent-for-comment ()
|
|
421 "Indent this line's comment appropriately, or insert an empty comment.
|
|
422 If adding a new comment on a blank line, use `block-comment-start' instead
|
|
423 of `comment-start' to open the comment."
|
|
424 ;; by Stig@hackvan.com
|
|
425 ;; #### - This functionality, the recognition of block-comment-{start,end},
|
|
426 ;; will perhaps be standardized across modes and move to indent-for-comment.
|
|
427 (interactive)
|
|
428 (if (and block-comment-start
|
|
429 (save-excursion (beginning-of-line) (looking-at "^[ \t]*$")))
|
|
430 (insert block-comment-start))
|
|
431 (indent-for-comment))
|
|
432
|
|
433 (defconst lisp-indent-offset nil "")
|
|
434 (defconst lisp-indent-function 'lisp-indent-function "")
|
|
435
|
|
436 (defun lisp-indent-line (&optional whole-exp)
|
|
437 "Indent current line as Lisp code.
|
|
438 With argument, indent any additional lines of the same expression
|
|
439 rigidly along with this one."
|
|
440 (interactive "P")
|
|
441 (let ((indent (calculate-lisp-indent)) shift-amt beg end
|
|
442 (pos (- (point-max) (point))))
|
|
443 (beginning-of-line)
|
|
444 (setq beg (point))
|
|
445 (skip-chars-forward " \t")
|
|
446 (if (looking-at "\\s<\\s<\\s<")
|
|
447 ;; Don't alter indentation of a ;;; comment line.
|
|
448 (goto-char (- (point-max) pos))
|
|
449 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
|
|
450 ;; Single-semicolon comment lines should be indented
|
|
451 ;; as comment lines, not as code.
|
|
452 (progn (indent-for-comment) (forward-char -1))
|
|
453 (if (listp indent) (setq indent (car indent)))
|
|
454 (setq shift-amt (- indent (current-column)))
|
|
455 (if (zerop shift-amt)
|
|
456 nil
|
|
457 (delete-region beg (point))
|
|
458 (indent-to indent)))
|
|
459 ;; If initial point was within line's indentation,
|
|
460 ;; position after the indentation. Else stay at same point in text.
|
|
461 (if (> (- (point-max) pos) (point))
|
|
462 (goto-char (- (point-max) pos)))
|
|
463 ;; If desired, shift remaining lines of expression the same amount.
|
|
464 (and whole-exp (not (zerop shift-amt))
|
|
465 (save-excursion
|
|
466 (goto-char beg)
|
|
467 (forward-sexp 1)
|
|
468 (setq end (point))
|
|
469 (goto-char beg)
|
|
470 (forward-line 1)
|
|
471 (setq beg (point))
|
|
472 (> end beg))
|
|
473 (indent-code-rigidly beg end shift-amt)))))
|
|
474
|
|
475 (defvar calculate-lisp-indent-last-sexp)
|
|
476
|
|
477 (defun calculate-lisp-indent (&optional parse-start)
|
|
478 "Return appropriate indentation for current line as Lisp code.
|
|
479 In usual case returns an integer: the column to indent to.
|
|
480 Can instead return a list, whose car is the column to indent to.
|
|
481 This means that following lines at the same level of indentation
|
|
482 should not necessarily be indented the same way.
|
|
483 The second element of the list is the buffer position
|
|
484 of the start of the containing expression."
|
|
485 (save-excursion
|
|
486 (beginning-of-line)
|
|
487 (let ((indent-point (point))
|
2
|
488 ;; XEmacs change (remove paren-depth)
|
0
|
489 state ;;paren-depth
|
|
490 ;; setting this to a number inhibits calling hook
|
|
491 (desired-indent nil)
|
|
492 (retry t)
|
|
493 calculate-lisp-indent-last-sexp containing-sexp)
|
|
494 (if parse-start
|
|
495 (goto-char parse-start)
|
|
496 (beginning-of-defun))
|
|
497 ;; Find outermost containing sexp
|
|
498 (while (< (point) indent-point)
|
|
499 (setq state (parse-partial-sexp (point) indent-point 0)))
|
|
500 ;; Find innermost containing sexp
|
|
501 (while (and retry
|
|
502 state
|
2
|
503 ;; XEmacs change (remove paren-depth)
|
0
|
504 (> ;;(setq paren-depth (elt state 0))
|
|
505 (elt state 0)
|
|
506 0))
|
|
507 (setq retry nil)
|
|
508 (setq calculate-lisp-indent-last-sexp (elt state 2))
|
|
509 (setq containing-sexp (elt state 1))
|
|
510 ;; Position following last unclosed open.
|
|
511 (goto-char (1+ containing-sexp))
|
|
512 ;; Is there a complete sexp since then?
|
|
513 (if (and calculate-lisp-indent-last-sexp
|
|
514 (> calculate-lisp-indent-last-sexp (point)))
|
|
515 ;; Yes, but is there a containing sexp after that?
|
|
516 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp
|
|
517 indent-point 0)))
|
|
518 (if (setq retry (car (cdr peek))) (setq state peek)))))
|
|
519 (if retry
|
|
520 nil
|
|
521 ;; Innermost containing sexp found
|
|
522 (goto-char (1+ containing-sexp))
|
|
523 (if (not calculate-lisp-indent-last-sexp)
|
|
524 ;; indent-point immediately follows open paren.
|
|
525 ;; Don't call hook.
|
|
526 (setq desired-indent (current-column))
|
|
527 ;; Find the start of first element of containing sexp.
|
|
528 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
529 (cond ((looking-at "\\s(")
|
|
530 ;; First element of containing sexp is a list.
|
|
531 ;; Indent under that list.
|
|
532 )
|
|
533 ((> (save-excursion (forward-line 1) (point))
|
|
534 calculate-lisp-indent-last-sexp)
|
|
535 ;; This is the first line to start within the containing sexp.
|
|
536 ;; It's almost certainly a function call.
|
|
537 (if (= (point) calculate-lisp-indent-last-sexp)
|
|
538 ;; Containing sexp has nothing before this line
|
|
539 ;; except the first element. Indent under that element.
|
|
540 nil
|
|
541 ;; Skip the first element, find start of second (the first
|
|
542 ;; argument of the function call) and indent under.
|
|
543 (progn (forward-sexp 1)
|
|
544 (parse-partial-sexp (point)
|
|
545 calculate-lisp-indent-last-sexp
|
|
546 0 t)))
|
|
547 (backward-prefix-chars))
|
|
548 (t
|
|
549 ;; Indent beneath first sexp on same line as
|
|
550 ;; calculate-lisp-indent-last-sexp. Again, it's
|
|
551 ;; almost certainly a function call.
|
|
552 (goto-char calculate-lisp-indent-last-sexp)
|
|
553 (beginning-of-line)
|
|
554 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp
|
|
555 0 t)
|
|
556 (backward-prefix-chars)))))
|
|
557 ;; Point is at the point to indent under unless we are inside a string.
|
|
558 ;; Call indentation hook except when overridden by lisp-indent-offset
|
|
559 ;; or if the desired indentation has already been computed.
|
|
560 (let ((normal-indent (current-column)))
|
|
561 (cond ((elt state 3)
|
|
562 ;; Inside a string, don't change indentation.
|
|
563 (goto-char indent-point)
|
|
564 (skip-chars-forward " \t")
|
|
565 (current-column))
|
|
566 (desired-indent)
|
|
567 ((and (boundp 'lisp-indent-function)
|
|
568 lisp-indent-function
|
|
569 (not retry))
|
|
570 (or (funcall lisp-indent-function indent-point state)
|
|
571 normal-indent))
|
2
|
572 ;; XEmacs change:
|
0
|
573 ;; lisp-indent-offset shouldn't override lisp-indent-function !
|
|
574 ((and (integerp lisp-indent-offset) containing-sexp)
|
|
575 ;; Indent by constant offset
|
|
576 (goto-char containing-sexp)
|
|
577 (+ normal-indent lisp-indent-offset))
|
|
578 (t
|
|
579 normal-indent))))))
|
|
580
|
|
581 (defun lisp-indent-function (indent-point state)
|
|
582 ;; free reference to `calculate-lisp-indent-last-sexp'
|
|
583 ;; in #'calculate-lisp-indent
|
|
584 (let ((normal-indent (current-column)))
|
|
585 (goto-char (1+ (elt state 1)))
|
|
586 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
587 (if (and (elt state 2)
|
|
588 (not (looking-at "\\sw\\|\\s_")))
|
|
589 ;; car of form doesn't seem to be a a symbol
|
|
590 (progn
|
|
591 (if (not (> (save-excursion (forward-line 1) (point))
|
|
592 calculate-lisp-indent-last-sexp))
|
|
593 (progn (goto-char calculate-lisp-indent-last-sexp)
|
|
594 (beginning-of-line)
|
|
595 (parse-partial-sexp (point)
|
|
596 calculate-lisp-indent-last-sexp 0 t)))
|
|
597 ;; Indent under the list or under the first sexp on the same
|
|
598 ;; line as calculate-lisp-indent-last-sexp. Note that first
|
|
599 ;; thing on that line has to be complete sexp since we are
|
|
600 ;; inside the innermost containing sexp.
|
|
601 (backward-prefix-chars)
|
|
602 (current-column))
|
|
603 (let ((function (buffer-substring (point)
|
|
604 (progn (forward-sexp 1) (point))))
|
|
605 method)
|
|
606 (setq method (or (get (intern-soft function) 'lisp-indent-function)
|
2
|
607 (get (intern-soft function) 'lisp-indent-hook)))
|
0
|
608 (cond ((or (eq method 'defun)
|
|
609 (and (null method)
|
|
610 (> (length function) 3)
|
|
611 (string-match "\\`def" function)))
|
|
612 (lisp-indent-defform state indent-point))
|
|
613 ((integerp method)
|
|
614 (lisp-indent-specform method state
|
|
615 indent-point normal-indent))
|
|
616 (method
|
|
617 (funcall method state indent-point)))))))
|
|
618
|
|
619 (defconst lisp-body-indent 2
|
|
620 "Number of columns to indent the second line of a `(def...)' form.")
|
|
621
|
|
622 (defun lisp-indent-specform (count state indent-point normal-indent)
|
|
623 (let ((containing-form-start (elt state 1))
|
|
624 (i count)
|
|
625 body-indent containing-form-column)
|
|
626 ;; Move to the start of containing form, calculate indentation
|
|
627 ;; to use for non-distinguished forms (> count), and move past the
|
|
628 ;; function symbol. lisp-indent-function guarantees that there is at
|
|
629 ;; least one word or symbol character following open paren of containing
|
|
630 ;; form.
|
|
631 (goto-char containing-form-start)
|
|
632 (setq containing-form-column (current-column))
|
|
633 (setq body-indent (+ lisp-body-indent containing-form-column))
|
|
634 (forward-char 1)
|
|
635 (forward-sexp 1)
|
|
636 ;; Now find the start of the last form.
|
|
637 (parse-partial-sexp (point) indent-point 1 t)
|
|
638 (while (and (< (point) indent-point)
|
|
639 (condition-case ()
|
|
640 (progn
|
|
641 (setq count (1- count))
|
|
642 (forward-sexp 1)
|
|
643 (parse-partial-sexp (point) indent-point 1 t))
|
|
644 (error nil))))
|
|
645 ;; Point is sitting on first character of last (or count) sexp.
|
|
646 (if (> count 0)
|
|
647 ;; A distinguished form. If it is the first or second form use double
|
|
648 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound
|
|
649 ;; to 2 (the default), this just happens to work the same with if as
|
|
650 ;; the older code, but it makes unwind-protect, condition-case,
|
|
651 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older,
|
|
652 ;; less hacked, behavior can be obtained by replacing below with
|
|
653 ;; (list normal-indent containing-form-start).
|
|
654 (if (<= (- i count) 1)
|
|
655 (list (+ containing-form-column (* 2 lisp-body-indent))
|
|
656 containing-form-start)
|
|
657 (list normal-indent containing-form-start))
|
|
658 ;; A non-distinguished form. Use body-indent if there are no
|
|
659 ;; distinguished forms and this is the first undistinguished form,
|
|
660 ;; or if this is the first undistinguished form and the preceding
|
|
661 ;; distinguished form has indentation at least as great as body-indent.
|
|
662 (if (or (and (= i 0) (= count 0))
|
|
663 (and (= count 0) (<= body-indent normal-indent)))
|
|
664 body-indent
|
|
665 normal-indent))))
|
|
666
|
|
667 (defun lisp-indent-defform (state indent-point)
|
|
668 (goto-char (car (cdr state)))
|
|
669 (forward-line 1)
|
|
670 (if (> (point) (car (cdr (cdr state))))
|
|
671 (progn
|
|
672 (goto-char (car (cdr state)))
|
|
673 (+ lisp-body-indent (current-column)))))
|
|
674
|
|
675
|
|
676 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
|
|
677 ;; like defun if the first form is placed on the next line, otherwise
|
|
678 ;; it is indented like any other form (i.e. forms line up under first).
|
|
679
|
|
680 (put 'lambda 'lisp-indent-function 'defun)
|
|
681 (put 'autoload 'lisp-indent-function 'defun)
|
|
682 (put 'progn 'lisp-indent-function 0)
|
|
683 (put 'prog1 'lisp-indent-function 1)
|
|
684 (put 'prog2 'lisp-indent-function 2)
|
|
685 (put 'save-excursion 'lisp-indent-function 0)
|
|
686 (put 'save-window-excursion 'lisp-indent-function 0)
|
|
687 (put 'save-selected-window 'lisp-indent-function 0)
|
|
688 (put 'save-restriction 'lisp-indent-function 0)
|
|
689 (put 'save-match-data 'lisp-indent-function 0)
|
|
690 (put 'let 'lisp-indent-function 1)
|
|
691 (put 'let* 'lisp-indent-function 1)
|
|
692 (put 'while 'lisp-indent-function 1)
|
|
693 (put 'if 'lisp-indent-function 2)
|
|
694 (put 'catch 'lisp-indent-function 1)
|
|
695 (put 'condition-case 'lisp-indent-function 2)
|
|
696 (put 'unwind-protect 'lisp-indent-function 1)
|
|
697 (put 'with-output-to-temp-buffer 'lisp-indent-function 1)
|
|
698
|
|
699 (defun indent-sexp (&optional endpos)
|
|
700 "Indent each line of the list starting just after point.
|
|
701 If optional arg ENDPOS is given, indent each line, stopping when
|
|
702 ENDPOS is encountered."
|
|
703 (interactive)
|
|
704 (let ((indent-stack (list nil))
|
2
|
705 (next-depth 0)
|
0
|
706 ;; If ENDPOS is non-nil, use nil as STARTING-POINT
|
|
707 ;; so that calculate-lisp-indent will find the beginning of
|
|
708 ;; the defun we are in.
|
|
709 ;; If ENDPOS is nil, it is safe not to scan before point
|
|
710 ;; since every line we indent is more deeply nested than point is.
|
|
711 (starting-point (if endpos nil (point)))
|
2
|
712 (last-point (point))
|
|
713 last-depth bol outer-loop-done inner-loop-done state this-indent)
|
0
|
714 (or endpos
|
|
715 ;; Get error now if we don't have a complete sexp after point.
|
|
716 (save-excursion (forward-sexp 1)))
|
|
717 (save-excursion
|
|
718 (setq outer-loop-done nil)
|
|
719 (while (if endpos (< (point) endpos)
|
|
720 (not outer-loop-done))
|
|
721 (setq last-depth next-depth
|
|
722 inner-loop-done nil)
|
|
723 ;; Parse this line so we can learn the state
|
|
724 ;; to indent the next line.
|
|
725 ;; This inner loop goes through only once
|
|
726 ;; unless a line ends inside a string.
|
|
727 (while (and (not inner-loop-done)
|
|
728 (not (setq outer-loop-done (eobp))))
|
|
729 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
|
|
730 nil nil state))
|
|
731 (setq next-depth (car state))
|
|
732 ;; If the line contains a comment other than the sort
|
|
733 ;; that is indented like code,
|
|
734 ;; indent it now with indent-for-comment.
|
|
735 ;; Comments indented like code are right already.
|
|
736 ;; In any case clear the in-comment flag in the state
|
|
737 ;; because parse-partial-sexp never sees the newlines.
|
|
738 (if (car (nthcdr 4 state))
|
|
739 (progn (indent-for-comment)
|
|
740 (end-of-line)
|
|
741 (setcar (nthcdr 4 state) nil)))
|
|
742 ;; If this line ends inside a string,
|
|
743 ;; go straight to next line, remaining within the inner loop,
|
|
744 ;; and turn off the \-flag.
|
|
745 (if (car (nthcdr 3 state))
|
|
746 (progn
|
|
747 (forward-line 1)
|
|
748 (setcar (nthcdr 5 state) nil))
|
|
749 (setq inner-loop-done t)))
|
|
750 (and endpos
|
|
751 (<= next-depth 0)
|
|
752 (progn
|
|
753 (setq indent-stack (append indent-stack
|
|
754 (make-list (- next-depth) nil))
|
|
755 last-depth (- last-depth next-depth)
|
|
756 next-depth 0)))
|
|
757 (or outer-loop-done endpos
|
2
|
758 (setq outer-loop-done (<= next-depth 0)))
|
0
|
759 (if outer-loop-done
|
|
760 (forward-line 1)
|
|
761 (while (> last-depth next-depth)
|
|
762 (setq indent-stack (cdr indent-stack)
|
|
763 last-depth (1- last-depth)))
|
|
764 (while (< last-depth next-depth)
|
|
765 (setq indent-stack (cons nil indent-stack)
|
|
766 last-depth (1+ last-depth)))
|
|
767 ;; Now go to the next line and indent it according
|
|
768 ;; to what we learned from parsing the previous one.
|
|
769 (forward-line 1)
|
|
770 (setq bol (point))
|
|
771 (skip-chars-forward " \t")
|
|
772 ;; But not if the line is blank, or just a comment
|
|
773 ;; (except for double-semi comments; indent them as usual).
|
|
774 (if (or (eobp) (looking-at "\\s<\\|\n"))
|
|
775 nil
|
|
776 (if (and (car indent-stack)
|
|
777 (>= (car indent-stack) 0))
|
|
778 (setq this-indent (car indent-stack))
|
|
779 (let ((val (calculate-lisp-indent
|
2
|
780 (if (car indent-stack) (- (car indent-stack))
|
|
781 starting-point))))
|
0
|
782 (if (integerp val)
|
|
783 (setcar indent-stack
|
|
784 (setq this-indent val))
|
|
785 (setcar indent-stack (- (car (cdr val))))
|
|
786 (setq this-indent (car val)))))
|
|
787 (if (/= (current-column) this-indent)
|
|
788 (progn (delete-region bol (point))
|
|
789 (indent-to this-indent)))))
|
|
790 (or outer-loop-done
|
|
791 (setq outer-loop-done (= (point) last-point))
|
|
792 (setq last-point (point)))))))
|
|
793
|
|
794 ;; Indent every line whose first char is between START and END inclusive.
|
|
795 (defun lisp-indent-region (start end)
|
|
796 (save-excursion
|
|
797 (let ((endmark (copy-marker end)))
|
|
798 (goto-char start)
|
|
799 (and (bolp) (not (eolp))
|
|
800 (lisp-indent-line))
|
|
801 (indent-sexp endmark)
|
|
802 (set-marker endmark nil))))
|
|
803
|
|
804 ;;;; Lisp paragraph filling commands.
|
|
805
|
|
806 (defun lisp-fill-paragraph (&optional justify)
|
|
807 "Like \\[fill-paragraph], but handle Emacs Lisp comments.
|
|
808 If any of the current line is a comment, fill the comment or the
|
|
809 paragraph of it that point is in, preserving the comment's indentation
|
|
810 and initial semicolons."
|
|
811 (interactive "P")
|
|
812 (let (
|
|
813 ;; Non-nil if the current line contains a comment.
|
|
814 has-comment
|
|
815
|
2
|
816 ;; Non-nil if the current line contains code and a comment.
|
|
817 has-code-and-comment
|
|
818
|
0
|
819 ;; If has-comment, the appropriate fill-prefix for the comment.
|
|
820 comment-fill-prefix
|
|
821 )
|
|
822
|
|
823 ;; Figure out what kind of comment we are looking at.
|
|
824 (save-excursion
|
|
825 (beginning-of-line)
|
|
826 (cond
|
|
827
|
|
828 ;; A line with nothing but a comment on it?
|
|
829 ((looking-at "[ \t]*;[; \t]*")
|
|
830 (setq has-comment t
|
|
831 comment-fill-prefix (buffer-substring (match-beginning 0)
|
|
832 (match-end 0))))
|
|
833
|
|
834 ;; A line with some code, followed by a comment? Remember that the
|
|
835 ;; semi which starts the comment shouldn't be part of a string or
|
|
836 ;; character.
|
2
|
837 ;; XEmacs Try this the FSF and see if it works.
|
|
838 ; ((progn
|
|
839 ; (while (not (looking-at ";\\|$"))
|
|
840 ; (skip-chars-forward "^;\n\"\\\\?")
|
|
841 ; (cond
|
|
842 ; ((eq (char-after (point)) ?\\) (forward-char 2))
|
|
843 ; ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
|
|
844 ; (looking-at ";+[\t ]*"))
|
|
845 ; (setq has-comment t)
|
|
846 ((condition-case nil
|
|
847 (save-restriction
|
|
848 (narrow-to-region (point-min)
|
|
849 (save-excursion (end-of-line) (point)))
|
|
850 (while (not (looking-at ";\\|$"))
|
|
851 (skip-chars-forward "^;\n\"\\\\?")
|
|
852 (cond
|
|
853 ((eq (char-after (point)) ?\\) (forward-char 2))
|
|
854 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
|
|
855 (looking-at ";+[\t ]*"))
|
|
856 (error nil))
|
|
857 (setq has-comment t has-code-and-comment t)
|
0
|
858 (setq comment-fill-prefix
|
2
|
859 (concat (make-string (/ (current-column) 8) ?\t)
|
|
860 (make-string (% (current-column) 8) ?\ )
|
0
|
861 (buffer-substring (match-beginning 0) (match-end 0)))))))
|
|
862
|
|
863 (if (not has-comment)
|
|
864 (fill-paragraph justify)
|
|
865
|
|
866 ;; Narrow to include only the comment, and then fill the region.
|
2
|
867 (save-excursion
|
|
868 (save-restriction
|
|
869 (beginning-of-line)
|
|
870 (narrow-to-region
|
|
871 ;; Find the first line we should include in the region to fill.
|
|
872 (save-excursion
|
|
873 (while (and (zerop (forward-line -1))
|
0
|
874 (looking-at "^[ \t]*;")))
|
2
|
875 ;; We may have gone too far. Go forward again.
|
|
876 (or (looking-at ".*;")
|
|
877 (forward-line 1))
|
|
878 (point))
|
|
879 ;; Find the beginning of the first line past the region to fill.
|
|
880 (save-excursion
|
|
881 (while (progn (forward-line 1)
|
|
882 (looking-at "^[ \t]*;")))
|
|
883 (point)))
|
0
|
884
|
2
|
885 ;; Lines with only semicolons on them can be paragraph boundaries.
|
|
886 (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))
|
|
887 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
|
|
888 (paragraph-ignore-fill-prefix nil)
|
|
889 (fill-prefix comment-fill-prefix)
|
|
890 (after-line (if has-code-and-comment
|
|
891 (save-excursion
|
|
892 (forward-line 1) (point))))
|
|
893 (end (progn
|
|
894 (forward-paragraph)
|
|
895 (or (bolp) (newline 1))
|
|
896 (point)))
|
|
897 ;; If this comment starts on a line with code,
|
|
898 ;; include that like in the filling.
|
|
899 (beg (progn (backward-paragraph)
|
|
900 (if (eq (point) after-line)
|
|
901 (forward-line -1))
|
|
902 (point))))
|
|
903 (fill-region-as-paragraph beg end
|
|
904 justify nil
|
|
905 (save-excursion
|
|
906 (goto-char beg)
|
|
907 (if (looking-at fill-prefix)
|
|
908 nil
|
|
909 (re-search-forward comment-start-skip)
|
|
910 (point))))))))
|
0
|
911 t))
|
|
912
|
|
913 (defun indent-code-rigidly (start end arg &optional nochange-regexp)
|
|
914 "Indent all lines of code, starting in the region, sideways by ARG columns.
|
2
|
915 Does not affect lines starting inside comments or strings, assuming that
|
|
916 the start of the region is not inside them.
|
|
917
|
0
|
918 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
|
|
919 The last is a regexp which, if matched at the beginning of a line,
|
|
920 means don't indent that line."
|
|
921 (interactive "r\np")
|
|
922 (let (state)
|
|
923 (save-excursion
|
|
924 (goto-char end)
|
|
925 (setq end (point-marker))
|
|
926 (goto-char start)
|
|
927 (or (bolp)
|
|
928 (setq state (parse-partial-sexp (point)
|
|
929 (progn
|
|
930 (forward-line 1) (point))
|
|
931 nil nil state)))
|
|
932 (while (< (point) end)
|
|
933 (or (car (nthcdr 3 state))
|
|
934 (and nochange-regexp
|
|
935 (looking-at nochange-regexp))
|
|
936 ;; If line does not start in string, indent it
|
|
937 (let ((indent (current-indentation)))
|
|
938 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
|
|
939 (or (eolp)
|
|
940 (indent-to (max 0 (+ indent arg)) 0))))
|
|
941 (setq state (parse-partial-sexp (point)
|
|
942 (progn
|
|
943 (forward-line 1) (point))
|
|
944 nil nil state))))))
|
|
945
|
|
946 (provide 'lisp-mode)
|
|
947
|
|
948 ;;; lisp-mode.el ends here
|