comparison lisp/simple.el @ 11313:5704f8216dbd

(completion-setup-function): Undo March 11 change. Add some doc strings to completion-related variables.
author Richard M. Stallman <rms@gnu.org>
date Sat, 08 Apr 1995 22:42:47 +0000
parents e6bdaaa6ce1b
children 45947c4ff70b
comparison
equal deleted inserted replaced
11312:f48922d85166 11313:5704f8216dbd
2620 (eval-minibuffer (format "Set %s to value: " var))))))) 2620 (eval-minibuffer (format "Set %s to value: " var)))))))
2621 (set var val)) 2621 (set var val))
2622 2622
2623 ;; Define the major mode for lists of completions. 2623 ;; Define the major mode for lists of completions.
2624 2624
2625 (defvar completion-list-mode-map nil) 2625 (defvar completion-list-mode-map nil
2626 "Local map for completion list buffers.")
2626 (or completion-list-mode-map 2627 (or completion-list-mode-map
2627 (let ((map (make-sparse-keymap))) 2628 (let ((map (make-sparse-keymap)))
2628 (define-key map [mouse-2] 'mouse-choose-completion) 2629 (define-key map [mouse-2] 'mouse-choose-completion)
2629 (define-key map [down-mouse-2] nil) 2630 (define-key map [down-mouse-2] nil)
2630 (define-key map "\C-m" 'choose-completion) 2631 (define-key map "\C-m" 'choose-completion)
2634 (setq completion-list-mode-map map))) 2635 (setq completion-list-mode-map map)))
2635 2636
2636 ;; Completion mode is suitable only for specially formatted data. 2637 ;; Completion mode is suitable only for specially formatted data.
2637 (put 'completion-list-mode 'mode-class 'special) 2638 (put 'completion-list-mode 'mode-class 'special)
2638 2639
2639 ;; Record the buffer that was current when the completion list was requested. 2640 (defvar completion-reference-buffer nil
2640 ;; Initial value is nil to avoid some compiler warnings. 2641 "Record the buffer that was current when the completion list was requested.
2641 (defvar completion-reference-buffer nil) 2642 This is a local variable in the completion list buffer.
2642 2643 Initial value is nil to avoid some compiler warnings."
2643 ;; This records the length of the text at the beginning of the buffer 2644
2644 ;; which was not included in the completion. 2645 (defvar completion-base-size nil
2645 (defvar completion-base-size nil) 2646 "Number of chars at beginning of minibuffer not involved in completion.
2647 This is a local variable in the completion list buffer
2648 but it talks about the buffer in `completion-reference-buffer'.
2649 If this is nil, it means to compare text to determine which part
2650 of the tail end of the buffer's text is involved in completion.")
2646 2651
2647 (defun delete-completion-window () 2652 (defun delete-completion-window ()
2648 "Delete the completion list window. 2653 "Delete the completion list window.
2649 Go to the window from which completion was requested." 2654 Go to the window from which completion was requested."
2650 (interactive) 2655 (interactive)
2722 (not (string= tail (substring string 0 len))))) 2727 (not (string= tail (substring string 0 len)))))
2723 (setq len (1- len)) 2728 (setq len (1- len))
2724 (forward-char 1)) 2729 (forward-char 1))
2725 (delete-char len))) 2730 (delete-char len)))
2726 2731
2732 ;; Switch to BUFFER and insert the completion choice CHOICE.
2733 ;; BASE-SIZE, if non-nil, says how many characters of BUFFER's text
2734 ;; to keep. If it is nil, use choose-completion-delete-max-match instead.
2727 (defun choose-completion-string (choice &optional buffer base-size) 2735 (defun choose-completion-string (choice &optional buffer base-size)
2728 (let ((buffer (or buffer completion-reference-buffer))) 2736 (let ((buffer (or buffer completion-reference-buffer)))
2729 ;; If BUFFER is a minibuffer, barf unless it's the currently 2737 ;; If BUFFER is a minibuffer, barf unless it's the currently
2730 ;; active minibuffer. 2738 ;; active minibuffer.
2731 (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer)) 2739 (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer))
2762 (setq major-mode 'completion-list-mode) 2770 (setq major-mode 'completion-list-mode)
2763 (make-local-variable 'completion-base-size) 2771 (make-local-variable 'completion-base-size)
2764 (setq completion-base-size nil) 2772 (setq completion-base-size nil)
2765 (run-hooks 'completion-list-mode-hook)) 2773 (run-hooks 'completion-list-mode-hook))
2766 2774
2767 (defvar completion-fixup-function nil) 2775 (defvar completion-fixup-function nil
2776 "A function to customize how completions are identified in completion lists.
2777 `completion-setup-function' calls this function with no arguments
2778 each time it has found what it thinks is one completion.
2779 Point is at the end of the completion in the completion list buffer.
2780 If this function moves point, it can alter the end of that completion.")
2781
2782 ;; This function goes in completion-setup-hook, so that it is called
2783 ;; after the text of the completion list buffer is written.
2768 2784
2769 (defun completion-setup-function () 2785 (defun completion-setup-function ()
2770 (save-excursion 2786 (save-excursion
2771 (let ((mainbuf (current-buffer)) 2787 (let ((mainbuf (current-buffer)))
2772 (base-size (- (point-max) (point-min))))
2773 (set-buffer standard-output) 2788 (set-buffer standard-output)
2774 (completion-list-mode) 2789 (completion-list-mode)
2775 (make-local-variable 'completion-reference-buffer) 2790 (make-local-variable 'completion-reference-buffer)
2776 (setq completion-reference-buffer mainbuf) 2791 (setq completion-reference-buffer mainbuf)
2777 (setq completion-base-size base-size) 2792 ;;; The value 0 is right in most cases, but not for file name completion.
2793 ;;; so this has to be turned off.
2794 ;;; (setq completion-base-size 0)
2778 (goto-char (point-min)) 2795 (goto-char (point-min))
2779 (if window-system 2796 (if window-system
2780 (insert (substitute-command-keys 2797 (insert (substitute-command-keys
2781 "Click \\[mouse-choose-completion] on a completion to select it.\n"))) 2798 "Click \\[mouse-choose-completion] on a completion to select it.\n")))
2782 (insert (substitute-command-keys 2799 (insert (substitute-command-keys