Mercurial > emacs
comparison lisp/emacs-lisp/lisp-mode.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 0d8b17d428b5 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
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, 2000, 2001 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1986, 1999, 2000, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Maintainer: FSF | 6 ;; Maintainer: FSF |
6 ;; Keywords: lisp, languages | 7 ;; Keywords: lisp, languages |
7 | 8 |
8 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 ;; GNU General Public License for more details. | 19 ;; GNU General Public License for more details. |
19 | 20 |
20 ;; You should have received a copy of the GNU General Public License | 21 ;; 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 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02110-1301, USA. |
24 | 25 |
25 ;;; Commentary: | 26 ;;; Commentary: |
26 | 27 |
27 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). | 28 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). |
28 ;; This mode is documented in the Emacs manual. | 29 ;; This mode is documented in the Emacs manual. |
29 | 30 |
30 ;;; Code: | 31 ;;; Code: |
32 | |
33 (defvar font-lock-comment-face) | |
34 (defvar font-lock-doc-face) | |
35 (defvar font-lock-keywords-case-fold-search) | |
36 (defvar font-lock-string-face) | |
31 | 37 |
32 (defvar lisp-mode-abbrev-table nil) | 38 (defvar lisp-mode-abbrev-table nil) |
33 | 39 |
34 (defvar emacs-lisp-mode-syntax-table | 40 (defvar emacs-lisp-mode-syntax-table |
35 (let ((table (make-syntax-table))) | 41 (let ((table (make-syntax-table))) |
47 (setq i (1+ i))) | 53 (setq i (1+ i))) |
48 (setq i (1+ ?z)) | 54 (setq i (1+ ?z)) |
49 (while (< i 128) | 55 (while (< i 128) |
50 (modify-syntax-entry i "_ " table) | 56 (modify-syntax-entry i "_ " table) |
51 (setq i (1+ i))) | 57 (setq i (1+ i))) |
52 (modify-syntax-entry ? " " table) | 58 (modify-syntax-entry ?\s " " table) |
53 (modify-syntax-entry ?\t " " table) | 59 (modify-syntax-entry ?\t " " table) |
54 (modify-syntax-entry ?\f " " table) | 60 (modify-syntax-entry ?\f " " table) |
55 (modify-syntax-entry ?\n "> " table) | 61 (modify-syntax-entry ?\n "> " table) |
56 ;; Give CR the same syntax as newline, for selective-display. | 62 ;; This is probably obsolete since nowadays such features use overlays. |
57 (modify-syntax-entry ?\^m "> " table) | 63 ;; ;; Give CR the same syntax as newline, for selective-display. |
64 ;; (modify-syntax-entry ?\^m "> " table) | |
58 (modify-syntax-entry ?\; "< " table) | 65 (modify-syntax-entry ?\; "< " table) |
59 (modify-syntax-entry ?` "' " table) | 66 (modify-syntax-entry ?` "' " table) |
60 (modify-syntax-entry ?' "' " table) | 67 (modify-syntax-entry ?' "' " table) |
61 (modify-syntax-entry ?, "' " table) | 68 (modify-syntax-entry ?, "' " table) |
69 (modify-syntax-entry ?@ "' " table) | |
62 ;; Used to be singlequote; changed for flonums. | 70 ;; Used to be singlequote; changed for flonums. |
63 (modify-syntax-entry ?. "_ " table) | 71 (modify-syntax-entry ?. "_ " table) |
64 (modify-syntax-entry ?# "' " table) | 72 (modify-syntax-entry ?# "' " table) |
65 (modify-syntax-entry ?\" "\" " table) | 73 (modify-syntax-entry ?\" "\" " table) |
66 (modify-syntax-entry ?\\ "\\ " table) | 74 (modify-syntax-entry ?\\ "\\ " table) |
72 | 80 |
73 (defvar lisp-mode-syntax-table | 81 (defvar lisp-mode-syntax-table |
74 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table))) | 82 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table))) |
75 (modify-syntax-entry ?\[ "_ " table) | 83 (modify-syntax-entry ?\[ "_ " table) |
76 (modify-syntax-entry ?\] "_ " table) | 84 (modify-syntax-entry ?\] "_ " table) |
77 (modify-syntax-entry ?# "' 14bn" table) | 85 (modify-syntax-entry ?# "' 14b" table) |
78 (modify-syntax-entry ?| "\" 23b" table) | 86 (modify-syntax-entry ?| "\" 23bn" table) |
79 table)) | 87 table)) |
80 | 88 |
81 (define-abbrev-table 'lisp-mode-abbrev-table ()) | 89 (define-abbrev-table 'lisp-mode-abbrev-table ()) |
82 | 90 |
83 (defvar lisp-imenu-generic-expression | 91 (defvar lisp-imenu-generic-expression |
86 (purecopy (concat "^\\s-*(" | 94 (purecopy (concat "^\\s-*(" |
87 (eval-when-compile | 95 (eval-when-compile |
88 (regexp-opt | 96 (regexp-opt |
89 '("defun" "defun*" "defsubst" "defmacro" | 97 '("defun" "defun*" "defsubst" "defmacro" |
90 "defadvice" "define-skeleton" | 98 "defadvice" "define-skeleton" |
91 "define-minor-mode" "define-derived-mode" | 99 "define-minor-mode" "define-global-minor-mode" |
100 "define-derived-mode" "define-generic-mode" | |
92 "define-compiler-macro" "define-modify-macro" | 101 "define-compiler-macro" "define-modify-macro" |
93 "defsetf" "define-setf-expander" | 102 "defsetf" "define-setf-expander" |
94 "define-method-combination" | 103 "define-method-combination" |
95 "defgeneric" "defmethod") t)) | 104 "defgeneric" "defmethod") t)) |
96 "\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)")) | 105 "\\s-+\\(\\(\\sw\\|\\s_\\)+\\)")) |
97 2) | 106 2) |
98 (list (purecopy "Variables") | 107 (list (purecopy "Variables") |
99 (purecopy (concat "^\\s-*(" | 108 (purecopy (concat "^\\s-*(" |
100 (eval-when-compile | 109 (eval-when-compile |
101 (regexp-opt | 110 (regexp-opt |
102 '("defvar" "defconst" "defconstant" "defcustom" | 111 '("defvar" "defconst" "defconstant" "defcustom" |
103 "defparameter" "define-symbol-macro") t)) | 112 "defparameter" "define-symbol-macro") t)) |
104 "\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)")) | 113 "\\s-+\\(\\(\\sw\\|\\s_\\)+\\)")) |
105 2) | 114 2) |
106 (list (purecopy "Types") | 115 (list (purecopy "Types") |
107 (purecopy (concat "^\\s-*(" | 116 (purecopy (concat "^\\s-*(" |
108 (eval-when-compile | 117 (eval-when-compile |
109 (regexp-opt | 118 (regexp-opt |
110 '("defgroup" "deftheme" "deftype" "defstruct" | 119 '("defgroup" "deftheme" "deftype" "defstruct" |
111 "defclass" "define-condition" "define-widget" | 120 "defclass" "define-condition" "define-widget" |
112 "defface" "defpackage") t)) | 121 "defface" "defpackage") t)) |
113 "\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)")) | 122 "\\s-+'?\\(\\(\\sw\\|\\s_\\)+\\)")) |
114 2)) | 123 2)) |
115 | 124 |
116 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") | 125 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") |
117 | 126 |
118 ;; This was originally in autoload.el and is still used there. | 127 ;; This was originally in autoload.el and is still used there. |
124 (put 'deftheme 'doc-string-elt 2) | 133 (put 'deftheme 'doc-string-elt 2) |
125 (put 'defconst 'doc-string-elt 3) | 134 (put 'defconst 'doc-string-elt 3) |
126 (put 'defmacro 'doc-string-elt 3) | 135 (put 'defmacro 'doc-string-elt 3) |
127 (put 'defmacro* 'doc-string-elt 3) | 136 (put 'defmacro* 'doc-string-elt 3) |
128 (put 'defsubst 'doc-string-elt 3) | 137 (put 'defsubst 'doc-string-elt 3) |
138 (put 'defstruct 'doc-string-elt 2) | |
129 (put 'define-skeleton 'doc-string-elt 2) | 139 (put 'define-skeleton 'doc-string-elt 2) |
130 (put 'define-derived-mode 'doc-string-elt 4) | 140 (put 'define-derived-mode 'doc-string-elt 4) |
141 (put 'define-compilation-mode 'doc-string-elt 3) | |
131 (put 'easy-mmode-define-minor-mode 'doc-string-elt 2) | 142 (put 'easy-mmode-define-minor-mode 'doc-string-elt 2) |
132 (put 'define-minor-mode 'doc-string-elt 2) | 143 (put 'define-minor-mode 'doc-string-elt 2) |
144 (put 'easy-mmode-define-global-mode 'doc-string-elt 2) | |
145 (put 'define-global-minor-mode 'doc-string-elt 2) | |
133 (put 'define-generic-mode 'doc-string-elt 7) | 146 (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) | 147 (put 'define-ibuffer-filter 'doc-string-elt 2) |
137 (put 'define-ibuffer-op 'doc-string-elt 3) | 148 (put 'define-ibuffer-op 'doc-string-elt 3) |
138 (put 'define-ibuffer-sorter 'doc-string-elt 2) | 149 (put 'define-ibuffer-sorter 'doc-string-elt 2) |
150 (put 'lambda 'doc-string-elt 2) | |
151 (put 'defalias 'doc-string-elt 3) | |
152 (put 'defvaralias 'doc-string-elt 3) | |
153 (put 'define-category 'doc-string-elt 2) | |
154 | |
155 (defvar lisp-doc-string-elt-property 'doc-string-elt | |
156 "The symbol property that holds the docstring position info.") | |
139 | 157 |
140 (defun lisp-font-lock-syntactic-face-function (state) | 158 (defun lisp-font-lock-syntactic-face-function (state) |
141 (if (nth 3 state) | 159 (if (nth 3 state) |
142 (if (and (eq (nth 0 state) 1) | 160 ;; This might be a (doc)string or a |...| symbol. |
143 ;; This might be a docstring. | 161 (let ((startpos (nth 8 state))) |
144 (save-excursion | 162 (if (eq (char-after startpos) ?|) |
145 (let ((n 0)) | 163 ;; This is not a string, but a |...| symbol. |
146 (goto-char (nth 8 state)) | 164 nil |
147 (condition-case nil | 165 (let* ((listbeg (nth 1 state)) |
148 (while (progn (backward-sexp 1) (setq n (1+ n)))) | 166 (firstsym (and listbeg |
149 (scan-error nil)) | 167 (save-excursion |
150 (when (> n 0) | 168 (goto-char listbeg) |
151 (let ((sym (intern-soft | 169 (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)") |
152 (buffer-substring | 170 (match-string 1))))) |
153 (point) (progn (forward-sexp 1) (point)))))) | 171 (docelt (and firstsym (get (intern-soft firstsym) |
154 (eq n (or (get sym 'doc-string-elt) 3))))))) | 172 lisp-doc-string-elt-property)))) |
155 font-lock-doc-face | 173 (if (and docelt |
156 font-lock-string-face) | 174 ;; It's a string in a form that can have a docstring. |
175 ;; Check whether it's in docstring position. | |
176 (save-excursion | |
177 (when (functionp docelt) | |
178 (goto-char (match-end 1)) | |
179 (setq docelt (funcall docelt))) | |
180 (goto-char listbeg) | |
181 (forward-char 1) | |
182 (condition-case nil | |
183 (while (and (> docelt 0) (< (point) startpos) | |
184 (progn (forward-sexp 1) t)) | |
185 (setq docelt (1- docelt))) | |
186 (error nil)) | |
187 (and (zerop docelt) (<= (point) startpos) | |
188 (progn (forward-comment (point-max)) t) | |
189 (= (point) (nth 8 state))))) | |
190 font-lock-doc-face | |
191 font-lock-string-face)))) | |
157 font-lock-comment-face)) | 192 font-lock-comment-face)) |
158 | 193 |
159 ;; The LISP-SYNTAX argument is used by code in inf-lisp.el and is | 194 ;; 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 | 195 ;; (uselessly) passed from pp.el, chistory.el, gnus-kill.el and score-mode.el |
161 (defun lisp-mode-variables (&optional lisp-syntax) | 196 (defun lisp-mode-variables (&optional lisp-syntax) |
164 (setq local-abbrev-table lisp-mode-abbrev-table) | 199 (setq local-abbrev-table lisp-mode-abbrev-table) |
165 (make-local-variable 'paragraph-ignore-fill-prefix) | 200 (make-local-variable 'paragraph-ignore-fill-prefix) |
166 (setq paragraph-ignore-fill-prefix t) | 201 (setq paragraph-ignore-fill-prefix t) |
167 (make-local-variable 'fill-paragraph-function) | 202 (make-local-variable 'fill-paragraph-function) |
168 (setq fill-paragraph-function 'lisp-fill-paragraph) | 203 (setq fill-paragraph-function 'lisp-fill-paragraph) |
204 ;; Adaptive fill mode gets the fill wrong for a one-line paragraph made of | |
205 ;; a single docstring. Let's fix it here. | |
206 (set (make-local-variable 'adaptive-fill-function) | |
207 (lambda () (if (looking-at "\\s-+\"[^\n\"]+\"\\s-*$") ""))) | |
169 ;; Adaptive fill mode gets in the way of auto-fill, | 208 ;; Adaptive fill mode gets in the way of auto-fill, |
170 ;; and should make no difference for explicit fill | 209 ;; and should make no difference for explicit fill |
171 ;; because lisp-fill-paragraph should do the job. | 210 ;; because lisp-fill-paragraph should do the job. |
172 ;; I believe that newcomment's auto-fill code properly deals with it -stef | 211 ;; I believe that newcomment's auto-fill code properly deals with it -stef |
173 ;;(set (make-local-variable 'adaptive-fill-mode) nil) | 212 ;;(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) | 213 (make-local-variable 'indent-line-function) |
177 (setq indent-line-function 'lisp-indent-line) | 214 (setq indent-line-function 'lisp-indent-line) |
178 (make-local-variable 'indent-region-function) | 215 (make-local-variable 'indent-region-function) |
179 (setq indent-region-function 'lisp-indent-region) | 216 (setq indent-region-function 'lisp-indent-region) |
180 (make-local-variable 'parse-sexp-ignore-comments) | 217 (make-local-variable 'parse-sexp-ignore-comments) |
181 (setq parse-sexp-ignore-comments t) | 218 (setq parse-sexp-ignore-comments t) |
182 (make-local-variable 'outline-regexp) | 219 (make-local-variable 'outline-regexp) |
183 (setq outline-regexp ";;;;* \\|(") | 220 (setq outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(") |
184 (make-local-variable 'outline-level) | 221 (make-local-variable 'outline-level) |
185 (setq outline-level 'lisp-outline-level) | 222 (setq outline-level 'lisp-outline-level) |
186 (make-local-variable 'comment-start) | 223 (make-local-variable 'comment-start) |
187 (setq comment-start ";") | 224 (setq comment-start ";") |
188 (make-local-variable 'comment-start-skip) | 225 (make-local-variable 'comment-start-skip) |
189 ;; Look within the line for a ; following an even number of backslashes | 226 ;; Look within the line for a ; following an even number of backslashes |
190 ;; after either a non-backslash or the line beginning. | 227 ;; after either a non-backslash or the line beginning. |
191 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *") | 228 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *") |
229 (make-local-variable 'font-lock-comment-start-skip) | |
230 ;; Font lock mode uses this only when it KNOWS a comment is starting. | |
231 (setq font-lock-comment-start-skip ";+ *") | |
192 (make-local-variable 'comment-add) | 232 (make-local-variable 'comment-add) |
193 (setq comment-add 1) ;default to `;;' in comment-region | 233 (setq comment-add 1) ;default to `;;' in comment-region |
194 (make-local-variable 'comment-column) | 234 (make-local-variable 'comment-column) |
195 (setq comment-column 40) | 235 (setq comment-column 40) |
196 (make-local-variable 'comment-indent-function) | 236 ;; Don't get confused by `;' in doc strings when paragraph-filling. |
197 (setq comment-indent-function 'lisp-comment-indent) | 237 (set (make-local-variable 'comment-use-global-state) t) |
198 (make-local-variable 'imenu-generic-expression) | 238 (make-local-variable 'imenu-generic-expression) |
199 (setq imenu-generic-expression lisp-imenu-generic-expression) | 239 (setq imenu-generic-expression lisp-imenu-generic-expression) |
200 (make-local-variable 'multibyte-syntax-as-symbol) | 240 (make-local-variable 'multibyte-syntax-as-symbol) |
201 (setq multibyte-syntax-as-symbol t) | 241 (setq multibyte-syntax-as-symbol t) |
202 (set (make-local-variable 'syntax-begin-function) 'beginning-of-defun) | 242 (set (make-local-variable 'syntax-begin-function) 'beginning-of-defun) |
203 (setq font-lock-defaults | 243 (setq font-lock-defaults |
204 '((lisp-font-lock-keywords | 244 '((lisp-font-lock-keywords |
205 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) | 245 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) |
206 nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun | 246 nil nil (("+-*/.<>=!?$%_&~^:@" . "w")) nil |
207 (font-lock-mark-block-function . mark-defun) | 247 (font-lock-mark-block-function . mark-defun) |
208 (font-lock-syntactic-face-function | 248 (font-lock-syntactic-face-function |
209 . lisp-font-lock-syntactic-face-function)))) | 249 . lisp-font-lock-syntactic-face-function)))) |
210 | 250 |
211 (defun lisp-outline-level () | 251 (defun lisp-outline-level () |
212 "Lisp mode `outline-level' function." | 252 "Lisp mode `outline-level' function." |
213 (if (looking-at "(") | 253 (let ((len (- (match-end 0) (match-beginning 0)))) |
214 1000 | 254 (if (looking-at "(\\|;;;###autoload") |
215 (looking-at outline-regexp) | 255 1000 |
216 (- (match-end 0) (match-beginning 0)))) | 256 len))) |
217 | |
218 | 257 |
219 (defvar lisp-mode-shared-map | 258 (defvar lisp-mode-shared-map |
220 (let ((map (make-sparse-keymap))) | 259 (let ((map (make-sparse-keymap))) |
221 (define-key map "\t" 'lisp-indent-line) | 260 (define-key map "\t" 'lisp-indent-line) |
222 (define-key map "\e\C-q" 'indent-sexp) | 261 (define-key map "\e\C-q" 'indent-sexp) |
237 (let ((map (make-sparse-keymap "Emacs-Lisp"))) | 276 (let ((map (make-sparse-keymap "Emacs-Lisp"))) |
238 (setq emacs-lisp-mode-map (make-sparse-keymap)) | 277 (setq emacs-lisp-mode-map (make-sparse-keymap)) |
239 (set-keymap-parent emacs-lisp-mode-map lisp-mode-shared-map) | 278 (set-keymap-parent emacs-lisp-mode-map lisp-mode-shared-map) |
240 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol) | 279 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol) |
241 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun) | 280 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun) |
281 (define-key emacs-lisp-mode-map "\e\C-q" 'indent-pp-sexp) | |
242 (define-key emacs-lisp-mode-map [menu-bar] (make-sparse-keymap)) | 282 (define-key emacs-lisp-mode-map [menu-bar] (make-sparse-keymap)) |
243 (define-key emacs-lisp-mode-map [menu-bar emacs-lisp] | 283 (define-key emacs-lisp-mode-map [menu-bar emacs-lisp] |
244 (cons "Emacs-Lisp" map)) | 284 (cons "Emacs-Lisp" map)) |
245 (define-key map [edebug-defun] | 285 (define-key map [edebug-defun] |
246 '("Instrument Function for Debugging" . edebug-defun)) | 286 '("Instrument Function for Debugging" . edebug-defun)) |
316 (set-syntax-table emacs-lisp-mode-syntax-table) | 356 (set-syntax-table emacs-lisp-mode-syntax-table) |
317 (setq major-mode 'emacs-lisp-mode) | 357 (setq major-mode 'emacs-lisp-mode) |
318 (setq mode-name "Emacs-Lisp") | 358 (setq mode-name "Emacs-Lisp") |
319 (lisp-mode-variables) | 359 (lisp-mode-variables) |
320 (setq imenu-case-fold-search nil) | 360 (setq imenu-case-fold-search nil) |
321 (run-hooks 'emacs-lisp-mode-hook)) | 361 (run-mode-hooks 'emacs-lisp-mode-hook)) |
362 (put 'emacs-lisp-mode 'custom-mode-group 'lisp) | |
322 | 363 |
323 (defvar lisp-mode-map | 364 (defvar lisp-mode-map |
324 (let ((map (make-sparse-keymap))) | 365 (let ((map (make-sparse-keymap))) |
325 (set-keymap-parent map lisp-mode-shared-map) | 366 (set-keymap-parent map lisp-mode-shared-map) |
326 (define-key map "\e\C-x" 'lisp-eval-defun) | 367 (define-key map "\e\C-x" 'lisp-eval-defun) |
351 "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *") | 392 "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *") |
352 (make-local-variable 'font-lock-keywords-case-fold-search) | 393 (make-local-variable 'font-lock-keywords-case-fold-search) |
353 (setq font-lock-keywords-case-fold-search t) | 394 (setq font-lock-keywords-case-fold-search t) |
354 (setq imenu-case-fold-search t) | 395 (setq imenu-case-fold-search t) |
355 (set-syntax-table lisp-mode-syntax-table) | 396 (set-syntax-table lisp-mode-syntax-table) |
356 (run-hooks 'lisp-mode-hook)) | 397 (run-mode-hooks 'lisp-mode-hook)) |
398 (put 'lisp-mode 'find-tag-default-function 'lisp-find-tag-default) | |
399 | |
400 (defun lisp-find-tag-default () | |
401 (let ((default (find-tag-default))) | |
402 (when (stringp default) | |
403 (if (string-match ":+" default) | |
404 (substring default (match-end 0)) | |
405 default)))) | |
406 | |
407 ;; Used in old LispM code. | |
408 (defalias 'common-lisp-mode 'lisp-mode) | |
357 | 409 |
358 ;; This will do unless inf-lisp.el is loaded. | 410 ;; This will do unless inf-lisp.el is loaded. |
359 (defun lisp-eval-defun (&optional and-go) | 411 (defun lisp-eval-defun (&optional and-go) |
360 "Send the current defun to the Lisp process made by \\[run-lisp]." | 412 "Send the current defun to the Lisp process made by \\[run-lisp]." |
361 (interactive) | 413 (interactive) |
363 | 415 |
364 (defvar lisp-interaction-mode-map | 416 (defvar lisp-interaction-mode-map |
365 (let ((map (make-sparse-keymap))) | 417 (let ((map (make-sparse-keymap))) |
366 (set-keymap-parent map lisp-mode-shared-map) | 418 (set-keymap-parent map lisp-mode-shared-map) |
367 (define-key map "\e\C-x" 'eval-defun) | 419 (define-key map "\e\C-x" 'eval-defun) |
420 (define-key map "\e\C-q" 'indent-pp-sexp) | |
368 (define-key map "\e\t" 'lisp-complete-symbol) | 421 (define-key map "\e\t" 'lisp-complete-symbol) |
369 (define-key map "\n" 'eval-print-last-sexp) | 422 (define-key map "\n" 'eval-print-last-sexp) |
370 map) | 423 map) |
371 "Keymap for Lisp Interaction mode. | 424 "Keymap for Lisp Interaction mode. |
372 All commands in `lisp-mode-shared-map' are inherited by this map.") | 425 All commands in `lisp-mode-shared-map' are inherited by this map.") |
417 help-echo "RET, mouse-2: toggle abbreviated display" | 470 help-echo "RET, mouse-2: toggle abbreviated display" |
418 rear-nonsticky (mouse-face keymap help-echo | 471 rear-nonsticky (mouse-face keymap help-echo |
419 printed-value))))) | 472 printed-value))))) |
420 | 473 |
421 | 474 |
422 (defun last-sexp-toggle-display () | 475 (defun last-sexp-toggle-display (&optional arg) |
423 "Toggle between abbreviated and unabbreviated printed representations." | 476 "Toggle between abbreviated and unabbreviated printed representations." |
424 (interactive) | 477 (interactive "P") |
425 (let ((value (get-text-property (point) 'printed-value))) | 478 (save-restriction |
426 (when value | 479 (widen) |
427 (let ((beg (or (previous-single-property-change (point) 'printed-value) (point))) | 480 (let ((value (get-text-property (point) 'printed-value))) |
428 (end (or (next-single-char-property-change (point) 'printed-value) (point))) | 481 (when value |
429 (standard-output (current-buffer)) | 482 (let ((beg (or (previous-single-property-change (min (point-max) (1+ (point))) |
430 (point (point))) | 483 'printed-value) |
431 (delete-region beg end) | 484 (point))) |
432 (insert (nth 1 value)) | 485 (end (or (next-single-char-property-change (point) 'printed-value) (point))) |
433 (last-sexp-setup-props beg (point) | 486 (standard-output (current-buffer)) |
434 (nth 0 value) | 487 (point (point))) |
435 (nth 2 value) | 488 (delete-region beg end) |
436 (nth 1 value)) | 489 (insert (nth 1 value)) |
437 (goto-char (min (point-max) point)))))) | 490 (last-sexp-setup-props beg (point) |
491 (nth 0 value) | |
492 (nth 2 value) | |
493 (nth 1 value)) | |
494 (goto-char (min (point-max) point))))))) | |
495 | |
496 (defun prin1-char (char) | |
497 "Return a string representing CHAR as a character rather than as an integer. | |
498 If CHAR is not a character, return nil." | |
499 (and (integerp char) | |
500 (eventp char) | |
501 (let ((c (event-basic-type char)) | |
502 (mods (event-modifiers char)) | |
503 string) | |
504 ;; Prevent ?A from turning into ?\S-a. | |
505 (if (and (memq 'shift mods) | |
506 (zerop (logand char ?\S-\^@)) | |
507 (not (let ((case-fold-search nil)) | |
508 (char-equal c (upcase c))))) | |
509 (setq c (upcase c) mods nil)) | |
510 ;; What string are we considering using? | |
511 (condition-case nil | |
512 (setq string | |
513 (concat | |
514 "?" | |
515 (mapconcat | |
516 (lambda (modif) | |
517 (cond ((eq modif 'super) "\\s-") | |
518 (t (string ?\\ (upcase (aref (symbol-name modif) 0)) ?-)))) | |
519 mods "") | |
520 (cond | |
521 ((memq c '(?\; ?\( ?\) ?\{ ?\} ?\[ ?\] ?\" ?\' ?\\)) (string ?\\ c)) | |
522 ((eq c 127) "\\C-?") | |
523 (t | |
524 (string c))))) | |
525 (error nil)) | |
526 ;; Verify the string reads a CHAR, not to some other character. | |
527 ;; If it doesn't, return nil instead. | |
528 (and string | |
529 (= (car (read-from-string string)) char) | |
530 string)))) | |
438 | 531 |
439 | 532 |
440 (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) | 533 (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) |
441 "Evaluate sexp before point; print value in minibuffer. | 534 "Evaluate sexp before point; print value in minibuffer. |
442 With argument, print output into current buffer." | 535 With argument, print output into current buffer." |
444 (let ((value | 537 (let ((value |
445 (eval (let ((stab (syntax-table)) | 538 (eval (let ((stab (syntax-table)) |
446 (opoint (point)) | 539 (opoint (point)) |
447 ignore-quotes | 540 ignore-quotes |
448 expr) | 541 expr) |
449 (unwind-protect | 542 (save-excursion |
450 (save-excursion | 543 (with-syntax-table emacs-lisp-mode-syntax-table |
451 (set-syntax-table emacs-lisp-mode-syntax-table) | 544 ;; If this sexp appears to be enclosed in `...' |
452 ;; If this sexp appears to be enclosed in `...' | 545 ;; then ignore the surrounding quotes. |
453 ;; then ignore the surrounding quotes. | 546 (setq ignore-quotes |
454 (setq ignore-quotes | 547 (or (eq (following-char) ?\') |
455 (or (eq (following-char) ?\') | 548 (eq (preceding-char) ?\'))) |
456 (eq (preceding-char) ?\'))) | 549 (forward-sexp -1) |
457 (forward-sexp -1) | 550 ;; If we were after `?\e' (or similar case), |
458 ;; If we were after `?\e' (or similar case), | 551 ;; use the whole thing, not just the `e'. |
459 ;; use the whole thing, not just the `e'. | 552 (when (eq (preceding-char) ?\\) |
460 (when (eq (preceding-char) ?\\) | 553 (forward-char -1) |
461 (forward-char -1) | 554 (when (eq (preceding-char) ??) |
462 (when (eq (preceding-char) ??) | 555 (forward-char -1))) |
463 (forward-char -1))) | 556 |
464 | 557 ;; Skip over `#N='s. |
465 ;; Skip over `#N='s. | 558 (when (eq (preceding-char) ?=) |
466 (when (eq (preceding-char) ?=) | 559 (let (labeled-p) |
467 (let (labeled-p) | 560 (save-excursion |
468 (save-excursion | 561 (skip-chars-backward "0-9#=") |
469 (skip-chars-backward "0-9#=") | 562 (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) |
470 (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) | 563 (when labeled-p |
471 (when labeled-p | 564 (forward-sexp -1)))) |
472 (forward-sexp -1)))) | 565 |
473 | 566 (save-restriction |
474 (save-restriction | 567 ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in |
475 ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in | 568 ;; `variable' so that the value is returned, not the |
476 ;; `variable' so that the value is returned, not the | 569 ;; name |
477 ;; name | 570 (if (and ignore-quotes |
478 (if (and ignore-quotes | 571 (eq (following-char) ?`)) |
479 (eq (following-char) ?`)) | 572 (forward-char)) |
480 (forward-char)) | 573 (narrow-to-region (point-min) opoint) |
481 (narrow-to-region (point-min) opoint) | 574 (setq expr (read (current-buffer))) |
482 (setq expr (read (current-buffer))) | 575 ;; If it's an (interactive ...) form, it's more |
483 ;; If it's an (interactive ...) form, it's more | 576 ;; useful to show how an interactive call would |
484 ;; useful to show how an interactive call would | 577 ;; use it. |
485 ;; use it. | 578 (and (consp expr) |
486 (and (consp expr) | 579 (eq (car expr) 'interactive) |
487 (eq (car expr) 'interactive) | 580 (setq expr |
488 (setq expr | 581 (list 'call-interactively |
489 (list 'call-interactively | 582 (list 'quote |
490 (list 'quote | 583 (list 'lambda |
491 (list 'lambda | 584 '(&rest args) |
492 '(&rest args) | 585 expr |
493 expr | 586 'args))))) |
494 'args))))) | 587 expr))))))) |
495 expr)) | 588 (eval-last-sexp-print-value value)))) |
496 (set-syntax-table stab)))))) | 589 |
497 (let ((unabbreviated (let ((print-length nil) (print-level nil)) | 590 (defun eval-last-sexp-print-value (value) |
498 (prin1-to-string value))) | 591 (let ((unabbreviated (let ((print-length nil) (print-level nil)) |
499 (print-length eval-expression-print-length) | 592 (prin1-to-string value))) |
500 (print-level eval-expression-print-level) | 593 (print-length eval-expression-print-length) |
501 (beg (point)) | 594 (print-level eval-expression-print-level) |
502 end) | 595 (beg (point)) |
503 (prog1 | 596 end) |
504 (prin1 value) | 597 (prog1 |
505 (setq end (point)) | 598 (prin1 value) |
506 (when (and (bufferp standard-output) | 599 (let ((str (eval-expression-print-format value))) |
507 (or (not (null print-length)) | 600 (if str (princ str))) |
508 (not (null print-level))) | 601 (setq end (point)) |
509 (not (string= unabbreviated | 602 (when (and (bufferp standard-output) |
510 (buffer-substring-no-properties beg end)))) | 603 (or (not (null print-length)) |
511 (last-sexp-setup-props beg end value | 604 (not (null print-level))) |
512 unabbreviated | 605 (not (string= unabbreviated |
513 (buffer-substring-no-properties beg end)) | 606 (buffer-substring-no-properties beg end)))) |
514 )))))) | 607 (last-sexp-setup-props beg end value |
515 | 608 unabbreviated |
609 (buffer-substring-no-properties beg end)) | |
610 )))) | |
611 | |
612 | |
613 (defvar eval-last-sexp-fake-value (make-symbol "t")) | |
516 | 614 |
517 (defun eval-last-sexp (eval-last-sexp-arg-internal) | 615 (defun eval-last-sexp (eval-last-sexp-arg-internal) |
518 "Evaluate sexp before point; print value in minibuffer. | 616 "Evaluate sexp before point; print value in minibuffer. |
519 Interactively, with prefix argument, print output into current buffer." | 617 Interactively, with prefix argument, print output into current buffer." |
520 (interactive "P") | 618 (interactive "P") |
521 (if (null eval-expression-debug-on-error) | 619 (if (null eval-expression-debug-on-error) |
522 (eval-last-sexp-1 eval-last-sexp-arg-internal) | 620 (eval-last-sexp-1 eval-last-sexp-arg-internal) |
523 (let ((old-value (make-symbol "t")) new-value value) | 621 (let ((old-value eval-last-sexp-fake-value) new-value value) |
524 (let ((debug-on-error old-value)) | 622 (let ((debug-on-error old-value)) |
525 (setq value (eval-last-sexp-1 eval-last-sexp-arg-internal)) | 623 (setq value (eval-last-sexp-1 eval-last-sexp-arg-internal)) |
526 (setq new-value debug-on-error)) | 624 (setq new-value debug-on-error)) |
527 (unless (eq old-value new-value) | 625 (unless (eq old-value new-value) |
528 (setq debug-on-error new-value)) | 626 (setq debug-on-error new-value)) |
529 value))) | 627 value))) |
530 | 628 |
531 (defun eval-defun-1 (form) | 629 (defun eval-defun-1 (form) |
532 "Change defvar into defconst within FORM. | 630 "Treat some expressions specially. |
533 Likewise for other constructs as necessary." | 631 Reset the `defvar' and `defcustom' variables to the initial value. |
632 Reinitialize the face according to the `defface' specification." | |
534 ;; The code in edebug-defun should be consistent with this, but not | 633 ;; The code in edebug-defun should be consistent with this, but not |
535 ;; the same, since this gets a macroexpended form. | 634 ;; the same, since this gets a macroexpended form. |
536 (cond ((not (listp form)) | 635 (cond ((not (listp form)) |
537 form) | 636 form) |
538 ((and (eq (car form) 'defvar) | 637 ((and (eq (car form) 'defvar) |
539 (cdr-safe (cdr-safe form))) | 638 (cdr-safe (cdr-safe form)) |
540 ;; Force variable to be bound. | 639 (boundp (cadr form))) |
541 (cons 'defconst (cdr form))) | 640 ;; Force variable to be re-set. |
641 `(progn (defvar ,(nth 1 form) nil ,@(nthcdr 3 form)) | |
642 (setq-default ,(nth 1 form) ,(nth 2 form)))) | |
542 ;; `defcustom' is now macroexpanded to | 643 ;; `defcustom' is now macroexpanded to |
543 ;; `custom-declare-variable' with a quoted value arg. | 644 ;; `custom-declare-variable' with a quoted value arg. |
544 ((and (eq (car form) 'custom-declare-variable) | 645 ((and (eq (car form) 'custom-declare-variable) |
545 (default-boundp (eval (nth 1 form)))) | 646 (default-boundp (eval (nth 1 form)))) |
546 ;; Force variable to be bound. | 647 ;; Force variable to be bound. |
547 (set-default (eval (nth 1 form)) (eval (nth 1 (nth 2 form)))) | 648 (set-default (eval (nth 1 form)) (eval (nth 1 (nth 2 form)))) |
548 form) | 649 form) |
650 ;; `defface' is macroexpanded to `custom-declare-face'. | |
651 ((eq (car form) 'custom-declare-face) | |
652 ;; Reset the face. | |
653 (setq face-new-frame-defaults | |
654 (assq-delete-all (eval (nth 1 form)) face-new-frame-defaults)) | |
655 (put (eval (nth 1 form)) 'face-defface-spec nil) | |
656 ;; Setting `customized-face' to the new spec after calling | |
657 ;; the form, but preserving the old saved spec in `saved-face', | |
658 ;; imitates the situation when the new face spec is set | |
659 ;; temporarily for the current session in the customize | |
660 ;; buffer, thus allowing `face-user-default-spec' to use the | |
661 ;; new customized spec instead of the saved spec. | |
662 ;; Resetting `saved-face' temporarily to nil is needed to let | |
663 ;; `defface' change the spec, regardless of a saved spec. | |
664 (prog1 `(prog1 ,form | |
665 (put ,(nth 1 form) 'saved-face | |
666 ',(get (eval (nth 1 form)) 'saved-face)) | |
667 (put ,(nth 1 form) 'customized-face | |
668 ,(nth 2 form))) | |
669 (put (eval (nth 1 form)) 'saved-face nil))) | |
549 ((eq (car form) 'progn) | 670 ((eq (car form) 'progn) |
550 (cons 'progn (mapcar 'eval-defun-1 (cdr form)))) | 671 (cons 'progn (mapcar 'eval-defun-1 (cdr form)))) |
551 (t form))) | 672 (t form))) |
552 | 673 |
553 (defun eval-defun-2 () | 674 (defun eval-defun-2 () |
579 (end-of-defun) | 700 (end-of-defun) |
580 (beginning-of-defun) | 701 (beginning-of-defun) |
581 (setq beg (point)) | 702 (setq beg (point)) |
582 (setq form (read (current-buffer))) | 703 (setq form (read (current-buffer))) |
583 (setq end (point))) | 704 (setq end (point))) |
584 ;; Alter the form if necessary, changing defvar into defconst, etc. | 705 ;; Alter the form if necessary. |
585 (setq form (eval-defun-1 (macroexpand form))) | 706 (setq form (eval-defun-1 (macroexpand form))) |
586 (list beg end standard-output | 707 (list beg end standard-output |
587 `(lambda (ignore) | 708 `(lambda (ignore) |
588 ;; Skipping to the end of the specified region | 709 ;; Skipping to the end of the specified region |
589 ;; will make eval-region return. | 710 ;; will make eval-region return. |
624 (setq new-value debug-on-error)) | 745 (setq new-value debug-on-error)) |
625 (unless (eq old-value new-value) | 746 (unless (eq old-value new-value) |
626 (setq debug-on-error new-value)) | 747 (setq debug-on-error new-value)) |
627 value))))) | 748 value))))) |
628 | 749 |
629 | 750 ;; May still be used by some external Lisp-mode variant. |
630 (defun lisp-comment-indent () | 751 (define-obsolete-function-alias 'lisp-comment-indent 'comment-indent-default) |
631 (if (looking-at "\\s<\\s<\\s<") | |
632 (current-column) | |
633 (if (looking-at "\\s<\\s<") | |
634 (let ((tem (or (calculate-lisp-indent) (current-column)))) | |
635 (if (listp tem) (car tem) tem)) | |
636 (skip-chars-backward " \t") | |
637 (max (if (bolp) 0 (1+ (current-column))) | |
638 comment-column)))) | |
639 | 752 |
640 ;; This function just forces a more costly detection of comments (using | 753 ;; This function just forces a more costly detection of comments (using |
641 ;; parse-partial-sexp from beginning-of-defun). I.e. It avoids the problem of | 754 ;; parse-partial-sexp from beginning-of-defun). I.e. It avoids the problem of |
642 ;; taking a `;' inside a string started on another line for a comment starter. | 755 ;; taking a `;' inside a string started on another line for a comment starter. |
643 ;; Note: `newcomment' gets it right in 99% of the cases if you're using | 756 ;; Note: `newcomment' gets it right now since we set comment-use-global-state |
644 ;; font-lock, anyway, so we could get rid of it. -stef | 757 ;; so we could get rid of it. -stef |
645 (defun lisp-mode-auto-fill () | 758 (defun lisp-mode-auto-fill () |
646 (if (> (current-column) (current-fill-column)) | 759 (if (> (current-column) (current-fill-column)) |
647 (if (save-excursion | 760 (if (save-excursion |
648 (nth 4 (syntax-ppss (point)))) | 761 (nth 4 (syntax-ppss (point)))) |
649 (do-auto-fill) | 762 (do-auto-fill) |
808 If the current line is in a call to a Lisp function | 921 If the current line is in a call to a Lisp function |
809 which has a non-nil property `lisp-indent-function', | 922 which has a non-nil property `lisp-indent-function', |
810 that specifies how to do the indentation. The property value can be | 923 that specifies how to do the indentation. The property value can be |
811 * `defun', meaning indent `defun'-style; | 924 * `defun', meaning indent `defun'-style; |
812 * an integer N, meaning indent the first N arguments specially | 925 * an integer N, meaning indent the first N arguments specially |
813 like ordinary function arguments and then indent any further | 926 like ordinary function arguments and then indent any further |
814 aruments like a body; | 927 arguments like a body; |
815 * a function to call just as this function was called. | 928 * a function to call just as this function was called. |
816 If that function returns nil, that means it doesn't specify | 929 If that function returns nil, that means it doesn't specify |
817 the indentation. | 930 the indentation. |
818 | 931 |
819 This function also returns nil meaning don't specify the indentation." | 932 This function also returns nil meaning don't specify the indentation." |
820 (let ((normal-indent (current-column))) | 933 (let ((normal-indent (current-column))) |
821 (goto-char (1+ (elt state 1))) | 934 (goto-char (1+ (elt state 1))) |
822 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) | 935 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
824 (not (looking-at "\\sw\\|\\s_"))) | 937 (not (looking-at "\\sw\\|\\s_"))) |
825 ;; car of form doesn't seem to be a symbol | 938 ;; car of form doesn't seem to be a symbol |
826 (progn | 939 (progn |
827 (if (not (> (save-excursion (forward-line 1) (point)) | 940 (if (not (> (save-excursion (forward-line 1) (point)) |
828 calculate-lisp-indent-last-sexp)) | 941 calculate-lisp-indent-last-sexp)) |
829 (progn (goto-char calculate-lisp-indent-last-sexp) | 942 (progn (goto-char calculate-lisp-indent-last-sexp) |
830 (beginning-of-line) | 943 (beginning-of-line) |
831 (parse-partial-sexp (point) | 944 (parse-partial-sexp (point) |
832 calculate-lisp-indent-last-sexp 0 t))) | 945 calculate-lisp-indent-last-sexp 0 t))) |
833 ;; Indent under the list or under the first sexp on the same | 946 ;; Indent under the list or under the first sexp on the same |
834 ;; line as calculate-lisp-indent-last-sexp. Note that first | 947 ;; line as calculate-lisp-indent-last-sexp. Note that first |
835 ;; thing on that line has to be complete sexp since we are | 948 ;; thing on that line has to be complete sexp since we are |
836 ;; inside the innermost containing sexp. | 949 ;; inside the innermost containing sexp. |
837 (backward-prefix-chars) | 950 (backward-prefix-chars) |
838 (current-column)) | 951 (current-column)) |
839 (let ((function (buffer-substring (point) | 952 (let ((function (buffer-substring (point) |
840 (progn (forward-sexp 1) (point)))) | 953 (progn (forward-sexp 1) (point)))) |
848 (lisp-indent-defform state indent-point)) | 961 (lisp-indent-defform state indent-point)) |
849 ((integerp method) | 962 ((integerp method) |
850 (lisp-indent-specform method state | 963 (lisp-indent-specform method state |
851 indent-point normal-indent)) | 964 indent-point normal-indent)) |
852 (method | 965 (method |
853 (funcall method state indent-point))))))) | 966 (funcall method indent-point state))))))) |
854 | 967 |
855 (defvar lisp-body-indent 2 | 968 (defvar lisp-body-indent 2 |
856 "Number of columns to indent the second line of a `(def...)' form.") | 969 "Number of columns to indent the second line of a `(def...)' form.") |
857 | 970 |
858 (defun lisp-indent-specform (count state indent-point normal-indent) | 971 (defun lisp-indent-specform (count state indent-point normal-indent) |
1051 (and (bolp) (not (eolp)) | 1164 (and (bolp) (not (eolp)) |
1052 (lisp-indent-line)) | 1165 (lisp-indent-line)) |
1053 (indent-sexp endmark) | 1166 (indent-sexp endmark) |
1054 (set-marker endmark nil)))) | 1167 (set-marker endmark nil)))) |
1055 | 1168 |
1169 (defun indent-pp-sexp (&optional arg) | |
1170 "Indent each line of the list starting just after point, or prettyprint it. | |
1171 A prefix argument specifies pretty-printing." | |
1172 (interactive "P") | |
1173 (if arg | |
1174 (save-excursion | |
1175 (save-restriction | |
1176 (narrow-to-region (point) (progn (forward-sexp 1) (point))) | |
1177 (pp-buffer) | |
1178 (goto-char (point-max)) | |
1179 (if (eq (char-before) ?\n) | |
1180 (delete-char -1))))) | |
1181 (indent-sexp)) | |
1182 | |
1056 ;;;; Lisp paragraph filling commands. | 1183 ;;;; Lisp paragraph filling commands. |
1057 | 1184 |
1185 (defcustom emacs-lisp-docstring-fill-column 65 | |
1186 "Value of `fill-column' to use when filling a docstring. | |
1187 Any non-integer value means do not use a different value of | |
1188 `fill-column' when filling docstrings." | |
1189 :type '(choice (integer) | |
1190 (const :tag "Use the current `fill-column'" t)) | |
1191 :group 'lisp) | |
1192 | |
1058 (defun lisp-fill-paragraph (&optional justify) | 1193 (defun lisp-fill-paragraph (&optional justify) |
1059 "Like \\[fill-paragraph], but handle Emacs Lisp comments. | 1194 "Like \\[fill-paragraph], but handle Emacs Lisp comments and docstrings. |
1060 If any of the current line is a comment, fill the comment or the | 1195 If any of the current line is a comment, fill the comment or the |
1061 paragraph of it that point is in, preserving the comment's indentation | 1196 paragraph of it that point is in, preserving the comment's indentation |
1062 and initial semicolons." | 1197 and initial semicolons." |
1063 (interactive "P") | 1198 (interactive "P") |
1064 (or (fill-comment-paragraph justify) | 1199 (or (fill-comment-paragraph justify) |
1065 ;; `paragraph-start' is set here (not in the buffer-local | 1200 ;; Since fill-comment-paragraph returned nil, that means we're not in |
1066 ;; variable so that `forward-paragraph' et al work as | 1201 ;; a comment: Point is on a program line; we are interested |
1067 ;; expected) so that filling (doc) strings works sensibly. | 1202 ;; particularly in docstring lines. |
1068 ;; Adding the opening paren to avoid the following sexp being | 1203 ;; |
1069 ;; filled means that sexps generally aren't filled as normal | 1204 ;; We bind `paragraph-start' and `paragraph-separate' temporarily. They |
1070 ;; text, which is probably sensible. The `;' and `:' stop the | 1205 ;; are buffer-local, but we avoid changing them so that they can be set |
1071 ;; filled para at following comment lines and keywords | 1206 ;; to make `forward-paragraph' and friends do something the user wants. |
1072 ;; (typically in `defcustom'). | 1207 ;; |
1208 ;; `paragraph-start': The `(' in the character alternative and the | |
1209 ;; left-singlequote plus `(' sequence after the \\| alternative prevent | |
1210 ;; sexps and backquoted sexps that follow a docstring from being filled | |
1211 ;; with the docstring. This setting has the consequence of inhibiting | |
1212 ;; filling many program lines that are not docstrings, which is sensible, | |
1213 ;; because the user probably asked to fill program lines by accident, or | |
1214 ;; expecting indentation (perhaps we should try to do indenting in that | |
1215 ;; case). The `;' and `:' stop the paragraph being filled at following | |
1216 ;; comment lines and at keywords (e.g., in `defcustom'). Left parens are | |
1217 ;; escaped to keep font-locking, filling, & paren matching in the source | |
1218 ;; file happy. | |
1219 ;; | |
1220 ;; `paragraph-separate': A clever regexp distinguishes the first line of | |
1221 ;; a docstring and identifies it as a paragraph separator, so that it | |
1222 ;; won't be filled. (Since the first line of documentation stands alone | |
1223 ;; in some contexts, filling should not alter the contents the author has | |
1224 ;; chosen.) Only the first line of a docstring begins with whitespace | |
1225 ;; and a quotation mark and ends with a period or (rarely) a comma. | |
1226 ;; | |
1227 ;; The `fill-column' is temporarily bound to | |
1228 ;; `emacs-lisp-docstring-fill-column' if that value is an integer. | |
1073 (let ((paragraph-start (concat paragraph-start | 1229 (let ((paragraph-start (concat paragraph-start |
1074 "\\|\\s-*[\(;:\"]")) | 1230 "\\|\\s-*\\([(;:\"]\\|`(\\|#'(\\)")) |
1075 ;; Avoid filling the first line of docstring. | |
1076 (paragraph-separate | 1231 (paragraph-separate |
1077 (concat paragraph-separate "\\|\\s-*\".*\\.$"))) | 1232 (concat paragraph-separate "\\|\\s-*\".*[,\\.]$")) |
1233 (fill-column (if (integerp emacs-lisp-docstring-fill-column) | |
1234 emacs-lisp-docstring-fill-column | |
1235 fill-column))) | |
1078 (fill-paragraph justify)) | 1236 (fill-paragraph justify)) |
1079 ;; Never return nil. | 1237 ;; Never return nil. |
1080 t)) | 1238 t)) |
1081 | 1239 |
1082 (defun indent-code-rigidly (start end arg &optional nochange-regexp) | 1240 (defun indent-code-rigidly (start end arg &optional nochange-regexp) |
1112 (forward-line 1) (point)) | 1270 (forward-line 1) (point)) |
1113 nil nil state)))))) | 1271 nil nil state)))))) |
1114 | 1272 |
1115 (provide 'lisp-mode) | 1273 (provide 'lisp-mode) |
1116 | 1274 |
1275 ;; arch-tag: 414c7f93-c245-4b77-8ed5-ed05ef7ff1bf | |
1117 ;;; lisp-mode.el ends here | 1276 ;;; lisp-mode.el ends here |