e0030ea766a71fe0c4e60564a7ba2ff1306dbe01
[bpt/emacs.git] / lisp / emacs-lisp / lisp-mode.el
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands
2
3 ;; Copyright (C) 1985, 1986, 1999, 2000, 2001 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: lisp, languages
7
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; The base major mode for editing Lisp code (used also for Emacs Lisp).
28 ;; This mode is documented in the Emacs manual.
29
30 ;;; Code:
31
32 (defvar lisp-mode-abbrev-table nil)
33
34 (defvar emacs-lisp-mode-syntax-table
35 (let ((table (make-syntax-table)))
36 (let ((i 0))
37 (while (< i ?0)
38 (modify-syntax-entry i "_ " table)
39 (setq i (1+ i)))
40 (setq i (1+ ?9))
41 (while (< i ?A)
42 (modify-syntax-entry i "_ " table)
43 (setq i (1+ i)))
44 (setq i (1+ ?Z))
45 (while (< i ?a)
46 (modify-syntax-entry i "_ " table)
47 (setq i (1+ i)))
48 (setq i (1+ ?z))
49 (while (< i 128)
50 (modify-syntax-entry i "_ " table)
51 (setq i (1+ i)))
52 (modify-syntax-entry ? " " table)
53 (modify-syntax-entry ?\t " " table)
54 (modify-syntax-entry ?\f " " table)
55 (modify-syntax-entry ?\n "> " table)
56 ;; Give CR the same syntax as newline, for selective-display.
57 (modify-syntax-entry ?\^m "> " table)
58 (modify-syntax-entry ?\; "< " table)
59 (modify-syntax-entry ?` "' " table)
60 (modify-syntax-entry ?' "' " table)
61 (modify-syntax-entry ?, "' " table)
62 ;; Used to be singlequote; changed for flonums.
63 (modify-syntax-entry ?. "_ " table)
64 (modify-syntax-entry ?# "' " table)
65 (modify-syntax-entry ?\" "\" " table)
66 (modify-syntax-entry ?\\ "\\ " table)
67 (modify-syntax-entry ?\( "() " table)
68 (modify-syntax-entry ?\) ")( " table)
69 (modify-syntax-entry ?\[ "(] " table)
70 (modify-syntax-entry ?\] ")[ " table))
71 table))
72
73 (defvar lisp-mode-syntax-table
74 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
75 (modify-syntax-entry ?\[ "_ " table)
76 (modify-syntax-entry ?\] "_ " table)
77 (modify-syntax-entry ?# "' 14bn" table)
78 (modify-syntax-entry ?| "\" 23b" table)
79 table))
80
81 (define-abbrev-table 'lisp-mode-abbrev-table ())
82
83 (defvar lisp-imenu-generic-expression
84 (list
85 (list nil
86 (purecopy (concat "^\\s-*("
87 (eval-when-compile
88 (regexp-opt
89 '("defun" "defun*" "defsubst" "defmacro"
90 "defadvice" "define-skeleton"
91 "define-minor-mode" "define-derived-mode"
92 "define-compiler-macro" "define-modify-macro"
93 "defsetf" "define-setf-expander"
94 "define-method-combination"
95 "defgeneric" "defmethod") t))
96 "\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)"))
97 2)
98 (list (purecopy "Variables")
99 (purecopy (concat "^\\s-*("
100 (eval-when-compile
101 (regexp-opt
102 '("defvar" "defconst" "defconstant" "defcustom"
103 "defparameter" "define-symbol-macro") t))
104 "\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)"))
105 2)
106 (list (purecopy "Types")
107 (purecopy (concat "^\\s-*("
108 (eval-when-compile
109 (regexp-opt
110 '("defgroup" "deftheme" "deftype" "defstruct"
111 "defclass" "define-condition" "define-widget"
112 "defface" "defpackage") t))
113 "\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)"))
114 2))
115
116 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
117
118 ;; This was originally in autoload.el and is still used there.
119 (put 'autoload 'doc-string-elt 3)
120 (put 'defun 'doc-string-elt 3)
121 (put 'defun* 'doc-string-elt 3)
122 (put 'defvar 'doc-string-elt 3)
123 (put 'defcustom 'doc-string-elt 3)
124 (put 'deftheme 'doc-string-elt 2)
125 (put 'defconst 'doc-string-elt 3)
126 (put 'defmacro 'doc-string-elt 3)
127 (put 'defmacro* 'doc-string-elt 3)
128 (put 'defsubst 'doc-string-elt 3)
129 (put 'define-skeleton 'doc-string-elt 2)
130 (put 'define-derived-mode 'doc-string-elt 4)
131 (put 'easy-mmode-define-minor-mode 'doc-string-elt 2)
132 (put 'define-minor-mode 'doc-string-elt 2)
133 (put 'define-generic-mode 'doc-string-elt 7)
134 ;; define-global-mode has no explicit docstring.
135 (put 'easy-mmode-define-global-mode 'doc-string-elt 0)
136 (put 'define-ibuffer-filter 'doc-string-elt 2)
137 (put 'define-ibuffer-op 'doc-string-elt 3)
138 (put 'define-ibuffer-sorter 'doc-string-elt 2)
139
140 (defun lisp-font-lock-syntactic-face-function (state)
141 (if (nth 3 state)
142 (if (and (eq (nth 0 state) 1)
143 ;; This might be a docstring.
144 (save-excursion
145 (let ((n 0))
146 (goto-char (nth 8 state))
147 (condition-case nil
148 (while (progn (backward-sexp 1) (setq n (1+ n))))
149 (scan-error nil))
150 (when (> n 0)
151 (let ((sym (intern-soft
152 (buffer-substring
153 (point) (progn (forward-sexp 1) (point))))))
154 (eq n (or (get sym 'doc-string-elt) 3)))))))
155 font-lock-doc-face
156 font-lock-string-face)
157 font-lock-comment-face))
158
159 ;; The LISP-SYNTAX argument is used by code in inf-lisp.el and is
160 ;; (uselessly) passed from pp.el, chistory.el, gnus-kill.el and score-mode.el
161 (defun lisp-mode-variables (&optional lisp-syntax)
162 (when lisp-syntax
163 (set-syntax-table lisp-mode-syntax-table))
164 (setq local-abbrev-table lisp-mode-abbrev-table)
165 (make-local-variable 'paragraph-ignore-fill-prefix)
166 (setq paragraph-ignore-fill-prefix t)
167 (make-local-variable 'fill-paragraph-function)
168 (setq fill-paragraph-function 'lisp-fill-paragraph)
169 ;; Adaptive fill mode gets in the way of auto-fill,
170 ;; and should make no difference for explicit fill
171 ;; because lisp-fill-paragraph should do the job.
172 ;; I believe that newcomment's auto-fill code properly deals with it -stef
173 ;;(set (make-local-variable 'adaptive-fill-mode) nil)
174 (make-local-variable 'normal-auto-fill-function)
175 (setq normal-auto-fill-function 'lisp-mode-auto-fill)
176 (make-local-variable 'indent-line-function)
177 (setq indent-line-function 'lisp-indent-line)
178 (make-local-variable 'indent-region-function)
179 (setq indent-region-function 'lisp-indent-region)
180 (make-local-variable 'parse-sexp-ignore-comments)
181 (setq parse-sexp-ignore-comments t)
182 (make-local-variable 'outline-regexp)
183 (setq outline-regexp ";;;;* \\|(")
184 (make-local-variable 'outline-level)
185 (setq outline-level 'lisp-outline-level)
186 (make-local-variable 'comment-start)
187 (setq comment-start ";")
188 (make-local-variable 'comment-start-skip)
189 ;; Look within the line for a ; following an even number of backslashes
190 ;; after either a non-backslash or the line beginning.
191 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
192 (make-local-variable 'comment-add)
193 (setq comment-add 1) ;default to `;;' in comment-region
194 (make-local-variable 'comment-column)
195 (setq comment-column 40)
196 (make-local-variable 'comment-indent-function)
197 (setq comment-indent-function 'lisp-comment-indent)
198 (make-local-variable 'imenu-generic-expression)
199 (setq imenu-generic-expression lisp-imenu-generic-expression)
200 (make-local-variable 'multibyte-syntax-as-symbol)
201 (setq multibyte-syntax-as-symbol t)
202 (set (make-local-variable 'syntax-begin-function) 'beginning-of-defun)
203 (setq font-lock-defaults
204 '((lisp-font-lock-keywords
205 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
206 nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
207 (font-lock-mark-block-function . mark-defun)
208 (font-lock-syntactic-face-function
209 . lisp-font-lock-syntactic-face-function))))
210
211 (defun lisp-outline-level ()
212 "Lisp mode `outline-level' function."
213 (if (looking-at "(")
214 1000
215 (looking-at outline-regexp)
216 (- (match-end 0) (match-beginning 0))))
217
218
219 (defvar lisp-mode-shared-map
220 (let ((map (make-sparse-keymap)))
221 (define-key map "\t" 'lisp-indent-line)
222 (define-key map "\e\C-q" 'indent-sexp)
223 (define-key map "\177" 'backward-delete-char-untabify)
224 ;; This gets in the way when viewing a Lisp file in view-mode. As
225 ;; long as [backspace] is mapped into DEL via the
226 ;; function-key-map, this should remain disabled!!
227 ;;;(define-key map [backspace] 'backward-delete-char-untabify)
228 map)
229 "Keymap for commands shared by all sorts of Lisp modes.")
230
231 (defvar emacs-lisp-mode-map ()
232 "Keymap for Emacs Lisp mode.
233 All commands in `lisp-mode-shared-map' are inherited by this map.")
234
235 (if emacs-lisp-mode-map
236 ()
237 (let ((map (make-sparse-keymap "Emacs-Lisp")))
238 (setq emacs-lisp-mode-map (make-sparse-keymap))
239 (set-keymap-parent emacs-lisp-mode-map lisp-mode-shared-map)
240 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
241 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
242 (define-key emacs-lisp-mode-map [menu-bar] (make-sparse-keymap))
243 (define-key emacs-lisp-mode-map [menu-bar emacs-lisp]
244 (cons "Emacs-Lisp" map))
245 (define-key map [edebug-defun]
246 '("Instrument Function for Debugging" . edebug-defun))
247 (define-key map [byte-recompile]
248 '("Byte-recompile Directory..." . byte-recompile-directory))
249 (define-key map [emacs-byte-compile-and-load]
250 '("Byte-compile And Load" . emacs-lisp-byte-compile-and-load))
251 (define-key map [byte-compile]
252 '("Byte-compile This File" . emacs-lisp-byte-compile))
253 (define-key map [separator-eval] '("--"))
254 (define-key map [eval-buffer] '("Evaluate Buffer" . eval-current-buffer))
255 (define-key map [eval-region] '("Evaluate Region" . eval-region))
256 (define-key map [eval-sexp] '("Evaluate Last S-expression" . eval-last-sexp))
257 (define-key map [separator-format] '("--"))
258 (define-key map [comment-region] '("Comment Out Region" . comment-region))
259 (define-key map [indent-region] '("Indent Region" . indent-region))
260 (define-key map [indent-line] '("Indent Line" . lisp-indent-line))
261 (put 'eval-region 'menu-enable 'mark-active)
262 (put 'comment-region 'menu-enable 'mark-active)
263 (put 'indent-region 'menu-enable 'mark-active)))
264
265 (defun emacs-lisp-byte-compile ()
266 "Byte compile the file containing the current buffer."
267 (interactive)
268 (if buffer-file-name
269 (byte-compile-file buffer-file-name)
270 (error "The buffer must be saved in a file first")))
271
272 (defun emacs-lisp-byte-compile-and-load ()
273 "Byte-compile the current file (if it has changed), then load compiled code."
274 (interactive)
275 (or buffer-file-name
276 (error "The buffer must be saved in a file first"))
277 (require 'bytecomp)
278 ;; Recompile if file or buffer has changed since last compilation.
279 (if (and (buffer-modified-p)
280 (y-or-n-p (format "Save buffer %s first? " (buffer-name))))
281 (save-buffer))
282 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name)))
283 (if (file-newer-than-file-p compiled-file-name buffer-file-name)
284 (load-file compiled-file-name)
285 (byte-compile-file buffer-file-name t))))
286
287 (defcustom emacs-lisp-mode-hook nil
288 "Hook run when entering Emacs Lisp mode."
289 :options '(turn-on-eldoc-mode imenu-add-menubar-index checkdoc-minor-mode)
290 :type 'hook
291 :group 'lisp)
292
293 (defcustom lisp-mode-hook nil
294 "Hook run when entering Lisp mode."
295 :options '(imenu-add-menubar-index)
296 :type 'hook
297 :group 'lisp)
298
299 (defcustom lisp-interaction-mode-hook nil
300 "Hook run when entering Lisp Interaction mode."
301 :options '(turn-on-eldoc-mode)
302 :type 'hook
303 :group 'lisp)
304
305 (defun emacs-lisp-mode ()
306 "Major mode for editing Lisp code to run in Emacs.
307 Commands:
308 Delete converts tabs to spaces as it moves back.
309 Blank lines separate paragraphs. Semicolons start comments.
310 \\{emacs-lisp-mode-map}
311 Entry to this mode calls the value of `emacs-lisp-mode-hook'
312 if that value is non-nil."
313 (interactive)
314 (kill-all-local-variables)
315 (use-local-map emacs-lisp-mode-map)
316 (set-syntax-table emacs-lisp-mode-syntax-table)
317 (setq major-mode 'emacs-lisp-mode)
318 (setq mode-name "Emacs-Lisp")
319 (lisp-mode-variables)
320 (setq imenu-case-fold-search nil)
321 (run-hooks 'emacs-lisp-mode-hook))
322
323 (defvar lisp-mode-map
324 (let ((map (make-sparse-keymap)))
325 (set-keymap-parent map lisp-mode-shared-map)
326 (define-key map "\e\C-x" 'lisp-eval-defun)
327 (define-key map "\C-c\C-z" 'run-lisp)
328 map)
329 "Keymap for ordinary Lisp mode.
330 All commands in `lisp-mode-shared-map' are inherited by this map.")
331
332 (defun lisp-mode ()
333 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
334 Commands:
335 Delete converts tabs to spaces as it moves back.
336 Blank lines separate paragraphs. Semicolons start comments.
337 \\{lisp-mode-map}
338 Note that `run-lisp' may be used either to start an inferior Lisp job
339 or to switch back to an existing one.
340
341 Entry to this mode calls the value of `lisp-mode-hook'
342 if that value is non-nil."
343 (interactive)
344 (kill-all-local-variables)
345 (use-local-map lisp-mode-map)
346 (setq major-mode 'lisp-mode)
347 (setq mode-name "Lisp")
348 (lisp-mode-variables)
349 (make-local-variable 'comment-start-skip)
350 (setq comment-start-skip
351 "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
352 (make-local-variable 'font-lock-keywords-case-fold-search)
353 (setq font-lock-keywords-case-fold-search t)
354 (setq imenu-case-fold-search t)
355 (set-syntax-table lisp-mode-syntax-table)
356 (run-hooks 'lisp-mode-hook))
357
358 ;; This will do unless inf-lisp.el is loaded.
359 (defun lisp-eval-defun (&optional and-go)
360 "Send the current defun to the Lisp process made by \\[run-lisp]."
361 (interactive)
362 (error "Process lisp does not exist"))
363
364 (defvar lisp-interaction-mode-map
365 (let ((map (make-sparse-keymap)))
366 (set-keymap-parent map lisp-mode-shared-map)
367 (define-key map "\e\C-x" 'eval-defun)
368 (define-key map "\e\t" 'lisp-complete-symbol)
369 (define-key map "\n" 'eval-print-last-sexp)
370 map)
371 "Keymap for Lisp Interaction mode.
372 All commands in `lisp-mode-shared-map' are inherited by this map.")
373
374 (defvar lisp-interaction-mode-abbrev-table lisp-mode-abbrev-table)
375 (define-derived-mode lisp-interaction-mode emacs-lisp-mode "Lisp Interaction"
376 "Major mode for typing and evaluating Lisp forms.
377 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression
378 before point, and prints its value into the buffer, advancing point.
379 Note that printing is controlled by `eval-expression-print-length'
380 and `eval-expression-print-level'.
381
382 Commands:
383 Delete converts tabs to spaces as it moves back.
384 Paragraphs are separated only by blank lines.
385 Semicolons start comments.
386 \\{lisp-interaction-mode-map}
387 Entry to this mode calls the value of `lisp-interaction-mode-hook'
388 if that value is non-nil.")
389
390 (defun eval-print-last-sexp ()
391 "Evaluate sexp before point; print value into current buffer.
392
393 Note that printing the result is controlled by the variables
394 `eval-expression-print-length' and `eval-expression-print-level',
395 which see."
396 (interactive)
397 (let ((standard-output (current-buffer)))
398 (terpri)
399 (eval-last-sexp t)
400 (terpri)))
401
402
403 (defun last-sexp-setup-props (beg end value alt1 alt2)
404 "Set up text properties for the output of `eval-last-sexp-1'.
405 BEG and END are the start and end of the output in current-buffer.
406 VALUE is the Lisp value printed, ALT1 and ALT2 are strings for the
407 alternative printed representations that can be displayed."
408 (let ((map (make-sparse-keymap)))
409 (define-key map "\C-m" 'last-sexp-toggle-display)
410 (define-key map [down-mouse-2] 'mouse-set-point)
411 (define-key map [mouse-2] 'last-sexp-toggle-display)
412 (add-text-properties
413 beg end
414 `(printed-value (,value ,alt1 ,alt2)
415 mouse-face highlight
416 keymap ,map
417 help-echo "RET, mouse-2: toggle abbreviated display"
418 rear-nonsticky (mouse-face keymap help-echo
419 printed-value)))))
420
421
422 (defun last-sexp-toggle-display ()
423 "Toggle between abbreviated and unabbreviated printed representations."
424 (interactive)
425 (let ((value (get-text-property (point) 'printed-value)))
426 (when value
427 (let ((beg (or (previous-single-property-change (min (point-max) (1+ (point)))
428 'printed-value)
429 (point)))
430 (end (or (next-single-char-property-change (point) 'printed-value) (point)))
431 (standard-output (current-buffer))
432 (point (point)))
433 (delete-region beg end)
434 (insert (nth 1 value))
435 (last-sexp-setup-props beg (point)
436 (nth 0 value)
437 (nth 2 value)
438 (nth 1 value))
439 (goto-char (min (point-max) point))))))
440
441 (defun eval-last-sexp-1 (eval-last-sexp-arg-internal)
442 "Evaluate sexp before point; print value in minibuffer.
443 With argument, print output into current buffer."
444 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)))
445 (let ((value
446 (eval (let ((stab (syntax-table))
447 (opoint (point))
448 ignore-quotes
449 expr)
450 (unwind-protect
451 (save-excursion
452 (set-syntax-table emacs-lisp-mode-syntax-table)
453 ;; If this sexp appears to be enclosed in `...'
454 ;; then ignore the surrounding quotes.
455 (setq ignore-quotes
456 (or (eq (following-char) ?\')
457 (eq (preceding-char) ?\')))
458 (forward-sexp -1)
459 ;; If we were after `?\e' (or similar case),
460 ;; use the whole thing, not just the `e'.
461 (when (eq (preceding-char) ?\\)
462 (forward-char -1)
463 (when (eq (preceding-char) ??)
464 (forward-char -1)))
465
466 ;; Skip over `#N='s.
467 (when (eq (preceding-char) ?=)
468 (let (labeled-p)
469 (save-excursion
470 (skip-chars-backward "0-9#=")
471 (setq labeled-p (looking-at "\\(#[0-9]+=\\)+")))
472 (when labeled-p
473 (forward-sexp -1))))
474
475 (save-restriction
476 ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in
477 ;; `variable' so that the value is returned, not the
478 ;; name
479 (if (and ignore-quotes
480 (eq (following-char) ?`))
481 (forward-char))
482 (narrow-to-region (point-min) opoint)
483 (setq expr (read (current-buffer)))
484 ;; If it's an (interactive ...) form, it's more
485 ;; useful to show how an interactive call would
486 ;; use it.
487 (and (consp expr)
488 (eq (car expr) 'interactive)
489 (setq expr
490 (list 'call-interactively
491 (list 'quote
492 (list 'lambda
493 '(&rest args)
494 expr
495 'args)))))
496 expr))
497 (set-syntax-table stab))))))
498 (let ((unabbreviated (let ((print-length nil) (print-level nil))
499 (prin1-to-string value)))
500 (print-length eval-expression-print-length)
501 (print-level eval-expression-print-level)
502 (beg (point))
503 end)
504 (prog1
505 (prin1 value)
506 (setq end (point))
507 (when (and (bufferp standard-output)
508 (or (not (null print-length))
509 (not (null print-level)))
510 (not (string= unabbreviated
511 (buffer-substring-no-properties beg end))))
512 (last-sexp-setup-props beg end value
513 unabbreviated
514 (buffer-substring-no-properties beg end))
515 ))))))
516
517
518 (defun eval-last-sexp (eval-last-sexp-arg-internal)
519 "Evaluate sexp before point; print value in minibuffer.
520 Interactively, with prefix argument, print output into current buffer."
521 (interactive "P")
522 (if (null eval-expression-debug-on-error)
523 (eval-last-sexp-1 eval-last-sexp-arg-internal)
524 (let ((old-value (make-symbol "t")) new-value value)
525 (let ((debug-on-error old-value))
526 (setq value (eval-last-sexp-1 eval-last-sexp-arg-internal))
527 (setq new-value debug-on-error))
528 (unless (eq old-value new-value)
529 (setq debug-on-error new-value))
530 value)))
531
532 (defun eval-defun-1 (form)
533 "Change defvar into defconst within FORM.
534 Likewise for other constructs as necessary."
535 ;; The code in edebug-defun should be consistent with this, but not
536 ;; the same, since this gets a macroexpended form.
537 (cond ((not (listp form))
538 form)
539 ((and (eq (car form) 'defvar)
540 (cdr-safe (cdr-safe form)))
541 ;; Force variable to be bound.
542 (cons 'defconst (cdr form)))
543 ;; `defcustom' is now macroexpanded to
544 ;; `custom-declare-variable' with a quoted value arg.
545 ((and (eq (car form) 'custom-declare-variable)
546 (default-boundp (eval (nth 1 form))))
547 ;; Force variable to be bound.
548 (set-default (eval (nth 1 form)) (eval (nth 1 (nth 2 form))))
549 form)
550 ((eq (car form) 'progn)
551 (cons 'progn (mapcar 'eval-defun-1 (cdr form))))
552 (t form)))
553
554 (defun eval-defun-2 ()
555 "Evaluate defun that point is in or before.
556 The value is displayed in the minibuffer.
557 If the current defun is actually a call to `defvar',
558 then reset the variable using the initial value expression
559 even if the variable already has some other value.
560 \(Normally `defvar' does not change the variable's value
561 if it already has a value.\)
562
563 With argument, insert value in current buffer after the defun.
564 Return the result of evaluation."
565 (interactive "P")
566 (let ((debug-on-error eval-expression-debug-on-error)
567 (print-length eval-expression-print-length)
568 (print-level eval-expression-print-level))
569 (save-excursion
570 ;; Arrange for eval-region to "read" the (possibly) altered form.
571 ;; eval-region handles recording which file defines a function or
572 ;; variable. Re-written using `apply' to avoid capturing
573 ;; variables like `end'.
574 (apply
575 #'eval-region
576 (let ((standard-output t)
577 beg end form)
578 ;; Read the form from the buffer, and record where it ends.
579 (save-excursion
580 (end-of-defun)
581 (beginning-of-defun)
582 (setq beg (point))
583 (setq form (read (current-buffer)))
584 (setq end (point)))
585 ;; Alter the form if necessary, changing defvar into defconst, etc.
586 (setq form (eval-defun-1 (macroexpand form)))
587 (list beg end standard-output
588 `(lambda (ignore)
589 ;; Skipping to the end of the specified region
590 ;; will make eval-region return.
591 (goto-char ,end)
592 ',form))))))
593 ;; The result of evaluation has been put onto VALUES. So return it.
594 (car values))
595
596 (defun eval-defun (edebug-it)
597 "Evaluate the top-level form containing point, or after point.
598
599 If the current defun is actually a call to `defvar' or `defcustom',
600 evaluating it this way resets the variable using its initial value
601 expression even if the variable already has some other value.
602 \(Normally `defvar' and `defcustom' do not alter the value if there
603 already is one.)
604
605 With a prefix argument, instrument the code for Edebug.
606
607 If acting on a `defun' for FUNCTION, and the function was
608 instrumented, `Edebug: FUNCTION' is printed in the minibuffer. If not
609 instrumented, just FUNCTION is printed.
610
611 If not acting on a `defun', the result of evaluation is displayed in
612 the minibuffer. This display is controlled by the variables
613 `eval-expression-print-length' and `eval-expression-print-level',
614 which see."
615 (interactive "P")
616 (cond (edebug-it
617 (require 'edebug)
618 (eval-defun (not edebug-all-defs)))
619 (t
620 (if (null eval-expression-debug-on-error)
621 (eval-defun-2)
622 (let ((old-value (make-symbol "t")) new-value value)
623 (let ((debug-on-error old-value))
624 (setq value (eval-defun-2))
625 (setq new-value debug-on-error))
626 (unless (eq old-value new-value)
627 (setq debug-on-error new-value))
628 value)))))
629
630
631 (defun lisp-comment-indent ()
632 (if (looking-at "\\s<\\s<\\s<")
633 (current-column)
634 (if (looking-at "\\s<\\s<")
635 (let ((tem (or (calculate-lisp-indent) (current-column))))
636 (if (listp tem) (car tem) tem))
637 (skip-chars-backward " \t")
638 (max (if (bolp) 0 (1+ (current-column)))
639 comment-column))))
640
641 ;; This function just forces a more costly detection of comments (using
642 ;; parse-partial-sexp from beginning-of-defun). I.e. It avoids the problem of
643 ;; taking a `;' inside a string started on another line for a comment starter.
644 ;; Note: `newcomment' gets it right in 99% of the cases if you're using
645 ;; font-lock, anyway, so we could get rid of it. -stef
646 (defun lisp-mode-auto-fill ()
647 (if (> (current-column) (current-fill-column))
648 (if (save-excursion
649 (nth 4 (syntax-ppss (point))))
650 (do-auto-fill)
651 (unless (and (boundp 'comment-auto-fill-only-comments)
652 comment-auto-fill-only-comments)
653 (let ((comment-start nil) (comment-start-skip nil))
654 (do-auto-fill))))))
655
656 (defvar lisp-indent-offset nil
657 "If non-nil, indent second line of expressions that many more columns.")
658 (defvar lisp-indent-function 'lisp-indent-function)
659
660 (defun lisp-indent-line (&optional whole-exp)
661 "Indent current line as Lisp code.
662 With argument, indent any additional lines of the same expression
663 rigidly along with this one."
664 (interactive "P")
665 (let ((indent (calculate-lisp-indent)) shift-amt end
666 (pos (- (point-max) (point)))
667 (beg (progn (beginning-of-line) (point))))
668 (skip-chars-forward " \t")
669 (if (or (null indent) (looking-at "\\s<\\s<\\s<"))
670 ;; Don't alter indentation of a ;;; comment line
671 ;; or a line that starts in a string.
672 (goto-char (- (point-max) pos))
673 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
674 ;; Single-semicolon comment lines should be indented
675 ;; as comment lines, not as code.
676 (progn (indent-for-comment) (forward-char -1))
677 (if (listp indent) (setq indent (car indent)))
678 (setq shift-amt (- indent (current-column)))
679 (if (zerop shift-amt)
680 nil
681 (delete-region beg (point))
682 (indent-to indent)))
683 ;; If initial point was within line's indentation,
684 ;; position after the indentation. Else stay at same point in text.
685 (if (> (- (point-max) pos) (point))
686 (goto-char (- (point-max) pos)))
687 ;; If desired, shift remaining lines of expression the same amount.
688 (and whole-exp (not (zerop shift-amt))
689 (save-excursion
690 (goto-char beg)
691 (forward-sexp 1)
692 (setq end (point))
693 (goto-char beg)
694 (forward-line 1)
695 (setq beg (point))
696 (> end beg))
697 (indent-code-rigidly beg end shift-amt)))))
698
699 (defvar calculate-lisp-indent-last-sexp)
700
701 (defun calculate-lisp-indent (&optional parse-start)
702 "Return appropriate indentation for current line as Lisp code.
703 In usual case returns an integer: the column to indent to.
704 If the value is nil, that means don't change the indentation
705 because the line starts inside a string.
706
707 The value can also be a list of the form (COLUMN CONTAINING-SEXP-START).
708 This means that following lines at the same level of indentation
709 should not necessarily be indented the same as this line.
710 Then COLUMN is the column to indent to, and CONTAINING-SEXP-START
711 is the buffer position of the start of the containing expression."
712 (save-excursion
713 (beginning-of-line)
714 (let ((indent-point (point))
715 state paren-depth
716 ;; setting this to a number inhibits calling hook
717 (desired-indent nil)
718 (retry t)
719 calculate-lisp-indent-last-sexp containing-sexp)
720 (if parse-start
721 (goto-char parse-start)
722 (beginning-of-defun))
723 ;; Find outermost containing sexp
724 (while (< (point) indent-point)
725 (setq state (parse-partial-sexp (point) indent-point 0)))
726 ;; Find innermost containing sexp
727 (while (and retry
728 state
729 (> (setq paren-depth (elt state 0)) 0))
730 (setq retry nil)
731 (setq calculate-lisp-indent-last-sexp (elt state 2))
732 (setq containing-sexp (elt state 1))
733 ;; Position following last unclosed open.
734 (goto-char (1+ containing-sexp))
735 ;; Is there a complete sexp since then?
736 (if (and calculate-lisp-indent-last-sexp
737 (> calculate-lisp-indent-last-sexp (point)))
738 ;; Yes, but is there a containing sexp after that?
739 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp
740 indent-point 0)))
741 (if (setq retry (car (cdr peek))) (setq state peek)))))
742 (if retry
743 nil
744 ;; Innermost containing sexp found
745 (goto-char (1+ containing-sexp))
746 (if (not calculate-lisp-indent-last-sexp)
747 ;; indent-point immediately follows open paren.
748 ;; Don't call hook.
749 (setq desired-indent (current-column))
750 ;; Find the start of first element of containing sexp.
751 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
752 (cond ((looking-at "\\s(")
753 ;; First element of containing sexp is a list.
754 ;; Indent under that list.
755 )
756 ((> (save-excursion (forward-line 1) (point))
757 calculate-lisp-indent-last-sexp)
758 ;; This is the first line to start within the containing sexp.
759 ;; It's almost certainly a function call.
760 (if (= (point) calculate-lisp-indent-last-sexp)
761 ;; Containing sexp has nothing before this line
762 ;; except the first element. Indent under that element.
763 nil
764 ;; Skip the first element, find start of second (the first
765 ;; argument of the function call) and indent under.
766 (progn (forward-sexp 1)
767 (parse-partial-sexp (point)
768 calculate-lisp-indent-last-sexp
769 0 t)))
770 (backward-prefix-chars))
771 (t
772 ;; Indent beneath first sexp on same line as
773 ;; `calculate-lisp-indent-last-sexp'. Again, it's
774 ;; almost certainly a function call.
775 (goto-char calculate-lisp-indent-last-sexp)
776 (beginning-of-line)
777 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp
778 0 t)
779 (backward-prefix-chars)))))
780 ;; Point is at the point to indent under unless we are inside a string.
781 ;; Call indentation hook except when overridden by lisp-indent-offset
782 ;; or if the desired indentation has already been computed.
783 (let ((normal-indent (current-column)))
784 (cond ((elt state 3)
785 ;; Inside a string, don't change indentation.
786 nil)
787 ((and (integerp lisp-indent-offset) containing-sexp)
788 ;; Indent by constant offset
789 (goto-char containing-sexp)
790 (+ (current-column) lisp-indent-offset))
791 (desired-indent)
792 ((and (boundp 'lisp-indent-function)
793 lisp-indent-function
794 (not retry))
795 (or (funcall lisp-indent-function indent-point state)
796 normal-indent))
797 (t
798 normal-indent))))))
799
800 (defun lisp-indent-function (indent-point state)
801 "This function is the normal value of the variable `lisp-indent-function'.
802 It is used when indenting a line within a function call, to see if the
803 called function says anything special about how to indent the line.
804
805 INDENT-POINT is the position where the user typed TAB, or equivalent.
806 Point is located at the point to indent under (for default indentation);
807 STATE is the `parse-partial-sexp' state for that position.
808
809 If the current line is in a call to a Lisp function
810 which has a non-nil property `lisp-indent-function',
811 that specifies how to do the indentation. The property value can be
812 * `defun', meaning indent `defun'-style;
813 * an integer N, meaning indent the first N arguments specially
814 like ordinary function arguments and then indent any further
815 aruments like a body;
816 * a function to call just as this function was called.
817 If that function returns nil, that means it doesn't specify
818 the indentation.
819
820 This function also returns nil meaning don't specify the indentation."
821 (let ((normal-indent (current-column)))
822 (goto-char (1+ (elt state 1)))
823 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
824 (if (and (elt state 2)
825 (not (looking-at "\\sw\\|\\s_")))
826 ;; car of form doesn't seem to be a symbol
827 (progn
828 (if (not (> (save-excursion (forward-line 1) (point))
829 calculate-lisp-indent-last-sexp))
830 (progn (goto-char calculate-lisp-indent-last-sexp)
831 (beginning-of-line)
832 (parse-partial-sexp (point)
833 calculate-lisp-indent-last-sexp 0 t)))
834 ;; Indent under the list or under the first sexp on the same
835 ;; line as calculate-lisp-indent-last-sexp. Note that first
836 ;; thing on that line has to be complete sexp since we are
837 ;; inside the innermost containing sexp.
838 (backward-prefix-chars)
839 (current-column))
840 (let ((function (buffer-substring (point)
841 (progn (forward-sexp 1) (point))))
842 method)
843 (setq method (or (get (intern-soft function) 'lisp-indent-function)
844 (get (intern-soft function) 'lisp-indent-hook)))
845 (cond ((or (eq method 'defun)
846 (and (null method)
847 (> (length function) 3)
848 (string-match "\\`def" function)))
849 (lisp-indent-defform state indent-point))
850 ((integerp method)
851 (lisp-indent-specform method state
852 indent-point normal-indent))
853 (method
854 (funcall method state indent-point)))))))
855
856 (defvar lisp-body-indent 2
857 "Number of columns to indent the second line of a `(def...)' form.")
858
859 (defun lisp-indent-specform (count state indent-point normal-indent)
860 (let ((containing-form-start (elt state 1))
861 (i count)
862 body-indent containing-form-column)
863 ;; Move to the start of containing form, calculate indentation
864 ;; to use for non-distinguished forms (> count), and move past the
865 ;; function symbol. lisp-indent-function guarantees that there is at
866 ;; least one word or symbol character following open paren of containing
867 ;; form.
868 (goto-char containing-form-start)
869 (setq containing-form-column (current-column))
870 (setq body-indent (+ lisp-body-indent containing-form-column))
871 (forward-char 1)
872 (forward-sexp 1)
873 ;; Now find the start of the last form.
874 (parse-partial-sexp (point) indent-point 1 t)
875 (while (and (< (point) indent-point)
876 (condition-case ()
877 (progn
878 (setq count (1- count))
879 (forward-sexp 1)
880 (parse-partial-sexp (point) indent-point 1 t))
881 (error nil))))
882 ;; Point is sitting on first character of last (or count) sexp.
883 (if (> count 0)
884 ;; A distinguished form. If it is the first or second form use double
885 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound
886 ;; to 2 (the default), this just happens to work the same with if as
887 ;; the older code, but it makes unwind-protect, condition-case,
888 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older,
889 ;; less hacked, behavior can be obtained by replacing below with
890 ;; (list normal-indent containing-form-start).
891 (if (<= (- i count) 1)
892 (list (+ containing-form-column (* 2 lisp-body-indent))
893 containing-form-start)
894 (list normal-indent containing-form-start))
895 ;; A non-distinguished form. Use body-indent if there are no
896 ;; distinguished forms and this is the first undistinguished form,
897 ;; or if this is the first undistinguished form and the preceding
898 ;; distinguished form has indentation at least as great as body-indent.
899 (if (or (and (= i 0) (= count 0))
900 (and (= count 0) (<= body-indent normal-indent)))
901 body-indent
902 normal-indent))))
903
904 (defun lisp-indent-defform (state indent-point)
905 (goto-char (car (cdr state)))
906 (forward-line 1)
907 (if (> (point) (car (cdr (cdr state))))
908 (progn
909 (goto-char (car (cdr state)))
910 (+ lisp-body-indent (current-column)))))
911
912
913 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
914 ;; like defun if the first form is placed on the next line, otherwise
915 ;; it is indented like any other form (i.e. forms line up under first).
916
917 (put 'lambda 'lisp-indent-function 'defun)
918 (put 'autoload 'lisp-indent-function 'defun)
919 (put 'progn 'lisp-indent-function 0)
920 (put 'prog1 'lisp-indent-function 1)
921 (put 'prog2 'lisp-indent-function 2)
922 (put 'save-excursion 'lisp-indent-function 0)
923 (put 'save-window-excursion 'lisp-indent-function 0)
924 (put 'save-selected-window 'lisp-indent-function 0)
925 (put 'save-restriction 'lisp-indent-function 0)
926 (put 'save-match-data 'lisp-indent-function 0)
927 (put 'save-current-buffer 'lisp-indent-function 0)
928 (put 'with-current-buffer 'lisp-indent-function 1)
929 (put 'combine-after-change-calls 'lisp-indent-function 0)
930 (put 'with-output-to-string 'lisp-indent-function 0)
931 (put 'with-temp-file 'lisp-indent-function 1)
932 (put 'with-temp-buffer 'lisp-indent-function 0)
933 (put 'with-temp-message 'lisp-indent-function 1)
934 (put 'with-syntax-table 'lisp-indent-function 1)
935 (put 'let 'lisp-indent-function 1)
936 (put 'let* 'lisp-indent-function 1)
937 (put 'while 'lisp-indent-function 1)
938 (put 'if 'lisp-indent-function 2)
939 (put 'read-if 'lisp-indent-function 2)
940 (put 'catch 'lisp-indent-function 1)
941 (put 'condition-case 'lisp-indent-function 2)
942 (put 'unwind-protect 'lisp-indent-function 1)
943 (put 'with-output-to-temp-buffer 'lisp-indent-function 1)
944 (put 'eval-after-load 'lisp-indent-function 1)
945 (put 'dolist 'lisp-indent-function 1)
946 (put 'dotimes 'lisp-indent-function 1)
947 (put 'when 'lisp-indent-function 1)
948 (put 'unless 'lisp-indent-function 1)
949
950 (defun indent-sexp (&optional endpos)
951 "Indent each line of the list starting just after point.
952 If optional arg ENDPOS is given, indent each line, stopping when
953 ENDPOS is encountered."
954 (interactive)
955 (let ((indent-stack (list nil))
956 (next-depth 0)
957 ;; If ENDPOS is non-nil, use nil as STARTING-POINT
958 ;; so that calculate-lisp-indent will find the beginning of
959 ;; the defun we are in.
960 ;; If ENDPOS is nil, it is safe not to scan before point
961 ;; since every line we indent is more deeply nested than point is.
962 (starting-point (if endpos nil (point)))
963 (last-point (point))
964 last-depth bol outer-loop-done inner-loop-done state this-indent)
965 (or endpos
966 ;; Get error now if we don't have a complete sexp after point.
967 (save-excursion (forward-sexp 1)))
968 (save-excursion
969 (setq outer-loop-done nil)
970 (while (if endpos (< (point) endpos)
971 (not outer-loop-done))
972 (setq last-depth next-depth
973 inner-loop-done nil)
974 ;; Parse this line so we can learn the state
975 ;; to indent the next line.
976 ;; This inner loop goes through only once
977 ;; unless a line ends inside a string.
978 (while (and (not inner-loop-done)
979 (not (setq outer-loop-done (eobp))))
980 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
981 nil nil state))
982 (setq next-depth (car state))
983 ;; If the line contains a comment other than the sort
984 ;; that is indented like code,
985 ;; indent it now with indent-for-comment.
986 ;; Comments indented like code are right already.
987 ;; In any case clear the in-comment flag in the state
988 ;; because parse-partial-sexp never sees the newlines.
989 (if (car (nthcdr 4 state))
990 (progn (indent-for-comment)
991 (end-of-line)
992 (setcar (nthcdr 4 state) nil)))
993 ;; If this line ends inside a string,
994 ;; go straight to next line, remaining within the inner loop,
995 ;; and turn off the \-flag.
996 (if (car (nthcdr 3 state))
997 (progn
998 (forward-line 1)
999 (setcar (nthcdr 5 state) nil))
1000 (setq inner-loop-done t)))
1001 (and endpos
1002 (<= next-depth 0)
1003 (progn
1004 (setq indent-stack (nconc indent-stack
1005 (make-list (- next-depth) nil))
1006 last-depth (- last-depth next-depth)
1007 next-depth 0)))
1008 (or outer-loop-done endpos
1009 (setq outer-loop-done (<= next-depth 0)))
1010 (if outer-loop-done
1011 (forward-line 1)
1012 (while (> last-depth next-depth)
1013 (setq indent-stack (cdr indent-stack)
1014 last-depth (1- last-depth)))
1015 (while (< last-depth next-depth)
1016 (setq indent-stack (cons nil indent-stack)
1017 last-depth (1+ last-depth)))
1018 ;; Now go to the next line and indent it according
1019 ;; to what we learned from parsing the previous one.
1020 (forward-line 1)
1021 (setq bol (point))
1022 (skip-chars-forward " \t")
1023 ;; But not if the line is blank, or just a comment
1024 ;; (except for double-semi comments; indent them as usual).
1025 (if (or (eobp) (looking-at "\\s<\\|\n"))
1026 nil
1027 (if (and (car indent-stack)
1028 (>= (car indent-stack) 0))
1029 (setq this-indent (car indent-stack))
1030 (let ((val (calculate-lisp-indent
1031 (if (car indent-stack) (- (car indent-stack))
1032 starting-point))))
1033 (if (null val)
1034 (setq this-indent val)
1035 (if (integerp val)
1036 (setcar indent-stack
1037 (setq this-indent val))
1038 (setcar indent-stack (- (car (cdr val))))
1039 (setq this-indent (car val))))))
1040 (if (and this-indent (/= (current-column) this-indent))
1041 (progn (delete-region bol (point))
1042 (indent-to this-indent)))))
1043 (or outer-loop-done
1044 (setq outer-loop-done (= (point) last-point))
1045 (setq last-point (point)))))))
1046
1047 (defun lisp-indent-region (start end)
1048 "Indent every line whose first char is between START and END inclusive."
1049 (save-excursion
1050 (let ((endmark (copy-marker end)))
1051 (goto-char start)
1052 (and (bolp) (not (eolp))
1053 (lisp-indent-line))
1054 (indent-sexp endmark)
1055 (set-marker endmark nil))))
1056
1057 ;;;; Lisp paragraph filling commands.
1058
1059 (defcustom emacs-lisp-docstring-fill-column 65
1060 "Value of `fill-column' to use when filling a docstring.
1061 Any non-integer value means do not use a different value of
1062 `fill-column' when filling docstrings."
1063 :type '(choice (integer)
1064 (const :tag "Use the current `fill-column'" t))
1065 :group 'lisp)
1066
1067 (defun lisp-fill-paragraph (&optional justify)
1068 "Like \\[fill-paragraph], but handle Emacs Lisp comments and docstrings.
1069 If any of the current line is a comment, fill the comment or the
1070 paragraph of it that point is in, preserving the comment's indentation
1071 and initial semicolons."
1072 (interactive "P")
1073 (or (fill-comment-paragraph justify)
1074 ;; Point is on a program line (a line no comment); we are interested
1075 ;; particularly in docstring lines.
1076 ;;
1077 ;; We bind `paragraph-start' and `paragraph-separate' temporarily. They
1078 ;; are buffer-local, but we avoid changing them so that they can be set
1079 ;; to make `forward-paragraph' and friends do something the user wants.
1080 ;;
1081 ;; `paragraph-start': The `(' in the character alternative and the
1082 ;; left-singlequote plus `(' sequence after the \\| alternative prevent
1083 ;; sexps and backquoted sexps that follow a docstring from being filled
1084 ;; with the docstring. This setting has the consequence of inhibiting
1085 ;; filling many program lines that are not docstrings, which is sensible,
1086 ;; because the user probably asked to fill program lines by accident, or
1087 ;; expecting indentation (perhaps we should try to do indenting in that
1088 ;; case). The `;' and `:' stop the paragraph being filled at following
1089 ;; comment lines and at keywords (e.g., in `defcustom'). Left parens are
1090 ;; escaped to keep font-locking, filling, & paren matching in the source
1091 ;; file happy.
1092 ;;
1093 ;; `paragraph-separate': A clever regexp distinguishes the first line of
1094 ;; a docstring and identifies it as a paragraph separator, so that it
1095 ;; won't be filled. (Since the first line of documentation stands alone
1096 ;; in some contexts, filling should not alter the contents the author has
1097 ;; chosen.) Only the first line of a docstring begins with whitespace
1098 ;; and a quotation mark and ends with a period or (rarely) a comma.
1099 ;;
1100 ;; The `fill-column' is temporarily bound to
1101 ;; `emacs-lisp-docstring-fill-column' if that value is an integer.
1102 (let ((paragraph-start (concat paragraph-start
1103 "\\|\\s-*\\([\(;:\"]\\|`\(\\)"))
1104 (paragraph-separate
1105 (concat paragraph-separate "\\|\\s-*\".*[,\\.]$"))
1106 (fill-column (if (integerp emacs-lisp-docstring-fill-column)
1107 emacs-lisp-docstring-fill-column
1108 fill-column)))
1109 (fill-paragraph justify))
1110 ;; Never return nil.
1111 t))
1112
1113 (defun indent-code-rigidly (start end arg &optional nochange-regexp)
1114 "Indent all lines of code, starting in the region, sideways by ARG columns.
1115 Does not affect lines starting inside comments or strings, assuming that
1116 the start of the region is not inside them.
1117
1118 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
1119 The last is a regexp which, if matched at the beginning of a line,
1120 means don't indent that line."
1121 (interactive "r\np")
1122 (let (state)
1123 (save-excursion
1124 (goto-char end)
1125 (setq end (point-marker))
1126 (goto-char start)
1127 (or (bolp)
1128 (setq state (parse-partial-sexp (point)
1129 (progn
1130 (forward-line 1) (point))
1131 nil nil state)))
1132 (while (< (point) end)
1133 (or (car (nthcdr 3 state))
1134 (and nochange-regexp
1135 (looking-at nochange-regexp))
1136 ;; If line does not start in string, indent it
1137 (let ((indent (current-indentation)))
1138 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
1139 (or (eolp)
1140 (indent-to (max 0 (+ indent arg)) 0))))
1141 (setq state (parse-partial-sexp (point)
1142 (progn
1143 (forward-line 1) (point))
1144 nil nil state))))))
1145
1146 (provide 'lisp-mode)
1147
1148 ;;; lisp-mode.el ends here