Mercurial > emacs
annotate lisp/emacs-lisp/lisp.el @ 6369:881009b034b3
(defun-prompt-regexp): Doc fix.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 15 Mar 1994 23:36:48 +0000 |
parents | 4fa3d631dae8 |
children | 1740ec160ff8 |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
215
diff
changeset
|
1 ;;; lisp.el --- Lisp editing commands for Emacs |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
215
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
5 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
6 ;; Keywords: lisp, languages |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
7 |
84 | 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:
659
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
84 | 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:
2247
diff
changeset
|
24 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
25 |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2823
diff
changeset
|
26 ;; Lisp editing commands to go with Lisp major mode. |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
28 ;;; Code: |
84 | 29 |
6369 | 30 ;; Note that this variable is used by non-lisp modes too. |
84 | 31 (defvar defun-prompt-regexp nil |
6369 | 32 "*Non-nil => regexp to ignore, before the character that starts a defun. |
33 This is only necessary if the opening paren or brace is not in column 0. | |
34 See `beginning-of-defun'.") | |
84 | 35 |
3758
e212a0863773
(parens-require-spaces): Var renamed and sense changed.
Richard M. Stallman <rms@gnu.org>
parents:
3733
diff
changeset
|
36 (defvar parens-require-spaces t |
e212a0863773
(parens-require-spaces): Var renamed and sense changed.
Richard M. Stallman <rms@gnu.org>
parents:
3733
diff
changeset
|
37 "Non-nil => `insert-parentheses' should insert whitespace as needed.") |
3733
c1c105ffdd0c
(parens-dont-require-spaces): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
38 |
84 | 39 (defun forward-sexp (&optional arg) |
40 "Move forward across one balanced expression (sexp). | |
215 | 41 With argument, do it that many times. Negative arg -N means |
42 move backward across N balanced expressions." | |
84 | 43 (interactive "p") |
44 (or arg (setq arg 1)) | |
45 (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) | |
46 (if (< arg 0) (backward-prefix-chars))) | |
47 | |
48 (defun backward-sexp (&optional arg) | |
49 "Move backward across one balanced expression (sexp). | |
215 | 50 With argument, do it that many times. Negative arg -N means |
51 move forward across N balanced expressions." | |
84 | 52 (interactive "p") |
53 (or arg (setq arg 1)) | |
54 (forward-sexp (- arg))) | |
55 | |
56 (defun mark-sexp (arg) | |
57 "Set mark ARG sexps from point. | |
215 | 58 The place mark goes is the same place \\[forward-sexp] would |
59 move to with the same argument." | |
84 | 60 (interactive "p") |
61 (push-mark | |
62 (save-excursion | |
63 (forward-sexp arg) | |
2823
8ab0e280fbf0
(mark-sexp, mark-defun): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
64 (point)) |
8ab0e280fbf0
(mark-sexp, mark-defun): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
65 nil t)) |
84 | 66 |
67 (defun forward-list (&optional arg) | |
68 "Move forward across one balanced group of parentheses. | |
69 With argument, do it that many times. | |
70 Negative arg -N means move backward across N groups of parentheses." | |
71 (interactive "p") | |
72 (or arg (setq arg 1)) | |
73 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))) | |
74 | |
75 (defun backward-list (&optional arg) | |
76 "Move backward across one balanced group of parentheses. | |
77 With argument, do it that many times. | |
78 Negative arg -N means move forward across N groups of parentheses." | |
79 (interactive "p") | |
80 (or arg (setq arg 1)) | |
81 (forward-list (- arg))) | |
82 | |
83 (defun down-list (arg) | |
84 "Move forward down one level of parentheses. | |
85 With argument, do this that many times. | |
86 A negative argument means move backward but still go down a level. | |
87 In Lisp programs, an argument is required." | |
88 (interactive "p") | |
89 (let ((inc (if (> arg 0) 1 -1))) | |
90 (while (/= arg 0) | |
91 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) | |
92 (setq arg (- arg inc))))) | |
93 | |
94 (defun backward-up-list (arg) | |
95 "Move backward out of one level of parentheses. | |
96 With argument, do this that many times. | |
97 A negative argument means move forward but still to a less deep spot. | |
98 In Lisp programs, an argument is required." | |
99 (interactive "p") | |
100 (up-list (- arg))) | |
101 | |
102 (defun up-list (arg) | |
103 "Move forward out of one level of parentheses. | |
104 With argument, do this that many times. | |
105 A negative argument means move backward but still to a less deep spot. | |
106 In Lisp programs, an argument is required." | |
107 (interactive "p") | |
108 (let ((inc (if (> arg 0) 1 -1))) | |
109 (while (/= arg 0) | |
110 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) | |
111 (setq arg (- arg inc))))) | |
112 | |
113 (defun kill-sexp (arg) | |
114 "Kill the sexp (balanced expression) following the cursor. | |
115 With argument, kill that many sexps after the cursor. | |
116 Negative arg -N means kill N sexps before the cursor." | |
117 (interactive "p") | |
118 (let ((opoint (point))) | |
119 (forward-sexp arg) | |
120 (kill-region opoint (point)))) | |
121 | |
122 (defun backward-kill-sexp (arg) | |
123 "Kill the sexp (balanced expression) preceding the cursor. | |
124 With argument, kill that many sexps before the cursor. | |
125 Negative arg -N means kill N sexps after the cursor." | |
126 (interactive "p") | |
127 (kill-sexp (- arg))) | |
128 | |
129 (defun beginning-of-defun (&optional arg) | |
130 "Move backward to the beginning of a defun. | |
131 With argument, do it that many times. Negative arg -N | |
132 means move forward to Nth following beginning of defun. | |
133 Returns t unless search stops due to beginning or end of buffer. | |
134 | |
135 Normally a defun starts when there is an char with open-parenthesis | |
136 syntax at the beginning of a line. If `defun-prompt-regexp' is | |
137 non-nil, then a string which matches that regexp may precede the | |
138 open-parenthesis." | |
139 (interactive "p") | |
140 (and arg (< arg 0) (forward-char 1)) | |
141 (and (re-search-backward (if defun-prompt-regexp | |
142 (concat "^\\s(\\|" | |
143 "\\(" defun-prompt-regexp "\\)\\s(") | |
144 "^\\s(") | |
145 nil 'move (or arg 1)) | |
146 (progn (beginning-of-line) t))) | |
147 | |
148 (defun buffer-end (arg) | |
149 (if (> arg 0) (point-max) (point-min))) | |
150 | |
151 (defun end-of-defun (&optional arg) | |
152 "Move forward to next end of defun. With argument, do it that many times. | |
153 Negative argument -N means move back to Nth preceding end of defun. | |
154 | |
155 An end of a defun occurs right after the close-parenthesis that matches | |
156 the open-parenthesis that starts a defun; see `beginning-of-defun'." | |
157 (interactive "p") | |
158 (if (or (null arg) (= arg 0)) (setq arg 1)) | |
159 (let ((first t)) | |
160 (while (and (> arg 0) (< (point) (point-max))) | |
161 (let ((pos (point)) npos) | |
162 (while (progn | |
163 (if (and first | |
164 (progn | |
165 (forward-char 1) | |
166 (beginning-of-defun 1))) | |
167 nil | |
168 (or (bobp) (forward-char -1)) | |
169 (beginning-of-defun -1)) | |
170 (setq first nil) | |
171 (forward-list 1) | |
172 (skip-chars-forward " \t") | |
173 (if (looking-at "\\s<\\|\n") | |
174 (forward-line 1)) | |
175 (<= (point) pos)))) | |
176 (setq arg (1- arg))) | |
177 (while (< arg 0) | |
178 (let ((pos (point))) | |
179 (beginning-of-defun 1) | |
180 (forward-sexp 1) | |
181 (forward-line 1) | |
182 (if (>= (point) pos) | |
183 (if (beginning-of-defun 2) | |
184 (progn | |
185 (forward-list 1) | |
186 (skip-chars-forward " \t") | |
187 (if (looking-at "[;\n]") | |
188 (forward-line 1))) | |
189 (goto-char (point-min))))) | |
190 (setq arg (1+ arg))))) | |
191 | |
192 (defun mark-defun () | |
193 "Put mark at end of this defun, point at beginning. | |
194 The defun marked is the one that contains point or follows point." | |
195 (interactive) | |
196 (push-mark (point)) | |
197 (end-of-defun) | |
2823
8ab0e280fbf0
(mark-sexp, mark-defun): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
198 (push-mark (point) nil t) |
84 | 199 (beginning-of-defun) |
200 (re-search-backward "^\n" (- (point) 1) t)) | |
201 | |
202 (defun insert-parentheses (arg) | |
203 "Put parentheses around next ARG sexps. Leave point after open-paren. | |
3733
c1c105ffdd0c
(parens-dont-require-spaces): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
204 No argument is equivalent to zero: just insert `()' and leave point between. |
5838 | 205 If `parens-require-spaces' is non-nil, this command also inserts a space |
206 before and after, depending on the surrounding characters." | |
84 | 207 (interactive "P") |
133
2f5b3f50773d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
119
diff
changeset
|
208 (if arg (setq arg (prefix-numeric-value arg)) |
2f5b3f50773d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
119
diff
changeset
|
209 (setq arg 0)) |
2f5b3f50773d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
119
diff
changeset
|
210 (or (eq arg 0) (skip-chars-forward " \t")) |
3758
e212a0863773
(parens-require-spaces): Var renamed and sense changed.
Richard M. Stallman <rms@gnu.org>
parents:
3733
diff
changeset
|
211 (and parens-require-spaces |
3733
c1c105ffdd0c
(parens-dont-require-spaces): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
212 (memq (char-syntax (preceding-char)) '(?w ?_ ?\) )) |
84 | 213 (insert " ")) |
214 (insert ?\() | |
215 (save-excursion | |
133
2f5b3f50773d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
119
diff
changeset
|
216 (or (eq arg 0) (forward-sexp arg)) |
84 | 217 (insert ?\)) |
3758
e212a0863773
(parens-require-spaces): Var renamed and sense changed.
Richard M. Stallman <rms@gnu.org>
parents:
3733
diff
changeset
|
218 (and parens-require-spaces |
3733
c1c105ffdd0c
(parens-dont-require-spaces): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
219 (memq (char-syntax (following-char)) '(?w ?_ ?\( )) |
133
2f5b3f50773d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
119
diff
changeset
|
220 (insert " ")))) |
84 | 221 |
222 (defun move-past-close-and-reindent () | |
223 "Move past next `)', delete indentation before it, then indent after it." | |
224 (interactive) | |
225 (up-list 1) | |
226 (forward-char -1) | |
227 (while (save-excursion ; this is my contribution | |
228 (let ((before-paren (point))) | |
229 (back-to-indentation) | |
230 (= (point) before-paren))) | |
231 (delete-indentation)) | |
232 (forward-char 1) | |
233 (newline-and-indent)) | |
234 | |
235 (defun lisp-complete-symbol () | |
6004
4fa3d631dae8
(lisp-complete-symbol): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5981
diff
changeset
|
236 "Perform completion on Lisp symbol preceding point. |
4fa3d631dae8
(lisp-complete-symbol): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5981
diff
changeset
|
237 Compare that symbol against the known Lisp symbols. |
4fa3d631dae8
(lisp-complete-symbol): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5981
diff
changeset
|
238 |
4fa3d631dae8
(lisp-complete-symbol): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5981
diff
changeset
|
239 The context determines which symbols are considered. |
4fa3d631dae8
(lisp-complete-symbol): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5981
diff
changeset
|
240 If the symbol starts just after an open-parenthesis, only symbols |
215 | 241 with function definitions are considered. Otherwise, all symbols with |
242 function definitions, values or properties are considered." | |
84 | 243 (interactive) |
244 (let* ((end (point)) | |
245 (buffer-syntax (syntax-table)) | |
119 | 246 (beg (unwind-protect |
247 (save-excursion | |
248 (set-syntax-table emacs-lisp-mode-syntax-table) | |
249 (backward-sexp 1) | |
250 (while (= (char-syntax (following-char)) ?\') | |
251 (forward-char 1)) | |
252 (point)) | |
84 | 253 (set-syntax-table buffer-syntax))) |
254 (pattern (buffer-substring beg end)) | |
255 (predicate | |
256 (if (eq (char-after (1- beg)) ?\() | |
257 'fboundp | |
258 (function (lambda (sym) | |
259 (or (boundp sym) (fboundp sym) | |
260 (symbol-plist sym)))))) | |
261 (completion (try-completion pattern obarray predicate))) | |
262 (cond ((eq completion t)) | |
263 ((null completion) | |
264 (message "Can't find completion for \"%s\"" pattern) | |
265 (ding)) | |
266 ((not (string= pattern completion)) | |
267 (delete-region beg end) | |
268 (insert completion)) | |
269 (t | |
270 (message "Making completion list...") | |
271 (let ((list (all-completions pattern obarray predicate))) | |
272 (or (eq predicate 'fboundp) | |
273 (let (new) | |
274 (while list | |
275 (setq new (cons (if (fboundp (intern (car list))) | |
276 (list (car list) " <f>") | |
277 (car list)) | |
278 new)) | |
279 (setq list (cdr list))) | |
280 (setq list (nreverse new)))) | |
281 (with-output-to-temp-buffer " *Completions*" | |
282 (display-completion-list list))) | |
283 (message "Making completion list...%s" "done"))))) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
215
diff
changeset
|
284 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
215
diff
changeset
|
285 ;;; lisp.el ends here |