Mercurial > emacs
comparison lisp/emacs-lisp/lisp.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | d9a861a5b9d6 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; lisp.el --- Lisp editing commands for Emacs | 1 ;;; lisp.el --- Lisp editing commands for Emacs |
2 | 2 |
3 ;; Copyright (C) 1985, 1986, 1994, 2000 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1986, 1994, 2000, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Maintainer: FSF | 6 ;; Maintainer: FSF |
6 ;; Keywords: lisp, languages | 7 ;; Keywords: lisp, languages |
7 | 8 |
8 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 ;; GNU General Public License for more details. | 19 ;; GNU General Public License for more details. |
19 | 20 |
20 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02110-1301, USA. |
24 | 25 |
25 ;;; Commentary: | 26 ;;; Commentary: |
26 | 27 |
27 ;; Lisp editing commands to go with Lisp major mode. More-or-less | 28 ;; Lisp editing commands to go with Lisp major mode. More-or-less |
28 ;; applicable in other modes too. | 29 ;; applicable in other modes too. |
29 | 30 |
30 ;;; Code: | 31 ;;; Code: |
31 | 32 |
32 ;; Note that this variable is used by non-lisp modes too. | 33 ;; Note that this variable is used by non-lisp modes too. |
33 (defcustom defun-prompt-regexp nil | 34 (defcustom defun-prompt-regexp nil |
34 "*If non-nil, a regexp to ignore before the character that starts a defun. | 35 "*If non-nil, a regexp to ignore before a defun. |
35 This is only necessary if the opening paren or brace is not in column 0. | 36 This is only necessary if the opening paren or brace is not in column 0. |
36 See function `beginning-of-defun'. | 37 See function `beginning-of-defun'." |
37 | |
38 Setting this variable automatically makes it local to the current buffer." | |
39 :type '(choice (const nil) | 38 :type '(choice (const nil) |
40 regexp) | 39 regexp) |
41 :group 'lisp) | 40 :group 'lisp) |
42 (make-variable-buffer-local 'defun-prompt-regexp) | 41 (make-variable-buffer-local 'defun-prompt-regexp) |
43 | 42 |
44 (defcustom parens-require-spaces t | 43 (defcustom parens-require-spaces t |
45 "Non-nil means `insert-parentheses' should insert whitespace as needed." | 44 "If non-nil, `insert-parentheses' inserts whitespace as needed." |
46 :type 'boolean | 45 :type 'boolean |
47 :group 'lisp) | 46 :group 'lisp) |
48 | 47 |
49 (defvar forward-sexp-function nil | 48 (defvar forward-sexp-function nil |
50 "If non-nil, `forward-sexp' delegates to this function. | 49 "If non-nil, `forward-sexp' delegates to this function. |
67 move forward across N balanced expressions." | 66 move forward across N balanced expressions." |
68 (interactive "p") | 67 (interactive "p") |
69 (or arg (setq arg 1)) | 68 (or arg (setq arg 1)) |
70 (forward-sexp (- arg))) | 69 (forward-sexp (- arg))) |
71 | 70 |
72 (defun mark-sexp (&optional arg) | 71 (defun mark-sexp (&optional arg allow-extend) |
73 "Set mark ARG sexps from point. | 72 "Set mark ARG sexps from point. |
74 The place mark goes is the same place \\[forward-sexp] would | 73 The place mark goes is the same place \\[forward-sexp] would |
75 move to with the same argument. | 74 move to with the same argument. |
76 If this command is repeated, it marks the next ARG sexps after the ones | 75 Interactively, if this command is repeated |
77 already marked." | 76 or (in Transient Mark mode) if the mark is active, |
78 (interactive "p") | 77 it marks the next ARG sexps after the ones already marked." |
79 (cond ((and (eq last-command this-command) (mark t)) | 78 (interactive "P\np") |
79 (cond ((and allow-extend | |
80 (or (and (eq last-command this-command) (mark t)) | |
81 (and transient-mark-mode mark-active))) | |
82 (setq arg (if arg (prefix-numeric-value arg) | |
83 (if (< (mark) (point)) -1 1))) | |
80 (set-mark | 84 (set-mark |
81 (save-excursion | 85 (save-excursion |
82 (goto-char (mark)) | 86 (goto-char (mark)) |
83 (forward-sexp (or arg 1)) | 87 (forward-sexp arg) |
84 (point)))) | 88 (point)))) |
85 (t | 89 (t |
86 (push-mark | 90 (push-mark |
87 (save-excursion | 91 (save-excursion |
88 (forward-sexp (or arg 1)) | 92 (forward-sexp (prefix-numeric-value arg)) |
89 (point)) | 93 (point)) |
90 nil t)))) | 94 nil t)))) |
91 | 95 |
92 (defun forward-list (&optional arg) | 96 (defun forward-list (&optional arg) |
93 "Move forward across one balanced group of parentheses. | 97 "Move forward across one balanced group of parentheses. |
133 (while (/= arg 0) | 137 (while (/= arg 0) |
134 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) | 138 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) |
135 (setq arg (- arg inc))))) | 139 (setq arg (- arg inc))))) |
136 | 140 |
137 (defun kill-sexp (&optional arg) | 141 (defun kill-sexp (&optional arg) |
138 "Kill the sexp (balanced expression) following the cursor. | 142 "Kill the sexp (balanced expression) following point. |
139 With ARG, kill that many sexps after the cursor. | 143 With ARG, kill that many sexps after point. |
140 Negative arg -N means kill N sexps before the cursor." | 144 Negative arg -N means kill N sexps before point." |
141 (interactive "p") | 145 (interactive "p") |
142 (let ((opoint (point))) | 146 (let ((opoint (point))) |
143 (forward-sexp (or arg 1)) | 147 (forward-sexp (or arg 1)) |
144 (kill-region opoint (point)))) | 148 (kill-region opoint (point)))) |
145 | 149 |
146 (defun backward-kill-sexp (&optional arg) | 150 (defun backward-kill-sexp (&optional arg) |
147 "Kill the sexp (balanced expression) preceding the cursor. | 151 "Kill the sexp (balanced expression) preceding point. |
148 With ARG, kill that many sexps before the cursor. | 152 With ARG, kill that many sexps before point. |
149 Negative arg -N means kill N sexps after the cursor." | 153 Negative arg -N means kill N sexps after point." |
150 (interactive "p") | 154 (interactive "p") |
151 (kill-sexp (- (or arg 1)))) | 155 (kill-sexp (- (or arg 1)))) |
156 | |
157 ;; After Zmacs: | |
158 (defun kill-backward-up-list (&optional arg) | |
159 "Kill the form containing the current sexp, leaving the sexp itself. | |
160 A prefix argument ARG causes the relevant number of surrounding | |
161 forms to be removed." | |
162 (interactive "*p") | |
163 (let ((current-sexp (thing-at-point 'sexp))) | |
164 (if current-sexp | |
165 (save-excursion | |
166 (backward-up-list arg) | |
167 (kill-sexp) | |
168 (insert current-sexp)) | |
169 (error "Not at a sexp")))) | |
152 | 170 |
153 (defvar beginning-of-defun-function nil | 171 (defvar beginning-of-defun-function nil |
154 "If non-nil, function for `beginning-of-defun-raw' to call. | 172 "If non-nil, function for `beginning-of-defun-raw' to call. |
155 This is used to find the beginning of the defun instead of using the | 173 This is used to find the beginning of the defun instead of using the |
156 normal recipe (see `beginning-of-defun'). Major modes can define this | 174 normal recipe (see `beginning-of-defun'). Major modes can define this |
157 if defining `defun-prompt-regexp' is not sufficient to handle the mode's | 175 if defining `defun-prompt-regexp' is not sufficient to handle the mode's |
158 needs. | 176 needs. |
159 | 177 |
160 The function should go to the line on which the current defun starts, | 178 The function (of no args) should go to the line on which the current |
161 and return non-nil, or should return nil if it can't find the beginning.") | 179 defun starts, and return non-nil, or should return nil if it can't |
180 find the beginning.") | |
162 | 181 |
163 (defun beginning-of-defun (&optional arg) | 182 (defun beginning-of-defun (&optional arg) |
164 "Move backward to the beginning of a defun. | 183 "Move backward to the beginning of a defun. |
165 With ARG, do it that many times. Negative arg -N | 184 With ARG, do it that many times. Negative arg -N |
166 means move forward to Nth following beginning of defun. | 185 means move forward to Nth following beginning of defun. |
172 open-parenthesis, and point ends up at the beginning of the line. | 191 open-parenthesis, and point ends up at the beginning of the line. |
173 | 192 |
174 If variable `beginning-of-defun-function' is non-nil, its value | 193 If variable `beginning-of-defun-function' is non-nil, its value |
175 is called as a function to find the defun's beginning." | 194 is called as a function to find the defun's beginning." |
176 (interactive "p") | 195 (interactive "p") |
196 (or (not (eq this-command 'beginning-of-defun)) | |
197 (eq last-command 'beginning-of-defun) | |
198 (and transient-mark-mode mark-active) | |
199 (push-mark)) | |
177 (and (beginning-of-defun-raw arg) | 200 (and (beginning-of-defun-raw arg) |
178 (progn (beginning-of-line) t))) | 201 (progn (beginning-of-line) t))) |
179 | 202 |
180 (defun beginning-of-defun-raw (&optional arg) | 203 (defun beginning-of-defun-raw (&optional arg) |
181 "Move point to the character that starts a defun. | 204 "Move point to the character that starts a defun. |
185 | 208 |
186 If variable `beginning-of-defun-function' is non-nil, its value | 209 If variable `beginning-of-defun-function' is non-nil, its value |
187 is called as a function to find the defun's beginning." | 210 is called as a function to find the defun's beginning." |
188 (interactive "p") | 211 (interactive "p") |
189 (if beginning-of-defun-function | 212 (if beginning-of-defun-function |
190 (funcall beginning-of-defun-function) | 213 (if (> (setq arg (or arg 1)) 0) |
214 (dotimes (i arg) | |
215 (funcall beginning-of-defun-function)) | |
216 ;; Better not call end-of-defun-function directly, in case | |
217 ;; it's not defined. | |
218 (end-of-defun (- arg))) | |
191 (and arg (< arg 0) (not (eobp)) (forward-char 1)) | 219 (and arg (< arg 0) (not (eobp)) (forward-char 1)) |
192 (and (re-search-backward (if defun-prompt-regexp | 220 (and (re-search-backward (if defun-prompt-regexp |
193 (concat (if open-paren-in-column-0-is-defun-start | 221 (concat (if open-paren-in-column-0-is-defun-start |
194 "^\\s(\\|" "") | 222 "^\\s(\\|" "") |
195 "\\(" defun-prompt-regexp "\\)\\s(") | 223 "\\(?:" defun-prompt-regexp "\\)\\s(") |
196 "^\\s(") | 224 "^\\s(") |
197 nil 'move (or arg 1)) | 225 nil 'move (or arg 1)) |
198 (progn (goto-char (1- (match-end 0)))) t))) | 226 (progn (goto-char (1- (match-end 0)))) t))) |
199 | 227 |
200 (defvar end-of-defun-function nil | 228 (defvar end-of-defun-function nil |
202 This is used to find the end of the defun instead of using the normal | 230 This is used to find the end of the defun instead of using the normal |
203 recipe (see `end-of-defun'). Major modes can define this if the | 231 recipe (see `end-of-defun'). Major modes can define this if the |
204 normal method is not appropriate.") | 232 normal method is not appropriate.") |
205 | 233 |
206 (defun buffer-end (arg) | 234 (defun buffer-end (arg) |
235 "Return the \"far end\" position of the buffer, in direction ARG. | |
236 If ARG is positive, that's the end of the buffer. | |
237 Otherwise, that's the beginning of the buffer." | |
207 (if (> arg 0) (point-max) (point-min))) | 238 (if (> arg 0) (point-max) (point-min))) |
208 | 239 |
209 (defun end-of-defun (&optional arg) | 240 (defun end-of-defun (&optional arg) |
210 "Move forward to next end of defun. With argument, do it that many times. | 241 "Move forward to next end of defun. |
242 With argument, do it that many times. | |
211 Negative argument -N means move back to Nth preceding end of defun. | 243 Negative argument -N means move back to Nth preceding end of defun. |
212 | 244 |
213 An end of a defun occurs right after the close-parenthesis that | 245 An end of a defun occurs right after the close-parenthesis that |
214 matches the open-parenthesis that starts a defun; see function | 246 matches the open-parenthesis that starts a defun; see function |
215 `beginning-of-defun'. | 247 `beginning-of-defun'. |
216 | 248 |
217 If variable `end-of-defun-function' is non-nil, its value | 249 If variable `end-of-defun-function' is non-nil, its value |
218 is called as a function to find the defun's end." | 250 is called as a function to find the defun's end." |
219 (interactive "p") | 251 (interactive "p") |
252 (or (not (eq this-command 'end-of-defun)) | |
253 (eq last-command 'end-of-defun) | |
254 (and transient-mark-mode mark-active) | |
255 (push-mark)) | |
256 (if (or (null arg) (= arg 0)) (setq arg 1)) | |
220 (if end-of-defun-function | 257 (if end-of-defun-function |
221 (funcall end-of-defun-function) | 258 (if (> arg 0) |
222 (if (or (null arg) (= arg 0)) (setq arg 1)) | 259 (dotimes (i arg) |
260 (funcall end-of-defun-function)) | |
261 ;; Better not call beginning-of-defun-function | |
262 ;; directly, in case it's not defined. | |
263 (beginning-of-defun (- arg))) | |
223 (let ((first t)) | 264 (let ((first t)) |
224 (while (and (> arg 0) (< (point) (point-max))) | 265 (while (and (> arg 0) (< (point) (point-max))) |
225 (let ((pos (point)) npos) | 266 (let ((pos (point))) |
226 (while (progn | 267 (while (progn |
227 (if (and first | 268 (if (and first |
228 (progn | 269 (progn |
229 (end-of-line 1) | 270 (end-of-line 1) |
230 (beginning-of-defun-raw 1))) | 271 (beginning-of-defun-raw 1))) |
251 (if (looking-at "\\s<\\|\n") | 292 (if (looking-at "\\s<\\|\n") |
252 (forward-line 1))) | 293 (forward-line 1))) |
253 (goto-char (point-min))))) | 294 (goto-char (point-min))))) |
254 (setq arg (1+ arg)))))) | 295 (setq arg (1+ arg)))))) |
255 | 296 |
256 (defun mark-defun () | 297 (defun mark-defun (&optional allow-extend) |
257 "Put mark at end of this defun, point at beginning. | 298 "Put mark at end of this defun, point at beginning. |
258 The defun marked is the one that contains point or follows point. | 299 The defun marked is the one that contains point or follows point. |
259 If this command is repeated, marks more defuns after the ones | 300 |
260 already marked." | 301 Interactively, if this command is repeated |
261 (interactive) | 302 or (in Transient Mark mode) if the mark is active, |
262 (cond ((and (eq last-command this-command) (mark t)) | 303 it marks the next defun after the ones already marked." |
304 (interactive "p") | |
305 (cond ((and allow-extend | |
306 (or (and (eq last-command this-command) (mark t)) | |
307 (and transient-mark-mode mark-active))) | |
263 (set-mark | 308 (set-mark |
264 (save-excursion | 309 (save-excursion |
265 (goto-char (mark)) | 310 (goto-char (mark)) |
266 (end-of-defun) | 311 (end-of-defun) |
267 (point)))) | 312 (point)))) |
268 (t | 313 (t |
269 (push-mark (point)) | 314 (let ((opoint (point)) |
270 (end-of-defun) | 315 beg end) |
271 (push-mark (point) nil t) | 316 (push-mark opoint) |
272 (beginning-of-defun) | 317 ;; Try first in this order for the sake of languages with nested |
273 (re-search-backward "^\n" (- (point) 1) t)))) | 318 ;; functions where several can end at the same place as with |
319 ;; the offside rule, e.g. Python. | |
320 (beginning-of-defun) | |
321 (setq beg (point)) | |
322 (end-of-defun) | |
323 (setq end (point)) | |
324 (while (looking-at "^\n") | |
325 (forward-line 1)) | |
326 (if (> (point) opoint) | |
327 (progn | |
328 ;; We got the right defun. | |
329 (push-mark beg nil t) | |
330 (goto-char end) | |
331 (exchange-point-and-mark)) | |
332 ;; beginning-of-defun moved back one defun | |
333 ;; so we got the wrong one. | |
334 (goto-char opoint) | |
335 (end-of-defun) | |
336 (push-mark (point) nil t) | |
337 (beginning-of-defun)) | |
338 (re-search-backward "^\n" (- (point) 1) t))))) | |
274 | 339 |
275 (defun narrow-to-defun (&optional arg) | 340 (defun narrow-to-defun (&optional arg) |
276 "Make text outside current defun invisible. | 341 "Make text outside current defun invisible. |
277 The defun visible is the one that contains point or follows point. | 342 The defun visible is the one that contains point or follows point. |
278 Optional ARG is ignored." | 343 Optional ARG is ignored." |
279 (interactive) | 344 (interactive) |
280 (save-excursion | 345 (save-excursion |
281 (widen) | 346 (widen) |
282 (end-of-defun) | 347 (let ((opoint (point)) |
283 (let ((end (point))) | 348 beg end) |
349 ;; Try first in this order for the sake of languages with nested | |
350 ;; functions where several can end at the same place as with | |
351 ;; the offside rule, e.g. Python. | |
284 (beginning-of-defun) | 352 (beginning-of-defun) |
285 (narrow-to-region (point) end)))) | 353 (setq beg (point)) |
286 | 354 (end-of-defun) |
287 (defun insert-parentheses (arg) | 355 (setq end (point)) |
288 "Enclose following ARG sexps in parentheses. Leave point after open-paren. | 356 (while (looking-at "^\n") |
357 (forward-line 1)) | |
358 (unless (> (point) opoint) | |
359 ;; beginning-of-defun moved back one defun | |
360 ;; so we got the wrong one. | |
361 (goto-char opoint) | |
362 (end-of-defun) | |
363 (setq end (point)) | |
364 (beginning-of-defun) | |
365 (setq beg (point))) | |
366 (goto-char end) | |
367 (re-search-backward "^\n" (- (point) 1) t) | |
368 (narrow-to-region beg end)))) | |
369 | |
370 (defvar insert-pair-alist | |
371 '((?\( ?\)) (?\[ ?\]) (?\{ ?\}) (?\< ?\>) (?\" ?\") (?\' ?\') (?\` ?\')) | |
372 "Alist of paired characters inserted by `insert-pair'. | |
373 Each element looks like (OPEN-CHAR CLOSE-CHAR) or (COMMAND-CHAR | |
374 OPEN-CHAR CLOSE-CHAR). The characters OPEN-CHAR and CLOSE-CHAR | |
375 of the pair whose key is equal to the last input character with | |
376 or without modifiers, are inserted by `insert-pair'.") | |
377 | |
378 (defun insert-pair (&optional arg open close) | |
379 "Enclose following ARG sexps in a pair of OPEN and CLOSE characters. | |
380 Leave point after the first character. | |
381 A negative ARG encloses the preceding ARG sexps instead. | |
382 No argument is equivalent to zero: just insert characters | |
383 and leave point between. | |
384 If `parens-require-spaces' is non-nil, this command also inserts a space | |
385 before and after, depending on the surrounding characters. | |
386 If region is active, insert enclosing characters at region boundaries. | |
387 | |
388 If arguments OPEN and CLOSE are nil, the character pair is found | |
389 from the variable `insert-pair-alist' according to the last input | |
390 character with or without modifiers. If no character pair is | |
391 found in the variable `insert-pair-alist', then the last input | |
392 character is inserted ARG times." | |
393 (interactive "P") | |
394 (if (not (and open close)) | |
395 (let ((pair (or (assq last-command-char insert-pair-alist) | |
396 (assq (event-basic-type last-command-event) | |
397 insert-pair-alist)))) | |
398 (if pair | |
399 (if (nth 2 pair) | |
400 (setq open (nth 1 pair) close (nth 2 pair)) | |
401 (setq open (nth 0 pair) close (nth 1 pair)))))) | |
402 (if (and open close) | |
403 (if (and transient-mark-mode mark-active) | |
404 (progn | |
405 (save-excursion (goto-char (region-end)) (insert close)) | |
406 (save-excursion (goto-char (region-beginning)) (insert open))) | |
407 (if arg (setq arg (prefix-numeric-value arg)) | |
408 (setq arg 0)) | |
409 (cond ((> arg 0) (skip-chars-forward " \t")) | |
410 ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) | |
411 (and parens-require-spaces | |
412 (not (bobp)) | |
413 (memq (char-syntax (preceding-char)) (list ?w ?_ (char-syntax close))) | |
414 (insert " ")) | |
415 (insert open) | |
416 (save-excursion | |
417 (or (eq arg 0) (forward-sexp arg)) | |
418 (insert close) | |
419 (and parens-require-spaces | |
420 (not (eobp)) | |
421 (memq (char-syntax (following-char)) (list ?w ?_ (char-syntax open))) | |
422 (insert " ")))) | |
423 (insert-char (event-basic-type last-command-event) | |
424 (prefix-numeric-value arg)))) | |
425 | |
426 (defun insert-parentheses (&optional arg) | |
427 "Enclose following ARG sexps in parentheses. | |
428 Leave point after open-paren. | |
289 A negative ARG encloses the preceding ARG sexps instead. | 429 A negative ARG encloses the preceding ARG sexps instead. |
290 No argument is equivalent to zero: just insert `()' and leave point between. | 430 No argument is equivalent to zero: just insert `()' and leave point between. |
291 If `parens-require-spaces' is non-nil, this command also inserts a space | 431 If `parens-require-spaces' is non-nil, this command also inserts a space |
292 before and after, depending on the surrounding characters." | 432 before and after, depending on the surrounding characters. |
433 If region is active, insert enclosing characters at region boundaries." | |
293 (interactive "P") | 434 (interactive "P") |
294 (if arg (setq arg (prefix-numeric-value arg)) | 435 (insert-pair arg ?\( ?\))) |
295 (setq arg 0)) | 436 |
296 (cond ((> arg 0) (skip-chars-forward " \t")) | 437 (defun delete-pair () |
297 ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) | 438 "Delete a pair of characters enclosing the sexp that follows point." |
298 (and parens-require-spaces | 439 (interactive) |
299 (not (bobp)) | 440 (save-excursion (forward-sexp 1) (delete-char -1)) |
300 (memq (char-syntax (preceding-char)) '(?w ?_ ?\) )) | 441 (delete-char 1)) |
301 (insert " ")) | 442 |
302 (insert ?\() | 443 (defun raise-sexp (&optional arg) |
303 (save-excursion | 444 "Raise ARG sexps higher up the tree." |
304 (or (eq arg 0) (forward-sexp arg)) | 445 (interactive "p") |
305 (insert ?\)) | 446 (let ((s (if (and transient-mark-mode mark-active) |
306 (and parens-require-spaces | 447 (buffer-substring (region-beginning) (region-end)) |
307 (not (eobp)) | 448 (buffer-substring |
308 (memq (char-syntax (following-char)) '(?w ?_ ?\( )) | 449 (point) |
309 (insert " ")))) | 450 (save-excursion (forward-sexp arg) (point)))))) |
451 (backward-up-list 1) | |
452 (delete-region (point) (save-excursion (forward-sexp 1) (point))) | |
453 (save-excursion (insert s)))) | |
310 | 454 |
311 (defun move-past-close-and-reindent () | 455 (defun move-past-close-and-reindent () |
312 "Move past next `)', delete indentation before it, then indent after it." | 456 "Move past next `)', delete indentation before it, then indent after it." |
313 (interactive) | 457 (interactive) |
314 (up-list 1) | 458 (up-list 1) |
342 (defun check-parens () ; lame name? | 486 (defun check-parens () ; lame name? |
343 "Check for unbalanced parentheses in the current buffer. | 487 "Check for unbalanced parentheses in the current buffer. |
344 More accurately, check the narrowed part of the buffer for unbalanced | 488 More accurately, check the narrowed part of the buffer for unbalanced |
345 expressions (\"sexps\") in general. This is done according to the | 489 expressions (\"sexps\") in general. This is done according to the |
346 current syntax table and will find unbalanced brackets or quotes as | 490 current syntax table and will find unbalanced brackets or quotes as |
347 appropriate. (See Info node `(emacs)Lists and Sexps'.) If imbalance | 491 appropriate. (See Info node `(emacs)Parentheses'.) If imbalance is |
348 is found, an error is signalled and point is left at the first | 492 found, an error is signaled and point is left at the first unbalanced |
349 unbalanced character." | 493 character." |
350 (interactive) | 494 (interactive) |
351 (condition-case data | 495 (condition-case data |
352 ;; Buffer can't have more than (point-max) sexps. | 496 ;; Buffer can't have more than (point-max) sexps. |
353 (scan-sexps (point-min) (point-max)) | 497 (scan-sexps (point-min) (point-max)) |
354 (scan-error (goto-char (nth 2 data)) | 498 (scan-error (goto-char (nth 2 data)) |
425 ((null completion) | 569 ((null completion) |
426 (message "Can't find completion for \"%s\"" pattern) | 570 (message "Can't find completion for \"%s\"" pattern) |
427 (ding)) | 571 (ding)) |
428 ((not (string= pattern completion)) | 572 ((not (string= pattern completion)) |
429 (delete-region beg end) | 573 (delete-region beg end) |
430 (insert completion)) | 574 (insert completion) |
575 ;; Don't leave around a completions buffer that's out of date. | |
576 (let ((win (get-buffer-window "*Completions*" 0))) | |
577 (if win (with-selected-window win (bury-buffer))))) | |
431 (t | 578 (t |
432 (message "Making completion list...") | 579 (let ((minibuf-is-in-use |
433 (let ((list (all-completions pattern obarray predicate))) | 580 (eq (minibuffer-window) (selected-window)))) |
434 (setq list (sort list 'string<)) | 581 (unless minibuf-is-in-use |
435 (or (eq predicate 'fboundp) | 582 (message "Making completion list...")) |
436 (let (new) | 583 (let ((list (all-completions pattern obarray predicate))) |
437 (while list | 584 (setq list (sort list 'string<)) |
438 (setq new (cons (if (fboundp (intern (car list))) | 585 (or (eq predicate 'fboundp) |
439 (list (car list) " <f>") | 586 (let (new) |
440 (car list)) | 587 (while list |
441 new)) | 588 (setq new (cons (if (fboundp (intern (car list))) |
442 (setq list (cdr list))) | 589 (list (car list) " <f>") |
443 (setq list (nreverse new)))) | 590 (car list)) |
444 (with-output-to-temp-buffer "*Completions*" | 591 new)) |
445 (display-completion-list list))) | 592 (setq list (cdr list))) |
446 (message "Making completion list...%s" "done"))))))) | 593 (setq list (nreverse new)))) |
447 | 594 (if (> (length list) 1) |
595 (with-output-to-temp-buffer "*Completions*" | |
596 (display-completion-list list pattern)) | |
597 ;; Don't leave around a completions buffer that's | |
598 ;; out of date. | |
599 (let ((win (get-buffer-window "*Completions*" 0))) | |
600 (if win (with-selected-window win (bury-buffer)))))) | |
601 (unless minibuf-is-in-use | |
602 (message "Making completion list...%s" "done"))))))))) | |
603 | |
604 ;; arch-tag: aa7fa8a4-2e6f-4e9b-9cd9-fef06340e67e | |
448 ;;; lisp.el ends here | 605 ;;; lisp.el ends here |