comparison lisp/emacs-lisp/lisp.el @ 42658:c45e40c77be6

(lisp-complete-symbol): Repeating the command after displaying a completion list scrolls the list.
author Richard M. Stallman <rms@gnu.org>
date Fri, 11 Jan 2002 21:22:28 +0000
parents b75e56ea3973
children 898b4b31410f
comparison
equal deleted inserted replaced
42657:e5083d725922 42658:c45e40c77be6
350 (t (signal (car data) (cdr data))))))) 350 (t (signal (car data) (cdr data)))))))
351 351
352 (defun lisp-complete-symbol (&optional predicate) 352 (defun lisp-complete-symbol (&optional predicate)
353 "Perform completion on Lisp symbol preceding point. 353 "Perform completion on Lisp symbol preceding point.
354 Compare that symbol against the known Lisp symbols. 354 Compare that symbol against the known Lisp symbols.
355 If no characters can be completed, display a list of possible completions.
356 Repeating the command at that point scrolls the list.
355 357
356 When called from a program, optional arg PREDICATE is a predicate 358 When called from a program, optional arg PREDICATE is a predicate
357 determining which symbols are considered, e.g. `commandp'. 359 determining which symbols are considered, e.g. `commandp'.
358 If PREDICATE is nil, the context determines which symbols are 360 If PREDICATE is nil, the context determines which symbols are
359 considered. If the symbol starts just after an open-parenthesis, only 361 considered. If the symbol starts just after an open-parenthesis, only
360 symbols with function definitions are considered. Otherwise, all 362 symbols with function definitions are considered. Otherwise, all
361 symbols with function definitions, values or properties are 363 symbols with function definitions, values or properties are
362 considered." 364 considered."
363 (interactive) 365 (interactive)
364 (let* ((end (point)) 366
365 (beg (with-syntax-table emacs-lisp-mode-syntax-table 367 (let ((window (get-buffer-window "*Completions*")))
366 (save-excursion 368 (if (and (eq last-command this-command)
367 (backward-sexp 1) 369 window (window-live-p window) (window-buffer window)
368 (while (= (char-syntax (following-char)) ?\') 370 (buffer-name (window-buffer window)))
369 (forward-char 1)) 371 ;; If this command was repeated, and
370 (point)))) 372 ;; there's a fresh completion window with a live buffer,
371 (pattern (buffer-substring-no-properties beg end)) 373 ;; and this command is repeated, scroll that window.
372 (predicate 374 (with-current-buffer (window-buffer window)
373 (or predicate 375 (if (pos-visible-in-window-p (point-max) window)
374 (save-excursion 376 (set-window-start window (point-min))
375 (goto-char beg) 377 (save-selected-window
376 (if (not (eq (char-before) ?\()) 378 (select-window window)
377 (lambda (sym) ;why not just nil ? -sm 379 (scroll-up))))
378 (or (boundp sym) (fboundp sym) 380
379 (symbol-plist sym))) 381 ;; Do completion.
380 ;; Looks like a funcall position. Let's double check. 382 (let* ((end (point))
381 (if (condition-case nil 383 (beg (with-syntax-table emacs-lisp-mode-syntax-table
382 (progn (up-list -2) (forward-char 1) 384 (save-excursion
383 (eq (char-after) ?\()) 385 (backward-sexp 1)
384 (error nil)) 386 (while (= (char-syntax (following-char)) ?\')
385 ;; If the first element of the parent list is an open 387 (forward-char 1))
386 ;; parenthesis we are probably not in a funcall position. 388 (point))))
387 ;; Maybe a `let' varlist or something. 389 (pattern (buffer-substring-no-properties beg end))
388 nil 390 (predicate
389 ;; Else, we assume that a function name is expected. 391 (or predicate
390 'fboundp))))) 392 (save-excursion
391 (completion (try-completion pattern obarray predicate))) 393 (goto-char beg)
392 (cond ((eq completion t)) 394 (if (not (eq (char-before) ?\())
393 ((null completion) 395 (lambda (sym) ;why not just nil ? -sm
394 (message "Can't find completion for \"%s\"" pattern) 396 (or (boundp sym) (fboundp sym)
395 (ding)) 397 (symbol-plist sym)))
396 ((not (string= pattern completion)) 398 ;; Looks like a funcall position. Let's double check.
397 (delete-region beg end) 399 (if (condition-case nil
398 (insert completion)) 400 (progn (up-list -2) (forward-char 1)
399 (t 401 (eq (char-after) ?\())
400 (message "Making completion list...") 402 (error nil))
401 (let ((list (all-completions pattern obarray predicate))) 403 ;; If the first element of the parent list is an open
402 (setq list (sort list 'string<)) 404 ;; parenthesis we are probably not in a funcall position.
403 (or (eq predicate 'fboundp) 405 ;; Maybe a `let' varlist or something.
404 (let (new) 406 nil
405 (while list 407 ;; Else, we assume that a function name is expected.
406 (setq new (cons (if (fboundp (intern (car list))) 408 'fboundp)))))
407 (list (car list) " <f>") 409 (completion (try-completion pattern obarray predicate)))
408 (car list)) 410 (cond ((eq completion t))
409 new)) 411 ((null completion)
410 (setq list (cdr list))) 412 (message "Can't find completion for \"%s\"" pattern)
411 (setq list (nreverse new)))) 413 (ding))
412 (with-output-to-temp-buffer "*Completions*" 414 ((not (string= pattern completion))
413 (display-completion-list list))) 415 (delete-region beg end)
414 (message "Making completion list...%s" "done"))))) 416 (insert completion))
417 (t
418 (message "Making completion list...")
419 (let ((list (all-completions pattern obarray predicate)))
420 (setq list (sort list 'string<))
421 (or (eq predicate 'fboundp)
422 (let (new)
423 (while list
424 (setq new (cons (if (fboundp (intern (car list)))
425 (list (car list) " <f>")
426 (car list))
427 new))
428 (setq list (cdr list)))
429 (setq list (nreverse new))))
430 (with-output-to-temp-buffer "*Completions*"
431 (display-completion-list list)))
432 (message "Making completion list...%s" "done")))))))
415 433
416 ;;; lisp.el ends here 434 ;;; lisp.el ends here