comparison lisp/simple.el @ 6549:d66e48956d3e

(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.
author Richard M. Stallman <rms@gnu.org>
date Sun, 27 Mar 1994 22:21:04 +0000
parents b705afc2b2ec
children 7ada27b4bf3c
comparison
equal deleted inserted replaced
6548:2b0355912ba6 6549:d66e48956d3e
2363 2363
2364 (defvar completion-list-mode-map nil) 2364 (defvar completion-list-mode-map nil)
2365 (or completion-list-mode-map 2365 (or completion-list-mode-map
2366 (let ((map (make-sparse-keymap))) 2366 (let ((map (make-sparse-keymap)))
2367 (define-key map [mouse-2] 'mouse-choose-completion) 2367 (define-key map [mouse-2] 'mouse-choose-completion)
2368 (define-key map "\C-m" 'choose-completion)
2369 (define-key map [return] 'choose-completion)
2368 (setq completion-list-mode-map map))) 2370 (setq completion-list-mode-map map)))
2369 2371
2370 ;; Completion mode is suitable only for specially formatted data. 2372 ;; Completion mode is suitable only for specially formatted data.
2371 (put 'completion-list-mode 'mode-class 'special) 2373 (put 'completion-list-mode 'mode-class 'special)
2372 2374
2373 ;; Record the buffer that was current when the completion list was requested. 2375 ;; Record the buffer that was current when the completion list was requested.
2374 (defvar completion-reference-buffer) 2376 (defvar completion-reference-buffer)
2375 2377
2378 (defun choose-completion ()
2379 "Choose the completion that point is in or next to."
2380 (interactive)
2381 (let (beg end)
2382 (skip-chars-forward "^ \t\n")
2383 (setq end (point))
2384 (skip-chars-backward "^ \t\n")
2385 (setq beg (point))
2386 (choose-completion-string (buffer-substring beg end))))
2387
2388 ;; Delete the longest partial match for STRING
2389 ;; that can be found before POINT.
2390 (defun choose-completion-delete-max-match (string)
2391 (let ((opoint (point))
2392 (len (min (length string)
2393 (- (point) (point-min)))))
2394 (goto-char (- (point) (length string)))
2395 (while (and (> len 0)
2396 (let ((tail (buffer-substring (point)
2397 (+ (point) len))))
2398 (not (string= tail (substring string 0 len)))))
2399 (setq len (1- len))
2400 (forward-char 1))
2401 (delete-char len)))
2402
2403 (defun choose-completion-string (choice &optional buffer)
2404 (let ((buffer (or buffer completion-reference-buffer)))
2405 (set-buffer buffer)
2406 (choose-completion-delete-max-match choice)
2407 (insert choice)
2408 ;; Update point in the window that BUFFER is showing in.
2409 (let ((window (get-buffer-window buffer t)))
2410 (set-window-point window (point)))
2411 (and (equal buffer (window-buffer (minibuffer-window)))
2412 (minibuffer-complete-and-exit))))
2413
2376 (defun completion-list-mode () 2414 (defun completion-list-mode ()
2377 "Major mode for buffers showing lists of possible completions. 2415 "Major mode for buffers showing lists of possible completions.
2378 Type \\<completion-list-mode-map>\\[mouse-choose-completion] to select 2416 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\
2379 a completion with the mouse." 2417 to select the completion near point.
2418 Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
2419 with the mouse."
2380 (interactive) 2420 (interactive)
2381 (kill-all-local-variables) 2421 (kill-all-local-variables)
2382 (use-local-map completion-list-mode-map) 2422 (use-local-map completion-list-mode-map)
2383 (setq mode-name "Completion List") 2423 (setq mode-name "Completion List")
2384 (setq major-mode 'completion-list-mode) 2424 (setq major-mode 'completion-list-mode)
2392 (make-local-variable 'completion-reference-buffer) 2432 (make-local-variable 'completion-reference-buffer)
2393 (setq completion-reference-buffer mainbuf) 2433 (setq completion-reference-buffer mainbuf)
2394 (goto-char (point-min)) 2434 (goto-char (point-min))
2395 (if window-system 2435 (if window-system
2396 (insert (substitute-command-keys 2436 (insert (substitute-command-keys
2397 "Click \\[mouse-choose-completion] on a completion to select it.\n\n")))))) 2437 "Click \\[mouse-choose-completion] on a completion to select it.\n")))
2438 (insert (substitute-command-keys
2439 "In this buffer, type \\[choose-completion] to \
2440 select the completion near point.\n\n")))))
2398 2441
2399 (add-hook 'completion-setup-hook 'completion-setup-function) 2442 (add-hook 'completion-setup-hook 'completion-setup-function)
2400 2443
2401 ;;;; Keypad support. 2444 ;;;; Keypad support.
2402 2445