Mercurial > emacs
annotate lisp/emacs-lisp/lisp-mode.el @ 14326:e5799768c51b
(rmail-edit-current-message): Pass proper format string to message.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 25 Jan 1996 00:56:48 +0000 |
parents | fc9c72889fec |
children | ea15aa9bae36 |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
5 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: lisp, languages |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
7 |
213 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
213 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
213 | 24 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
25 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
26 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
27 ;; The base major mode for editing Lisp code (used also for Emacs Lisp). |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
28 ;; This mode is documented in the Emacs manual |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
29 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
30 ;;; Code: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
31 |
213 | 32 (defvar lisp-mode-syntax-table nil "") |
33 (defvar emacs-lisp-mode-syntax-table nil "") | |
34 (defvar lisp-mode-abbrev-table nil "") | |
35 | |
36 (if (not emacs-lisp-mode-syntax-table) | |
37 (let ((i 0)) | |
38 (setq emacs-lisp-mode-syntax-table (make-syntax-table)) | |
39 (while (< i ?0) | |
40 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
41 (setq i (1+ i))) | |
42 (setq i (1+ ?9)) | |
43 (while (< i ?A) | |
44 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
45 (setq i (1+ i))) | |
46 (setq i (1+ ?Z)) | |
47 (while (< i ?a) | |
48 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
49 (setq i (1+ i))) | |
50 (setq i (1+ ?z)) | |
51 (while (< i 128) | |
52 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | |
53 (setq i (1+ i))) | |
54 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) | |
55 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) | |
56 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table) | |
8325
2c8b3c988b10
(emacs-lisp-mode-syntax-table): Give RET the same syntax as newline.
Richard M. Stallman <rms@gnu.org>
parents:
7301
diff
changeset
|
57 ;; Give CR the same syntax as newline, for selective-display. |
2c8b3c988b10
(emacs-lisp-mode-syntax-table): Give RET the same syntax as newline.
Richard M. Stallman <rms@gnu.org>
parents:
7301
diff
changeset
|
58 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table) |
213 | 59 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table) |
60 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table) | |
61 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table) | |
62 (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table) | |
63 ;; Used to be singlequote; changed for flonums. | |
64 (modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table) | |
65 (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table) | |
66 (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table) | |
67 (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table) | |
68 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table) | |
69 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table) | |
70 (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table) | |
71 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table))) | |
72 | |
285 | 73 (if (not lisp-mode-syntax-table) |
74 (progn (setq lisp-mode-syntax-table | |
75 (copy-syntax-table emacs-lisp-mode-syntax-table)) | |
76 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table) | |
77 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table) | |
78 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table))) | |
79 | |
213 | 80 (define-abbrev-table 'lisp-mode-abbrev-table ()) |
81 | |
12701
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
82 (defvar lisp-imenu-generic-expression |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
83 '( |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
84 (nil |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
85 "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2) |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
86 ("Variables" |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
87 "^\\s-*(def\\(var\\|const\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2) |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
88 ("Types" |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
89 "^\\s-*(def\\(type\\|struct\\|class\\|ine-condition\\)\\s-+\\([-A-Za-z0-9+]+\\)" |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
90 2)) |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
91 |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
92 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
93 |
213 | 94 (defun lisp-mode-variables (lisp-syntax) |
95 (cond (lisp-syntax | |
96 (set-syntax-table lisp-mode-syntax-table))) | |
97 (setq local-abbrev-table lisp-mode-abbrev-table) | |
98 (make-local-variable 'paragraph-start) | |
13504
1319330ca7ff
(lisp-mode-variables, lisp-fill-paragraph): Remove
Richard M. Stallman <rms@gnu.org>
parents:
12701
diff
changeset
|
99 (setq paragraph-start (concat page-delimiter "\\|$" )) |
213 | 100 (make-local-variable 'paragraph-separate) |
101 (setq paragraph-separate paragraph-start) | |
102 (make-local-variable 'paragraph-ignore-fill-prefix) | |
103 (setq paragraph-ignore-fill-prefix t) | |
10628
04591bafb562
(shared-lisp-mode-map): Don't bind M-q.
Richard M. Stallman <rms@gnu.org>
parents:
10594
diff
changeset
|
104 (make-local-variable 'fill-paragraph-function) |
04591bafb562
(shared-lisp-mode-map): Don't bind M-q.
Richard M. Stallman <rms@gnu.org>
parents:
10594
diff
changeset
|
105 (setq fill-paragraph-function 'lisp-fill-paragraph) |
213 | 106 (make-local-variable 'indent-line-function) |
107 (setq indent-line-function 'lisp-indent-line) | |
108 (make-local-variable 'indent-region-function) | |
109 (setq indent-region-function 'lisp-indent-region) | |
110 (make-local-variable 'parse-sexp-ignore-comments) | |
111 (setq parse-sexp-ignore-comments t) | |
6076
4f76564fc2cd
(lisp-mode-variables): Set outline-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
5103
diff
changeset
|
112 (make-local-variable 'outline-regexp) |
7301
edad1db699ab
(lisp-mode-variables): Added missing backslash to outline-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
7170
diff
changeset
|
113 (setq outline-regexp ";;; \\|(....") |
213 | 114 (make-local-variable 'comment-start) |
115 (setq comment-start ";") | |
116 (make-local-variable 'comment-start-skip) | |
7170
3b452d97f111
(lisp-mode-variables): Undo previous change.
Karl Heuer <kwzh@gnu.org>
parents:
7079
diff
changeset
|
117 (setq comment-start-skip ";+ *") |
213 | 118 (make-local-variable 'comment-column) |
119 (setq comment-column 40) | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
120 (make-local-variable 'comment-indent-function) |
12701
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
121 (setq comment-indent-function 'lisp-comment-indent) |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
122 (make-local-variable 'imenu-generic-expression) |
c50826e44362
(lisp-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12682
diff
changeset
|
123 (setq imenu-generic-expression lisp-imenu-generic-expression)) |
213 | 124 |
125 (defvar shared-lisp-mode-map () | |
126 "Keymap for commands shared by all sorts of Lisp modes.") | |
127 | |
128 (if shared-lisp-mode-map | |
129 () | |
130 (setq shared-lisp-mode-map (make-sparse-keymap)) | |
131 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) | |
12682
66b3d052d4fe
(shared-lisp-mode-map): Don't bind TAB, just set indent-line-function.
Richard M. Stallman <rms@gnu.org>
parents:
12352
diff
changeset
|
132 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify)) |
213 | 133 |
134 (defvar emacs-lisp-mode-map () | |
135 "Keymap for Emacs Lisp mode. | |
12682
66b3d052d4fe
(shared-lisp-mode-map): Don't bind TAB, just set indent-line-function.
Richard M. Stallman <rms@gnu.org>
parents:
12352
diff
changeset
|
136 All commands in `shared-lisp-mode-map' are inherited by this map.") |
213 | 137 |
138 (if emacs-lisp-mode-map | |
139 () | |
12035
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
140 (let ((map (make-sparse-keymap "Emacs-Lisp"))) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
141 (setq emacs-lisp-mode-map |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
142 (nconc (make-sparse-keymap) shared-lisp-mode-map)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
143 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
144 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
145 (define-key emacs-lisp-mode-map [menu-bar] (make-sparse-keymap)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
146 (define-key emacs-lisp-mode-map [menu-bar emacs-lisp] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
147 (cons "Emacs-Lisp" map)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
148 (define-key map [edebug-defun] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
149 '("Instrument Function for Debugging" . edebug-defun)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
150 (define-key map [byte-recompile] |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
151 '("Byte-recompile Directory..." . byte-recompile-directory)) |
14290
fc9c72889fec
(emacs-lisp-mode-map): Avoid duplicate in menu bindings.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
152 (define-key map [emacs-byte-compile-and-load] |
14116
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
153 '("Byte-compile And Load" . emacs-lisp-compile-and-load)) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
154 (define-key map [byte-compile] |
12035
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
155 '("Byte-compile This File" . emacs-lisp-byte-compile)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
156 (define-key map [separator-eval] '("--")) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
157 (define-key map [eval-buffer] '("Evaluate Buffer" . eval-current-buffer)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
158 (define-key map [eval-region] '("Evaluate Region" . eval-region)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
159 (define-key map [eval-sexp] '("Evaluate Last S-expression" . eval-last-sexp)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
160 (define-key map [separator-format] '("--")) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
161 (define-key map [comment-region] '("Comment Out Region" . comment-region)) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
162 (define-key map [indent-region] '("Indent Region" . indent-region)) |
12218
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
163 (define-key map [indent-line] '("Indent Line" . lisp-indent-line)) |
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
164 (put 'eval-region 'menu-enable 'mark-active) |
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
165 (put 'comment-region 'menu-enable 'mark-active) |
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
166 (put 'indent-region 'menu-enable 'mark-active))) |
12035
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
167 |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
168 (defun emacs-lisp-byte-compile () |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
169 "Byte compile the file containing the current buffer." |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
170 (interactive) |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
171 (if buffer-file-name |
c3747e64cff0
(emacs-lisp-mode-map): Add a menu.
Karl Heuer <kwzh@gnu.org>
parents:
10968
diff
changeset
|
172 (byte-compile-file buffer-file-name) |
14116
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
173 (error "The buffer must be saved in a file first"))) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
174 |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
175 (defun emacs-lisp-compile-and-load () |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
176 "Byte-compile the current file (if it has changed), then load compiled code." |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
177 (interactive) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
178 (or buffer-file-name |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
179 (error "The buffer must be saved in a file first")) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
180 (require 'bytecomp) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
181 ;; Recompile if file or buffer has changed since last compilation. |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
182 (or (buffer-modified-p) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
183 (file-newer-than-file-p (byte-compile-dest-file buffer-file-name) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
184 buffer-file-name) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
185 (byte-compile-file buffer-file-name)) |
5f985037b64f
(emacs-lisp-byte-compile): Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
13802
diff
changeset
|
186 (load-file (byte-compile-dest-file buffer-file-name))) |
213 | 187 |
188 (defun emacs-lisp-mode () | |
189 "Major mode for editing Lisp code to run in Emacs. | |
190 Commands: | |
191 Delete converts tabs to spaces as it moves back. | |
192 Blank lines separate paragraphs. Semicolons start comments. | |
193 \\{emacs-lisp-mode-map} | |
194 Entry to this mode calls the value of `emacs-lisp-mode-hook' | |
195 if that value is non-nil." | |
196 (interactive) | |
197 (kill-all-local-variables) | |
198 (use-local-map emacs-lisp-mode-map) | |
199 (set-syntax-table emacs-lisp-mode-syntax-table) | |
200 (setq major-mode 'emacs-lisp-mode) | |
201 (setq mode-name "Emacs-Lisp") | |
202 (lisp-mode-variables nil) | |
203 (run-hooks 'emacs-lisp-mode-hook)) | |
204 | |
205 (defvar lisp-mode-map () | |
206 "Keymap for ordinary Lisp mode. | |
207 All commands in `shared-lisp-mode-map' are inherited by this map.") | |
208 | |
209 (if lisp-mode-map | |
210 () | |
211 (setq lisp-mode-map | |
212 (nconc (make-sparse-keymap) shared-lisp-mode-map)) | |
5103
40b068fb4c37
(lisp-eval-defun): Renamed from lisp-send-defun.
Richard M. Stallman <rms@gnu.org>
parents:
3638
diff
changeset
|
213 (define-key lisp-mode-map "\e\C-x" 'lisp-eval-defun) |
40b068fb4c37
(lisp-eval-defun): Renamed from lisp-send-defun.
Richard M. Stallman <rms@gnu.org>
parents:
3638
diff
changeset
|
214 (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)) |
213 | 215 |
216 (defun lisp-mode () | |
217 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp. | |
218 Commands: | |
219 Delete converts tabs to spaces as it moves back. | |
220 Blank lines separate paragraphs. Semicolons start comments. | |
221 \\{lisp-mode-map} | |
222 Note that `run-lisp' may be used either to start an inferior Lisp job | |
223 or to switch back to an existing one. | |
224 | |
225 Entry to this mode calls the value of `lisp-mode-hook' | |
226 if that value is non-nil." | |
227 (interactive) | |
228 (kill-all-local-variables) | |
229 (use-local-map lisp-mode-map) | |
230 (setq major-mode 'lisp-mode) | |
231 (setq mode-name "Lisp") | |
232 (lisp-mode-variables t) | |
233 (set-syntax-table lisp-mode-syntax-table) | |
234 (run-hooks 'lisp-mode-hook)) | |
235 | |
236 ;; This will do unless shell.el is loaded. | |
5103
40b068fb4c37
(lisp-eval-defun): Renamed from lisp-send-defun.
Richard M. Stallman <rms@gnu.org>
parents:
3638
diff
changeset
|
237 (defun lisp-eval-defun nil |
213 | 238 "Send the current defun to the Lisp process made by \\[run-lisp]." |
239 (interactive) | |
240 (error "Process lisp does not exist")) | |
241 | |
242 (defvar lisp-interaction-mode-map () | |
243 "Keymap for Lisp Interaction moe. | |
244 All commands in `shared-lisp-mode-map' are inherited by this map.") | |
245 | |
246 (if lisp-interaction-mode-map | |
247 () | |
248 (setq lisp-interaction-mode-map | |
249 (nconc (make-sparse-keymap) shared-lisp-mode-map)) | |
250 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun) | |
878
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
251 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol) |
213 | 252 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp)) |
253 | |
254 (defun lisp-interaction-mode () | |
255 "Major mode for typing and evaluating Lisp forms. | |
256 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression | |
257 before point, and prints its value into the buffer, advancing point. | |
258 | |
259 Commands: | |
260 Delete converts tabs to spaces as it moves back. | |
261 Paragraphs are separated only by blank lines. | |
262 Semicolons start comments. | |
263 \\{lisp-interaction-mode-map} | |
264 Entry to this mode calls the value of `lisp-interaction-mode-hook' | |
265 if that value is non-nil." | |
266 (interactive) | |
267 (kill-all-local-variables) | |
268 (use-local-map lisp-interaction-mode-map) | |
269 (setq major-mode 'lisp-interaction-mode) | |
270 (setq mode-name "Lisp Interaction") | |
271 (set-syntax-table emacs-lisp-mode-syntax-table) | |
272 (lisp-mode-variables nil) | |
273 (run-hooks 'lisp-interaction-mode-hook)) | |
274 | |
248 | 275 (defun eval-print-last-sexp () |
213 | 276 "Evaluate sexp before point; print value into current buffer." |
248 | 277 (interactive) |
422 | 278 (let ((standard-output (current-buffer))) |
279 (terpri) | |
280 (eval-last-sexp t) | |
281 (terpri))) | |
213 | 282 |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
283 (defun eval-last-sexp (eval-last-sexp-arg-internal) |
213 | 284 "Evaluate sexp before point; print value in minibuffer. |
285 With argument, print output into current buffer." | |
286 (interactive "P") | |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
287 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)) |
1163 | 288 (opoint (point))) |
249 | 289 (prin1 (let ((stab (syntax-table))) |
290 (eval (unwind-protect | |
291 (save-excursion | |
292 (set-syntax-table emacs-lisp-mode-syntax-table) | |
293 (forward-sexp -1) | |
1163 | 294 (save-restriction |
295 (narrow-to-region (point-min) opoint) | |
296 (read (current-buffer)))) | |
249 | 297 (set-syntax-table stab))))))) |
213 | 298 |
2450
17d258d8e8e4
(eval-defun): Rename argument to avoid collision.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
299 (defun eval-defun (eval-defun-arg-internal) |
248 | 300 "Evaluate defun that point is in or before. |
301 Print value in minibuffer. | |
302 With argument, insert value in current buffer after the defun." | |
213 | 303 (interactive "P") |
10968
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
304 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
305 (form (save-excursion |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
306 (end-of-defun) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
307 (beginning-of-defun) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
308 (read (current-buffer))))) |
12352
e6b42a6ea8e6
(eval-defun): Don't change defvar to defconst
Richard M. Stallman <rms@gnu.org>
parents:
12218
diff
changeset
|
309 (if (and (eq (car form) 'defvar) |
e6b42a6ea8e6
(eval-defun): Don't change defvar to defconst
Richard M. Stallman <rms@gnu.org>
parents:
12218
diff
changeset
|
310 (cdr-safe (cdr-safe form))) |
10968
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
311 (setq form (cons 'defconst (cdr form)))) |
bea3ee51b843
(eval-defun): Convert defvar to defconst.
Richard M. Stallman <rms@gnu.org>
parents:
10629
diff
changeset
|
312 (prin1 (eval form)))) |
213 | 313 |
314 (defun lisp-comment-indent () | |
315 (if (looking-at "\\s<\\s<\\s<") | |
316 (current-column) | |
317 (if (looking-at "\\s<\\s<") | |
318 (let ((tem (calculate-lisp-indent))) | |
319 (if (listp tem) (car tem) tem)) | |
320 (skip-chars-backward " \t") | |
321 (max (if (bolp) 0 (1+ (current-column))) | |
322 comment-column)))) | |
323 | |
324 (defconst lisp-indent-offset nil "") | |
325 (defconst lisp-indent-function 'lisp-indent-function "") | |
326 | |
327 (defun lisp-indent-line (&optional whole-exp) | |
328 "Indent current line as Lisp code. | |
329 With argument, indent any additional lines of the same expression | |
330 rigidly along with this one." | |
331 (interactive "P") | |
332 (let ((indent (calculate-lisp-indent)) shift-amt beg end | |
333 (pos (- (point-max) (point)))) | |
334 (beginning-of-line) | |
335 (setq beg (point)) | |
336 (skip-chars-forward " \t") | |
337 (if (looking-at "\\s<\\s<\\s<") | |
338 ;; Don't alter indentation of a ;;; comment line. | |
677
7a9b4ea68565
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
659
diff
changeset
|
339 (goto-char (- (point-max) pos)) |
213 | 340 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<"))) |
341 ;; Single-semicolon comment lines should be indented | |
342 ;; as comment lines, not as code. | |
343 (progn (indent-for-comment) (forward-char -1)) | |
344 (if (listp indent) (setq indent (car indent))) | |
345 (setq shift-amt (- indent (current-column))) | |
346 (if (zerop shift-amt) | |
347 nil | |
348 (delete-region beg (point)) | |
349 (indent-to indent))) | |
350 ;; If initial point was within line's indentation, | |
351 ;; position after the indentation. Else stay at same point in text. | |
352 (if (> (- (point-max) pos) (point)) | |
353 (goto-char (- (point-max) pos))) | |
354 ;; If desired, shift remaining lines of expression the same amount. | |
355 (and whole-exp (not (zerop shift-amt)) | |
356 (save-excursion | |
357 (goto-char beg) | |
358 (forward-sexp 1) | |
359 (setq end (point)) | |
360 (goto-char beg) | |
361 (forward-line 1) | |
362 (setq beg (point)) | |
363 (> end beg)) | |
364 (indent-code-rigidly beg end shift-amt))))) | |
365 | |
9424
738999b0296f
Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
9423
diff
changeset
|
366 (defvar calculate-lisp-indent-last-sexp) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
367 |
213 | 368 (defun calculate-lisp-indent (&optional parse-start) |
369 "Return appropriate indentation for current line as Lisp code. | |
370 In usual case returns an integer: the column to indent to. | |
371 Can instead return a list, whose car is the column to indent to. | |
372 This means that following lines at the same level of indentation | |
373 should not necessarily be indented the same way. | |
374 The second element of the list is the buffer position | |
375 of the start of the containing expression." | |
376 (save-excursion | |
377 (beginning-of-line) | |
378 (let ((indent-point (point)) | |
379 state paren-depth | |
380 ;; setting this to a number inhibits calling hook | |
381 (desired-indent nil) | |
382 (retry t) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
383 calculate-lisp-indent-last-sexp containing-sexp) |
213 | 384 (if parse-start |
385 (goto-char parse-start) | |
386 (beginning-of-defun)) | |
387 ;; Find outermost containing sexp | |
388 (while (< (point) indent-point) | |
389 (setq state (parse-partial-sexp (point) indent-point 0))) | |
390 ;; Find innermost containing sexp | |
391 (while (and retry | |
392 state | |
393 (> (setq paren-depth (elt state 0)) 0)) | |
394 (setq retry nil) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
395 (setq calculate-lisp-indent-last-sexp (elt state 2)) |
213 | 396 (setq containing-sexp (elt state 1)) |
397 ;; Position following last unclosed open. | |
398 (goto-char (1+ containing-sexp)) | |
399 ;; Is there a complete sexp since then? | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
400 (if (and calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
401 (> calculate-lisp-indent-last-sexp (point))) |
213 | 402 ;; Yes, but is there a containing sexp after that? |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
403 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
404 indent-point 0))) |
213 | 405 (if (setq retry (car (cdr peek))) (setq state peek))))) |
406 (if retry | |
407 nil | |
408 ;; Innermost containing sexp found | |
409 (goto-char (1+ containing-sexp)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
410 (if (not calculate-lisp-indent-last-sexp) |
213 | 411 ;; indent-point immediately follows open paren. |
412 ;; Don't call hook. | |
413 (setq desired-indent (current-column)) | |
414 ;; Find the start of first element of containing sexp. | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
415 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
213 | 416 (cond ((looking-at "\\s(") |
417 ;; First element of containing sexp is a list. | |
418 ;; Indent under that list. | |
419 ) | |
420 ((> (save-excursion (forward-line 1) (point)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
421 calculate-lisp-indent-last-sexp) |
213 | 422 ;; This is the first line to start within the containing sexp. |
423 ;; It's almost certainly a function call. | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
424 (if (= (point) calculate-lisp-indent-last-sexp) |
213 | 425 ;; Containing sexp has nothing before this line |
426 ;; except the first element. Indent under that element. | |
427 nil | |
428 ;; Skip the first element, find start of second (the first | |
429 ;; argument of the function call) and indent under. | |
430 (progn (forward-sexp 1) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
431 (parse-partial-sexp (point) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
432 calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
433 0 t))) |
213 | 434 (backward-prefix-chars)) |
435 (t | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
436 ;; Indent beneath first sexp on same line as |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
437 ;; calculate-lisp-indent-last-sexp. Again, it's |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
438 ;; almost certainly a function call. |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
439 (goto-char calculate-lisp-indent-last-sexp) |
213 | 440 (beginning-of-line) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
441 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
442 0 t) |
213 | 443 (backward-prefix-chars))))) |
444 ;; Point is at the point to indent under unless we are inside a string. | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3241
diff
changeset
|
445 ;; Call indentation hook except when overridden by lisp-indent-offset |
213 | 446 ;; or if the desired indentation has already been computed. |
447 (let ((normal-indent (current-column))) | |
448 (cond ((elt state 3) | |
449 ;; Inside a string, don't change indentation. | |
450 (goto-char indent-point) | |
451 (skip-chars-forward " \t") | |
452 (current-column)) | |
453 ((and (integerp lisp-indent-offset) containing-sexp) | |
454 ;; Indent by constant offset | |
455 (goto-char containing-sexp) | |
456 (+ (current-column) lisp-indent-offset)) | |
457 (desired-indent) | |
458 ((and (boundp 'lisp-indent-function) | |
459 lisp-indent-function | |
460 (not retry)) | |
461 (or (funcall lisp-indent-function indent-point state) | |
462 normal-indent)) | |
463 (t | |
214 | 464 normal-indent)))))) |
213 | 465 |
466 (defun lisp-indent-function (indent-point state) | |
467 (let ((normal-indent (current-column))) | |
468 (goto-char (1+ (elt state 1))) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
469 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
213 | 470 (if (and (elt state 2) |
471 (not (looking-at "\\sw\\|\\s_"))) | |
472 ;; car of form doesn't seem to be a a symbol | |
473 (progn | |
474 (if (not (> (save-excursion (forward-line 1) (point)) | |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
475 calculate-lisp-indent-last-sexp)) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
476 (progn (goto-char calculate-lisp-indent-last-sexp) |
213 | 477 (beginning-of-line) |
9423
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
478 (parse-partial-sexp (point) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
479 calculate-lisp-indent-last-sexp 0 t))) |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
480 ;; Indent under the list or under the first sexp on the same |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
481 ;; line as calculate-lisp-indent-last-sexp. Note that first |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
482 ;; thing on that line has to be complete sexp since we are |
9076245a9fed
(calculate-lisp-indent): Local var
Richard M. Stallman <rms@gnu.org>
parents:
9415
diff
changeset
|
483 ;; inside the innermost containing sexp. |
213 | 484 (backward-prefix-chars) |
485 (current-column)) | |
486 (let ((function (buffer-substring (point) | |
487 (progn (forward-sexp 1) (point)))) | |
488 method) | |
3638
45169f86d3a4
(lisp-indent-function): Look for either
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
489 (setq method (or (get (intern-soft function) 'lisp-indent-function) |
45169f86d3a4
(lisp-indent-function): Look for either
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
490 (get (intern-soft function) 'lisp-indent-hook))) |
213 | 491 (cond ((or (eq method 'defun) |
492 (and (null method) | |
493 (> (length function) 3) | |
494 (string-match "\\`def" function))) | |
495 (lisp-indent-defform state indent-point)) | |
496 ((integerp method) | |
497 (lisp-indent-specform method state | |
498 indent-point normal-indent)) | |
499 (method | |
500 (funcall method state indent-point))))))) | |
501 | |
2933
420dfaaacfc5
(lisp-body-indent): Add doc.
Richard M. Stallman <rms@gnu.org>
parents:
2450
diff
changeset
|
502 (defconst lisp-body-indent 2 |
420dfaaacfc5
(lisp-body-indent): Add doc.
Richard M. Stallman <rms@gnu.org>
parents:
2450
diff
changeset
|
503 "Number of columns to indent the second line of a `(def...)' form.") |
213 | 504 |
505 (defun lisp-indent-specform (count state indent-point normal-indent) | |
506 (let ((containing-form-start (elt state 1)) | |
507 (i count) | |
508 body-indent containing-form-column) | |
509 ;; Move to the start of containing form, calculate indentation | |
510 ;; to use for non-distinguished forms (> count), and move past the | |
511 ;; function symbol. lisp-indent-function guarantees that there is at | |
512 ;; least one word or symbol character following open paren of containing | |
513 ;; form. | |
514 (goto-char containing-form-start) | |
515 (setq containing-form-column (current-column)) | |
516 (setq body-indent (+ lisp-body-indent containing-form-column)) | |
517 (forward-char 1) | |
518 (forward-sexp 1) | |
519 ;; Now find the start of the last form. | |
520 (parse-partial-sexp (point) indent-point 1 t) | |
521 (while (and (< (point) indent-point) | |
522 (condition-case () | |
523 (progn | |
524 (setq count (1- count)) | |
525 (forward-sexp 1) | |
526 (parse-partial-sexp (point) indent-point 1 t)) | |
527 (error nil)))) | |
528 ;; Point is sitting on first character of last (or count) sexp. | |
529 (if (> count 0) | |
530 ;; A distinguished form. If it is the first or second form use double | |
531 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound | |
532 ;; to 2 (the default), this just happens to work the same with if as | |
533 ;; the older code, but it makes unwind-protect, condition-case, | |
534 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older, | |
535 ;; less hacked, behavior can be obtained by replacing below with | |
536 ;; (list normal-indent containing-form-start). | |
537 (if (<= (- i count) 1) | |
538 (list (+ containing-form-column (* 2 lisp-body-indent)) | |
539 containing-form-start) | |
540 (list normal-indent containing-form-start)) | |
541 ;; A non-distinguished form. Use body-indent if there are no | |
542 ;; distinguished forms and this is the first undistinguished form, | |
543 ;; or if this is the first undistinguished form and the preceding | |
544 ;; distinguished form has indentation at least as great as body-indent. | |
545 (if (or (and (= i 0) (= count 0)) | |
546 (and (= count 0) (<= body-indent normal-indent))) | |
547 body-indent | |
548 normal-indent)))) | |
549 | |
550 (defun lisp-indent-defform (state indent-point) | |
551 (goto-char (car (cdr state))) | |
552 (forward-line 1) | |
553 (if (> (point) (car (cdr (cdr state)))) | |
554 (progn | |
555 (goto-char (car (cdr state))) | |
556 (+ lisp-body-indent (current-column))))) | |
557 | |
558 | |
559 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented | |
560 ;; like defun if the first form is placed on the next line, otherwise | |
561 ;; it is indented like any other form (i.e. forms line up under first). | |
562 | |
563 (put 'lambda 'lisp-indent-function 'defun) | |
564 (put 'autoload 'lisp-indent-function 'defun) | |
565 (put 'progn 'lisp-indent-function 0) | |
566 (put 'prog1 'lisp-indent-function 1) | |
567 (put 'prog2 'lisp-indent-function 2) | |
568 (put 'save-excursion 'lisp-indent-function 0) | |
569 (put 'save-window-excursion 'lisp-indent-function 0) | |
12218
a4f383dd5adb
Put mark-active for menu-enable property on eval-region, comment-region, and indent-region symbols.
Simon Marshall <simon@gnu.org>
parents:
12035
diff
changeset
|
570 (put 'save-selected-window 'lisp-indent-function 0) |
213 | 571 (put 'save-restriction 'lisp-indent-function 0) |
1163 | 572 (put 'save-match-data 'lisp-indent-function 0) |
213 | 573 (put 'let 'lisp-indent-function 1) |
574 (put 'let* 'lisp-indent-function 1) | |
575 (put 'while 'lisp-indent-function 1) | |
576 (put 'if 'lisp-indent-function 2) | |
577 (put 'catch 'lisp-indent-function 1) | |
578 (put 'condition-case 'lisp-indent-function 2) | |
579 (put 'unwind-protect 'lisp-indent-function 1) | |
580 (put 'with-output-to-temp-buffer 'lisp-indent-function 1) | |
581 | |
582 (defun indent-sexp (&optional endpos) | |
583 "Indent each line of the list starting just after point. | |
584 If optional arg ENDPOS is given, indent each line, stopping when | |
585 ENDPOS is encountered." | |
586 (interactive) | |
727 | 587 (let ((indent-stack (list nil)) |
588 (next-depth 0) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
589 ;; If ENDPOS is non-nil, use nil as STARTING-POINT |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
590 ;; so that calculate-lisp-indent will find the beginning of |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
591 ;; the defun we are in. |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
592 ;; If ENDPOS is nil, it is safe not to scan before point |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
593 ;; since every line we indent is more deeply nested than point is. |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
594 (starting-point (if endpos nil (point))) |
727 | 595 (last-point (point)) |
596 last-depth bol outer-loop-done inner-loop-done state this-indent) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
597 (or endpos |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
598 ;; Get error now if we don't have a complete sexp after point. |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
599 (save-excursion (forward-sexp 1))) |
213 | 600 (save-excursion |
601 (setq outer-loop-done nil) | |
602 (while (if endpos (< (point) endpos) | |
603 (not outer-loop-done)) | |
604 (setq last-depth next-depth | |
605 inner-loop-done nil) | |
606 ;; Parse this line so we can learn the state | |
607 ;; to indent the next line. | |
608 ;; This inner loop goes through only once | |
609 ;; unless a line ends inside a string. | |
610 (while (and (not inner-loop-done) | |
611 (not (setq outer-loop-done (eobp)))) | |
612 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) | |
613 nil nil state)) | |
614 (setq next-depth (car state)) | |
615 ;; If the line contains a comment other than the sort | |
616 ;; that is indented like code, | |
617 ;; indent it now with indent-for-comment. | |
618 ;; Comments indented like code are right already. | |
619 ;; In any case clear the in-comment flag in the state | |
620 ;; because parse-partial-sexp never sees the newlines. | |
621 (if (car (nthcdr 4 state)) | |
622 (progn (indent-for-comment) | |
623 (end-of-line) | |
624 (setcar (nthcdr 4 state) nil))) | |
625 ;; If this line ends inside a string, | |
626 ;; go straight to next line, remaining within the inner loop, | |
627 ;; and turn off the \-flag. | |
628 (if (car (nthcdr 3 state)) | |
629 (progn | |
630 (forward-line 1) | |
631 (setcar (nthcdr 5 state) nil)) | |
632 (setq inner-loop-done t))) | |
633 (and endpos | |
727 | 634 (<= next-depth 0) |
635 (progn | |
636 (setq indent-stack (append indent-stack | |
637 (make-list (- next-depth) nil)) | |
638 last-depth (- last-depth next-depth) | |
639 next-depth 0))) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
640 (or outer-loop-done endpos |
213 | 641 (setq outer-loop-done (<= next-depth 0))) |
642 (if outer-loop-done | |
3241
6c9b5f6dca70
(indent-sexp): Even if outer-loop-done is t, still move down one line.
Richard M. Stallman <rms@gnu.org>
parents:
2933
diff
changeset
|
643 (forward-line 1) |
213 | 644 (while (> last-depth next-depth) |
645 (setq indent-stack (cdr indent-stack) | |
646 last-depth (1- last-depth))) | |
647 (while (< last-depth next-depth) | |
648 (setq indent-stack (cons nil indent-stack) | |
649 last-depth (1+ last-depth))) | |
650 ;; Now go to the next line and indent it according | |
651 ;; to what we learned from parsing the previous one. | |
652 (forward-line 1) | |
653 (setq bol (point)) | |
654 (skip-chars-forward " \t") | |
655 ;; But not if the line is blank, or just a comment | |
656 ;; (except for double-semi comments; indent them as usual). | |
657 (if (or (eobp) (looking-at "\\s<\\|\n")) | |
658 nil | |
659 (if (and (car indent-stack) | |
660 (>= (car indent-stack) 0)) | |
661 (setq this-indent (car indent-stack)) | |
662 (let ((val (calculate-lisp-indent | |
663 (if (car indent-stack) (- (car indent-stack)) | |
727 | 664 starting-point)))) |
213 | 665 (if (integerp val) |
666 (setcar indent-stack | |
667 (setq this-indent val)) | |
668 (setcar indent-stack (- (car (cdr val)))) | |
669 (setq this-indent (car val))))) | |
670 (if (/= (current-column) this-indent) | |
671 (progn (delete-region bol (point)) | |
672 (indent-to this-indent))))) | |
673 (or outer-loop-done | |
674 (setq outer-loop-done (= (point) last-point)) | |
675 (setq last-point (point))))))) | |
676 | |
677 ;; Indent every line whose first char is between START and END inclusive. | |
678 (defun lisp-indent-region (start end) | |
679 (save-excursion | |
680 (let ((endmark (copy-marker end))) | |
10594
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
681 (goto-char start) |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
682 (and (bolp) (not (eolp)) |
aadef46f00f7
(lisp-indent-region): Set endmark before indenting first line.
Richard M. Stallman <rms@gnu.org>
parents:
9424
diff
changeset
|
683 (lisp-indent-line)) |
213 | 684 (indent-sexp endmark) |
685 (set-marker endmark nil)))) | |
686 | |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
687 ;;;; Lisp paragraph filling commands. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
688 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
689 (defun lisp-fill-paragraph (&optional justify) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
690 "Like \\[fill-paragraph], but handle Emacs Lisp comments. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
691 If any of the current line is a comment, fill the comment or the |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
692 paragraph of it that point is in, preserving the comment's indentation |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
693 and initial semicolons." |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
694 (interactive "P") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
695 (let ( |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
696 ;; Non-nil if the current line contains a comment. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
697 has-comment |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
698 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
699 ;; If has-comment, the appropriate fill-prefix for the comment. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
700 comment-fill-prefix |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
701 ) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
702 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
703 ;; Figure out what kind of comment we are looking at. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
704 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
705 (beginning-of-line) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
706 (cond |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
707 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
708 ;; A line with nothing but a comment on it? |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
709 ((looking-at "[ \t]*;[; \t]*") |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
710 (setq has-comment t |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
711 comment-fill-prefix (buffer-substring (match-beginning 0) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
712 (match-end 0)))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
713 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
714 ;; A line with some code, followed by a comment? Remember that the |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
715 ;; semi which starts the comment shouldn't be part of a string or |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
716 ;; character. |
13802
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
717 ((condition-case nil |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
718 (save-restriction |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
719 (narrow-to-region (point-min) |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
720 (save-excursion (end-of-line) (point))) |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
721 (while (not (looking-at ";\\|$")) |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
722 (skip-chars-forward "^;\n\"\\\\?") |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
723 (cond |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
724 ((eq (char-after (point)) ?\\) (forward-char 2)) |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
725 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1)))) |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
726 (looking-at ";+[\t ]*")) |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
727 (error nil)) |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
728 (setq has-comment t) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
729 (setq comment-fill-prefix |
13802
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
730 (concat (make-string (/ (current-column) 8) ?\t) |
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
731 (make-string (% (current-column) 8) ?\ ) |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
732 (buffer-substring (match-beginning 0) (match-end 0))))))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
733 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
734 (if (not has-comment) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
735 (fill-paragraph justify) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
736 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
737 ;; Narrow to include only the comment, and then fill the region. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
738 (save-restriction |
13802
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
739 (beginning-of-line) |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
740 (narrow-to-region |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
741 ;; Find the first line we should include in the region to fill. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
742 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
743 (while (and (zerop (forward-line -1)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
744 (looking-at "^[ \t]*;"))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
745 ;; We may have gone to far. Go forward again. |
13802
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
746 (or (looking-at ".*;") |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
747 (forward-line 1)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
748 (point)) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
749 ;; Find the beginning of the first line past the region to fill. |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
750 (save-excursion |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
751 (while (progn (forward-line 1) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
752 (looking-at "^[ \t]*;"))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
753 (point))) |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
754 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
755 ;; Lines with only semicolons on them can be paragraph boundaries. |
13504
1319330ca7ff
(lisp-mode-variables, lisp-fill-paragraph): Remove
Richard M. Stallman <rms@gnu.org>
parents:
12701
diff
changeset
|
756 (let ((paragraph-start (concat paragraph-start "\\|[ \t;]*$")) |
1319330ca7ff
(lisp-mode-variables, lisp-fill-paragraph): Remove
Richard M. Stallman <rms@gnu.org>
parents:
12701
diff
changeset
|
757 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$")) |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
758 (fill-prefix comment-fill-prefix)) |
13802
8107433d6a22
(lisp-fill-paragraph): Several changes.
Karl Heuer <kwzh@gnu.org>
parents:
13504
diff
changeset
|
759 (fill-region (point-min) (point-max) justify t)))) |
10629
2c9bdcab7052
(lisp-fill-paragraph): Return t.
Richard M. Stallman <rms@gnu.org>
parents:
10628
diff
changeset
|
760 t)) |
1865
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
761 |
05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
Jim Blandy <jimb@redhat.com>
parents:
1163
diff
changeset
|
762 |
213 | 763 (defun indent-code-rigidly (start end arg &optional nochange-regexp) |
764 "Indent all lines of code, starting in the region, sideways by ARG columns. | |
765 Does not affect lines starting inside comments or strings, assuming that | |
766 the start of the region is not inside them. | |
767 | |
768 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP. | |
769 The last is a regexp which, if matched at the beginning of a line, | |
770 means don't indent that line." | |
771 (interactive "r\np") | |
772 (let (state) | |
773 (save-excursion | |
774 (goto-char end) | |
775 (setq end (point-marker)) | |
776 (goto-char start) | |
777 (or (bolp) | |
778 (setq state (parse-partial-sexp (point) | |
779 (progn | |
780 (forward-line 1) (point)) | |
781 nil nil state))) | |
782 (while (< (point) end) | |
783 (or (car (nthcdr 3 state)) | |
784 (and nochange-regexp | |
785 (looking-at nochange-regexp)) | |
786 ;; If line does not start in string, indent it | |
787 (let ((indent (current-indentation))) | |
788 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
789 (or (eolp) | |
790 (indent-to (max 0 (+ indent arg)) 0)))) | |
791 (setq state (parse-partial-sexp (point) | |
792 (progn | |
793 (forward-line 1) (point)) | |
794 nil nil state)))))) | |
584 | 795 |
796 (provide 'lisp-mode) | |
797 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
798 ;;; lisp-mode.el ends here |