# HG changeset patch # User Richard M. Stallman # Date 764806864 0 # Node ID d66e48956d3e2e55812e9c068b4a588b59510380 # Parent 2b0355912ba6edcd2c0cd062d4329a0b7c8c42fa (choose-completion-delete-max-match): Renamed from mouse-completion-delete-max-match and moved here. (choose-completion-string): New function. (choose-completion): New command. (completion-list-mode-map): Add binding for choose-completion. (completion-setup-function): Mention RET. diff -r 2b0355912ba6 -r d66e48956d3e lisp/simple.el --- a/lisp/simple.el Sun Mar 27 22:18:55 1994 +0000 +++ b/lisp/simple.el Sun Mar 27 22:21:04 1994 +0000 @@ -2365,6 +2365,8 @@ (or completion-list-mode-map (let ((map (make-sparse-keymap))) (define-key map [mouse-2] 'mouse-choose-completion) + (define-key map "\C-m" 'choose-completion) + (define-key map [return] 'choose-completion) (setq completion-list-mode-map map))) ;; Completion mode is suitable only for specially formatted data. @@ -2373,10 +2375,48 @@ ;; Record the buffer that was current when the completion list was requested. (defvar completion-reference-buffer) +(defun choose-completion () + "Choose the completion that point is in or next to." + (interactive) + (let (beg end) + (skip-chars-forward "^ \t\n") + (setq end (point)) + (skip-chars-backward "^ \t\n") + (setq beg (point)) + (choose-completion-string (buffer-substring beg end)))) + +;; Delete the longest partial match for STRING +;; that can be found before POINT. +(defun choose-completion-delete-max-match (string) + (let ((opoint (point)) + (len (min (length string) + (- (point) (point-min))))) + (goto-char (- (point) (length string))) + (while (and (> len 0) + (let ((tail (buffer-substring (point) + (+ (point) len)))) + (not (string= tail (substring string 0 len))))) + (setq len (1- len)) + (forward-char 1)) + (delete-char len))) + +(defun choose-completion-string (choice &optional buffer) + (let ((buffer (or buffer completion-reference-buffer))) + (set-buffer buffer) + (choose-completion-delete-max-match choice) + (insert choice) + ;; Update point in the window that BUFFER is showing in. + (let ((window (get-buffer-window buffer t))) + (set-window-point window (point))) + (and (equal buffer (window-buffer (minibuffer-window))) + (minibuffer-complete-and-exit)))) + (defun completion-list-mode () "Major mode for buffers showing lists of possible completions. -Type \\\\[mouse-choose-completion] to select -a completion with the mouse." +Type \\\\[choose-completion] in the completion list\ + to select the completion near point. +Use \\\\[mouse-choose-completion] to select one\ + with the mouse." (interactive) (kill-all-local-variables) (use-local-map completion-list-mode-map) @@ -2394,7 +2434,10 @@ (goto-char (point-min)) (if window-system (insert (substitute-command-keys - "Click \\[mouse-choose-completion] on a completion to select it.\n\n")))))) + "Click \\[mouse-choose-completion] on a completion to select it.\n"))) + (insert (substitute-command-keys + "In this buffer, type \\[choose-completion] to \ +select the completion near point.\n\n"))))) (add-hook 'completion-setup-hook 'completion-setup-function)