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