diff options
| author | Jambunathan K | 2012-11-29 16:32:24 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2012-11-29 16:32:24 -0500 |
| commit | cc37e70f6699cbadb1a8f5467e8dc9fcea986aa1 (patch) | |
| tree | d0bd2e2dc9ebf2f2a958c7acb9cff788f11788ca | |
| parent | 83e12fe07c18a6190c6c5ef6e959697eb0ac9f19 (diff) | |
| download | emacs-cc37e70f6699cbadb1a8f5467e8dc9fcea986aa1.tar.gz emacs-cc37e70f6699cbadb1a8f5467e8dc9fcea986aa1.zip | |
* lisp/icomplete.el: Change separator; add ido-style commands.
(icomplete-show-key-bindings): Remove custom var.
(icomplete-get-keys): Remove function.
(icomplete-forward-completions, icomplete-backward-completions):
New commands.
(icomplete-minibuffer-map): New var.
(icomplete-minibuffer-setup): Use it.
(icomplete-exhibit): Don't delay if the list of completions is known.
(icomplete-separator): New custom.
(icomplete-completions): Use it.
* lisp/minibuffer.el (completion-all-sorted-completions): Delete duplicates.
(minibuffer-force-complete-and-exit): New command.
(minibuffer--complete-and-exit): New function extracted from
minibuffer-complete-and-exit.
(minibuffer-complete-and-exit): Use it.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/ChangeLog | 19 | ||||
| -rw-r--r-- | lisp/icomplete.el | 107 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 42 |
4 files changed, 116 insertions, 56 deletions
| @@ -29,6 +29,10 @@ so we will look at it and add it to the manual. | |||
| 29 | 29 | ||
| 30 | * Changes in Specialized Modes and Packages in Emacs 24.4 | 30 | * Changes in Specialized Modes and Packages in Emacs 24.4 |
| 31 | 31 | ||
| 32 | ** Icomplete is a bit more like IDO. | ||
| 33 | *** key bindings to navigate through and select the completions. | ||
| 34 | *** The icomplete-separator is customizable, and its default has changed. | ||
| 35 | *** Removed icomplete-show-key-bindings. | ||
| 32 | ** Calc | 36 | ** Calc |
| 33 | 37 | ||
| 34 | *** Calc by default now uses the Gregorian calendar for all dates, and | 38 | *** Calc by default now uses the Gregorian calendar for all dates, and |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 20de699a5ed..73a58600ba2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,4 +1,21 @@ | |||
| 1 | 2012-11-29 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2012-11-29 Jambunathan K <kjambunathan@gmail.com> |
| 2 | Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 3 | |||
| 4 | * icomplete.el: Change separator; add ido-style commands. | ||
| 5 | (icomplete-show-key-bindings): Remove custom var. | ||
| 6 | (icomplete-get-keys): Remove function. | ||
| 7 | (icomplete-forward-completions, icomplete-backward-completions): | ||
| 8 | New commands. | ||
| 9 | (icomplete-minibuffer-map): New var. | ||
| 10 | (icomplete-minibuffer-setup): Use it. | ||
| 11 | (icomplete-exhibit): Don't delay if the list of completions is known. | ||
| 12 | (icomplete-separator): New custom. | ||
| 13 | (icomplete-completions): Use it. | ||
| 14 | * minibuffer.el (completion-all-sorted-completions): Delete duplicates. | ||
| 15 | (minibuffer-force-complete-and-exit): New command. | ||
| 16 | (minibuffer--complete-and-exit): New function extracted from | ||
| 17 | minibuffer-complete-and-exit. | ||
| 18 | (minibuffer-complete-and-exit): Use it. | ||
| 2 | 19 | ||
| 3 | * progmodes/etags.el (visit-tags-table-buffer): Give a more precise | 20 | * progmodes/etags.el (visit-tags-table-buffer): Give a more precise |
| 4 | error message when the file doesn't exist (bug#12974). | 21 | error message when the file doesn't exist (bug#12974). |
diff --git a/lisp/icomplete.el b/lisp/icomplete.el index a4e3e339470..768692281f8 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el | |||
| @@ -71,6 +71,11 @@ | |||
| 71 | (make-obsolete-variable | 71 | (make-obsolete-variable |
| 72 | 'icomplete-prospects-length 'icomplete-prospects-height "23.1") | 72 | 'icomplete-prospects-length 'icomplete-prospects-height "23.1") |
| 73 | 73 | ||
| 74 | (defcustom icomplete-separator " | " | ||
| 75 | "String used by icomplete to separate alternatives in the minibuffer." | ||
| 76 | :type 'string | ||
| 77 | :version "24.3") | ||
| 78 | |||
| 74 | ;;;_* User Customization variables | 79 | ;;;_* User Customization variables |
| 75 | (defcustom icomplete-prospects-height | 80 | (defcustom icomplete-prospects-height |
| 76 | ;; 20 is an estimated common size for the prompt + minibuffer content, to | 81 | ;; 20 is an estimated common size for the prompt + minibuffer content, to |
| @@ -97,11 +102,6 @@ See `icomplete-delay-completions-threshold'." | |||
| 97 | :type 'integer | 102 | :type 'integer |
| 98 | :group 'icomplete) | 103 | :group 'icomplete) |
| 99 | 104 | ||
| 100 | (defcustom icomplete-show-key-bindings t | ||
| 101 | "If non-nil, show key bindings as well as completion for sole matches." | ||
| 102 | :type 'boolean | ||
| 103 | :group 'icomplete) | ||
| 104 | |||
| 105 | (defcustom icomplete-minibuffer-setup-hook nil | 105 | (defcustom icomplete-minibuffer-setup-hook nil |
| 106 | "Icomplete-specific customization of minibuffer setup. | 106 | "Icomplete-specific customization of minibuffer setup. |
| 107 | 107 | ||
| @@ -145,23 +145,6 @@ Use `icomplete-mode' function to set it up properly for incremental | |||
| 145 | minibuffer completion.") | 145 | minibuffer completion.") |
| 146 | (add-hook 'icomplete-post-command-hook 'icomplete-exhibit) | 146 | (add-hook 'icomplete-post-command-hook 'icomplete-exhibit) |
| 147 | 147 | ||
| 148 | (defun icomplete-get-keys (func-name) | ||
| 149 | "Return strings naming keys bound to FUNC-NAME, or nil if none. | ||
| 150 | Examines the prior, not current, buffer, presuming that current buffer | ||
| 151 | is minibuffer." | ||
| 152 | (when (commandp func-name) | ||
| 153 | (save-excursion | ||
| 154 | (let* ((sym (intern func-name)) | ||
| 155 | (buf (other-buffer nil t)) | ||
| 156 | (keys (with-current-buffer buf (where-is-internal sym)))) | ||
| 157 | (when keys | ||
| 158 | (concat "<" | ||
| 159 | (mapconcat 'key-description | ||
| 160 | (sort keys | ||
| 161 | #'(lambda (x y) | ||
| 162 | (< (length x) (length y)))) | ||
| 163 | ", ") | ||
| 164 | ">")))))) | ||
| 165 | ;;;_ = icomplete-with-completion-tables | 148 | ;;;_ = icomplete-with-completion-tables |
| 166 | (defvar icomplete-with-completion-tables '(internal-complete-buffer) | 149 | (defvar icomplete-with-completion-tables '(internal-complete-buffer) |
| 167 | "Specialized completion tables with which icomplete should operate. | 150 | "Specialized completion tables with which icomplete should operate. |
| @@ -169,6 +152,37 @@ is minibuffer." | |||
| 169 | Icomplete does not operate with any specialized completion tables | 152 | Icomplete does not operate with any specialized completion tables |
| 170 | except those on this list.") | 153 | except those on this list.") |
| 171 | 154 | ||
| 155 | (defvar icomplete-minibuffer-map | ||
| 156 | (let ((map (make-sparse-keymap))) | ||
| 157 | (define-key map [?\M-\t] 'minibuffer-force-complete) | ||
| 158 | (define-key map [?\C-j] 'minibuffer-force-complete-and-exit) | ||
| 159 | (define-key map [?\C-s] 'icomplete-forward-completions) | ||
| 160 | (define-key map [?\C-r] 'icomplete-backward-completions) | ||
| 161 | map)) | ||
| 162 | |||
| 163 | (defun icomplete-forward-completions () | ||
| 164 | "Step forward completions by one entry. | ||
| 165 | Second entry becomes the first and can be selected with | ||
| 166 | `minibuffer-force-complete-and-exit'." | ||
| 167 | (interactive) | ||
| 168 | (let* ((comps (completion-all-sorted-completions)) | ||
| 169 | (last (last comps))) | ||
| 170 | (setcdr last (cons (car comps) (cdr last))) | ||
| 171 | (completion--cache-all-sorted-completions (cdr comps)))) | ||
| 172 | |||
| 173 | (defun icomplete-backward-completions () | ||
| 174 | "Step backward completions by one entry. | ||
| 175 | Last entry becomes the first and can be selected with | ||
| 176 | `minibuffer-force-complete-and-exit'." | ||
| 177 | (interactive) | ||
| 178 | (let* ((comps (completion-all-sorted-completions)) | ||
| 179 | (last-but-one (last comps 2)) | ||
| 180 | (last (cdr last-but-one))) | ||
| 181 | (when last | ||
| 182 | (setcdr last-but-one (cdr last)) | ||
| 183 | (push (car last) comps) | ||
| 184 | (completion--cache-all-sorted-completions comps)))) | ||
| 185 | |||
| 172 | ;;;_ > icomplete-mode (&optional prefix) | 186 | ;;;_ > icomplete-mode (&optional prefix) |
| 173 | ;;;###autoload | 187 | ;;;###autoload |
| 174 | (define-minor-mode icomplete-mode | 188 | (define-minor-mode icomplete-mode |
| @@ -208,6 +222,8 @@ Conditions are: | |||
| 208 | Usually run by inclusion in `minibuffer-setup-hook'." | 222 | Usually run by inclusion in `minibuffer-setup-hook'." |
| 209 | (when (and icomplete-mode (icomplete-simple-completing-p)) | 223 | (when (and icomplete-mode (icomplete-simple-completing-p)) |
| 210 | (set (make-local-variable 'completion-show-inline-help) nil) | 224 | (set (make-local-variable 'completion-show-inline-help) nil) |
| 225 | (use-local-map (make-composed-keymap icomplete-minibuffer-map | ||
| 226 | (current-local-map))) | ||
| 211 | (add-hook 'pre-command-hook | 227 | (add-hook 'pre-command-hook |
| 212 | (lambda () (let ((non-essential t)) | 228 | (lambda () (let ((non-essential t)) |
| 213 | (run-hooks 'icomplete-pre-command-hook))) | 229 | (run-hooks 'icomplete-pre-command-hook))) |
| @@ -239,27 +255,29 @@ and `minibuffer-setup-hook'." | |||
| 239 | (goto-char (point-max)) | 255 | (goto-char (point-max)) |
| 240 | ; Insert the match-status information: | 256 | ; Insert the match-status information: |
| 241 | (if (and (> (point-max) (minibuffer-prompt-end)) | 257 | (if (and (> (point-max) (minibuffer-prompt-end)) |
| 242 | buffer-undo-list ; Wait for some user input. | 258 | buffer-undo-list ; Wait for some user input. |
| 243 | (or | 259 | (or |
| 244 | ;; Don't bother with delay after certain number of chars: | 260 | ;; Don't bother with delay after certain number of chars: |
| 245 | (> (- (point) (field-beginning)) icomplete-max-delay-chars) | 261 | (> (- (point) (field-beginning)) icomplete-max-delay-chars) |
| 246 | ;; Don't delay if alternatives number is small enough: | 262 | ;; Don't delay if the completions are known. |
| 247 | (and (sequencep minibuffer-completion-table) | 263 | completion-all-sorted-completions |
| 248 | (< (length minibuffer-completion-table) | 264 | ;; Don't delay if alternatives number is small enough: |
| 249 | icomplete-delay-completions-threshold)) | 265 | (and (sequencep minibuffer-completion-table) |
| 250 | ;; Delay - give some grace time for next keystroke, before | 266 | (< (length minibuffer-completion-table) |
| 267 | icomplete-delay-completions-threshold)) | ||
| 268 | ;; Delay - give some grace time for next keystroke, before | ||
| 251 | ;; embarking on computing completions: | 269 | ;; embarking on computing completions: |
| 252 | (sit-for icomplete-compute-delay))) | 270 | (sit-for icomplete-compute-delay))) |
| 253 | (let ((text (while-no-input | 271 | (let ((text (while-no-input |
| 254 | (icomplete-completions | 272 | (icomplete-completions |
| 255 | (field-string) | 273 | (field-string) |
| 256 | minibuffer-completion-table | 274 | minibuffer-completion-table |
| 257 | minibuffer-completion-predicate | 275 | minibuffer-completion-predicate |
| 258 | (not minibuffer-completion-confirm)))) | 276 | (not minibuffer-completion-confirm)))) |
| 259 | (buffer-undo-list t) | 277 | (buffer-undo-list t) |
| 260 | deactivate-mark) | 278 | deactivate-mark) |
| 261 | ;; Do nothing if while-no-input was aborted. | 279 | ;; Do nothing if while-no-input was aborted. |
| 262 | (when (stringp text) | 280 | (when (stringp text) |
| 263 | (move-overlay icomplete-overlay (point) (point) (current-buffer)) | 281 | (move-overlay icomplete-overlay (point) (point) (current-buffer)) |
| 264 | ;; The current C cursor code doesn't know to use the overlay's | 282 | ;; The current C cursor code doesn't know to use the overlay's |
| 265 | ;; marker's stickiness to figure out whether to place the cursor | 283 | ;; marker's stickiness to figure out whether to place the cursor |
| @@ -365,17 +383,14 @@ are exhibited within the square braces.)" | |||
| 365 | (if prospects | 383 | (if prospects |
| 366 | (concat determ | 384 | (concat determ |
| 367 | "{" | 385 | "{" |
| 368 | (and most-is-exact ",") | 386 | (and most-is-exact |
| 369 | (mapconcat 'identity (nreverse prospects) ",") | 387 | (substring icomplete-separator |
| 370 | (and limit ",...") | 388 | (string-match "[^ ]" icomplete-separator))) |
| 389 | (mapconcat 'identity (nreverse prospects) | ||
| 390 | icomplete-separator) | ||
| 391 | (and limit (concat icomplete-separator "…")) | ||
| 371 | "}") | 392 | "}") |
| 372 | (concat determ | 393 | (concat determ " [Matched]")))))) |
| 373 | " [Matched" | ||
| 374 | (let ((keys (and icomplete-show-key-bindings | ||
| 375 | (commandp (intern-soft most)) | ||
| 376 | (icomplete-get-keys most)))) | ||
| 377 | (if keys (concat "; " keys) "")) | ||
| 378 | "]")))))) | ||
| 379 | 394 | ||
| 380 | ;;_* Local emacs vars. | 395 | ;;_* Local emacs vars. |
| 381 | ;;Local variables: | 396 | ;;Local variables: |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 6e704fad807..7fe50e930ce 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -1106,6 +1106,13 @@ scroll the window of possible completions." | |||
| 1106 | (sort-fun (completion-metadata-get all-md 'cycle-sort-function))) | 1106 | (sort-fun (completion-metadata-get all-md 'cycle-sort-function))) |
| 1107 | (when last | 1107 | (when last |
| 1108 | (setcdr last nil) | 1108 | (setcdr last nil) |
| 1109 | |||
| 1110 | ;; Delete duplicates: do it after setting last's cdr to nil (so | ||
| 1111 | ;; it's a proper list), and be careful to reset `last' since it | ||
| 1112 | ;; may be a different cons-cell. | ||
| 1113 | (setq all (delete-dups all)) | ||
| 1114 | (setq last (last all)) | ||
| 1115 | |||
| 1109 | (setq all (if sort-fun (funcall sort-fun all) | 1116 | (setq all (if sort-fun (funcall sort-fun all) |
| 1110 | ;; Prefer shorter completions, by default. | 1117 | ;; Prefer shorter completions, by default. |
| 1111 | (sort all (lambda (c1 c2) (< (length c1) (length c2)))))) | 1118 | (sort all (lambda (c1 c2) (< (length c1) (length c2)))))) |
| @@ -1120,6 +1127,15 @@ scroll the window of possible completions." | |||
| 1120 | ;; all possibilities. | 1127 | ;; all possibilities. |
| 1121 | (completion--cache-all-sorted-completions (nconc all base-size)))))) | 1128 | (completion--cache-all-sorted-completions (nconc all base-size)))))) |
| 1122 | 1129 | ||
| 1130 | (defun minibuffer-force-complete-and-exit () | ||
| 1131 | "Complete the minibuffer with first of the matches and exit." | ||
| 1132 | (interactive) | ||
| 1133 | (minibuffer-force-complete) | ||
| 1134 | (minibuffer--complete-and-exit | ||
| 1135 | ;; If the previous completion completed to an element which fails | ||
| 1136 | ;; test-completion, then we shouldn't exit, but that should be rare. | ||
| 1137 | (lambda () (minibuffer-message "Incomplete")))) | ||
| 1138 | |||
| 1123 | (defun minibuffer-force-complete () | 1139 | (defun minibuffer-force-complete () |
| 1124 | "Complete the minibuffer to an exact match. | 1140 | "Complete the minibuffer to an exact match. |
| 1125 | Repeated uses step through the possible completions." | 1141 | Repeated uses step through the possible completions." |
| @@ -1192,6 +1208,22 @@ If `minibuffer-completion-confirm' is `confirm-after-completion', | |||
| 1192 | `minibuffer-confirm-exit-commands', and accept the input | 1208 | `minibuffer-confirm-exit-commands', and accept the input |
| 1193 | otherwise." | 1209 | otherwise." |
| 1194 | (interactive) | 1210 | (interactive) |
| 1211 | (minibuffer--complete-and-exit | ||
| 1212 | (lambda () | ||
| 1213 | (pcase (condition-case nil | ||
| 1214 | (completion--do-completion nil 'expect-exact) | ||
| 1215 | (error 1)) | ||
| 1216 | ((or #b001 #b011) (exit-minibuffer)) | ||
| 1217 | (#b111 (if (not minibuffer-completion-confirm) | ||
| 1218 | (exit-minibuffer) | ||
| 1219 | (minibuffer-message "Confirm") | ||
| 1220 | nil)) | ||
| 1221 | (_ nil))))) | ||
| 1222 | |||
| 1223 | (defun minibuffer--complete-and-exit (completion-function) | ||
| 1224 | "Exit from `require-match' minibuffer. | ||
| 1225 | COMPLETION-FUNCTION is called if the current buffer's content does not | ||
| 1226 | appear to be a match." | ||
| 1195 | (let ((beg (field-beginning)) | 1227 | (let ((beg (field-beginning)) |
| 1196 | (end (field-end))) | 1228 | (end (field-end))) |
| 1197 | (cond | 1229 | (cond |
| @@ -1239,15 +1271,7 @@ If `minibuffer-completion-confirm' is `confirm-after-completion', | |||
| 1239 | 1271 | ||
| 1240 | (t | 1272 | (t |
| 1241 | ;; Call do-completion, but ignore errors. | 1273 | ;; Call do-completion, but ignore errors. |
| 1242 | (pcase (condition-case nil | 1274 | (funcall completion-function))))) |
| 1243 | (completion--do-completion nil 'expect-exact) | ||
| 1244 | (error 1)) | ||
| 1245 | ((or #b001 #b011) (exit-minibuffer)) | ||
| 1246 | (#b111 (if (not minibuffer-completion-confirm) | ||
| 1247 | (exit-minibuffer) | ||
| 1248 | (minibuffer-message "Confirm") | ||
| 1249 | nil)) | ||
| 1250 | (_ nil)))))) | ||
| 1251 | 1275 | ||
| 1252 | (defun completion--try-word-completion (string table predicate point md) | 1276 | (defun completion--try-word-completion (string table predicate point md) |
| 1253 | (let ((comp (completion-try-completion string table predicate point md))) | 1277 | (let ((comp (completion-try-completion string table predicate point md))) |