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