(x_draw_relief_rect): Remove unused variable `dpy'.
[emacs.git] / lisp / emacs-lisp / lisp.el
blob4fd6fe7a17f0d77fbce5aacd4f52a5b2f8e02648
1 ;;; lisp.el --- Lisp editing commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1994, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: lisp, languages
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;; Lisp editing commands to go with Lisp major mode. More-or-less
29 ;; applicable in other modes too.
31 ;;; Code:
33 ;; Note that this variable is used by non-lisp modes too.
34 (defcustom defun-prompt-regexp nil
35 "*If non-nil, a regexp to ignore before a defun.
36 This is only necessary if the opening paren or brace is not in column 0.
37 See function `beginning-of-defun'."
38 :type '(choice (const nil)
39 regexp)
40 :group 'lisp)
41 (make-variable-buffer-local 'defun-prompt-regexp)
43 (defcustom parens-require-spaces t
44 "If non-nil, add whitespace as needed when inserting parentheses.
45 This affects `insert-parentheses' and `insert-pair'."
46 :type 'boolean
47 :group 'lisp)
49 (defvar forward-sexp-function nil
50 "If non-nil, `forward-sexp' delegates to this function.
51 Should take the same arguments and behave similarly to `forward-sexp'.")
53 (defun forward-sexp (&optional arg)
54 "Move forward across one balanced expression (sexp).
55 With ARG, do it that many times. Negative arg -N means
56 move backward across N balanced expressions."
57 (interactive "p")
58 (or arg (setq arg 1))
59 (if forward-sexp-function
60 (funcall forward-sexp-function arg)
61 (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
62 (if (< arg 0) (backward-prefix-chars))))
64 (defun backward-sexp (&optional arg)
65 "Move backward across one balanced expression (sexp).
66 With ARG, do it that many times. Negative arg -N means
67 move forward across N balanced expressions."
68 (interactive "p")
69 (or arg (setq arg 1))
70 (forward-sexp (- arg)))
72 (defun mark-sexp (&optional arg allow-extend)
73 "Set mark ARG sexps from point.
74 The place mark goes is the same place \\[forward-sexp] would
75 move to with the same argument.
76 Interactively, if this command is repeated
77 or (in Transient Mark mode) if the mark is active,
78 it marks the next ARG sexps after the ones already marked."
79 (interactive "P\np")
80 (cond ((and allow-extend
81 (or (and (eq last-command this-command) (mark t))
82 (and transient-mark-mode mark-active)))
83 (setq arg (if arg (prefix-numeric-value arg)
84 (if (< (mark) (point)) -1 1)))
85 (set-mark
86 (save-excursion
87 (goto-char (mark))
88 (forward-sexp arg)
89 (point))))
91 (push-mark
92 (save-excursion
93 (forward-sexp (prefix-numeric-value arg))
94 (point))
95 nil t))))
97 (defun forward-list (&optional arg)
98 "Move forward across one balanced group of parentheses.
99 With ARG, do it that many times.
100 Negative arg -N means move backward across N groups of parentheses."
101 (interactive "p")
102 (or arg (setq arg 1))
103 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg))))
105 (defun backward-list (&optional arg)
106 "Move backward across one balanced group of parentheses.
107 With ARG, do it that many times.
108 Negative arg -N means move forward across N groups of parentheses."
109 (interactive "p")
110 (or arg (setq arg 1))
111 (forward-list (- arg)))
113 (defun down-list (&optional arg)
114 "Move forward down one level of parentheses.
115 With ARG, do this that many times.
116 A negative argument means move backward but still go down a level."
117 (interactive "p")
118 (or arg (setq arg 1))
119 (let ((inc (if (> arg 0) 1 -1)))
120 (while (/= arg 0)
121 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
122 (setq arg (- arg inc)))))
124 (defun backward-up-list (&optional arg)
125 "Move backward out of one level of parentheses.
126 With ARG, do this that many times.
127 A negative argument means move forward but still to a less deep spot."
128 (interactive "p")
129 (up-list (- (or arg 1))))
131 (defun up-list (&optional arg)
132 "Move forward out of one level of parentheses.
133 With ARG, do this that many times.
134 A negative argument means move backward but still to a less deep spot."
135 (interactive "p")
136 (or arg (setq arg 1))
137 (let ((inc (if (> arg 0) 1 -1)))
138 (while (/= arg 0)
139 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg)))
140 (setq arg (- arg inc)))))
142 (defun kill-sexp (&optional arg)
143 "Kill the sexp (balanced expression) following point.
144 With ARG, kill that many sexps after point.
145 Negative arg -N means kill N sexps before point."
146 (interactive "p")
147 (let ((opoint (point)))
148 (forward-sexp (or arg 1))
149 (kill-region opoint (point))))
151 (defun backward-kill-sexp (&optional arg)
152 "Kill the sexp (balanced expression) preceding point.
153 With ARG, kill that many sexps before point.
154 Negative arg -N means kill N sexps after point."
155 (interactive "p")
156 (kill-sexp (- (or arg 1))))
158 ;; After Zmacs:
159 (defun kill-backward-up-list (&optional arg)
160 "Kill the form containing the current sexp, leaving the sexp itself.
161 A prefix argument ARG causes the relevant number of surrounding
162 forms to be removed."
163 (interactive "*p")
164 (let ((current-sexp (thing-at-point 'sexp)))
165 (if current-sexp
166 (save-excursion
167 (backward-up-list arg)
168 (kill-sexp)
169 (insert current-sexp))
170 (error "Not at a sexp"))))
172 (defvar beginning-of-defun-function nil
173 "If non-nil, function for `beginning-of-defun-raw' to call.
174 This is used to find the beginning of the defun instead of using the
175 normal recipe (see `beginning-of-defun'). Major modes can define this
176 if defining `defun-prompt-regexp' is not sufficient to handle the mode's
177 needs.
179 The function (of no args) should go to the line on which the current
180 defun starts, and return non-nil, or should return nil if it can't
181 find the beginning.")
183 (defun beginning-of-defun (&optional arg)
184 "Move backward to the beginning of a defun.
185 With ARG, do it that many times. Negative arg -N
186 means move forward to Nth following beginning of defun.
187 Returns t unless search stops due to beginning or end of buffer.
189 If variable `beginning-of-defun-function' is non-nil, its value
190 is called as a function to find the defun's beginning.
192 Normally a defun is assumed to start where there is a char with
193 open-parenthesis syntax at the beginning of a line. If
194 `defun-prompt-regexp' is non-nil, then a string which matches
195 that regexp may precede the open-parenthesis, and point ends up
196 at the beginning of the line.
198 If `defun-prompt-regexp' and `open-paren-in-column-0-is-defun-start'
199 are both nil, the function instead finds an open-paren at the
200 outermost level."
201 (interactive "p")
202 (or (not (eq this-command 'beginning-of-defun))
203 (eq last-command 'beginning-of-defun)
204 (and transient-mark-mode mark-active)
205 (push-mark))
206 (and (beginning-of-defun-raw arg)
207 (progn (beginning-of-line) t)))
209 (defun beginning-of-defun-raw (&optional arg)
210 "Move point to the character that starts a defun.
211 This is identical to function `beginning-of-defun', except that point
212 does not move to the beginning of the line when `defun-prompt-regexp'
213 is non-nil.
215 If variable `beginning-of-defun-function' is non-nil, its value
216 is called as a function to find the defun's beginning."
217 (interactive "p") ; change this to "P", maybe, if we ever come to pass ARG
218 ; to beginning-of-defun-function.
219 (unless arg (setq arg 1))
220 (cond
221 (beginning-of-defun-function
222 (if (> arg 0)
223 (dotimes (i arg)
224 (funcall beginning-of-defun-function))
225 ;; Better not call end-of-defun-function directly, in case
226 ;; it's not defined.
227 (end-of-defun (- arg))))
229 ((or defun-prompt-regexp open-paren-in-column-0-is-defun-start)
230 (and (< arg 0) (not (eobp)) (forward-char 1))
231 (and (re-search-backward (if defun-prompt-regexp
232 (concat (if open-paren-in-column-0-is-defun-start
233 "^\\s(\\|" "")
234 "\\(?:" defun-prompt-regexp "\\)\\s(")
235 "^\\s(")
236 nil 'move arg)
237 (progn (goto-char (1- (match-end 0)))) t))
239 ;; If open-paren-in-column-0-is-defun-start and defun-prompt-regexp
240 ;; are both nil, column 0 has no significance - so scan forward
241 ;; from BOB to see how nested point is, then carry on from there.
243 ;; It is generally not a good idea to land up here, because the
244 ;; call to scan-lists below can be extremely slow. This is because
245 ;; back_comment in syntax.c may have to scan from bob to find the
246 ;; beginning of each comment. Fixing this is not trivial -- cyd.
248 ((eq arg 0))
250 (let ((floor (point-min))
251 (ceiling (point-max))
252 (arg-+ve (> arg 0)))
253 (save-restriction
254 (widen)
255 (let ((ppss (let (syntax-begin-function
256 font-lock-beginning-of-syntax-function)
257 (syntax-ppss)))
258 ;; position of least enclosing paren, or nil.
259 encl-pos)
260 ;; Back out of any comment/string, so that encl-pos will always
261 ;; become nil if we're at top-level.
262 (when (nth 8 ppss)
263 (goto-char (nth 8 ppss))
264 (setq ppss (syntax-ppss))) ; should be fast, due to cache.
265 (setq encl-pos (syntax-ppss-toplevel-pos ppss))
266 (if encl-pos (goto-char encl-pos))
268 (and encl-pos arg-+ve (setq arg (1- arg)))
269 (and (not encl-pos) (not arg-+ve) (not (looking-at "\\s("))
270 (setq arg (1+ arg)))
272 (condition-case nil ; to catch crazy parens.
273 (progn
274 (goto-char (scan-lists (point) (- arg) 0))
275 (if arg-+ve
276 (if (>= (point) floor)
278 (goto-char floor)
279 nil)
280 ;; forward to next (, or trigger the c-c
281 (goto-char (1- (scan-lists (point) 1 -1)))
282 (if (<= (point) ceiling)
284 (goto-char ceiling)
285 nil)))
286 (error
287 (goto-char (if arg-+ve floor ceiling))
288 nil))))))))
290 (defvar end-of-defun-function nil
291 "If non-nil, function for function `end-of-defun' to call.
292 This is used to find the end of the defun instead of using the normal
293 recipe (see `end-of-defun'). Major modes can define this if the
294 normal method is not appropriate.")
296 (defun buffer-end (arg)
297 "Return the \"far end\" position of the buffer, in direction ARG.
298 If ARG is positive, that's the end of the buffer.
299 Otherwise, that's the beginning of the buffer."
300 (if (> arg 0) (point-max) (point-min)))
302 (defun end-of-defun (&optional arg)
303 "Move forward to next end of defun.
304 With argument, do it that many times.
305 Negative argument -N means move back to Nth preceding end of defun.
307 An end of a defun occurs right after the close-parenthesis that
308 matches the open-parenthesis that starts a defun; see function
309 `beginning-of-defun'.
311 If variable `end-of-defun-function' is non-nil, its value
312 is called as a function to find the defun's end."
313 (interactive "p")
314 (or (not (eq this-command 'end-of-defun))
315 (eq last-command 'end-of-defun)
316 (and transient-mark-mode mark-active)
317 (push-mark))
318 (if (or (null arg) (= arg 0)) (setq arg 1))
319 (if end-of-defun-function
320 (if (> arg 0)
321 (dotimes (i arg)
322 (funcall end-of-defun-function))
323 ;; Better not call beginning-of-defun-function
324 ;; directly, in case it's not defined.
325 (beginning-of-defun (- arg)))
326 (let ((first t))
327 (while (and (> arg 0) (< (point) (point-max)))
328 (let ((pos (point)))
329 (while (progn
330 (if (and first
331 (progn
332 (end-of-line 1)
333 (beginning-of-defun-raw 1)))
335 (or (bobp) (forward-char -1))
336 (beginning-of-defun-raw -1))
337 (setq first nil)
338 (forward-list 1)
339 (skip-chars-forward " \t")
340 (if (looking-at "\\s<\\|\n")
341 (forward-line 1))
342 (<= (point) pos))))
343 (setq arg (1- arg)))
344 (while (< arg 0)
345 (let ((pos (point)))
346 (beginning-of-defun-raw 1)
347 (forward-sexp 1)
348 (forward-line 1)
349 (if (>= (point) pos)
350 (if (beginning-of-defun-raw 2)
351 (progn
352 (forward-list 1)
353 (skip-chars-forward " \t")
354 (if (looking-at "\\s<\\|\n")
355 (forward-line 1)))
356 (goto-char (point-min)))))
357 (setq arg (1+ arg))))))
359 (defun mark-defun (&optional allow-extend)
360 "Put mark at end of this defun, point at beginning.
361 The defun marked is the one that contains point or follows point.
363 Interactively, if this command is repeated
364 or (in Transient Mark mode) if the mark is active,
365 it marks the next defun after the ones already marked."
366 (interactive "p")
367 (cond ((and allow-extend
368 (or (and (eq last-command this-command) (mark t))
369 (and transient-mark-mode mark-active)))
370 (set-mark
371 (save-excursion
372 (goto-char (mark))
373 (end-of-defun)
374 (point))))
376 (let ((opoint (point))
377 beg end)
378 (push-mark opoint)
379 ;; Try first in this order for the sake of languages with nested
380 ;; functions where several can end at the same place as with
381 ;; the offside rule, e.g. Python.
382 (beginning-of-defun)
383 (setq beg (point))
384 (end-of-defun)
385 (setq end (point))
386 (while (looking-at "^\n")
387 (forward-line 1))
388 (if (> (point) opoint)
389 (progn
390 ;; We got the right defun.
391 (push-mark beg nil t)
392 (goto-char end)
393 (exchange-point-and-mark))
394 ;; beginning-of-defun moved back one defun
395 ;; so we got the wrong one.
396 (goto-char opoint)
397 (end-of-defun)
398 (push-mark (point) nil t)
399 (beginning-of-defun))
400 (re-search-backward "^\n" (- (point) 1) t)))))
402 (defun narrow-to-defun (&optional arg)
403 "Make text outside current defun invisible.
404 The defun visible is the one that contains point or follows point.
405 Optional ARG is ignored."
406 (interactive)
407 (save-excursion
408 (widen)
409 (let ((opoint (point))
410 beg end)
411 ;; Try first in this order for the sake of languages with nested
412 ;; functions where several can end at the same place as with
413 ;; the offside rule, e.g. Python.
414 (beginning-of-defun)
415 (setq beg (point))
416 (end-of-defun)
417 (setq end (point))
418 (while (looking-at "^\n")
419 (forward-line 1))
420 (unless (> (point) opoint)
421 ;; beginning-of-defun moved back one defun
422 ;; so we got the wrong one.
423 (goto-char opoint)
424 (end-of-defun)
425 (setq end (point))
426 (beginning-of-defun)
427 (setq beg (point)))
428 (goto-char end)
429 (re-search-backward "^\n" (- (point) 1) t)
430 (narrow-to-region beg end))))
432 (defvar insert-pair-alist
433 '((?\( ?\)) (?\[ ?\]) (?\{ ?\}) (?\< ?\>) (?\" ?\") (?\' ?\') (?\` ?\'))
434 "Alist of paired characters inserted by `insert-pair'.
435 Each element looks like (OPEN-CHAR CLOSE-CHAR) or (COMMAND-CHAR
436 OPEN-CHAR CLOSE-CHAR). The characters OPEN-CHAR and CLOSE-CHAR
437 of the pair whose key is equal to the last input character with
438 or without modifiers, are inserted by `insert-pair'.")
440 (defun insert-pair (&optional arg open close)
441 "Enclose following ARG sexps in a pair of OPEN and CLOSE characters.
442 Leave point after the first character.
443 A negative ARG encloses the preceding ARG sexps instead.
444 No argument is equivalent to zero: just insert characters
445 and leave point between.
446 If `parens-require-spaces' is non-nil, this command also inserts a space
447 before and after, depending on the surrounding characters.
448 If region is active, insert enclosing characters at region boundaries.
450 If arguments OPEN and CLOSE are nil, the character pair is found
451 from the variable `insert-pair-alist' according to the last input
452 character with or without modifiers. If no character pair is
453 found in the variable `insert-pair-alist', then the last input
454 character is inserted ARG times."
455 (interactive "P")
456 (if (not (and open close))
457 (let ((pair (or (assq last-command-char insert-pair-alist)
458 (assq (event-basic-type last-command-event)
459 insert-pair-alist))))
460 (if pair
461 (if (nth 2 pair)
462 (setq open (nth 1 pair) close (nth 2 pair))
463 (setq open (nth 0 pair) close (nth 1 pair))))))
464 (if (and open close)
465 (if (and transient-mark-mode mark-active)
466 (progn
467 (save-excursion (goto-char (region-end)) (insert close))
468 (save-excursion (goto-char (region-beginning)) (insert open)))
469 (if arg (setq arg (prefix-numeric-value arg))
470 (setq arg 0))
471 (cond ((> arg 0) (skip-chars-forward " \t"))
472 ((< arg 0) (forward-sexp arg) (setq arg (- arg))))
473 (and parens-require-spaces
474 (not (bobp))
475 (memq (char-syntax (preceding-char)) (list ?w ?_ (char-syntax close)))
476 (insert " "))
477 (insert open)
478 (save-excursion
479 (or (eq arg 0) (forward-sexp arg))
480 (insert close)
481 (and parens-require-spaces
482 (not (eobp))
483 (memq (char-syntax (following-char)) (list ?w ?_ (char-syntax open)))
484 (insert " "))))
485 (insert-char (event-basic-type last-command-event)
486 (prefix-numeric-value arg))))
488 (defun insert-parentheses (&optional arg)
489 "Enclose following ARG sexps in parentheses.
490 Leave point after open-paren.
491 A negative ARG encloses the preceding ARG sexps instead.
492 No argument is equivalent to zero: just insert `()' and leave point between.
493 If `parens-require-spaces' is non-nil, this command also inserts a space
494 before and after, depending on the surrounding characters.
495 If region is active, insert enclosing characters at region boundaries."
496 (interactive "P")
497 (insert-pair arg ?\( ?\)))
499 (defun delete-pair ()
500 "Delete a pair of characters enclosing the sexp that follows point."
501 (interactive)
502 (save-excursion (forward-sexp 1) (delete-char -1))
503 (delete-char 1))
505 (defun raise-sexp (&optional arg)
506 "Raise ARG sexps higher up the tree."
507 (interactive "p")
508 (let ((s (if (and transient-mark-mode mark-active)
509 (buffer-substring (region-beginning) (region-end))
510 (buffer-substring
511 (point)
512 (save-excursion (forward-sexp arg) (point))))))
513 (backward-up-list 1)
514 (delete-region (point) (save-excursion (forward-sexp 1) (point)))
515 (save-excursion (insert s))))
517 (defun move-past-close-and-reindent ()
518 "Move past next `)', delete indentation before it, then indent after it."
519 (interactive)
520 (up-list 1)
521 (forward-char -1)
522 (while (save-excursion ; this is my contribution
523 (let ((before-paren (point)))
524 (back-to-indentation)
525 (and (= (point) before-paren)
526 (progn
527 ;; Move to end of previous line.
528 (beginning-of-line)
529 (forward-char -1)
530 ;; Verify it doesn't end within a string or comment.
531 (let ((end (point))
532 state)
533 (beginning-of-line)
534 ;; Get state at start of line.
535 (setq state (list 0 nil nil
536 (null (calculate-lisp-indent))
537 nil nil nil nil
538 nil))
539 ;; Parse state across the line to get state at end.
540 (setq state (parse-partial-sexp (point) end nil nil
541 state))
542 ;; Check not in string or comment.
543 (and (not (elt state 3)) (not (elt state 4))))))))
544 (delete-indentation))
545 (forward-char 1)
546 (newline-and-indent))
548 (defun check-parens () ; lame name?
549 "Check for unbalanced parentheses in the current buffer.
550 More accurately, check the narrowed part of the buffer for unbalanced
551 expressions (\"sexps\") in general. This is done according to the
552 current syntax table and will find unbalanced brackets or quotes as
553 appropriate. (See Info node `(emacs)Parentheses'.) If imbalance is
554 found, an error is signaled and point is left at the first unbalanced
555 character."
556 (interactive)
557 (condition-case data
558 ;; Buffer can't have more than (point-max) sexps.
559 (scan-sexps (point-min) (point-max))
560 (scan-error (goto-char (nth 2 data))
561 ;; Could print (nth 1 data), which is either
562 ;; "Containing expression ends prematurely" or
563 ;; "Unbalanced parentheses", but those may not be so
564 ;; accurate/helpful, e.g. quotes may actually be
565 ;; mismatched.
566 (error "Unmatched bracket or quote"))
567 (error (cond ((eq 'scan-error (car data))
568 (goto-char (nth 2 data))
569 (error "Unmatched bracket or quote"))
570 (t (signal (car data) (cdr data)))))))
572 (defun lisp-complete-symbol (&optional predicate)
573 "Perform completion on Lisp symbol preceding point.
574 Compare that symbol against the known Lisp symbols.
575 If no characters can be completed, display a list of possible completions.
576 Repeating the command at that point scrolls the list.
578 When called from a program, optional arg PREDICATE is a predicate
579 determining which symbols are considered, e.g. `commandp'.
580 If PREDICATE is nil, the context determines which symbols are
581 considered. If the symbol starts just after an open-parenthesis, only
582 symbols with function definitions are considered. Otherwise, all
583 symbols with function definitions, values or properties are
584 considered."
585 (interactive)
586 (let ((window (get-buffer-window "*Completions*" 0)))
587 (if (and (eq last-command this-command)
588 window (window-live-p window) (window-buffer window)
589 (buffer-name (window-buffer window)))
590 ;; If this command was repeated, and
591 ;; there's a fresh completion window with a live buffer,
592 ;; and this command is repeated, scroll that window.
593 (with-current-buffer (window-buffer window)
594 (if (pos-visible-in-window-p (point-max) window)
595 (set-window-start window (point-min))
596 (save-selected-window
597 (select-window window)
598 (scroll-up))))
600 ;; Do completion.
601 (let* ((end (point))
602 (beg (with-syntax-table emacs-lisp-mode-syntax-table
603 (save-excursion
604 (backward-sexp 1)
605 (while (= (char-syntax (following-char)) ?\')
606 (forward-char 1))
607 (point))))
608 (pattern (buffer-substring-no-properties beg end))
609 (predicate
610 (or predicate
611 (save-excursion
612 (goto-char beg)
613 (if (not (eq (char-before) ?\())
614 (lambda (sym) ;why not just nil ? -sm
615 (or (boundp sym) (fboundp sym)
616 (symbol-plist sym)))
617 ;; Looks like a funcall position. Let's double check.
618 (if (condition-case nil
619 (progn (up-list -2) (forward-char 1)
620 (eq (char-after) ?\())
621 (error nil))
622 ;; If the first element of the parent list is an open
623 ;; parenthesis we are probably not in a funcall position.
624 ;; Maybe a `let' varlist or something.
626 ;; Else, we assume that a function name is expected.
627 'fboundp)))))
628 (completion (try-completion pattern obarray predicate)))
629 (cond ((eq completion t))
630 ((null completion)
631 (message "Can't find completion for \"%s\"" pattern)
632 (ding))
633 ((not (string= pattern completion))
634 (delete-region beg end)
635 (insert completion)
636 ;; Don't leave around a completions buffer that's out of date.
637 (let ((win (get-buffer-window "*Completions*" 0)))
638 (if win (with-selected-window win (bury-buffer)))))
640 (let ((minibuf-is-in-use
641 (eq (minibuffer-window) (selected-window))))
642 (unless minibuf-is-in-use
643 (message "Making completion list..."))
644 (let ((list (all-completions pattern obarray predicate)))
645 (setq list (sort list 'string<))
646 (or (eq predicate 'fboundp)
647 (let (new)
648 (while list
649 (setq new (cons (if (fboundp (intern (car list)))
650 (list (car list) " <f>")
651 (car list))
652 new))
653 (setq list (cdr list)))
654 (setq list (nreverse new))))
655 (if (> (length list) 1)
656 (with-output-to-temp-buffer "*Completions*"
657 (display-completion-list list pattern))
658 ;; Don't leave around a completions buffer that's
659 ;; out of date.
660 (let ((win (get-buffer-window "*Completions*" 0)))
661 (if win (with-selected-window win (bury-buffer))))))
662 (unless minibuf-is-in-use
663 (message "Making completion list...%s" "done")))))))))
665 ;; arch-tag: aa7fa8a4-2e6f-4e9b-9cd9-fef06340e67e
666 ;;; lisp.el ends here