comparison lisp/simple.el @ 8479:582ac9a744c4

(completion-base-size): New variable. (completion-list-mode): Make it local. (choose-completion): Pass its value to choose-completion-string. (choose-completion-string): New arg base-size. Use that when deciding how much to delete.
author Richard M. Stallman <rms@gnu.org>
date Sun, 07 Aug 1994 18:11:58 +0000
parents 52940ba43041
children 509daefd2d13
comparison
equal deleted inserted replaced
8478:9d3d84a3c3fa 8479:582ac9a744c4
2478 (put 'completion-list-mode 'mode-class 'special) 2478 (put 'completion-list-mode 'mode-class 'special)
2479 2479
2480 ;; Record the buffer that was current when the completion list was requested. 2480 ;; Record the buffer that was current when the completion list was requested.
2481 (defvar completion-reference-buffer) 2481 (defvar completion-reference-buffer)
2482 2482
2483 ;; This records the length of the text at the beginning of the buffer
2484 ;; which was not included in the completion.
2485 (defvar completion-base-size nil)
2486
2483 (defun choose-completion () 2487 (defun choose-completion ()
2484 "Choose the completion that point is in or next to." 2488 "Choose the completion that point is in or next to."
2485 (interactive) 2489 (interactive)
2486 (let (beg end completion (buffer completion-reference-buffer)) 2490 (let (beg end completion (buffer completion-reference-buffer)
2491 (base-size completion-base-size))
2487 (if (and (not (eobp)) (get-text-property (point) 'mouse-face)) 2492 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
2488 (setq end (point) beg (1+ (point)))) 2493 (setq end (point) beg (1+ (point))))
2489 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) 2494 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
2490 (setq end (1- (point)) beg(point))) 2495 (setq end (1- (point)) beg(point)))
2491 (if (null beg) 2496 (if (null beg)
2499 ;; This is a special buffer's frame 2504 ;; This is a special buffer's frame
2500 (iconify-frame (selected-frame)) 2505 (iconify-frame (selected-frame))
2501 (or (window-dedicated-p (selected-window)) 2506 (or (window-dedicated-p (selected-window))
2502 (bury-buffer))) 2507 (bury-buffer)))
2503 (select-window owindow)) 2508 (select-window owindow))
2504 (choose-completion-string completion buffer))) 2509 (choose-completion-string completion buffer base-size)))
2505 2510
2506 ;; Delete the longest partial match for STRING 2511 ;; Delete the longest partial match for STRING
2507 ;; that can be found before POINT. 2512 ;; that can be found before POINT.
2508 (defun choose-completion-delete-max-match (string) 2513 (defun choose-completion-delete-max-match (string)
2509 (let ((opoint (point)) 2514 (let ((opoint (point))
2520 (not (string= tail (substring string 0 len))))) 2525 (not (string= tail (substring string 0 len)))))
2521 (setq len (1- len)) 2526 (setq len (1- len))
2522 (forward-char 1)) 2527 (forward-char 1))
2523 (delete-char len))) 2528 (delete-char len)))
2524 2529
2525 (defun choose-completion-string (choice &optional buffer) 2530 (defun choose-completion-string (choice &optional buffer base-size)
2526 (let ((buffer (or buffer completion-reference-buffer))) 2531 (let ((buffer (or buffer completion-reference-buffer)))
2527 ;; If BUFFER is a minibuffer, barf unless it's the currently 2532 ;; If BUFFER is a minibuffer, barf unless it's the currently
2528 ;; active minibuffer. 2533 ;; active minibuffer.
2529 (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer)) 2534 (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer))
2530 (or (not (minibuffer-window-active-p (minibuffer-window))) 2535 (or (not (minibuffer-window-active-p (minibuffer-window)))
2531 (not (equal buffer (window-buffer (minibuffer-window)))))) 2536 (not (equal buffer (window-buffer (minibuffer-window))))))
2532 (error "Minibuffer is not active for completion") 2537 (error "Minibuffer is not active for completion")
2533 ;; Insert the completion into the buffer where completion was requested. 2538 ;; Insert the completion into the buffer where completion was requested.
2534 (set-buffer buffer) 2539 (set-buffer buffer)
2535 (choose-completion-delete-max-match choice) 2540 (if base-size
2541 (delete-region (+ base-size (point-min)) (point))
2542 (choose-completion-delete-max-match choice))
2536 (insert choice) 2543 (insert choice)
2537 (remove-text-properties (- (point) (length choice)) (point) 2544 (remove-text-properties (- (point) (length choice)) (point)
2538 '(mouse-face nil)) 2545 '(mouse-face nil))
2539 ;; Update point in the window that BUFFER is showing in. 2546 ;; Update point in the window that BUFFER is showing in.
2540 (let ((window (get-buffer-window buffer t))) 2547 (let ((window (get-buffer-window buffer t)))
2552 (interactive) 2559 (interactive)
2553 (kill-all-local-variables) 2560 (kill-all-local-variables)
2554 (use-local-map completion-list-mode-map) 2561 (use-local-map completion-list-mode-map)
2555 (setq mode-name "Completion List") 2562 (setq mode-name "Completion List")
2556 (setq major-mode 'completion-list-mode) 2563 (setq major-mode 'completion-list-mode)
2564 (make-local-variable 'completion-base-size)
2565 (setq completion-base-size nil)
2557 (run-hooks 'completion-list-mode-hook)) 2566 (run-hooks 'completion-list-mode-hook))
2558 2567
2559 (defvar completion-fixup-function nil) 2568 (defvar completion-fixup-function nil)
2560 2569
2561 (defun completion-setup-function () 2570 (defun completion-setup-function ()