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)
|
153
|
205 ;; GDF - don't rebind the DEL key
|
|
206 ;; (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify)
|
|
207
|
|
208 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp))
|
0
|
209
|
|
210 (defvar emacs-lisp-mode-map ()
|
|
211 "Keymap for Emacs Lisp mode.
|
|
212 All commands in `shared-lisp-mode-map' are inherited by this map.")
|
|
213
|
|
214 (if emacs-lisp-mode-map
|
|
215 ()
|
2
|
216 ;; XEmacs: Ignore FSF nconc stuff
|
0
|
217 (setq emacs-lisp-mode-map (make-sparse-keymap))
|
|
218 (set-keymap-name emacs-lisp-mode-map 'emacs-lisp-mode-map)
|
|
219 (set-keymap-parents emacs-lisp-mode-map (list shared-lisp-mode-map))
|
|
220 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
|
2
|
221 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
|
|
222 ;; XEmacs: Not sure what the FSF menu bindings are. I hope XEmacs
|
|
223 ;; doesn't need them.
|
|
224 )
|
0
|
225
|
|
226 (defun emacs-lisp-byte-compile ()
|
|
227 "Byte compile the file containing the current buffer."
|
|
228 (interactive)
|
|
229 (if buffer-file-name
|
2
|
230 ;; XEmacs change. Force buffer save first
|
0
|
231 (progn
|
|
232 (save-buffer)
|
|
233 (byte-compile-file buffer-file-name))
|
|
234 (error "The buffer must be saved in a file first.")))
|
|
235
|
2
|
236 (defun emacs-lisp-byte-compile-and-load ()
|
|
237 "Byte-compile the current file (if it has changed), then load compiled code."
|
|
238 (interactive)
|
|
239 (or buffer-file-name
|
|
240 (error "The buffer must be saved in a file first"))
|
|
241 (require 'bytecomp)
|
|
242 ;; Recompile if file or buffer has changed since last compilation.
|
|
243 (if (and (buffer-modified-p)
|
|
244 (y-or-n-p (format "save buffer %s first? " (buffer-name))))
|
|
245 (save-buffer))
|
|
246 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name)))
|
|
247 (if (file-newer-than-file-p compiled-file-name buffer-file-name)
|
|
248 (load-file compiled-file-name)
|
|
249 (byte-compile-file buffer-file-name t))))
|
|
250
|
0
|
251 (defun emacs-lisp-mode ()
|
|
252 "Major mode for editing Lisp code to run in Emacs.
|
|
253 Commands:
|
|
254 Delete converts tabs to spaces as it moves back.
|
|
255 Blank lines separate paragraphs. Semicolons start comments.
|
|
256 \\{emacs-lisp-mode-map}
|
|
257 Entry to this mode calls the value of `emacs-lisp-mode-hook'
|
|
258 if that value is non-nil."
|
|
259 (interactive)
|
|
260 (kill-all-local-variables)
|
|
261 (use-local-map emacs-lisp-mode-map)
|
|
262 (set-syntax-table emacs-lisp-mode-syntax-table)
|
2
|
263 ;; XEmacs changes
|
0
|
264 (setq major-mode 'emacs-lisp-mode
|
|
265 mode-popup-menu emacs-lisp-mode-popup-menu
|
|
266 mode-name "Emacs-Lisp")
|
|
267 (if (and (featurep 'menubar)
|
|
268 current-menubar)
|
|
269 (progn
|
|
270 ;; make a local copy of the menubar, so our modes don't
|
|
271 ;; change the global menubar
|
|
272 (set-buffer-menubar current-menubar)
|
|
273 (add-submenu nil emacs-lisp-mode-menubar-menu)))
|
|
274 (lisp-mode-variables nil)
|
|
275 (run-hooks 'emacs-lisp-mode-hook))
|
|
276
|
|
277 (defvar lisp-mode-map ()
|
|
278 "Keymap for ordinary Lisp mode.
|
|
279 All commands in `shared-lisp-mode-map' are inherited by this map.")
|
|
280
|
|
281 (if lisp-mode-map
|
|
282 ()
|
2
|
283 ;; XEmacs changes
|
0
|
284 (setq lisp-mode-map (make-sparse-keymap))
|
|
285 (set-keymap-name lisp-mode-map 'lisp-mode-map)
|
|
286 (set-keymap-parents lisp-mode-map (list shared-lisp-mode-map))
|
|
287 (define-key lisp-mode-map "\e\C-x" 'lisp-send-defun)
|
|
288 ;; gag, no. use ilisp. -jwz
|
|
289 ;; (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)
|
|
290 )
|
|
291
|
|
292 (defun lisp-mode ()
|
|
293 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
|
|
294 Commands:
|
|
295 Delete converts tabs to spaces as it moves back.
|
|
296 Blank lines separate paragraphs. Semicolons start comments.
|
|
297 \\{lisp-mode-map}
|
|
298 Note that `run-lisp' may be used either to start an inferior Lisp job
|
|
299 or to switch back to an existing one.
|
|
300
|
|
301 Entry to this mode calls the value of `lisp-mode-hook'
|
|
302 if that value is non-nil."
|
|
303 (interactive)
|
|
304 (kill-all-local-variables)
|
|
305 (use-local-map lisp-mode-map)
|
|
306 (setq major-mode 'lisp-mode)
|
|
307 (setq mode-name "Lisp")
|
|
308 (lisp-mode-variables t)
|
|
309 (set-syntax-table lisp-mode-syntax-table)
|
|
310 (run-hooks 'lisp-mode-hook))
|
|
311
|
|
312 ;; This will do unless shell.el is loaded.
|
2
|
313 ;; XEmacs change
|
0
|
314 (defun lisp-send-defun ()
|
|
315 "Send the current defun to the Lisp process made by \\[run-lisp]."
|
|
316 (interactive)
|
|
317 (error "Process lisp does not exist"))
|
|
318
|
|
319 ;; XEmacs change: emacs-lisp-mode-map is a more appropriate parent.
|
2
|
320 (defvar lisp-interaction-mode-map ()
|
108
|
321 "Keymap for Lisp Interaction mode.
|
2
|
322 All commands in `shared-lisp-mode-map' are inherited by this map.")
|
0
|
323
|
|
324 (if lisp-interaction-mode-map
|
|
325 ()
|
2
|
326 ;; XEmacs set keymap our way
|
0
|
327 (setq lisp-interaction-mode-map (make-sparse-keymap))
|
|
328 (set-keymap-name lisp-interaction-mode-map 'lisp-interaction-mode-map)
|
|
329 (set-keymap-parents lisp-interaction-mode-map (list emacs-lisp-mode-map))
|
|
330 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun)
|
|
331 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol)
|
|
332 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))
|
|
333
|
|
334 (defun lisp-interaction-mode ()
|
|
335 "Major mode for typing and evaluating Lisp forms.
|
|
336 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression
|
|
337 before point, and prints its value into the buffer, advancing point.
|
|
338
|
|
339 Commands:
|
|
340 Delete converts tabs to spaces as it moves back.
|
2
|
341 Paragraphs are separated only by blank lines.
|
|
342 Semicolons start comments.
|
0
|
343 \\{lisp-interaction-mode-map}
|
|
344 Entry to this mode calls the value of `lisp-interaction-mode-hook'
|
|
345 if that value is non-nil."
|
|
346 (interactive)
|
|
347 (kill-all-local-variables)
|
|
348 (use-local-map lisp-interaction-mode-map)
|
2
|
349 (setq major-mode 'lisp-interaction-mode)
|
|
350 (setq mode-name "Lisp Interaction")
|
|
351 ;; XEmacs change
|
|
352 (setq mode-popup-menu lisp-interaction-mode-popup-menu)
|
0
|
353 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
354 (lisp-mode-variables nil)
|
|
355 (run-hooks 'lisp-interaction-mode-hook))
|
|
356
|
|
357 (defun eval-print-last-sexp ()
|
|
358 "Evaluate sexp before point; print value into current buffer."
|
|
359 (interactive)
|
|
360 (let ((standard-output (current-buffer)))
|
|
361 (terpri)
|
|
362 (eval-last-sexp t)
|
|
363 (terpri)))
|
|
364
|
2
|
365 ;; XEmacs change
|
0
|
366 (defun eval-interactive (expr)
|
|
367 "Like `eval' except that it transforms defvars to defconsts."
|
|
368 ;; by Stig@hackvan.com
|
|
369 (if (and (consp expr)
|
|
370 (eq (car expr) 'defvar)
|
|
371 (> (length expr) 2))
|
98
|
372 (eval (cons 'defconst (cdr expr)))
|
0
|
373 (eval expr)))
|
|
374
|
100
|
375 ;; XEmacs change, based on Bob Weiner suggestion
|
|
376 (defun eval-last-sexp (eval-last-sexp-arg-internal) ;dynamic scoping wonderment
|
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)))
|
100
|
382 (prin1 (let ((stab (syntax-table))
|
|
383 expr)
|
|
384 (eval-interactive
|
|
385 (unwind-protect
|
|
386 (save-excursion
|
|
387 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
388 (forward-sexp -1)
|
|
389 (save-restriction
|
|
390 (narrow-to-region (point-min) opoint)
|
|
391 (setq expr (read (current-buffer)))
|
|
392 (if (and (consp expr)
|
|
393 (eq (car expr) 'interactive))
|
|
394 (list 'quote
|
|
395 (call-interactively
|
|
396 (eval (` (lambda (&rest args)
|
|
397 (, expr) args)))))
|
|
398 expr)))
|
|
399 (set-syntax-table stab)))))))
|
0
|
400
|
2
|
401 (defun eval-defun (eval-defun-arg-internal)
|
0
|
402 "Evaluate defun that point is in or before.
|
|
403 Print value in minibuffer.
|
|
404 With argument, insert value in current buffer after the defun."
|
|
405 (interactive "P")
|
2
|
406 ;; XEmacs: FSF version works, so use it
|
|
407 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t))
|
|
408 (form (save-excursion
|
|
409 (end-of-defun)
|
|
410 (beginning-of-defun)
|
|
411 (read (current-buffer)))))
|
120
|
412 (cond ((and (eq (car form) 'defvar)
|
|
413 (cdr-safe (cdr-safe form)))
|
|
414 ;; Force variable to be bound.
|
|
415 (setq form (cons 'defconst (cdr form))))
|
|
416 ((and (eq (car form) 'defcustom)
|
|
417 (default-boundp (nth 1 form)))
|
|
418 ;; Force variable to be bound.
|
|
419 (set-default (nth 1 form) (eval (nth 2 form)))))
|
2
|
420 (prin1 (eval form))))
|
0
|
421
|
|
422 (defun lisp-comment-indent ()
|
|
423 (if (looking-at "\\s<\\s<\\s<")
|
|
424 (current-column)
|
|
425 (if (looking-at "\\s<\\s<")
|
|
426 (let ((tem (calculate-lisp-indent)))
|
|
427 (if (listp tem) (car tem) tem))
|
|
428 (skip-chars-backward " \t")
|
|
429 (max (if (bolp) 0 (1+ (current-column)))
|
|
430 comment-column))))
|
|
431
|
2
|
432 ;; XEmacs change
|
0
|
433 (defun lisp-indent-for-comment ()
|
|
434 "Indent this line's comment appropriately, or insert an empty comment.
|
|
435 If adding a new comment on a blank line, use `block-comment-start' instead
|
|
436 of `comment-start' to open the comment."
|
|
437 ;; by Stig@hackvan.com
|
|
438 ;; #### - This functionality, the recognition of block-comment-{start,end},
|
|
439 ;; will perhaps be standardized across modes and move to indent-for-comment.
|
|
440 (interactive)
|
|
441 (if (and block-comment-start
|
|
442 (save-excursion (beginning-of-line) (looking-at "^[ \t]*$")))
|
|
443 (insert block-comment-start))
|
|
444 (indent-for-comment))
|
|
445
|
|
446 (defconst lisp-indent-offset nil "")
|
|
447 (defconst lisp-indent-function 'lisp-indent-function "")
|
|
448
|
|
449 (defun lisp-indent-line (&optional whole-exp)
|
|
450 "Indent current line as Lisp code.
|
|
451 With argument, indent any additional lines of the same expression
|
|
452 rigidly along with this one."
|
|
453 (interactive "P")
|
|
454 (let ((indent (calculate-lisp-indent)) shift-amt beg end
|
|
455 (pos (- (point-max) (point))))
|
|
456 (beginning-of-line)
|
|
457 (setq beg (point))
|
|
458 (skip-chars-forward " \t")
|
|
459 (if (looking-at "\\s<\\s<\\s<")
|
|
460 ;; Don't alter indentation of a ;;; comment line.
|
|
461 (goto-char (- (point-max) pos))
|
|
462 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
|
|
463 ;; Single-semicolon comment lines should be indented
|
|
464 ;; as comment lines, not as code.
|
|
465 (progn (indent-for-comment) (forward-char -1))
|
|
466 (if (listp indent) (setq indent (car indent)))
|
|
467 (setq shift-amt (- indent (current-column)))
|
|
468 (if (zerop shift-amt)
|
|
469 nil
|
|
470 (delete-region beg (point))
|
|
471 (indent-to indent)))
|
|
472 ;; If initial point was within line's indentation,
|
|
473 ;; position after the indentation. Else stay at same point in text.
|
|
474 (if (> (- (point-max) pos) (point))
|
|
475 (goto-char (- (point-max) pos)))
|
|
476 ;; If desired, shift remaining lines of expression the same amount.
|
|
477 (and whole-exp (not (zerop shift-amt))
|
|
478 (save-excursion
|
|
479 (goto-char beg)
|
|
480 (forward-sexp 1)
|
|
481 (setq end (point))
|
|
482 (goto-char beg)
|
|
483 (forward-line 1)
|
|
484 (setq beg (point))
|
|
485 (> end beg))
|
|
486 (indent-code-rigidly beg end shift-amt)))))
|
|
487
|
|
488 (defvar calculate-lisp-indent-last-sexp)
|
|
489
|
|
490 (defun calculate-lisp-indent (&optional parse-start)
|
|
491 "Return appropriate indentation for current line as Lisp code.
|
|
492 In usual case returns an integer: the column to indent to.
|
|
493 Can instead return a list, whose car is the column to indent to.
|
|
494 This means that following lines at the same level of indentation
|
|
495 should not necessarily be indented the same way.
|
|
496 The second element of the list is the buffer position
|
|
497 of the start of the containing expression."
|
|
498 (save-excursion
|
|
499 (beginning-of-line)
|
|
500 (let ((indent-point (point))
|
2
|
501 ;; XEmacs change (remove paren-depth)
|
0
|
502 state ;;paren-depth
|
|
503 ;; setting this to a number inhibits calling hook
|
|
504 (desired-indent nil)
|
|
505 (retry t)
|
|
506 calculate-lisp-indent-last-sexp containing-sexp)
|
|
507 (if parse-start
|
|
508 (goto-char parse-start)
|
|
509 (beginning-of-defun))
|
|
510 ;; Find outermost containing sexp
|
|
511 (while (< (point) indent-point)
|
|
512 (setq state (parse-partial-sexp (point) indent-point 0)))
|
|
513 ;; Find innermost containing sexp
|
|
514 (while (and retry
|
|
515 state
|
2
|
516 ;; XEmacs change (remove paren-depth)
|
0
|
517 (> ;;(setq paren-depth (elt state 0))
|
|
518 (elt state 0)
|
|
519 0))
|
|
520 (setq retry nil)
|
|
521 (setq calculate-lisp-indent-last-sexp (elt state 2))
|
|
522 (setq containing-sexp (elt state 1))
|
|
523 ;; Position following last unclosed open.
|
|
524 (goto-char (1+ containing-sexp))
|
|
525 ;; Is there a complete sexp since then?
|
|
526 (if (and calculate-lisp-indent-last-sexp
|
|
527 (> calculate-lisp-indent-last-sexp (point)))
|
|
528 ;; Yes, but is there a containing sexp after that?
|
|
529 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp
|
|
530 indent-point 0)))
|
|
531 (if (setq retry (car (cdr peek))) (setq state peek)))))
|
|
532 (if retry
|
|
533 nil
|
|
534 ;; Innermost containing sexp found
|
|
535 (goto-char (1+ containing-sexp))
|
|
536 (if (not calculate-lisp-indent-last-sexp)
|
|
537 ;; indent-point immediately follows open paren.
|
|
538 ;; Don't call hook.
|
|
539 (setq desired-indent (current-column))
|
|
540 ;; Find the start of first element of containing sexp.
|
|
541 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
542 (cond ((looking-at "\\s(")
|
|
543 ;; First element of containing sexp is a list.
|
|
544 ;; Indent under that list.
|
|
545 )
|
|
546 ((> (save-excursion (forward-line 1) (point))
|
|
547 calculate-lisp-indent-last-sexp)
|
|
548 ;; This is the first line to start within the containing sexp.
|
|
549 ;; It's almost certainly a function call.
|
|
550 (if (= (point) calculate-lisp-indent-last-sexp)
|
|
551 ;; Containing sexp has nothing before this line
|
|
552 ;; except the first element. Indent under that element.
|
|
553 nil
|
|
554 ;; Skip the first element, find start of second (the first
|
|
555 ;; argument of the function call) and indent under.
|
|
556 (progn (forward-sexp 1)
|
|
557 (parse-partial-sexp (point)
|
|
558 calculate-lisp-indent-last-sexp
|
|
559 0 t)))
|
|
560 (backward-prefix-chars))
|
|
561 (t
|
|
562 ;; Indent beneath first sexp on same line as
|
|
563 ;; calculate-lisp-indent-last-sexp. Again, it's
|
|
564 ;; almost certainly a function call.
|
|
565 (goto-char calculate-lisp-indent-last-sexp)
|
|
566 (beginning-of-line)
|
|
567 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp
|
|
568 0 t)
|
|
569 (backward-prefix-chars)))))
|
|
570 ;; Point is at the point to indent under unless we are inside a string.
|
|
571 ;; Call indentation hook except when overridden by lisp-indent-offset
|
|
572 ;; or if the desired indentation has already been computed.
|
|
573 (let ((normal-indent (current-column)))
|
|
574 (cond ((elt state 3)
|
|
575 ;; Inside a string, don't change indentation.
|
|
576 (goto-char indent-point)
|
|
577 (skip-chars-forward " \t")
|
|
578 (current-column))
|
|
579 (desired-indent)
|
|
580 ((and (boundp 'lisp-indent-function)
|
|
581 lisp-indent-function
|
|
582 (not retry))
|
|
583 (or (funcall lisp-indent-function indent-point state)
|
|
584 normal-indent))
|
2
|
585 ;; XEmacs change:
|
0
|
586 ;; lisp-indent-offset shouldn't override lisp-indent-function !
|
|
587 ((and (integerp lisp-indent-offset) containing-sexp)
|
|
588 ;; Indent by constant offset
|
|
589 (goto-char containing-sexp)
|
|
590 (+ normal-indent lisp-indent-offset))
|
|
591 (t
|
|
592 normal-indent))))))
|
|
593
|
|
594 (defun lisp-indent-function (indent-point state)
|
|
595 ;; free reference to `calculate-lisp-indent-last-sexp'
|
|
596 ;; in #'calculate-lisp-indent
|
|
597 (let ((normal-indent (current-column)))
|
|
598 (goto-char (1+ (elt state 1)))
|
|
599 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
600 (if (and (elt state 2)
|
|
601 (not (looking-at "\\sw\\|\\s_")))
|
|
602 ;; car of form doesn't seem to be a a symbol
|
|
603 (progn
|
|
604 (if (not (> (save-excursion (forward-line 1) (point))
|
|
605 calculate-lisp-indent-last-sexp))
|
|
606 (progn (goto-char calculate-lisp-indent-last-sexp)
|
|
607 (beginning-of-line)
|
|
608 (parse-partial-sexp (point)
|
|
609 calculate-lisp-indent-last-sexp 0 t)))
|
|
610 ;; Indent under the list or under the first sexp on the same
|
|
611 ;; line as calculate-lisp-indent-last-sexp. Note that first
|
|
612 ;; thing on that line has to be complete sexp since we are
|
|
613 ;; inside the innermost containing sexp.
|
|
614 (backward-prefix-chars)
|
|
615 (current-column))
|
|
616 (let ((function (buffer-substring (point)
|
|
617 (progn (forward-sexp 1) (point))))
|
|
618 method)
|
|
619 (setq method (or (get (intern-soft function) 'lisp-indent-function)
|
2
|
620 (get (intern-soft function) 'lisp-indent-hook)))
|
0
|
621 (cond ((or (eq method 'defun)
|
|
622 (and (null method)
|
|
623 (> (length function) 3)
|
|
624 (string-match "\\`def" function)))
|
|
625 (lisp-indent-defform state indent-point))
|
|
626 ((integerp method)
|
|
627 (lisp-indent-specform method state
|
|
628 indent-point normal-indent))
|
|
629 (method
|
|
630 (funcall method state indent-point)))))))
|
|
631
|
|
632 (defconst lisp-body-indent 2
|
|
633 "Number of columns to indent the second line of a `(def...)' form.")
|
|
634
|
|
635 (defun lisp-indent-specform (count state indent-point normal-indent)
|
|
636 (let ((containing-form-start (elt state 1))
|
|
637 (i count)
|
|
638 body-indent containing-form-column)
|
|
639 ;; Move to the start of containing form, calculate indentation
|
|
640 ;; to use for non-distinguished forms (> count), and move past the
|
|
641 ;; function symbol. lisp-indent-function guarantees that there is at
|
|
642 ;; least one word or symbol character following open paren of containing
|
|
643 ;; form.
|
|
644 (goto-char containing-form-start)
|
|
645 (setq containing-form-column (current-column))
|
|
646 (setq body-indent (+ lisp-body-indent containing-form-column))
|
|
647 (forward-char 1)
|
|
648 (forward-sexp 1)
|
|
649 ;; Now find the start of the last form.
|
|
650 (parse-partial-sexp (point) indent-point 1 t)
|
|
651 (while (and (< (point) indent-point)
|
|
652 (condition-case ()
|
|
653 (progn
|
|
654 (setq count (1- count))
|
|
655 (forward-sexp 1)
|
|
656 (parse-partial-sexp (point) indent-point 1 t))
|
|
657 (error nil))))
|
|
658 ;; Point is sitting on first character of last (or count) sexp.
|
|
659 (if (> count 0)
|
|
660 ;; A distinguished form. If it is the first or second form use double
|
|
661 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound
|
|
662 ;; to 2 (the default), this just happens to work the same with if as
|
|
663 ;; the older code, but it makes unwind-protect, condition-case,
|
|
664 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older,
|
|
665 ;; less hacked, behavior can be obtained by replacing below with
|
|
666 ;; (list normal-indent containing-form-start).
|
|
667 (if (<= (- i count) 1)
|
|
668 (list (+ containing-form-column (* 2 lisp-body-indent))
|
|
669 containing-form-start)
|
|
670 (list normal-indent containing-form-start))
|
|
671 ;; A non-distinguished form. Use body-indent if there are no
|
|
672 ;; distinguished forms and this is the first undistinguished form,
|
|
673 ;; or if this is the first undistinguished form and the preceding
|
|
674 ;; distinguished form has indentation at least as great as body-indent.
|
|
675 (if (or (and (= i 0) (= count 0))
|
|
676 (and (= count 0) (<= body-indent normal-indent)))
|
|
677 body-indent
|
|
678 normal-indent))))
|
|
679
|
|
680 (defun lisp-indent-defform (state indent-point)
|
|
681 (goto-char (car (cdr state)))
|
|
682 (forward-line 1)
|
|
683 (if (> (point) (car (cdr (cdr state))))
|
|
684 (progn
|
|
685 (goto-char (car (cdr state)))
|
|
686 (+ lisp-body-indent (current-column)))))
|
|
687
|
|
688
|
|
689 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
|
|
690 ;; like defun if the first form is placed on the next line, otherwise
|
|
691 ;; it is indented like any other form (i.e. forms line up under first).
|
|
692
|
|
693 (put 'lambda 'lisp-indent-function 'defun)
|
|
694 (put 'autoload 'lisp-indent-function 'defun)
|
|
695 (put 'progn 'lisp-indent-function 0)
|
|
696 (put 'prog1 'lisp-indent-function 1)
|
|
697 (put 'prog2 'lisp-indent-function 2)
|
|
698 (put 'save-excursion 'lisp-indent-function 0)
|
|
699 (put 'save-window-excursion 'lisp-indent-function 0)
|
|
700 (put 'save-selected-window 'lisp-indent-function 0)
|
|
701 (put 'save-restriction 'lisp-indent-function 0)
|
|
702 (put 'save-match-data 'lisp-indent-function 0)
|
|
703 (put 'let 'lisp-indent-function 1)
|
|
704 (put 'let* 'lisp-indent-function 1)
|
|
705 (put 'while 'lisp-indent-function 1)
|
|
706 (put 'if 'lisp-indent-function 2)
|
|
707 (put 'catch 'lisp-indent-function 1)
|
|
708 (put 'condition-case 'lisp-indent-function 2)
|
|
709 (put 'unwind-protect 'lisp-indent-function 1)
|
|
710 (put 'with-output-to-temp-buffer 'lisp-indent-function 1)
|
|
711
|
|
712 (defun indent-sexp (&optional endpos)
|
|
713 "Indent each line of the list starting just after point.
|
|
714 If optional arg ENDPOS is given, indent each line, stopping when
|
|
715 ENDPOS is encountered."
|
|
716 (interactive)
|
|
717 (let ((indent-stack (list nil))
|
2
|
718 (next-depth 0)
|
0
|
719 ;; If ENDPOS is non-nil, use nil as STARTING-POINT
|
|
720 ;; so that calculate-lisp-indent will find the beginning of
|
|
721 ;; the defun we are in.
|
|
722 ;; If ENDPOS is nil, it is safe not to scan before point
|
|
723 ;; since every line we indent is more deeply nested than point is.
|
|
724 (starting-point (if endpos nil (point)))
|
2
|
725 (last-point (point))
|
|
726 last-depth bol outer-loop-done inner-loop-done state this-indent)
|
0
|
727 (or endpos
|
|
728 ;; Get error now if we don't have a complete sexp after point.
|
|
729 (save-excursion (forward-sexp 1)))
|
|
730 (save-excursion
|
|
731 (setq outer-loop-done nil)
|
|
732 (while (if endpos (< (point) endpos)
|
|
733 (not outer-loop-done))
|
|
734 (setq last-depth next-depth
|
|
735 inner-loop-done nil)
|
|
736 ;; Parse this line so we can learn the state
|
|
737 ;; to indent the next line.
|
|
738 ;; This inner loop goes through only once
|
|
739 ;; unless a line ends inside a string.
|
|
740 (while (and (not inner-loop-done)
|
|
741 (not (setq outer-loop-done (eobp))))
|
|
742 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
|
|
743 nil nil state))
|
|
744 (setq next-depth (car state))
|
|
745 ;; If the line contains a comment other than the sort
|
|
746 ;; that is indented like code,
|
|
747 ;; indent it now with indent-for-comment.
|
|
748 ;; Comments indented like code are right already.
|
|
749 ;; In any case clear the in-comment flag in the state
|
|
750 ;; because parse-partial-sexp never sees the newlines.
|
|
751 (if (car (nthcdr 4 state))
|
|
752 (progn (indent-for-comment)
|
|
753 (end-of-line)
|
|
754 (setcar (nthcdr 4 state) nil)))
|
|
755 ;; If this line ends inside a string,
|
|
756 ;; go straight to next line, remaining within the inner loop,
|
|
757 ;; and turn off the \-flag.
|
|
758 (if (car (nthcdr 3 state))
|
|
759 (progn
|
|
760 (forward-line 1)
|
|
761 (setcar (nthcdr 5 state) nil))
|
|
762 (setq inner-loop-done t)))
|
|
763 (and endpos
|
|
764 (<= next-depth 0)
|
|
765 (progn
|
|
766 (setq indent-stack (append indent-stack
|
|
767 (make-list (- next-depth) nil))
|
|
768 last-depth (- last-depth next-depth)
|
|
769 next-depth 0)))
|
|
770 (or outer-loop-done endpos
|
2
|
771 (setq outer-loop-done (<= next-depth 0)))
|
0
|
772 (if outer-loop-done
|
|
773 (forward-line 1)
|
|
774 (while (> last-depth next-depth)
|
|
775 (setq indent-stack (cdr indent-stack)
|
|
776 last-depth (1- last-depth)))
|
|
777 (while (< last-depth next-depth)
|
|
778 (setq indent-stack (cons nil indent-stack)
|
|
779 last-depth (1+ last-depth)))
|
|
780 ;; Now go to the next line and indent it according
|
|
781 ;; to what we learned from parsing the previous one.
|
|
782 (forward-line 1)
|
|
783 (setq bol (point))
|
|
784 (skip-chars-forward " \t")
|
|
785 ;; But not if the line is blank, or just a comment
|
|
786 ;; (except for double-semi comments; indent them as usual).
|
|
787 (if (or (eobp) (looking-at "\\s<\\|\n"))
|
|
788 nil
|
|
789 (if (and (car indent-stack)
|
|
790 (>= (car indent-stack) 0))
|
|
791 (setq this-indent (car indent-stack))
|
|
792 (let ((val (calculate-lisp-indent
|
2
|
793 (if (car indent-stack) (- (car indent-stack))
|
|
794 starting-point))))
|
0
|
795 (if (integerp val)
|
|
796 (setcar indent-stack
|
|
797 (setq this-indent val))
|
|
798 (setcar indent-stack (- (car (cdr val))))
|
|
799 (setq this-indent (car val)))))
|
|
800 (if (/= (current-column) this-indent)
|
|
801 (progn (delete-region bol (point))
|
|
802 (indent-to this-indent)))))
|
|
803 (or outer-loop-done
|
|
804 (setq outer-loop-done (= (point) last-point))
|
|
805 (setq last-point (point)))))))
|
|
806
|
|
807 ;; Indent every line whose first char is between START and END inclusive.
|
|
808 (defun lisp-indent-region (start end)
|
|
809 (save-excursion
|
|
810 (let ((endmark (copy-marker end)))
|
|
811 (goto-char start)
|
|
812 (and (bolp) (not (eolp))
|
|
813 (lisp-indent-line))
|
|
814 (indent-sexp endmark)
|
|
815 (set-marker endmark nil))))
|
|
816
|
|
817 ;;;; Lisp paragraph filling commands.
|
|
818
|
|
819 (defun lisp-fill-paragraph (&optional justify)
|
|
820 "Like \\[fill-paragraph], but handle Emacs Lisp comments.
|
|
821 If any of the current line is a comment, fill the comment or the
|
|
822 paragraph of it that point is in, preserving the comment's indentation
|
|
823 and initial semicolons."
|
|
824 (interactive "P")
|
|
825 (let (
|
|
826 ;; Non-nil if the current line contains a comment.
|
|
827 has-comment
|
|
828
|
2
|
829 ;; Non-nil if the current line contains code and a comment.
|
|
830 has-code-and-comment
|
|
831
|
0
|
832 ;; If has-comment, the appropriate fill-prefix for the comment.
|
|
833 comment-fill-prefix
|
|
834 )
|
|
835
|
|
836 ;; Figure out what kind of comment we are looking at.
|
|
837 (save-excursion
|
|
838 (beginning-of-line)
|
|
839 (cond
|
|
840
|
|
841 ;; A line with nothing but a comment on it?
|
|
842 ((looking-at "[ \t]*;[; \t]*")
|
|
843 (setq has-comment t
|
|
844 comment-fill-prefix (buffer-substring (match-beginning 0)
|
|
845 (match-end 0))))
|
|
846
|
|
847 ;; A line with some code, followed by a comment? Remember that the
|
|
848 ;; semi which starts the comment shouldn't be part of a string or
|
|
849 ;; character.
|
2
|
850 ;; XEmacs Try this the FSF and see if it works.
|
|
851 ; ((progn
|
|
852 ; (while (not (looking-at ";\\|$"))
|
|
853 ; (skip-chars-forward "^;\n\"\\\\?")
|
|
854 ; (cond
|
|
855 ; ((eq (char-after (point)) ?\\) (forward-char 2))
|
|
856 ; ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
|
|
857 ; (looking-at ";+[\t ]*"))
|
|
858 ; (setq has-comment t)
|
|
859 ((condition-case nil
|
|
860 (save-restriction
|
|
861 (narrow-to-region (point-min)
|
|
862 (save-excursion (end-of-line) (point)))
|
|
863 (while (not (looking-at ";\\|$"))
|
|
864 (skip-chars-forward "^;\n\"\\\\?")
|
|
865 (cond
|
|
866 ((eq (char-after (point)) ?\\) (forward-char 2))
|
|
867 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
|
|
868 (looking-at ";+[\t ]*"))
|
|
869 (error nil))
|
|
870 (setq has-comment t has-code-and-comment t)
|
0
|
871 (setq comment-fill-prefix
|
2
|
872 (concat (make-string (/ (current-column) 8) ?\t)
|
|
873 (make-string (% (current-column) 8) ?\ )
|
0
|
874 (buffer-substring (match-beginning 0) (match-end 0)))))))
|
|
875
|
|
876 (if (not has-comment)
|
|
877 (fill-paragraph justify)
|
|
878
|
|
879 ;; Narrow to include only the comment, and then fill the region.
|
2
|
880 (save-excursion
|
|
881 (save-restriction
|
|
882 (beginning-of-line)
|
|
883 (narrow-to-region
|
|
884 ;; Find the first line we should include in the region to fill.
|
|
885 (save-excursion
|
|
886 (while (and (zerop (forward-line -1))
|
0
|
887 (looking-at "^[ \t]*;")))
|
2
|
888 ;; We may have gone too far. Go forward again.
|
|
889 (or (looking-at ".*;")
|
|
890 (forward-line 1))
|
|
891 (point))
|
|
892 ;; Find the beginning of the first line past the region to fill.
|
|
893 (save-excursion
|
|
894 (while (progn (forward-line 1)
|
|
895 (looking-at "^[ \t]*;")))
|
|
896 (point)))
|
0
|
897
|
2
|
898 ;; Lines with only semicolons on them can be paragraph boundaries.
|
|
899 (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))
|
|
900 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
|
|
901 (paragraph-ignore-fill-prefix nil)
|
|
902 (fill-prefix comment-fill-prefix)
|
|
903 (after-line (if has-code-and-comment
|
|
904 (save-excursion
|
|
905 (forward-line 1) (point))))
|
|
906 (end (progn
|
|
907 (forward-paragraph)
|
|
908 (or (bolp) (newline 1))
|
|
909 (point)))
|
|
910 ;; If this comment starts on a line with code,
|
|
911 ;; include that like in the filling.
|
|
912 (beg (progn (backward-paragraph)
|
|
913 (if (eq (point) after-line)
|
|
914 (forward-line -1))
|
|
915 (point))))
|
|
916 (fill-region-as-paragraph beg end
|
|
917 justify nil
|
|
918 (save-excursion
|
|
919 (goto-char beg)
|
|
920 (if (looking-at fill-prefix)
|
|
921 nil
|
|
922 (re-search-forward comment-start-skip)
|
|
923 (point))))))))
|
0
|
924 t))
|
|
925
|
|
926 (defun indent-code-rigidly (start end arg &optional nochange-regexp)
|
|
927 "Indent all lines of code, starting in the region, sideways by ARG columns.
|
2
|
928 Does not affect lines starting inside comments or strings, assuming that
|
|
929 the start of the region is not inside them.
|
|
930
|
0
|
931 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
|
|
932 The last is a regexp which, if matched at the beginning of a line,
|
|
933 means don't indent that line."
|
|
934 (interactive "r\np")
|
|
935 (let (state)
|
|
936 (save-excursion
|
|
937 (goto-char end)
|
|
938 (setq end (point-marker))
|
|
939 (goto-char start)
|
|
940 (or (bolp)
|
|
941 (setq state (parse-partial-sexp (point)
|
|
942 (progn
|
|
943 (forward-line 1) (point))
|
|
944 nil nil state)))
|
|
945 (while (< (point) end)
|
|
946 (or (car (nthcdr 3 state))
|
|
947 (and nochange-regexp
|
|
948 (looking-at nochange-regexp))
|
|
949 ;; If line does not start in string, indent it
|
|
950 (let ((indent (current-indentation)))
|
|
951 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
|
|
952 (or (eolp)
|
|
953 (indent-to (max 0 (+ indent arg)) 0))))
|
|
954 (setq state (parse-partial-sexp (point)
|
|
955 (progn
|
|
956 (forward-line 1) (point))
|
|
957 nil nil state))))))
|
|
958
|
|
959 (provide 'lisp-mode)
|
|
960
|
|
961 ;;; lisp-mode.el ends here
|