aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/minibuffer.el65
-rw-r--r--lisp/simple.el61
3 files changed, 79 insertions, 64 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ab373f14766..2dd575ec3f8 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12008-04-29 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * minibuffer.el (completion-common-substring): Mark obsolete.
4 (completions-first-difference, completions-common-part):
5 Move from simple.el.
6 (completion-hilit-commonality): New fun.
7 (display-completion-list, completion-emacs21-all-completions)
8 (completion-emacs22-all-completions): Use it.
9 * simple.el (completions-first-difference, completions-common-part):
10 Move to minibuffer.el.
11 (choose-completion-string): Use field functions and minibufferp.
12 (completion-setup-function): Don't set completions faces.
13
12008-04-29 Glenn Morris <rgm@gnu.org> 142008-04-29 Glenn Morris <rgm@gnu.org>
2 15
3 * calendar/calendar.el (calendar-nth-named-absday) 16 * calendar/calendar.el (calendar-nth-named-absday)
@@ -29,8 +42,8 @@
29 42
302008-04-29 Nick Roberts <nickrob@snap.net.nz> 432008-04-29 Nick Roberts <nickrob@snap.net.nz>
31 44
32 * progmodes/gdb-ui.el (gdb-info-stack-custom): Use 45 * progmodes/gdb-ui.el (gdb-info-stack-custom):
33 gud-tool-bar-item-visible-no-fringe. 46 Use gud-tool-bar-item-visible-no-fringe.
34 (gdb-display-buffer): Don't pop new buffer if gud-comint-buffer 47 (gdb-display-buffer): Don't pop new buffer if gud-comint-buffer
35 is already visible in frame. Remove optional size parameter 48 is already visible in frame. Remove optional size parameter
36 and add optional frame parameter. 49 and add optional frame parameter.
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index f6fe6f849aa..51749ba5501 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -621,15 +621,54 @@ It also eliminates runs of equal strings."
621 (put-text-property (point) (progn (insert (cadr str)) (point)) 621 (put-text-property (point) (progn (insert (cadr str)) (point))
622 'mouse-face nil))))))) 622 'mouse-face nil)))))))
623 623
624(defvar completion-common-substring) 624(defvar completion-common-substring nil)
625(make-obsolete-variable 'completion-common-substring nil "23.1")
625 626
626(defvar completion-setup-hook nil 627(defvar completion-setup-hook nil
627 "Normal hook run at the end of setting up a completion list buffer. 628 "Normal hook run at the end of setting up a completion list buffer.
628When this hook is run, the current buffer is the one in which the 629When this hook is run, the current buffer is the one in which the
629command to display the completion list buffer was run. 630command to display the completion list buffer was run.
630The completion list buffer is available as the value of `standard-output'. 631The completion list buffer is available as the value of `standard-output'.
631The common prefix substring for completion may be available as the value 632See also `display-completion-list'.")
632of `completion-common-substring'. See also `display-completion-list'.") 633
634(defface completions-first-difference
635 '((t (:inherit bold)))
636 "Face put on the first uncommon character in completions in *Completions* buffer."
637 :group 'completion)
638
639(defface completions-common-part
640 '((t (:inherit default)))
641 "Face put on the common prefix substring in completions in *Completions* buffer.
642The idea of `completions-common-part' is that you can use it to
643make the common parts less visible than normal, so that the rest
644of the differing parts is, by contrast, slightly highlighted."
645 :group 'completion)
646
647(defun completion-hilit-commonality (completions prefix-len)
648 (when completions
649 (let* ((last (last completions))
650 (base-size (cdr last))
651 (com-str-len (- prefix-len (or base-size 0))))
652 ;; Remove base-size during mapcar, and add it back later.
653 (setcdr last nil)
654 (nconc
655 (mapcar
656 (lambda (elem)
657 (let ((str
658 (if (consp elem)
659 (car (setq elem (cons (copy-sequence (car elem))
660 (cdr elem))))
661 (setq elem (copy-sequence elem)))))
662 (put-text-property 0 com-str-len
663 'font-lock-face 'completions-common-part
664 str)
665 (if (> (length str) com-str-len)
666 (put-text-property com-str-len (1+ com-str-len)
667 'font-lock-face 'completions-first-difference
668 str)))
669 elem)
670 completions)
671 base-size))))
633 672
634(defun display-completion-list (completions &optional common-substring) 673(defun display-completion-list (completions &optional common-substring)
635 "Display the list of completions, COMPLETIONS, using `standard-output'. 674 "Display the list of completions, COMPLETIONS, using `standard-output'.
@@ -642,14 +681,14 @@ The actual completion alternatives, as inserted, are given `mouse-face'
642properties of `highlight'. 681properties of `highlight'.
643At the end, this runs the normal hook `completion-setup-hook'. 682At the end, this runs the normal hook `completion-setup-hook'.
644It can find the completion buffer in `standard-output'. 683It can find the completion buffer in `standard-output'.
645The optional second arg COMMON-SUBSTRING is a string. 684The obsolete optional second arg COMMON-SUBSTRING is a string.
646It is used to put faces, `completions-first-difference' and 685It is used to put faces, `completions-first-difference' and
647`completions-common-part' on the completion buffer. The 686`completions-common-part' on the completion buffer. The
648`completions-common-part' face is put on the common substring 687`completions-common-part' face is put on the common substring
649specified by COMMON-SUBSTRING. If COMMON-SUBSTRING is nil 688specified by COMMON-SUBSTRING."
650and the current buffer is not the minibuffer, the faces are not put. 689 (if common-substring
651Internally, COMMON-SUBSTRING is bound to `completion-common-substring' 690 (setq completions (completion-hilit-commonality
652during running `completion-setup-hook'." 691 completions (length common-substring))))
653 (if (not (bufferp standard-output)) 692 (if (not (bufferp standard-output))
654 ;; This *never* (ever) happens, so there's no point trying to be clever. 693 ;; This *never* (ever) happens, so there's no point trying to be clever.
655 (with-temp-buffer 694 (with-temp-buffer
@@ -670,6 +709,8 @@ during running `completion-setup-hook'."
670 (setcdr last nil)) ;Make completions a properly nil-terminated list. 709 (setcdr last nil)) ;Make completions a properly nil-terminated list.
671 (completion--insert-strings completions)))) 710 (completion--insert-strings completions))))
672 711
712 ;; The hilit used to be applied via completion-setup-hook, so there
713 ;; may still be some code that uses completion-common-substring.
673 (let ((completion-common-substring common-substring)) 714 (let ((completion-common-substring common-substring))
674 (run-hooks 'completion-setup-hook)) 715 (run-hooks 'completion-setup-hook))
675 nil) 716 nil)
@@ -1000,7 +1041,9 @@ Like `internal-complete-buffer', but removes BUFFER from the completion list."
1000 completion))) 1041 completion)))
1001 1042
1002(defun completion-emacs21-all-completions (string table pred point) 1043(defun completion-emacs21-all-completions (string table pred point)
1003 (all-completions string table pred t)) 1044 (completion-hilit-commonality
1045 (all-completions string table pred t)
1046 (length string)))
1004 1047
1005;;; Basic completion, used in Emacs-22. 1048;;; Basic completion, used in Emacs-22.
1006 1049
@@ -1025,7 +1068,9 @@ Like `internal-complete-buffer', but removes BUFFER from the completion list."
1025 (cons (concat completion suffix) (length completion))))) 1068 (cons (concat completion suffix) (length completion)))))
1026 1069
1027(defun completion-emacs22-all-completions (string table pred point) 1070(defun completion-emacs22-all-completions (string table pred point)
1028 (all-completions (substring string 0 point) table pred t)) 1071 (completion-hilit-commonality
1072 (all-completions (substring string 0 point) table pred t)
1073 point))
1029 1074
1030(defun completion-basic-try-completion (string table pred point) 1075(defun completion-basic-try-completion (string table pred point)
1031 (let ((suffix (substring string point)) 1076 (let ((suffix (substring string point))
diff --git a/lisp/simple.el b/lisp/simple.el
index 4ef352e1cd5..164862c1423 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5425,11 +5425,15 @@ to decide what to delete."
5425 'choose-completion-string-functions 5425 'choose-completion-string-functions
5426 choice buffer mini-p base-size) 5426 choice buffer mini-p base-size)
5427 ;; Insert the completion into the buffer where it was requested. 5427 ;; Insert the completion into the buffer where it was requested.
5428 ;; FIXME:
5429 ;; - There may not be a field at point, or there may be a field but
5430 ;; it's not a "completion field", in which case we have to
5431 ;; call choose-completion-delete-max-match even if base-size is set.
5432 ;; - we may need to delete further than (point) to (field-end),
5433 ;; depending on the completion-style, and for that we need to
5434 ;; extra data `completion-extra-size'.
5428 (if base-size 5435 (if base-size
5429 (delete-region (+ base-size (if mini-p 5436 (delete-region (+ base-size (field-beginning)) (point))
5430 (minibuffer-prompt-end)
5431 (point-min)))
5432 (point))
5433 (choose-completion-delete-max-match choice)) 5437 (choose-completion-delete-max-match choice))
5434 (insert choice) 5438 (insert choice)
5435 (remove-text-properties (- (point) (length choice)) (point) 5439 (remove-text-properties (- (point) (length choice)) (point)
@@ -5439,7 +5443,7 @@ to decide what to delete."
5439 (set-window-point window (point))) 5443 (set-window-point window (point)))
5440 ;; If completing for the minibuffer, exit it with this choice. 5444 ;; If completing for the minibuffer, exit it with this choice.
5441 (and (not completion-no-auto-exit) 5445 (and (not completion-no-auto-exit)
5442 (equal buffer (window-buffer (minibuffer-window))) 5446 (minibufferp buffer)
5443 minibuffer-completion-table 5447 minibuffer-completion-table
5444 ;; If this is reading a file name, and the file name chosen 5448 ;; If this is reading a file name, and the file name chosen
5445 ;; is a directory, don't exit the minibuffer. 5449 ;; is a directory, don't exit the minibuffer.
@@ -5478,34 +5482,12 @@ Called from `temp-buffer-show-hook'."
5478 :version "22.1" 5482 :version "22.1"
5479 :group 'completion) 5483 :group 'completion)
5480 5484
5481(defface completions-first-difference
5482 '((t (:inherit bold)))
5483 "Face put on the first uncommon character in completions in *Completions* buffer."
5484 :group 'completion)
5485
5486(defface completions-common-part
5487 '((t (:inherit default)))
5488 "Face put on the common prefix substring in completions in *Completions* buffer.
5489The idea of `completions-common-part' is that you can use it to
5490make the common parts less visible than normal, so that the rest
5491of the differing parts is, by contrast, slightly highlighted."
5492 :group 'completion)
5493
5494;; This is for packages that need to bind it to a non-default regexp 5485;; This is for packages that need to bind it to a non-default regexp
5495;; in order to make the first-differing character highlight work 5486;; in order to make the first-differing character highlight work
5496;; to their liking 5487;; to their liking
5497(defvar completion-root-regexp "^/" 5488(defvar completion-root-regexp "^/"
5498 "Regexp to use in `completion-setup-function' to find the root directory.") 5489 "Regexp to use in `completion-setup-function' to find the root directory.")
5499 5490
5500(defvar completion-common-substring nil
5501 "Common prefix substring to use in `completion-setup-function' to put faces.
5502The value is set by `display-completion-list' during running `completion-setup-hook'.
5503
5504To put faces `completions-first-difference' and `completions-common-part'
5505in the `*Completions*' buffer, the common prefix substring in completions
5506is needed as a hint. (The minibuffer is a special case. The content
5507of the minibuffer before point is always the common substring.)")
5508
5509;; This function goes in completion-setup-hook, so that it is called 5491;; This function goes in completion-setup-hook, so that it is called
5510;; after the text of the completion list buffer is written. 5492;; after the text of the completion list buffer is written.
5511(defun completion-setup-function () 5493(defun completion-setup-function ()
@@ -5539,31 +5521,6 @@ of the minibuffer before point is always the common substring.)")
5539 (minibuffer-completing-symbol nil) 5521 (minibuffer-completing-symbol nil)
5540 ;; Otherwise, in minibuffer, the base size is 0. 5522 ;; Otherwise, in minibuffer, the base size is 0.
5541 ((minibufferp mainbuf) 0)))) 5523 ((minibufferp mainbuf) 0))))
5542 (setq common-string-length
5543 (cond
5544 (completion-common-substring
5545 (length completion-common-substring))
5546 (completion-base-size
5547 (- (length mbuf-contents) completion-base-size))))
5548 ;; Put faces on first uncommon characters and common parts.
5549 (when (and (integerp common-string-length) (>= common-string-length 0))
5550 (let ((element-start (point-min))
5551 (maxp (point-max))
5552 element-common-end)
5553 (while (and (setq element-start
5554 (next-single-property-change
5555 element-start 'mouse-face))
5556 (< (setq element-common-end
5557 (+ element-start common-string-length))
5558 maxp))
5559 (when (get-char-property element-start 'mouse-face)
5560 (if (and (> common-string-length 0)
5561 (get-char-property (1- element-common-end) 'mouse-face))
5562 (put-text-property element-start element-common-end
5563 'font-lock-face 'completions-common-part))
5564 (if (get-char-property element-common-end 'mouse-face)
5565 (put-text-property element-common-end (1+ element-common-end)
5566 'font-lock-face 'completions-first-difference))))))
5567 ;; Maybe insert help string. 5524 ;; Maybe insert help string.
5568 (when completion-show-help 5525 (when completion-show-help
5569 (goto-char (point-min)) 5526 (goto-char (point-min))