Mercurial > emacs
comparison lisp/emacs-lisp/lisp-mode.el @ 27809:46468edab05e
(emacs-lisp-mode-syntax-table)
(lisp-mode-map, lisp-interaction-mode-map): Define all inside
defvar.
(lisp-mode-syntax-table): Set up for #|...|# comments.
(lisp-imenu-generic-expression): Purecopy strings. Use syntax
classes. Match `defface'.
(emacs-lisp-mode-hook): Add checkdoc-minor-mode to options.
(eval-defun-1): Fix for defcustom.
(lisp-indent-region): Doc fix.
author | Dave Love <fx@gnu.org> |
---|---|
date | Tue, 22 Feb 2000 20:13:31 +0000 |
parents | a681b4de47a1 |
children | f2abbe1d6b47 |
comparison
equal
deleted
inserted
replaced
27808:cc4885ac4603 | 27809:46468edab05e |
---|---|
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. | 1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. |
2 | 2 |
3 ;; Copyright (C) 1985, 1986, 1999 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1986, 1999, 2000 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Maintainer: FSF | 5 ;; Maintainer: FSF |
6 ;; Keywords: lisp, languages | 6 ;; Keywords: lisp, languages |
7 | 7 |
8 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
23 ;; Boston, MA 02111-1307, USA. | 23 ;; Boston, MA 02111-1307, USA. |
24 | 24 |
25 ;;; Commentary: | 25 ;;; Commentary: |
26 | 26 |
27 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). | 27 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). |
28 ;; This mode is documented in the Emacs manual | 28 ;; This mode is documented in the Emacs manual. |
29 | 29 |
30 ;;; Code: | 30 ;;; Code: |
31 | 31 |
32 (defvar lisp-mode-syntax-table nil "") | 32 (defvar lisp-mode-abbrev-table nil) |
33 (defvar emacs-lisp-mode-syntax-table nil "") | 33 |
34 (defvar lisp-mode-abbrev-table nil "") | 34 (defvar emacs-lisp-mode-syntax-table |
35 | 35 (let ((table (make-syntax-table))) |
36 (if (not emacs-lisp-mode-syntax-table) | |
37 (let ((i 0)) | 36 (let ((i 0)) |
38 (setq emacs-lisp-mode-syntax-table (make-syntax-table)) | |
39 (while (< i ?0) | 37 (while (< i ?0) |
40 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | 38 (modify-syntax-entry i "_ " table) |
41 (setq i (1+ i))) | 39 (setq i (1+ i))) |
42 (setq i (1+ ?9)) | 40 (setq i (1+ ?9)) |
43 (while (< i ?A) | 41 (while (< i ?A) |
44 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | 42 (modify-syntax-entry i "_ " table) |
45 (setq i (1+ i))) | 43 (setq i (1+ i))) |
46 (setq i (1+ ?Z)) | 44 (setq i (1+ ?Z)) |
47 (while (< i ?a) | 45 (while (< i ?a) |
48 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | 46 (modify-syntax-entry i "_ " table) |
49 (setq i (1+ i))) | 47 (setq i (1+ i))) |
50 (setq i (1+ ?z)) | 48 (setq i (1+ ?z)) |
51 (while (< i 128) | 49 (while (< i 128) |
52 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | 50 (modify-syntax-entry i "_ " table) |
53 (setq i (1+ i))) | 51 (setq i (1+ i))) |
54 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) | 52 (modify-syntax-entry ? " " table) |
55 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) | 53 (modify-syntax-entry ?\t " " table) |
56 (modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table) | 54 (modify-syntax-entry ?\f " " table) |
57 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table) | 55 (modify-syntax-entry ?\n "> " table) |
58 ;; Give CR the same syntax as newline, for selective-display. | 56 ;; Give CR the same syntax as newline, for selective-display. |
59 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table) | 57 (modify-syntax-entry ?\^m "> " table) |
60 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table) | 58 (modify-syntax-entry ?\; "< " table) |
61 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table) | 59 (modify-syntax-entry ?` "' " table) |
62 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table) | 60 (modify-syntax-entry ?' "' " table) |
63 (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table) | 61 (modify-syntax-entry ?, "' " table) |
64 ;; Used to be singlequote; changed for flonums. | 62 ;; Used to be singlequote; changed for flonums. |
65 (modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table) | 63 (modify-syntax-entry ?. "_ " table) |
66 (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table) | 64 (modify-syntax-entry ?# "' " table) |
67 (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table) | 65 (modify-syntax-entry ?\" "\" " table) |
68 (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table) | 66 (modify-syntax-entry ?\\ "\\ " table) |
69 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table) | 67 (modify-syntax-entry ?\( "() " table) |
70 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table) | 68 (modify-syntax-entry ?\) ")( " table) |
71 (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table) | 69 (modify-syntax-entry ?\[ "(] " table) |
72 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table) | 70 (modify-syntax-entry ?\] ")[ " table) |
73 ;; All non-word multibyte characters should be `symbol'. | 71 ;; All non-word multibyte characters should be `symbol'. |
74 (map-char-table | 72 (map-char-table |
75 (function (lambda (key val) | 73 (function (lambda (key val) |
76 (and (>= key 256) | 74 (and (>= key 256) |
77 (/= (char-syntax key) ?w) | 75 (/= (char-syntax key) ?w) |
78 (modify-syntax-entry key "_ " | 76 (modify-syntax-entry key "_ " |
79 emacs-lisp-mode-syntax-table)))) | 77 table)))) |
80 (standard-syntax-table)))) | 78 (standard-syntax-table))) |
81 | 79 table)) |
82 (if (not lisp-mode-syntax-table) | 80 |
83 (progn (setq lisp-mode-syntax-table | 81 (defvar lisp-mode-syntax-table |
84 (copy-syntax-table emacs-lisp-mode-syntax-table)) | 82 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table))) |
85 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table) | 83 (modify-syntax-entry ?\| "\" " table) |
86 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table) | 84 (modify-syntax-entry ?\[ "_ " table) |
87 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table))) | 85 (modify-syntax-entry ?\] "_ " table) |
86 (modify-syntax-entry ?# "' 14bn" table) | |
87 (modify-syntax-entry ?| "' 23b" table) | |
88 table)) | |
88 | 89 |
89 (define-abbrev-table 'lisp-mode-abbrev-table ()) | 90 (define-abbrev-table 'lisp-mode-abbrev-table ()) |
90 | 91 |
91 (defvar lisp-imenu-generic-expression | 92 (defvar lisp-imenu-generic-expression |
92 '( | 93 (list |
93 (nil | 94 (list nil |
94 "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\|ine-skeleton\\)\ | 95 (purecopy "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\|\ |
95 \\s-+\\([-A-Za-z0-9+*|:/]+\\)" 2) | 96 ine-skeleton\\|ine-minor-mode\\)\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2) |
96 ("Variables" | 97 (list (purecopy "Variables") |
97 "^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\\([-A-Za-z0-9+*|:/]+\\)" 2) | 98 (purecopy "^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\ |
98 ("Types" | 99 \\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2) |
99 "^\\s-*(def\\(group\\|type\\|struct\\|class\\|ine-condition\ | 100 (list (purecopy "Types") |
100 \\|ine-widget\\)\\s-+'?\\([-A-Za-z0-9+*|:/]+\\)" | 101 (purecopy "^\\s-*(def\\(group\\|type\\|struct\\|class\\|\ |
102 ine-condition\\|ine-widget\\|face\\)\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)") | |
101 2)) | 103 2)) |
102 | 104 |
103 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") | 105 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") |
104 | 106 |
105 (defun lisp-mode-variables (lisp-syntax) | 107 (defun lisp-mode-variables (lisp-syntax) |
208 (or buffer-file-name | 210 (or buffer-file-name |
209 (error "The buffer must be saved in a file first")) | 211 (error "The buffer must be saved in a file first")) |
210 (require 'bytecomp) | 212 (require 'bytecomp) |
211 ;; Recompile if file or buffer has changed since last compilation. | 213 ;; Recompile if file or buffer has changed since last compilation. |
212 (if (and (buffer-modified-p) | 214 (if (and (buffer-modified-p) |
213 (y-or-n-p (format "save buffer %s first? " (buffer-name)))) | 215 (y-or-n-p (format "Save buffer %s first? " (buffer-name)))) |
214 (save-buffer)) | 216 (save-buffer)) |
215 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name))) | 217 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name))) |
216 (if (file-newer-than-file-p compiled-file-name buffer-file-name) | 218 (if (file-newer-than-file-p compiled-file-name buffer-file-name) |
217 (load-file compiled-file-name) | 219 (load-file compiled-file-name) |
218 (byte-compile-file buffer-file-name t)))) | 220 (byte-compile-file buffer-file-name t)))) |
219 | 221 |
220 (defcustom emacs-lisp-mode-hook nil | 222 (defcustom emacs-lisp-mode-hook nil |
221 "Hook run when entering Emacs Lisp mode." | 223 "Hook run when entering Emacs Lisp mode." |
222 :options '(turn-on-eldoc-mode imenu-add-menubar-index) | 224 :options '(turn-on-eldoc-mode imenu-add-menubar-index checkdoc-minor-mode) |
223 :type 'hook | 225 :type 'hook |
224 :group 'lisp) | 226 :group 'lisp) |
225 | 227 |
226 (defcustom lisp-mode-hook nil | 228 (defcustom lisp-mode-hook nil |
227 "Hook run when entering Lisp mode." | 229 "Hook run when entering Lisp mode." |
251 (setq mode-name "Emacs-Lisp") | 253 (setq mode-name "Emacs-Lisp") |
252 (lisp-mode-variables nil) | 254 (lisp-mode-variables nil) |
253 (setq imenu-case-fold-search nil) | 255 (setq imenu-case-fold-search nil) |
254 (run-hooks 'emacs-lisp-mode-hook)) | 256 (run-hooks 'emacs-lisp-mode-hook)) |
255 | 257 |
256 (defvar lisp-mode-map () | 258 (defvar lisp-mode-map |
259 (let ((map (make-sparse-keymap))) | |
260 (set-keymap-parent map shared-lisp-mode-map) | |
261 (define-key map "\e\C-x" 'lisp-eval-defun) | |
262 (define-key map "\C-c\C-z" 'run-lisp) | |
263 map) | |
257 "Keymap for ordinary Lisp mode. | 264 "Keymap for ordinary Lisp mode. |
258 All commands in `shared-lisp-mode-map' are inherited by this map.") | 265 All commands in `shared-lisp-mode-map' are inherited by this map.") |
259 | |
260 (if lisp-mode-map | |
261 () | |
262 (setq lisp-mode-map (make-sparse-keymap)) | |
263 (set-keymap-parent lisp-mode-map shared-lisp-mode-map) | |
264 (define-key lisp-mode-map "\e\C-x" 'lisp-eval-defun) | |
265 (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)) | |
266 | 266 |
267 (defun lisp-mode () | 267 (defun lisp-mode () |
268 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp. | 268 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp. |
269 Commands: | 269 Commands: |
270 Delete converts tabs to spaces as it moves back. | 270 Delete converts tabs to spaces as it moves back. |
289 (defun lisp-eval-defun nil | 289 (defun lisp-eval-defun nil |
290 "Send the current defun to the Lisp process made by \\[run-lisp]." | 290 "Send the current defun to the Lisp process made by \\[run-lisp]." |
291 (interactive) | 291 (interactive) |
292 (error "Process lisp does not exist")) | 292 (error "Process lisp does not exist")) |
293 | 293 |
294 (defvar lisp-interaction-mode-map () | 294 (defvar lisp-interaction-mode-map |
295 (let ((map (make-sparse-keymap))) | |
296 (set-keymap-parent map shared-lisp-mode-map) | |
297 (define-key map "\e\C-x" 'eval-defun) | |
298 (define-key map "\e\t" 'lisp-complete-symbol) | |
299 (define-key map "\n" 'eval-print-last-sexp) | |
300 map) | |
295 "Keymap for Lisp Interaction mode. | 301 "Keymap for Lisp Interaction mode. |
296 All commands in `shared-lisp-mode-map' are inherited by this map.") | 302 All commands in `shared-lisp-mode-map' are inherited by this map.") |
297 | |
298 (if lisp-interaction-mode-map | |
299 () | |
300 (setq lisp-interaction-mode-map (make-sparse-keymap)) | |
301 (set-keymap-parent lisp-interaction-mode-map shared-lisp-mode-map) | |
302 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun) | |
303 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol) | |
304 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp)) | |
305 | 303 |
306 (defun lisp-interaction-mode () | 304 (defun lisp-interaction-mode () |
307 "Major mode for typing and evaluating Lisp forms. | 305 "Major mode for typing and evaluating Lisp forms. |
308 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression | 306 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression |
309 before point, and prints its value into the buffer, advancing point. | 307 before point, and prints its value into the buffer, advancing point. |
402 (defun eval-defun-1 (form) | 400 (defun eval-defun-1 (form) |
403 (cond ((and (eq (car form) 'defvar) | 401 (cond ((and (eq (car form) 'defvar) |
404 (cdr-safe (cdr-safe form))) | 402 (cdr-safe (cdr-safe form))) |
405 ;; Force variable to be bound. | 403 ;; Force variable to be bound. |
406 (cons 'defconst (cdr form))) | 404 (cons 'defconst (cdr form))) |
407 ((and (eq (car form) 'defcustom) | 405 ;; `defcustom' is now macroexpanded to `custom-declare-variable'. |
408 (default-boundp (nth 1 form))) | 406 ((and (eq (car form) 'custom-declare-variable) |
407 (default-boundp (eval (nth 1 form)))) | |
409 ;; Force variable to be bound. | 408 ;; Force variable to be bound. |
410 (set-default (nth 1 form) (eval (nth 2 form))) | 409 (set-default (eval (nth 1 form)) (eval (nth 2 form))) |
411 form) | 410 form) |
412 ((eq (car form) 'progn) | 411 ((eq (car form) 'progn) |
413 (cons 'progn (mapcar 'eval-defun-1 (cdr form)))) | 412 (cons 'progn (mapcar 'eval-defun-1 (cdr form)))) |
414 (t form))) | 413 (t form))) |
415 | 414 |
497 (point)))) | 496 (point)))) |
498 (do-auto-fill) | 497 (do-auto-fill) |
499 (let ((comment-start nil) (comment-start-skip nil)) | 498 (let ((comment-start nil) (comment-start-skip nil)) |
500 (do-auto-fill))))) | 499 (do-auto-fill))))) |
501 | 500 |
502 (defvar lisp-indent-offset nil "") | 501 (defvar lisp-indent-offset nil) |
503 (defvar lisp-indent-function 'lisp-indent-function "") | 502 (defvar lisp-indent-function 'lisp-indent-function) |
504 | 503 |
505 (defun lisp-indent-line (&optional whole-exp) | 504 (defun lisp-indent-line (&optional whole-exp) |
506 "Indent current line as Lisp code. | 505 "Indent current line as Lisp code. |
507 With argument, indent any additional lines of the same expression | 506 With argument, indent any additional lines of the same expression |
508 rigidly along with this one." | 507 rigidly along with this one." |
614 calculate-lisp-indent-last-sexp | 613 calculate-lisp-indent-last-sexp |
615 0 t))) | 614 0 t))) |
616 (backward-prefix-chars)) | 615 (backward-prefix-chars)) |
617 (t | 616 (t |
618 ;; Indent beneath first sexp on same line as | 617 ;; Indent beneath first sexp on same line as |
619 ;; calculate-lisp-indent-last-sexp. Again, it's | 618 ;; `calculate-lisp-indent-last-sexp'. Again, it's |
620 ;; almost certainly a function call. | 619 ;; almost certainly a function call. |
621 (goto-char calculate-lisp-indent-last-sexp) | 620 (goto-char calculate-lisp-indent-last-sexp) |
622 (beginning-of-line) | 621 (beginning-of-line) |
623 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp | 622 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp |
624 0 t) | 623 0 t) |
867 (indent-to this-indent))))) | 866 (indent-to this-indent))))) |
868 (or outer-loop-done | 867 (or outer-loop-done |
869 (setq outer-loop-done (= (point) last-point)) | 868 (setq outer-loop-done (= (point) last-point)) |
870 (setq last-point (point))))))) | 869 (setq last-point (point))))))) |
871 | 870 |
872 ;; Indent every line whose first char is between START and END inclusive. | |
873 (defun lisp-indent-region (start end) | 871 (defun lisp-indent-region (start end) |
872 "Indent every line whose first char is between START and END inclusive." | |
874 (save-excursion | 873 (save-excursion |
875 (let ((endmark (copy-marker end))) | 874 (let ((endmark (copy-marker end))) |
876 (goto-char start) | 875 (goto-char start) |
877 (and (bolp) (not (eolp)) | 876 (and (bolp) (not (eolp)) |
878 (lisp-indent-line)) | 877 (lisp-indent-line)) |