diff options
| author | Juri Linkov | 2005-12-16 19:08:21 +0000 |
|---|---|---|
| committer | Juri Linkov | 2005-12-16 19:08:21 +0000 |
| commit | 6cdd02110f87f869ab39f1cc34a1042404a5abbe (patch) | |
| tree | a154b9511fc5d10a76945098727ad6bf7b3a0a28 | |
| parent | 8aaba1c98eaa6578d0a0356dc8fa0391aa91b362 (diff) | |
| download | emacs-6cdd02110f87f869ab39f1cc34a1042404a5abbe.tar.gz emacs-6cdd02110f87f869ab39f1cc34a1042404a5abbe.zip | |
(choose-completion): Use `buffer-substring-no-properties'
instead of `buffer-substring'.
(completion-common-substring): Doc fix.
(completion-setup-function): Use minibuffer-completion-contents
instead of minibuffer-contents. Don't set common-string-length
initially. Remove special handling of partial-completion-mode.
Move computation of completion-base-size into one cond. Call
completion-base-size-function in mainbuf. In computation of
completion-base-size for file name completion don't move point to
the end of the minibuffer. Move computation of common-string-length
into one cond. Start putting faces only when common-string-length>=0.
Add condition to put completions-common-part when common-string-length>0.
| -rw-r--r-- | lisp/simple.el | 81 |
1 files changed, 33 insertions, 48 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index ec123c73cd8..d3af637ee30 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -4787,7 +4787,7 @@ With prefix argument N, move N items (negative N means move backward)." | |||
| 4787 | (error "No completion here")) | 4787 | (error "No completion here")) |
| 4788 | (setq beg (previous-single-property-change beg 'mouse-face)) | 4788 | (setq beg (previous-single-property-change beg 'mouse-face)) |
| 4789 | (setq end (or (next-single-property-change end 'mouse-face) (point-max))) | 4789 | (setq end (or (next-single-property-change end 'mouse-face) (point-max))) |
| 4790 | (setq completion (buffer-substring beg end)) | 4790 | (setq completion (buffer-substring-no-properties beg end)) |
| 4791 | (let ((owindow (selected-window))) | 4791 | (let ((owindow (selected-window))) |
| 4792 | (if (and (one-window-p t 'selected-frame) | 4792 | (if (and (one-window-p t 'selected-frame) |
| 4793 | (window-dedicated-p (selected-window))) | 4793 | (window-dedicated-p (selected-window))) |
| @@ -4944,68 +4944,52 @@ of the differing parts is, by contrast, slightly highlighted." | |||
| 4944 | "Common prefix substring to use in `completion-setup-function' to put faces. | 4944 | "Common prefix substring to use in `completion-setup-function' to put faces. |
| 4945 | The value is set by `display-completion-list' during running `completion-setup-hook'. | 4945 | The value is set by `display-completion-list' during running `completion-setup-hook'. |
| 4946 | 4946 | ||
| 4947 | To put faces, `completions-first-difference' and `completions-common-part' | 4947 | To put faces `completions-first-difference' and `completions-common-part' |
| 4948 | into \"*Completions*\* buffer, the common prefix substring in completions is | 4948 | in the `*Completions*' buffer, the common prefix substring in completions |
| 4949 | needed as a hint. (Minibuffer is a special case. The content of minibuffer itself | 4949 | is needed as a hint. (The minibuffer is a special case. The content |
| 4950 | is the substring.)") | 4950 | of the minibuffer before point is always the common substring.)") |
| 4951 | 4951 | ||
| 4952 | ;; This function goes in completion-setup-hook, so that it is called | 4952 | ;; This function goes in completion-setup-hook, so that it is called |
| 4953 | ;; after the text of the completion list buffer is written. | 4953 | ;; after the text of the completion list buffer is written. |
| 4954 | (defun completion-setup-function () | 4954 | (defun completion-setup-function () |
| 4955 | (let* ((mainbuf (current-buffer)) | 4955 | (let* ((mainbuf (current-buffer)) |
| 4956 | (mbuf-contents (minibuffer-contents)) | 4956 | (mbuf-contents (minibuffer-completion-contents)) |
| 4957 | (common-string-length (length mbuf-contents))) | 4957 | common-string-length) |
| 4958 | ;; When reading a file name in the minibuffer, | 4958 | ;; When reading a file name in the minibuffer, |
| 4959 | ;; set default-directory in the minibuffer | 4959 | ;; set default-directory in the minibuffer |
| 4960 | ;; so it will get copied into the completion list buffer. | 4960 | ;; so it will get copied into the completion list buffer. |
| 4961 | (if minibuffer-completing-file-name | 4961 | (if minibuffer-completing-file-name |
| 4962 | (with-current-buffer mainbuf | 4962 | (with-current-buffer mainbuf |
| 4963 | (setq default-directory (file-name-directory mbuf-contents)))) | 4963 | (setq default-directory (file-name-directory mbuf-contents)))) |
| 4964 | ;; If partial-completion-mode is on, point might not be after the | ||
| 4965 | ;; last character in the minibuffer. | ||
| 4966 | ;; FIXME: This hack should be moved to complete.el where we call | ||
| 4967 | ;; display-completion-list. | ||
| 4968 | (when partial-completion-mode | ||
| 4969 | (setq common-string-length | ||
| 4970 | (if (eq (char-after (field-beginning)) ?-) | ||
| 4971 | ;; If the text to be completed starts with a `-', there is no | ||
| 4972 | ;; common prefix. | ||
| 4973 | ;; FIXME: this probably still doesn't do the right thing | ||
| 4974 | ;; when completing file names. It's not even clear what | ||
| 4975 | ;; is TRT. | ||
| 4976 | 0 | ||
| 4977 | (- common-string-length (- (point-max) (point)))))) | ||
| 4978 | (with-current-buffer standard-output | 4964 | (with-current-buffer standard-output |
| 4979 | (completion-list-mode) | 4965 | (completion-list-mode) |
| 4980 | (set (make-local-variable 'completion-reference-buffer) mainbuf) | 4966 | (set (make-local-variable 'completion-reference-buffer) mainbuf) |
| 4981 | (setq completion-base-size | 4967 | (setq completion-base-size |
| 4982 | (if minibuffer-completing-file-name | 4968 | (cond |
| 4983 | ;; For file name completion, use the number of chars before | 4969 | ((and (symbolp minibuffer-completion-table) |
| 4984 | ;; the start of the last file name component. | 4970 | (get minibuffer-completion-table 'completion-base-size-function)) |
| 4985 | (with-current-buffer mainbuf | 4971 | ;; To compute base size, a function can use the global value of |
| 4986 | (save-excursion | 4972 | ;; completion-common-substring or minibuffer-completion-contents. |
| 4987 | (goto-char (point-max)) | 4973 | (with-current-buffer mainbuf |
| 4988 | (skip-chars-backward completion-root-regexp) | 4974 | (funcall (get minibuffer-completion-table |
| 4989 | (- (point) (minibuffer-prompt-end)))) | 4975 | 'completion-base-size-function)))) |
| 4990 | ;; Otherwise, in minibuffer, the whole input is being completed. | 4976 | (minibuffer-completing-file-name |
| 4991 | (if (minibufferp mainbuf) 0))) | 4977 | ;; For file name completion, use the number of chars before |
| 4992 | (if (and (symbolp minibuffer-completion-table) | 4978 | ;; the start of the file name component at point. |
| 4993 | (get minibuffer-completion-table 'completion-base-size-function)) | 4979 | (with-current-buffer mainbuf |
| 4994 | (setq completion-base-size | 4980 | (save-excursion |
| 4995 | ;; FIXME: without any extra arg, how is this function | 4981 | (skip-chars-backward completion-root-regexp) |
| 4996 | ;; expected to return anything else than a constant unless | 4982 | (- (point) (minibuffer-prompt-end))))) |
| 4997 | ;; it redoes part of the work of all-completions? | 4983 | ;; Otherwise, in minibuffer, the base size is 0. |
| 4998 | ;; In most cases this value would better be computed and | 4984 | ((minibufferp mainbuf) 0))) |
| 4999 | ;; returned at the same time as the list of all-completions | 4985 | (setq common-string-length |
| 5000 | ;; is computed. --Stef | 4986 | (cond |
| 5001 | (funcall (get minibuffer-completion-table | 4987 | (completion-common-substring |
| 5002 | 'completion-base-size-function)))) | 4988 | (length completion-common-substring)) |
| 4989 | (completion-base-size | ||
| 4990 | (- (length mbuf-contents) completion-base-size)))) | ||
| 5003 | ;; Put faces on first uncommon characters and common parts. | 4991 | ;; Put faces on first uncommon characters and common parts. |
| 5004 | (when (or completion-common-substring completion-base-size) | 4992 | (when (and (integerp common-string-length) (>= common-string-length 0)) |
| 5005 | (setq common-string-length | ||
| 5006 | (if completion-common-substring | ||
| 5007 | (length completion-common-substring) | ||
| 5008 | (- common-string-length completion-base-size))) | ||
| 5009 | (let ((element-start (point-min)) | 4993 | (let ((element-start (point-min)) |
| 5010 | (maxp (point-max)) | 4994 | (maxp (point-max)) |
| 5011 | element-common-end) | 4995 | element-common-end) |
| @@ -5016,7 +5000,8 @@ is the substring.)") | |||
| 5016 | (+ element-start common-string-length)) | 5000 | (+ element-start common-string-length)) |
| 5017 | maxp)) | 5001 | maxp)) |
| 5018 | (when (get-char-property element-start 'mouse-face) | 5002 | (when (get-char-property element-start 'mouse-face) |
| 5019 | (if (get-char-property (1- element-common-end) 'mouse-face) | 5003 | (if (and (> common-string-length 0) |
| 5004 | (get-char-property (1- element-common-end) 'mouse-face)) | ||
| 5020 | (put-text-property element-start element-common-end | 5005 | (put-text-property element-start element-common-end |
| 5021 | 'font-lock-face 'completions-common-part)) | 5006 | 'font-lock-face 'completions-common-part)) |
| 5022 | (if (get-char-property element-common-end 'mouse-face) | 5007 | (if (get-char-property element-common-end 'mouse-face) |