diff options
| author | Stefan Monnier | 2009-12-02 04:11:08 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-12-02 04:11:08 +0000 |
| commit | bb12edf129de7f0c9cb5eca4bbc58f4d04051d8d (patch) | |
| tree | 4adb0a29d3fdac32a0d8872eb39fb99c30ca517f /lisp/wid-edit.el | |
| parent | 96bdcdc44e15b72d1e5f2cb7729be4a3aed3ecf4 (diff) | |
| download | emacs-bb12edf129de7f0c9cb5eca4bbc58f4d04051d8d.tar.gz emacs-bb12edf129de7f0c9cb5eca4bbc58f4d04051d8d.zip | |
Use completion-in-buffer.
(widget-field-text-end): New function.
(widget-field-value-get): Use it.
(widget-string-complete, widget-file-complete)
(widget-color-complete): Use it and completion-in-region.
(widget-complete): Don't narrow the buffer.
Diffstat (limited to 'lisp/wid-edit.el')
| -rw-r--r-- | lisp/wid-edit.el | 107 |
1 files changed, 29 insertions, 78 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index 5a22b371db0..f96c71995a6 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el | |||
| @@ -1160,11 +1160,9 @@ the field." | |||
| 1160 | When not inside a field, move to the previous button or field." | 1160 | When not inside a field, move to the previous button or field." |
| 1161 | (interactive) | 1161 | (interactive) |
| 1162 | (let ((field (widget-field-find (point)))) | 1162 | (let ((field (widget-field-find (point)))) |
| 1163 | (if field | 1163 | (when field |
| 1164 | (save-restriction | 1164 | (widget-apply field :complete)) |
| 1165 | (widget-narrow-to-field) | 1165 | (error "Not in an editable field"))) |
| 1166 | (widget-apply field :complete)) | ||
| 1167 | (error "Not in an editable field")))) | ||
| 1168 | 1166 | ||
| 1169 | ;;; Setting up the buffer. | 1167 | ;;; Setting up the buffer. |
| 1170 | 1168 | ||
| @@ -1257,6 +1255,19 @@ When not inside a field, move to the previous button or field." | |||
| 1257 | (overlay-end overlay))) | 1255 | (overlay-end overlay))) |
| 1258 | (cdr overlay)))) | 1256 | (cdr overlay)))) |
| 1259 | 1257 | ||
| 1258 | (defun widget-field-text-end (widget) | ||
| 1259 | (let ((to (widget-field-end widget)) | ||
| 1260 | (size (widget-get widget :size))) | ||
| 1261 | (if (or (null size) (zerop size)) | ||
| 1262 | to | ||
| 1263 | (let ((from (widget-field-start widget))) | ||
| 1264 | (if (and from to) | ||
| 1265 | (with-current-buffer (widget-field-buffer widget) | ||
| 1266 | (while (and (> to from) | ||
| 1267 | (eq (char-after (1- to)) ?\s)) | ||
| 1268 | (setq to (1- to))) | ||
| 1269 | to)))))) | ||
| 1270 | |||
| 1260 | (defun widget-field-find (pos) | 1271 | (defun widget-field-find (pos) |
| 1261 | "Return the field at POS. | 1272 | "Return the field at POS. |
| 1262 | Unlike (get-char-property POS 'field), this works with empty fields too." | 1273 | Unlike (get-char-property POS 'field), this works with empty fields too." |
| @@ -1935,7 +1946,7 @@ the earlier input." | |||
| 1935 | (defun widget-field-value-get (widget) | 1946 | (defun widget-field-value-get (widget) |
| 1936 | "Return current text in editing field." | 1947 | "Return current text in editing field." |
| 1937 | (let ((from (widget-field-start widget)) | 1948 | (let ((from (widget-field-start widget)) |
| 1938 | (to (widget-field-end widget)) | 1949 | (to (widget-field-text-end widget)) |
| 1939 | (buffer (widget-field-buffer widget)) | 1950 | (buffer (widget-field-buffer widget)) |
| 1940 | (size (widget-get widget :size)) | 1951 | (size (widget-get widget :size)) |
| 1941 | (secret (widget-get widget :secret)) | 1952 | (secret (widget-get widget :secret)) |
| @@ -1943,11 +1954,6 @@ the earlier input." | |||
| 1943 | (if (and from to) | 1954 | (if (and from to) |
| 1944 | (progn | 1955 | (progn |
| 1945 | (set-buffer buffer) | 1956 | (set-buffer buffer) |
| 1946 | (while (and size | ||
| 1947 | (not (zerop size)) | ||
| 1948 | (> to from) | ||
| 1949 | (eq (char-after (1- to)) ?\s)) | ||
| 1950 | (setq to (1- to))) | ||
| 1951 | (let ((result (buffer-substring-no-properties from to))) | 1957 | (let ((result (buffer-substring-no-properties from to))) |
| 1952 | (when secret | 1958 | (when secret |
| 1953 | (let ((index 0)) | 1959 | (let ((index 0)) |
| @@ -3029,35 +3035,13 @@ as the value." | |||
| 3029 | Completions are taken from the :completion-alist property of the | 3035 | Completions are taken from the :completion-alist property of the |
| 3030 | widget. If that isn't a list, it's evalled and expected to yield a list." | 3036 | widget. If that isn't a list, it's evalled and expected to yield a list." |
| 3031 | (interactive) | 3037 | (interactive) |
| 3032 | (let* ((prefix (buffer-substring-no-properties (widget-field-start widget) | 3038 | (let* ((completion-ignore-case (widget-get widget :completion-ignore-case)) |
| 3033 | (point))) | ||
| 3034 | (completion-ignore-case (widget-get widget :completion-ignore-case)) | ||
| 3035 | (alist (widget-get widget :completion-alist)) | 3039 | (alist (widget-get widget :completion-alist)) |
| 3036 | (_ (unless (listp alist) | 3040 | (_ (unless (listp alist) |
| 3037 | (setq alist (eval alist)))) | 3041 | (setq alist (eval alist))))) |
| 3038 | (completion (try-completion prefix alist))) | 3042 | (completion-in-region (widget-field-start widget) |
| 3039 | (cond ((eq completion t) | 3043 | (max (point) (widget-field-text-end widget)) |
| 3040 | (when completion-ignore-case | 3044 | alist))) |
| 3041 | ;; Replace field with completion in case its case is different. | ||
| 3042 | (delete-region (widget-field-start widget) | ||
| 3043 | (widget-field-end widget)) | ||
| 3044 | (insert-and-inherit (car (assoc-string prefix alist t)))) | ||
| 3045 | (message "Only match")) | ||
| 3046 | ((null completion) | ||
| 3047 | (error "No match")) | ||
| 3048 | ((not (eq t (compare-strings prefix nil nil completion nil nil | ||
| 3049 | completion-ignore-case))) | ||
| 3050 | (when completion-ignore-case | ||
| 3051 | ;; Replace field with completion in case its case is different. | ||
| 3052 | (delete-region (widget-field-start widget) | ||
| 3053 | (widget-field-end widget)) | ||
| 3054 | (insert-and-inherit completion))) | ||
| 3055 | (t | ||
| 3056 | (message "Making completion list...") | ||
| 3057 | (with-output-to-temp-buffer "*Completions*" | ||
| 3058 | (display-completion-list | ||
| 3059 | (all-completions prefix alist nil))) | ||
| 3060 | (message "Making completion list...done"))))) | ||
| 3061 | 3045 | ||
| 3062 | (define-widget 'regexp 'string | 3046 | (define-widget 'regexp 'string |
| 3063 | "A regular expression." | 3047 | "A regular expression." |
| @@ -3096,29 +3080,9 @@ It reads a file name from an editable text field." | |||
| 3096 | (defun widget-file-complete () | 3080 | (defun widget-file-complete () |
| 3097 | "Perform completion on file name preceding point." | 3081 | "Perform completion on file name preceding point." |
| 3098 | (interactive) | 3082 | (interactive) |
| 3099 | (let* ((end (point)) | 3083 | (completion-in-region (widget-field-start widget) |
| 3100 | (beg (widget-field-start widget)) | 3084 | (max (point) (widget-field-text-end widget)) |
| 3101 | (pattern (buffer-substring beg end)) | 3085 | 'completion-file-name-table)) |
| 3102 | (name-part (file-name-nondirectory pattern)) | ||
| 3103 | ;; I think defaulting to root is right | ||
| 3104 | ;; because these really should be absolute file names. | ||
| 3105 | (directory (or (file-name-directory pattern) "/")) | ||
| 3106 | (completion (file-name-completion name-part directory))) | ||
| 3107 | (cond ((eq completion t)) | ||
| 3108 | ((null completion) | ||
| 3109 | (message "Can't find completion for \"%s\"" pattern) | ||
| 3110 | (ding)) | ||
| 3111 | ((not (string= name-part completion)) | ||
| 3112 | (delete-region beg end) | ||
| 3113 | (insert (expand-file-name completion directory))) | ||
| 3114 | (t | ||
| 3115 | (message "Making completion list...") | ||
| 3116 | (with-output-to-temp-buffer "*Completions*" | ||
| 3117 | (display-completion-list | ||
| 3118 | (sort (file-name-all-completions name-part directory) | ||
| 3119 | 'string<) | ||
| 3120 | name-part)) | ||
| 3121 | (message "Making completion list...%s" "done"))))) | ||
| 3122 | 3086 | ||
| 3123 | (defun widget-file-prompt-value (widget prompt value unbound) | 3087 | (defun widget-file-prompt-value (widget prompt value unbound) |
| 3124 | ;; Read file from minibuffer. | 3088 | ;; Read file from minibuffer. |
| @@ -3738,23 +3702,10 @@ example: | |||
| 3738 | (defun widget-color-complete (widget) | 3702 | (defun widget-color-complete (widget) |
| 3739 | "Complete the color in WIDGET." | 3703 | "Complete the color in WIDGET." |
| 3740 | (require 'facemenu) ; for facemenu-color-alist | 3704 | (require 'facemenu) ; for facemenu-color-alist |
| 3741 | (let* ((prefix (buffer-substring-no-properties (widget-field-start widget) | 3705 | (completion-in-region (widget-field-start widget) |
| 3742 | (point))) | 3706 | (max (point) (widget-field-text-end widget)) |
| 3743 | (list (or facemenu-color-alist | 3707 | (or facemenu-color-alist |
| 3744 | (sort (defined-colors) 'string-lessp))) | 3708 | (sort (defined-colors) 'string-lessp)))) |
| 3745 | (completion (try-completion prefix list))) | ||
| 3746 | (cond ((eq completion t) | ||
| 3747 | (message "Exact match.")) | ||
| 3748 | ((null completion) | ||
| 3749 | (error "Can't find completion for \"%s\"" prefix)) | ||
| 3750 | ((not (string-equal prefix completion)) | ||
| 3751 | (insert-and-inherit (substring completion (length prefix)))) | ||
| 3752 | (t | ||
| 3753 | (message "Making completion list...") | ||
| 3754 | (with-output-to-temp-buffer "*Completions*" | ||
| 3755 | (display-completion-list (all-completions prefix list nil) | ||
| 3756 | prefix)) | ||
| 3757 | (message "Making completion list...done"))))) | ||
| 3758 | 3709 | ||
| 3759 | (defun widget-color-sample-face-get (widget) | 3710 | (defun widget-color-sample-face-get (widget) |
| 3760 | (let* ((value (condition-case nil | 3711 | (let* ((value (condition-case nil |