comparison lisp/emacs-lisp/lisp-mode.el @ 39564:0e059993ad95

(lisp-imenu-generic-expression): Use regexp-opt. (doc-string-elt): Set symbol's prop. Copied from autoload.el. (lisp-font-lock-syntactic-face-function): New function. (lisp-mode-variables): Use it. Make arg optional. (emacs-lisp-mode): Don't pass an arg to lisp-mode-variables. (lisp-mode): Don't pass an arg to lisp-mode-variables. Set comment-start-skip.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 05 Oct 2001 09:31:27 +0000
parents f2c0f6df43ab
children 216728b10960
comparison
equal deleted inserted replaced
39563:925776635a57 39564:0e059993ad95
81 (define-abbrev-table 'lisp-mode-abbrev-table ()) 81 (define-abbrev-table 'lisp-mode-abbrev-table ())
82 82
83 (defvar lisp-imenu-generic-expression 83 (defvar lisp-imenu-generic-expression
84 (list 84 (list
85 (list nil 85 (list nil
86 (purecopy "^\\s-*(def\\(un\\*?\\|subst\\|macro\\|advice\\|\ 86 (purecopy (concat "^\\s-*("
87 ine-skeleton\\|ine-minor-mode\\)\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2) 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)
88 (list (purecopy "Variables") 98 (list (purecopy "Variables")
89 (purecopy "^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\ 99 (purecopy (concat "^\\s-*("
90 \\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2) 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)
91 (list (purecopy "Types") 106 (list (purecopy "Types")
92 (purecopy "^\\s-*(def\\(group\\|type\\|struct\\|class\\|\ 107 (purecopy (concat "^\\s-*("
93 ine-condition\\|ine-widget\\|face\\)\\s-+'?\\(\\sw\\(\\sw\\|\\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_\\)+\\)")))
94 2)) 114 2))
95 115
96 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") 116 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
97 117
98 (defun lisp-mode-variables (lisp-syntax) 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)
99 (cond (lisp-syntax 158 (cond (lisp-syntax
100 (set-syntax-table lisp-mode-syntax-table))) 159 (set-syntax-table lisp-mode-syntax-table)))
101 (setq local-abbrev-table lisp-mode-abbrev-table) 160 (setq local-abbrev-table lisp-mode-abbrev-table)
102 (make-local-variable 'paragraph-start) 161 (make-local-variable 'paragraph-start)
103 (setq paragraph-start (concat page-delimiter "\\|$" )) 162 (setq paragraph-start (concat page-delimiter "\\|$" ))
142 (setq multibyte-syntax-as-symbol t) 201 (setq multibyte-syntax-as-symbol t)
143 (setq font-lock-defaults 202 (setq font-lock-defaults
144 '((lisp-font-lock-keywords 203 '((lisp-font-lock-keywords
145 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) 204 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
146 nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun 205 nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
147 (font-lock-mark-block-function . mark-defun)))) 206 (font-lock-mark-block-function . mark-defun)
207 (font-lock-syntactic-face-function
208 . lisp-font-lock-syntactic-face-function))))
148 209
149 (defun lisp-outline-level () 210 (defun lisp-outline-level ()
150 "Lisp mode `outline-level' function." 211 "Lisp mode `outline-level' function."
151 (if (looking-at "(") 212 (if (looking-at "(")
152 1000 213 1000
246 Delete converts tabs to spaces as it moves back. 307 Delete converts tabs to spaces as it moves back.
247 Blank lines separate paragraphs. Semicolons start comments. 308 Blank lines separate paragraphs. Semicolons start comments.
248 \\{emacs-lisp-mode-map} 309 \\{emacs-lisp-mode-map}
249 Entry to this mode calls the value of `emacs-lisp-mode-hook' 310 Entry to this mode calls the value of `emacs-lisp-mode-hook'
250 if that value is non-nil." 311 if that value is non-nil."
251 (lisp-mode-variables nil) 312 (lisp-mode-variables)
252 (setq imenu-case-fold-search nil)) 313 (setq imenu-case-fold-search nil))
253 314
254 (defvar lisp-mode-map 315 (defvar lisp-mode-map
255 (let ((map (make-sparse-keymap))) 316 (let ((map (make-sparse-keymap)))
256 (set-keymap-parent map lisp-mode-shared-map) 317 (set-keymap-parent map lisp-mode-shared-map)
269 Note that `run-lisp' may be used either to start an inferior Lisp job 330 Note that `run-lisp' may be used either to start an inferior Lisp job
270 or to switch back to an existing one. 331 or to switch back to an existing one.
271 332
272 Entry to this mode calls the value of `lisp-mode-hook' 333 Entry to this mode calls the value of `lisp-mode-hook'
273 if that value is non-nil." 334 if that value is non-nil."
274 (lisp-mode-variables t) 335 (lisp-mode-variables)
275 (make-local-variable 'font-lock-keywords-case-fold-search) 336 (set (make-local-variable 'comment-start-skip)
276 (setq font-lock-keywords-case-fold-search t) 337 "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
338 (set (make-local-variable 'font-lock-keywords-case-fold-search) t)
277 (setq imenu-case-fold-search t)) 339 (setq imenu-case-fold-search t))
278 340
279 ;; This will do unless inf-lisp.el is loaded. 341 ;; This will do unless inf-lisp.el is loaded.
280 (defun lisp-eval-defun (&optional and-go) 342 (defun lisp-eval-defun (&optional and-go)
281 "Send the current defun to the Lisp process made by \\[run-lisp]." 343 "Send the current defun to the Lisp process made by \\[run-lisp]."
571 (defun lisp-indent-line (&optional whole-exp) 633 (defun lisp-indent-line (&optional whole-exp)
572 "Indent current line as Lisp code. 634 "Indent current line as Lisp code.
573 With argument, indent any additional lines of the same expression 635 With argument, indent any additional lines of the same expression
574 rigidly along with this one." 636 rigidly along with this one."
575 (interactive "P") 637 (interactive "P")
576 (let ((indent (calculate-lisp-indent)) shift-amt beg end 638 (let ((indent (calculate-lisp-indent)) shift-amt end
577 (pos (- (point-max) (point)))) 639 (pos (- (point-max) (point)))
578 (beginning-of-line) 640 (beg (progn (beginning-of-line) (point))))
579 (setq beg (point))
580 (skip-chars-forward " \t") 641 (skip-chars-forward " \t")
581 (if (or (null indent) (looking-at "\\s<\\s<\\s<")) 642 (if (or (null indent) (looking-at "\\s<\\s<\\s<"))
582 ;; Don't alter indentation of a ;;; comment line 643 ;; Don't alter indentation of a ;;; comment line
583 ;; or a line that starts in a string. 644 ;; or a line that starts in a string.
584 (goto-char (- (point-max) pos)) 645 (goto-char (- (point-max) pos))