Mercurial > hg > xemacs-beta
comparison lisp/modes/lisp-mode.el @ 2:ac2d302a0011 r19-15b2
Import from CVS: tag r19-15b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:35 +0200 |
parents | 376386a54a3c |
children | b82b59fe008d |
comparison
equal
deleted
inserted
replaced
1:c0c6a60d29db | 2:ac2d302a0011 |
---|---|
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, 1993, 1994 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1996 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Tinker Systems | 4 ;; Copyright (C) 1995 Tinker Systems |
5 | 5 |
6 ;; Maintainer: FSF | 6 ;; Maintainer: FSF |
7 ;; Keywords: lisp, languages | 7 ;; Keywords: lisp, languages |
8 | 8 |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 ;; General Public License for more details. | 19 ;; General Public License for more details. |
20 | 20 |
21 ;; 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 |
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 22 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
24 | 24 ;; 02111-1307, USA. |
25 ;;; Synched up with: FSF 19.30. | 25 |
26 ;;; Synched up with: FSF 19.34 (but starting to diverge). | |
26 | 27 |
27 ;;; Commentary: | 28 ;;; Commentary: |
28 | 29 |
29 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). | 30 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). |
30 ;; This mode is documented in the Emacs manual | 31 ;; This mode is documented in the Emacs manual |
33 | 34 |
34 (defvar lisp-mode-syntax-table nil "") | 35 (defvar lisp-mode-syntax-table nil "") |
35 (defvar emacs-lisp-mode-syntax-table nil "") | 36 (defvar emacs-lisp-mode-syntax-table nil "") |
36 (defvar lisp-mode-abbrev-table nil "") | 37 (defvar lisp-mode-abbrev-table nil "") |
37 | 38 |
39 ;; XEmacs change | |
38 (defvar lisp-interaction-mode-popup-menu | 40 (defvar lisp-interaction-mode-popup-menu |
39 (purecopy '("Lisp Interaction Menu" | 41 (purecopy '("Lisp Interaction Menu" |
40 ["Evaluate Last S-expression" eval-last-sexp t] | 42 ["Evaluate Last S-expression" eval-last-sexp t] |
41 ["Evaluate Entire Buffer" eval-current-buffer t] | 43 ["Evaluate Entire Buffer" eval-current-buffer t] |
42 ["Evaluate Region" eval-region (region-exists-p)] | 44 ["Evaluate Region" eval-region (region-exists-p)] |
96 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) | 98 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) |
97 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) | 99 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) |
98 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table) | 100 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table) |
99 ;; Give CR the same syntax as newline, for selective-display. | 101 ;; Give CR the same syntax as newline, for selective-display. |
100 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table) | 102 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table) |
103 ;; XEmacs change | |
101 ;; Treat ^L as whitespace. | 104 ;; Treat ^L as whitespace. |
102 (modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table) | 105 (modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table) |
103 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table) | 106 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table) |
104 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table) | 107 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table) |
105 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table) | 108 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table) |
115 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table))) | 118 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table))) |
116 | 119 |
117 (if (not lisp-mode-syntax-table) | 120 (if (not lisp-mode-syntax-table) |
118 (progn (setq lisp-mode-syntax-table | 121 (progn (setq lisp-mode-syntax-table |
119 (copy-syntax-table emacs-lisp-mode-syntax-table)) | 122 (copy-syntax-table emacs-lisp-mode-syntax-table)) |
123 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table) | |
120 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table) | 124 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table) |
125 ;; XEmacs changes | |
121 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table) | 126 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table) |
122 ;; | 127 ;; |
123 ;; If emacs was compiled with NEW_SYNTAX, then do | 128 ;; If emacs was compiled with NEW_SYNTAX, then do |
124 ;; CL's #| |# block comments. | 129 ;; CL's #| |# block comments. |
125 (if (= 8 (length (parse-partial-sexp (point) (point)))) | 130 (if (= 8 (length (parse-partial-sexp (point) (point)))) |
126 (progn | 131 (progn |
127 (modify-syntax-entry ?# "' 58" lisp-mode-syntax-table) | 132 (modify-syntax-entry ?# "' 58" lisp-mode-syntax-table) |
128 (modify-syntax-entry ?| ". 67" lisp-mode-syntax-table)) | 133 (modify-syntax-entry ?| ". 67" lisp-mode-syntax-table)) |
129 ;; else, old style | 134 ;; else, old style |
130 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table)))) | 135 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table)))) |
131 | 136 |
132 (define-abbrev-table 'lisp-mode-abbrev-table ()) | 137 (define-abbrev-table 'lisp-mode-abbrev-table ()) |
133 | 138 |
134 ;(defvar lisp-imenu-generic-expression | 139 ;(defvar lisp-imenu-generic-expression |
135 ; '( | 140 ; '( |
142 ; 2)) | 147 ; 2)) |
143 ; | 148 ; |
144 ; "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") | 149 ; "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") |
145 | 150 |
146 (defun lisp-mode-variables (lisp-syntax) | 151 (defun lisp-mode-variables (lisp-syntax) |
147 (if lisp-syntax | 152 (cond (lisp-syntax |
148 (set-syntax-table lisp-mode-syntax-table)) | 153 (set-syntax-table lisp-mode-syntax-table))) |
149 (setq local-abbrev-table lisp-mode-abbrev-table) | 154 (setq local-abbrev-table lisp-mode-abbrev-table) |
150 (make-local-variable 'paragraph-start) | 155 (make-local-variable 'paragraph-start) |
151 (setq paragraph-start (concat page-delimiter "\\|$" )) | 156 (setq paragraph-start (concat page-delimiter "\\|$" )) |
152 (make-local-variable 'paragraph-separate) | 157 (make-local-variable 'paragraph-separate) |
153 (setq paragraph-separate paragraph-start) | 158 (setq paragraph-separate paragraph-start) |
154 (make-local-variable 'paragraph-ignore-fill-prefix) | 159 (make-local-variable 'paragraph-ignore-fill-prefix) |
155 (setq paragraph-ignore-fill-prefix t) | 160 (setq paragraph-ignore-fill-prefix t) |
156 (make-local-variable 'fill-paragraph-function) | 161 (make-local-variable 'fill-paragraph-function) |
157 (setq fill-paragraph-function 'lisp-fill-paragraph) | 162 (setq fill-paragraph-function 'lisp-fill-paragraph) |
163 ;; Adaptive fill mode gets in the way of auto-fill, | |
164 ;; and should make no difference for explicit fill | |
165 ;; because lisp-fill-paragraph should do the job. | |
166 (make-local-variable 'adaptive-fill-mode) | |
167 (setq adaptive-fill-mode nil) | |
158 (make-local-variable 'indent-line-function) | 168 (make-local-variable 'indent-line-function) |
159 (setq indent-line-function 'lisp-indent-line) | 169 (setq indent-line-function 'lisp-indent-line) |
160 (make-local-variable 'indent-region-function) | 170 (make-local-variable 'indent-region-function) |
161 (setq indent-region-function 'lisp-indent-region) | 171 (setq indent-region-function 'lisp-indent-region) |
162 (make-local-variable 'parse-sexp-ignore-comments) | 172 (make-local-variable 'parse-sexp-ignore-comments) |
163 (setq parse-sexp-ignore-comments t) | 173 (setq parse-sexp-ignore-comments t) |
164 (make-local-variable 'outline-regexp) | 174 (make-local-variable 'outline-regexp) |
165 (setq outline-regexp ";;; \\|(....") | 175 (setq outline-regexp ";;; \\|(....") |
166 (set (make-local-variable 'comment-start) ";") | 176 (make-local-variable 'comment-start) |
177 (setq comment-start ";") | |
178 ;; XEmacs change | |
167 (set (make-local-variable 'block-comment-start) ";;") | 179 (set (make-local-variable 'block-comment-start) ";;") |
168 (make-local-variable 'comment-start-skip) | 180 (make-local-variable 'comment-start-skip) |
169 (setq comment-start-skip ";+[ \t]*") | 181 ;; Look within the line for a ; following an even number of backslashes |
182 ;; after either a non-backslash or the line beginning. | |
183 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *") | |
170 (make-local-variable 'comment-column) | 184 (make-local-variable 'comment-column) |
171 (setq comment-column 40) | 185 (setq comment-column 40) |
172 (make-local-variable 'comment-indent-function) | 186 (make-local-variable 'comment-indent-function) |
173 (setq comment-indent-function 'lisp-comment-indent) | 187 (setq comment-indent-function 'lisp-comment-indent) |
188 ;; XEmacs changes | |
174 ; (make-local-variable 'imenu-generic-expression) | 189 ; (make-local-variable 'imenu-generic-expression) |
175 ; (setq imenu-generic-expression lisp-imenu-generic-expression) | 190 ; (setq imenu-generic-expression lisp-imenu-generic-expression) |
176 (set (make-local-variable 'dabbrev-case-fold-search) nil) | 191 (set (make-local-variable 'dabbrev-case-fold-search) nil) |
177 (set (make-local-variable 'dabbrev-case-replace) nil) | 192 (set (make-local-variable 'dabbrev-case-replace) nil) |
178 ) | 193 ) |
182 "Keymap for commands shared by all sorts of Lisp modes.") | 197 "Keymap for commands shared by all sorts of Lisp modes.") |
183 | 198 |
184 (if shared-lisp-mode-map | 199 (if shared-lisp-mode-map |
185 () | 200 () |
186 (setq shared-lisp-mode-map (make-sparse-keymap)) | 201 (setq shared-lisp-mode-map (make-sparse-keymap)) |
202 ;; XEmacs changes | |
187 (set-keymap-name shared-lisp-mode-map 'shared-lisp-mode-map) | 203 (set-keymap-name shared-lisp-mode-map 'shared-lisp-mode-map) |
204 (define-key shared-lisp-mode-map "\M-;" 'lisp-indent-for-comment) | |
188 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) | 205 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) |
189 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify) | 206 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify)) |
190 (define-key shared-lisp-mode-map "\M-;" 'lisp-indent-for-comment)) | |
191 | 207 |
192 (defvar emacs-lisp-mode-map () | 208 (defvar emacs-lisp-mode-map () |
193 "Keymap for Emacs Lisp mode. | 209 "Keymap for Emacs Lisp mode. |
194 All commands in `shared-lisp-mode-map' are inherited by this map.") | 210 All commands in `shared-lisp-mode-map' are inherited by this map.") |
195 | 211 |
196 (if emacs-lisp-mode-map | 212 (if emacs-lisp-mode-map |
197 () | 213 () |
214 ;; XEmacs: Ignore FSF nconc stuff | |
198 (setq emacs-lisp-mode-map (make-sparse-keymap)) | 215 (setq emacs-lisp-mode-map (make-sparse-keymap)) |
199 (set-keymap-name emacs-lisp-mode-map 'emacs-lisp-mode-map) | 216 (set-keymap-name emacs-lisp-mode-map 'emacs-lisp-mode-map) |
200 (set-keymap-parents emacs-lisp-mode-map (list shared-lisp-mode-map)) | 217 (set-keymap-parents emacs-lisp-mode-map (list shared-lisp-mode-map)) |
201 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol) | 218 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol) |
202 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)) | 219 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun) |
220 ;; XEmacs: Not sure what the FSF menu bindings are. I hope XEmacs | |
221 ;; doesn't need them. | |
222 ) | |
203 | 223 |
204 (defun emacs-lisp-byte-compile () | 224 (defun emacs-lisp-byte-compile () |
205 "Byte compile the file containing the current buffer." | 225 "Byte compile the file containing the current buffer." |
206 (interactive) | 226 (interactive) |
207 (if buffer-file-name | 227 (if buffer-file-name |
228 ;; XEmacs change. Force buffer save first | |
208 (progn | 229 (progn |
209 (save-buffer) | 230 (save-buffer) |
210 (byte-compile-file buffer-file-name)) | 231 (byte-compile-file buffer-file-name)) |
211 (error "The buffer must be saved in a file first."))) | 232 (error "The buffer must be saved in a file first."))) |
233 | |
234 (defun emacs-lisp-byte-compile-and-load () | |
235 "Byte-compile the current file (if it has changed), then load compiled code." | |
236 (interactive) | |
237 (or buffer-file-name | |
238 (error "The buffer must be saved in a file first")) | |
239 (require 'bytecomp) | |
240 ;; Recompile if file or buffer has changed since last compilation. | |
241 (if (and (buffer-modified-p) | |
242 (y-or-n-p (format "save buffer %s first? " (buffer-name)))) | |
243 (save-buffer)) | |
244 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name))) | |
245 (if (file-newer-than-file-p compiled-file-name buffer-file-name) | |
246 (load-file compiled-file-name) | |
247 (byte-compile-file buffer-file-name t)))) | |
212 | 248 |
213 (defun emacs-lisp-mode () | 249 (defun emacs-lisp-mode () |
214 "Major mode for editing Lisp code to run in Emacs. | 250 "Major mode for editing Lisp code to run in Emacs. |
215 Commands: | 251 Commands: |
216 Delete converts tabs to spaces as it moves back. | 252 Delete converts tabs to spaces as it moves back. |
220 if that value is non-nil." | 256 if that value is non-nil." |
221 (interactive) | 257 (interactive) |
222 (kill-all-local-variables) | 258 (kill-all-local-variables) |
223 (use-local-map emacs-lisp-mode-map) | 259 (use-local-map emacs-lisp-mode-map) |
224 (set-syntax-table emacs-lisp-mode-syntax-table) | 260 (set-syntax-table emacs-lisp-mode-syntax-table) |
261 ;; XEmacs changes | |
225 (setq major-mode 'emacs-lisp-mode | 262 (setq major-mode 'emacs-lisp-mode |
226 mode-popup-menu emacs-lisp-mode-popup-menu | 263 mode-popup-menu emacs-lisp-mode-popup-menu |
227 mode-name "Emacs-Lisp") | 264 mode-name "Emacs-Lisp") |
228 (if (and (featurep 'menubar) | 265 (if (and (featurep 'menubar) |
229 current-menubar) | 266 current-menubar) |
239 "Keymap for ordinary Lisp mode. | 276 "Keymap for ordinary Lisp mode. |
240 All commands in `shared-lisp-mode-map' are inherited by this map.") | 277 All commands in `shared-lisp-mode-map' are inherited by this map.") |
241 | 278 |
242 (if lisp-mode-map | 279 (if lisp-mode-map |
243 () | 280 () |
281 ;; XEmacs changes | |
244 (setq lisp-mode-map (make-sparse-keymap)) | 282 (setq lisp-mode-map (make-sparse-keymap)) |
245 (set-keymap-name lisp-mode-map 'lisp-mode-map) | 283 (set-keymap-name lisp-mode-map 'lisp-mode-map) |
246 (set-keymap-parents lisp-mode-map (list shared-lisp-mode-map)) | 284 (set-keymap-parents lisp-mode-map (list shared-lisp-mode-map)) |
247 (define-key lisp-mode-map "\e\C-x" 'lisp-send-defun) | 285 (define-key lisp-mode-map "\e\C-x" 'lisp-send-defun) |
248 ;; gag, no. use ilisp. -jwz | 286 ;; gag, no. use ilisp. -jwz |
268 (lisp-mode-variables t) | 306 (lisp-mode-variables t) |
269 (set-syntax-table lisp-mode-syntax-table) | 307 (set-syntax-table lisp-mode-syntax-table) |
270 (run-hooks 'lisp-mode-hook)) | 308 (run-hooks 'lisp-mode-hook)) |
271 | 309 |
272 ;; This will do unless shell.el is loaded. | 310 ;; This will do unless shell.el is loaded. |
311 ;; XEmacs change | |
273 (defun lisp-send-defun () | 312 (defun lisp-send-defun () |
274 "Send the current defun to the Lisp process made by \\[run-lisp]." | 313 "Send the current defun to the Lisp process made by \\[run-lisp]." |
275 (interactive) | 314 (interactive) |
276 (error "Process lisp does not exist")) | 315 (error "Process lisp does not exist")) |
277 | 316 |
278 ;; XEmacs change: emacs-lisp-mode-map is a more appropriate parent. | 317 ;; XEmacs change: emacs-lisp-mode-map is a more appropriate parent. |
279 (defvar lisp-interaction-mode-map nil | 318 (defvar lisp-interaction-mode-map () |
280 "Keymap for Lisp Interaction moe. | 319 "Keymap for Lisp Interaction moe. |
281 All commands in `emacs-lisp-mode-map' are inherited by this map.") | 320 All commands in `shared-lisp-mode-map' are inherited by this map.") |
282 | 321 |
283 (if lisp-interaction-mode-map | 322 (if lisp-interaction-mode-map |
284 () | 323 () |
324 ;; XEmacs set keymap our way | |
285 (setq lisp-interaction-mode-map (make-sparse-keymap)) | 325 (setq lisp-interaction-mode-map (make-sparse-keymap)) |
286 (set-keymap-name lisp-interaction-mode-map 'lisp-interaction-mode-map) | 326 (set-keymap-name lisp-interaction-mode-map 'lisp-interaction-mode-map) |
287 (set-keymap-parents lisp-interaction-mode-map (list emacs-lisp-mode-map)) | 327 (set-keymap-parents lisp-interaction-mode-map (list emacs-lisp-mode-map)) |
288 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun) | 328 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun) |
289 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol) | 329 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol) |
294 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression | 334 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression |
295 before point, and prints its value into the buffer, advancing point. | 335 before point, and prints its value into the buffer, advancing point. |
296 | 336 |
297 Commands: | 337 Commands: |
298 Delete converts tabs to spaces as it moves back. | 338 Delete converts tabs to spaces as it moves back. |
299 Paragraphs are separated only by blank lines. Semicolons start comments. | 339 Paragraphs are separated only by blank lines. |
340 Semicolons start comments. | |
300 \\{lisp-interaction-mode-map} | 341 \\{lisp-interaction-mode-map} |
301 Entry to this mode calls the value of `lisp-interaction-mode-hook' | 342 Entry to this mode calls the value of `lisp-interaction-mode-hook' |
302 if that value is non-nil." | 343 if that value is non-nil." |
303 (interactive) | 344 (interactive) |
304 (kill-all-local-variables) | 345 (kill-all-local-variables) |
305 (use-local-map lisp-interaction-mode-map) | 346 (use-local-map lisp-interaction-mode-map) |
306 (setq major-mode 'lisp-interaction-mode | 347 (setq major-mode 'lisp-interaction-mode) |
307 mode-popup-menu lisp-interaction-mode-popup-menu | 348 (setq mode-name "Lisp Interaction") |
308 mode-name "Lisp Interaction") | 349 ;; XEmacs change |
350 (setq mode-popup-menu lisp-interaction-mode-popup-menu) | |
309 (set-syntax-table emacs-lisp-mode-syntax-table) | 351 (set-syntax-table emacs-lisp-mode-syntax-table) |
310 (lisp-mode-variables nil) | 352 (lisp-mode-variables nil) |
311 (run-hooks 'lisp-interaction-mode-hook)) | 353 (run-hooks 'lisp-interaction-mode-hook)) |
312 | 354 |
313 (defun eval-print-last-sexp () | 355 (defun eval-print-last-sexp () |
316 (let ((standard-output (current-buffer))) | 358 (let ((standard-output (current-buffer))) |
317 (terpri) | 359 (terpri) |
318 (eval-last-sexp t) | 360 (eval-last-sexp t) |
319 (terpri))) | 361 (terpri))) |
320 | 362 |
363 ;; XEmacs change | |
321 (defun eval-interactive (expr) | 364 (defun eval-interactive (expr) |
322 "Like `eval' except that it transforms defvars to defconsts." | 365 "Like `eval' except that it transforms defvars to defconsts." |
323 ;; by Stig@hackvan.com | 366 ;; by Stig@hackvan.com |
324 (if (and (consp expr) | 367 (if (and (consp expr) |
325 (eq (car expr) 'defvar) | 368 (eq (car expr) 'defvar) |
328 (message "defvar treated as defconst") | 371 (message "defvar treated as defconst") |
329 (sit-for 1) | 372 (sit-for 1) |
330 (message "")) | 373 (message "")) |
331 (eval expr))) | 374 (eval expr))) |
332 | 375 |
333 (defun eval-last-sexp (eval-last-sexp-arg-internal) ;dynamic scoping wonderment | 376 (defun eval-last-sexp (eval-last-sexp-arg-internal) |
334 "Evaluate sexp before point; print value in minibuffer. | 377 "Evaluate sexp before point; print value in minibuffer. |
335 With argument, print output into current buffer." | 378 With argument, print output into current buffer." |
336 (interactive "P") | 379 (interactive "P") |
337 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)) | 380 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)) |
338 (opoint (point))) | 381 (opoint (point))) |
339 (prin1 (let ((stab (syntax-table))) | 382 (prin1 (let ((stab (syntax-table))) |
383 ;; XEmacs change use eval-interactive not eval | |
340 (eval-interactive (unwind-protect | 384 (eval-interactive (unwind-protect |
341 (save-excursion | 385 (save-excursion |
342 (set-syntax-table emacs-lisp-mode-syntax-table) | 386 (set-syntax-table emacs-lisp-mode-syntax-table) |
343 (forward-sexp -1) | 387 (forward-sexp -1) |
344 (save-restriction | 388 (save-restriction |
345 (narrow-to-region (point-min) opoint) | 389 (narrow-to-region (point-min) opoint) |
346 (read (current-buffer)))) | 390 (read (current-buffer)))) |
347 (set-syntax-table stab))))))) | 391 (set-syntax-table stab))))))) |
348 | 392 |
349 (defun eval-defun (eval-defun-arg-internal) ;dynamic scoping wonderment | 393 (defun eval-defun (eval-defun-arg-internal) |
350 "Evaluate defun that point is in or before. | 394 "Evaluate defun that point is in or before. |
351 Print value in minibuffer. | 395 Print value in minibuffer. |
352 With argument, insert value in current buffer after the defun." | 396 With argument, insert value in current buffer after the defun." |
353 (interactive "P") | 397 (interactive "P") |
354 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t))) | 398 ;; XEmacs: FSF version works, so use it |
355 (prin1 (eval-interactive (save-excursion | 399 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) |
356 (end-of-defun) | 400 (form (save-excursion |
357 (beginning-of-defun) | 401 (end-of-defun) |
358 (read (current-buffer))))))) | 402 (beginning-of-defun) |
403 (read (current-buffer))))) | |
404 (if (and (eq (car form) 'defvar) | |
405 (cdr-safe (cdr-safe form))) | |
406 (setq form (cons 'defconst (cdr form)))) | |
407 (prin1 (eval form)))) | |
359 | 408 |
360 (defun lisp-comment-indent () | 409 (defun lisp-comment-indent () |
361 (if (looking-at "\\s<\\s<\\s<") | 410 (if (looking-at "\\s<\\s<\\s<") |
362 (current-column) | 411 (current-column) |
363 (if (looking-at "\\s<\\s<") | 412 (if (looking-at "\\s<\\s<") |
365 (if (listp tem) (car tem) tem)) | 414 (if (listp tem) (car tem) tem)) |
366 (skip-chars-backward " \t") | 415 (skip-chars-backward " \t") |
367 (max (if (bolp) 0 (1+ (current-column))) | 416 (max (if (bolp) 0 (1+ (current-column))) |
368 comment-column)))) | 417 comment-column)))) |
369 | 418 |
419 ;; XEmacs change | |
370 (defun lisp-indent-for-comment () | 420 (defun lisp-indent-for-comment () |
371 "Indent this line's comment appropriately, or insert an empty comment. | 421 "Indent this line's comment appropriately, or insert an empty comment. |
372 If adding a new comment on a blank line, use `block-comment-start' instead | 422 If adding a new comment on a blank line, use `block-comment-start' instead |
373 of `comment-start' to open the comment." | 423 of `comment-start' to open the comment." |
374 ;; by Stig@hackvan.com | 424 ;; by Stig@hackvan.com |
433 The second element of the list is the buffer position | 483 The second element of the list is the buffer position |
434 of the start of the containing expression." | 484 of the start of the containing expression." |
435 (save-excursion | 485 (save-excursion |
436 (beginning-of-line) | 486 (beginning-of-line) |
437 (let ((indent-point (point)) | 487 (let ((indent-point (point)) |
488 ;; XEmacs change (remove paren-depth) | |
438 state ;;paren-depth | 489 state ;;paren-depth |
439 ;; setting this to a number inhibits calling hook | 490 ;; setting this to a number inhibits calling hook |
440 (desired-indent nil) | 491 (desired-indent nil) |
441 (retry t) | 492 (retry t) |
442 calculate-lisp-indent-last-sexp containing-sexp) | 493 calculate-lisp-indent-last-sexp containing-sexp) |
447 (while (< (point) indent-point) | 498 (while (< (point) indent-point) |
448 (setq state (parse-partial-sexp (point) indent-point 0))) | 499 (setq state (parse-partial-sexp (point) indent-point 0))) |
449 ;; Find innermost containing sexp | 500 ;; Find innermost containing sexp |
450 (while (and retry | 501 (while (and retry |
451 state | 502 state |
503 ;; XEmacs change (remove paren-depth) | |
452 (> ;;(setq paren-depth (elt state 0)) | 504 (> ;;(setq paren-depth (elt state 0)) |
453 (elt state 0) | 505 (elt state 0) |
454 0)) | 506 0)) |
455 (setq retry nil) | 507 (setq retry nil) |
456 (setq calculate-lisp-indent-last-sexp (elt state 2)) | 508 (setq calculate-lisp-indent-last-sexp (elt state 2)) |
515 ((and (boundp 'lisp-indent-function) | 567 ((and (boundp 'lisp-indent-function) |
516 lisp-indent-function | 568 lisp-indent-function |
517 (not retry)) | 569 (not retry)) |
518 (or (funcall lisp-indent-function indent-point state) | 570 (or (funcall lisp-indent-function indent-point state) |
519 normal-indent)) | 571 normal-indent)) |
572 ;; XEmacs change: | |
520 ;; lisp-indent-offset shouldn't override lisp-indent-function ! | 573 ;; lisp-indent-offset shouldn't override lisp-indent-function ! |
521 ((and (integerp lisp-indent-offset) containing-sexp) | 574 ((and (integerp lisp-indent-offset) containing-sexp) |
522 ;; Indent by constant offset | 575 ;; Indent by constant offset |
523 (goto-char containing-sexp) | 576 (goto-char containing-sexp) |
524 (+ normal-indent lisp-indent-offset)) | 577 (+ normal-indent lisp-indent-offset)) |
549 (current-column)) | 602 (current-column)) |
550 (let ((function (buffer-substring (point) | 603 (let ((function (buffer-substring (point) |
551 (progn (forward-sexp 1) (point)))) | 604 (progn (forward-sexp 1) (point)))) |
552 method) | 605 method) |
553 (setq method (or (get (intern-soft function) 'lisp-indent-function) | 606 (setq method (or (get (intern-soft function) 'lisp-indent-function) |
554 (get (intern-soft function) 'lisp-indent-hook))) | 607 (get (intern-soft function) 'lisp-indent-hook))) |
555 (cond ((or (eq method 'defun) | 608 (cond ((or (eq method 'defun) |
556 (and (null method) | 609 (and (null method) |
557 (> (length function) 3) | 610 (> (length function) 3) |
558 (string-match "\\`def" function))) | 611 (string-match "\\`def" function))) |
559 (lisp-indent-defform state indent-point)) | 612 (lisp-indent-defform state indent-point)) |
647 "Indent each line of the list starting just after point. | 700 "Indent each line of the list starting just after point. |
648 If optional arg ENDPOS is given, indent each line, stopping when | 701 If optional arg ENDPOS is given, indent each line, stopping when |
649 ENDPOS is encountered." | 702 ENDPOS is encountered." |
650 (interactive) | 703 (interactive) |
651 (let ((indent-stack (list nil)) | 704 (let ((indent-stack (list nil)) |
652 (next-depth 0) | 705 (next-depth 0) |
653 ;; If ENDPOS is non-nil, use nil as STARTING-POINT | 706 ;; If ENDPOS is non-nil, use nil as STARTING-POINT |
654 ;; so that calculate-lisp-indent will find the beginning of | 707 ;; so that calculate-lisp-indent will find the beginning of |
655 ;; the defun we are in. | 708 ;; the defun we are in. |
656 ;; If ENDPOS is nil, it is safe not to scan before point | 709 ;; If ENDPOS is nil, it is safe not to scan before point |
657 ;; since every line we indent is more deeply nested than point is. | 710 ;; since every line we indent is more deeply nested than point is. |
658 (starting-point (if endpos nil (point))) | 711 (starting-point (if endpos nil (point))) |
659 (last-point (point)) | 712 (last-point (point)) |
660 last-depth | 713 last-depth bol outer-loop-done inner-loop-done state this-indent) |
661 bol | |
662 (outer-loop-done nil) | |
663 inner-loop-done | |
664 state | |
665 this-indent) | |
666 ;; Get error now if we don't have a complete sexp after point. | |
667 (or endpos | 714 (or endpos |
668 ;; Get error now if we don't have a complete sexp after point. | 715 ;; Get error now if we don't have a complete sexp after point. |
669 (save-excursion (forward-sexp 1))) | 716 (save-excursion (forward-sexp 1))) |
670 (save-excursion | 717 (save-excursion |
671 (setq outer-loop-done nil) | 718 (setq outer-loop-done nil) |
698 (if (car (nthcdr 3 state)) | 745 (if (car (nthcdr 3 state)) |
699 (progn | 746 (progn |
700 (forward-line 1) | 747 (forward-line 1) |
701 (setcar (nthcdr 5 state) nil)) | 748 (setcar (nthcdr 5 state) nil)) |
702 (setq inner-loop-done t))) | 749 (setq inner-loop-done t))) |
703 ; Chuck had a comment here saying that the alternate code | |
704 ; (the next sexp after this one) led to an infine loop. | |
705 ; Since merging some changes in from FSF 19.30, I'm going | |
706 ; to try going the FSF way and see what happens. | |
707 ; (and endpos | |
708 ; (while (<= next-depth 0) ;XEmacs change | |
709 ; (setq indent-stack (append indent-stack (list nil))) | |
710 ; (setq next-depth (1+ next-depth)) | |
711 ; (setq last-depth (1+ last-depth)))) | |
712 (and endpos | 750 (and endpos |
713 (<= next-depth 0) | 751 (<= next-depth 0) |
714 (progn | 752 (progn |
715 (setq indent-stack (append indent-stack | 753 (setq indent-stack (append indent-stack |
716 (make-list (- next-depth) nil)) | 754 (make-list (- next-depth) nil)) |
717 last-depth (- last-depth next-depth) | 755 last-depth (- last-depth next-depth) |
718 next-depth 0))) | 756 next-depth 0))) |
719 (or outer-loop-done endpos | 757 (or outer-loop-done endpos |
720 (setq outer-loop-done (<= next-depth 0))) | 758 (setq outer-loop-done (<= next-depth 0))) |
721 (if outer-loop-done | 759 (if outer-loop-done |
722 (forward-line 1) | 760 (forward-line 1) |
723 (while (> last-depth next-depth) | 761 (while (> last-depth next-depth) |
724 (setq indent-stack (cdr indent-stack) | 762 (setq indent-stack (cdr indent-stack) |
725 last-depth (1- last-depth))) | 763 last-depth (1- last-depth))) |
737 nil | 775 nil |
738 (if (and (car indent-stack) | 776 (if (and (car indent-stack) |
739 (>= (car indent-stack) 0)) | 777 (>= (car indent-stack) 0)) |
740 (setq this-indent (car indent-stack)) | 778 (setq this-indent (car indent-stack)) |
741 (let ((val (calculate-lisp-indent | 779 (let ((val (calculate-lisp-indent |
742 (if (car indent-stack) | 780 (if (car indent-stack) (- (car indent-stack)) |
743 (- (car indent-stack)) | 781 starting-point)))) |
744 starting-point)))) | |
745 (if (integerp val) | 782 (if (integerp val) |
746 (setcar indent-stack | 783 (setcar indent-stack |
747 (setq this-indent val)) | 784 (setq this-indent val)) |
748 (setcar indent-stack (- (car (cdr val)))) | 785 (setcar indent-stack (- (car (cdr val)))) |
749 (setq this-indent (car val))))) | 786 (setq this-indent (car val))))) |
761 (goto-char start) | 798 (goto-char start) |
762 (and (bolp) (not (eolp)) | 799 (and (bolp) (not (eolp)) |
763 (lisp-indent-line)) | 800 (lisp-indent-line)) |
764 (indent-sexp endmark) | 801 (indent-sexp endmark) |
765 (set-marker endmark nil)))) | 802 (set-marker endmark nil)))) |
766 | |
767 | 803 |
768 ;;;; Lisp paragraph filling commands. | 804 ;;;; Lisp paragraph filling commands. |
769 | 805 |
770 (defun lisp-fill-paragraph (&optional justify) | 806 (defun lisp-fill-paragraph (&optional justify) |
771 "Like \\[fill-paragraph], but handle Emacs Lisp comments. | 807 "Like \\[fill-paragraph], but handle Emacs Lisp comments. |
775 (interactive "P") | 811 (interactive "P") |
776 (let ( | 812 (let ( |
777 ;; Non-nil if the current line contains a comment. | 813 ;; Non-nil if the current line contains a comment. |
778 has-comment | 814 has-comment |
779 | 815 |
816 ;; Non-nil if the current line contains code and a comment. | |
817 has-code-and-comment | |
818 | |
780 ;; If has-comment, the appropriate fill-prefix for the comment. | 819 ;; If has-comment, the appropriate fill-prefix for the comment. |
781 comment-fill-prefix | 820 comment-fill-prefix |
782 ) | 821 ) |
783 | 822 |
784 ;; Figure out what kind of comment we are looking at. | 823 ;; Figure out what kind of comment we are looking at. |
793 (match-end 0)))) | 832 (match-end 0)))) |
794 | 833 |
795 ;; A line with some code, followed by a comment? Remember that the | 834 ;; A line with some code, followed by a comment? Remember that the |
796 ;; semi which starts the comment shouldn't be part of a string or | 835 ;; semi which starts the comment shouldn't be part of a string or |
797 ;; character. | 836 ;; character. |
798 ((progn | 837 ;; XEmacs Try this the FSF and see if it works. |
799 (while (not (looking-at ";\\|$")) | 838 ; ((progn |
800 (skip-chars-forward "^;\n\"\\\\?") | 839 ; (while (not (looking-at ";\\|$")) |
801 (cond | 840 ; (skip-chars-forward "^;\n\"\\\\?") |
802 ((eq (char-after (point)) ?\\) (forward-char 2)) | 841 ; (cond |
803 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1)))) | 842 ; ((eq (char-after (point)) ?\\) (forward-char 2)) |
804 (looking-at ";+[\t ]*")) | 843 ; ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1)))) |
805 (setq has-comment t) | 844 ; (looking-at ";+[\t ]*")) |
845 ; (setq has-comment t) | |
846 ((condition-case nil | |
847 (save-restriction | |
848 (narrow-to-region (point-min) | |
849 (save-excursion (end-of-line) (point))) | |
850 (while (not (looking-at ";\\|$")) | |
851 (skip-chars-forward "^;\n\"\\\\?") | |
852 (cond | |
853 ((eq (char-after (point)) ?\\) (forward-char 2)) | |
854 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1)))) | |
855 (looking-at ";+[\t ]*")) | |
856 (error nil)) | |
857 (setq has-comment t has-code-and-comment t) | |
806 (setq comment-fill-prefix | 858 (setq comment-fill-prefix |
807 (concat (make-string (current-column) ? ) | 859 (concat (make-string (/ (current-column) 8) ?\t) |
860 (make-string (% (current-column) 8) ?\ ) | |
808 (buffer-substring (match-beginning 0) (match-end 0))))))) | 861 (buffer-substring (match-beginning 0) (match-end 0))))))) |
809 | 862 |
810 (if (not has-comment) | 863 (if (not has-comment) |
811 (fill-paragraph justify) | 864 (fill-paragraph justify) |
812 | 865 |
813 ;; Narrow to include only the comment, and then fill the region. | 866 ;; Narrow to include only the comment, and then fill the region. |
814 (save-restriction | 867 (save-excursion |
815 (narrow-to-region | 868 (save-restriction |
816 ;; Find the first line we should include in the region to fill. | 869 (beginning-of-line) |
817 (save-excursion | 870 (narrow-to-region |
818 (while (and (zerop (forward-line -1)) | 871 ;; Find the first line we should include in the region to fill. |
819 (looking-at "^[ \t]*;"))) | 872 (save-excursion |
820 ;; We may have gone to far. Go forward again. | 873 (while (and (zerop (forward-line -1)) |
821 (or (looking-at "^[ \t]*;") | |
822 (forward-line 1)) | |
823 (point)) | |
824 ;; Find the beginning of the first line past the region to fill. | |
825 (save-excursion | |
826 (while (progn (forward-line 1) | |
827 (looking-at "^[ \t]*;"))) | 874 (looking-at "^[ \t]*;"))) |
828 (point))) | 875 ;; We may have gone too far. Go forward again. |
829 | 876 (or (looking-at ".*;") |
830 ;; Lines with only semicolons on them can be paragraph boundaries. | 877 (forward-line 1)) |
831 (let ((paragraph-start (concat paragraph-start "\\|[ \t;]*$")) | 878 (point)) |
832 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$")) | 879 ;; Find the beginning of the first line past the region to fill. |
833 (fill-prefix comment-fill-prefix)) | 880 (save-excursion |
834 (fill-paragraph justify)))) | 881 (while (progn (forward-line 1) |
882 (looking-at "^[ \t]*;"))) | |
883 (point))) | |
884 | |
885 ;; Lines with only semicolons on them can be paragraph boundaries. | |
886 (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$")) | |
887 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$")) | |
888 (paragraph-ignore-fill-prefix nil) | |
889 (fill-prefix comment-fill-prefix) | |
890 (after-line (if has-code-and-comment | |
891 (save-excursion | |
892 (forward-line 1) (point)))) | |
893 (end (progn | |
894 (forward-paragraph) | |
895 (or (bolp) (newline 1)) | |
896 (point))) | |
897 ;; If this comment starts on a line with code, | |
898 ;; include that like in the filling. | |
899 (beg (progn (backward-paragraph) | |
900 (if (eq (point) after-line) | |
901 (forward-line -1)) | |
902 (point)))) | |
903 (fill-region-as-paragraph beg end | |
904 justify nil | |
905 (save-excursion | |
906 (goto-char beg) | |
907 (if (looking-at fill-prefix) | |
908 nil | |
909 (re-search-forward comment-start-skip) | |
910 (point)))))))) | |
835 t)) | 911 t)) |
836 | |
837 | 912 |
838 (defun indent-code-rigidly (start end arg &optional nochange-regexp) | 913 (defun indent-code-rigidly (start end arg &optional nochange-regexp) |
839 "Indent all lines of code, starting in the region, sideways by ARG columns. | 914 "Indent all lines of code, starting in the region, sideways by ARG columns. |
840 Does not affect lines starting inside comments or strings, | 915 Does not affect lines starting inside comments or strings, assuming that |
841 assuming that the start of the region is not inside them. | 916 the start of the region is not inside them. |
917 | |
842 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP. | 918 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP. |
843 The last is a regexp which, if matched at the beginning of a line, | 919 The last is a regexp which, if matched at the beginning of a line, |
844 means don't indent that line." | 920 means don't indent that line." |
845 (interactive "r\np") | 921 (interactive "r\np") |
846 (let (state) | 922 (let (state) |