diff options
| author | Stefan Monnier | 2009-09-01 19:49:34 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-09-01 19:49:34 +0000 |
| commit | fcb68f70a4a3e003f543dd44cad370743f41fbbb (patch) | |
| tree | 756e8b6c58f288a39fbcb084f25bff6200b431c4 | |
| parent | 0142e36b61fc557fd3536e15e34518facc70ad94 (diff) | |
| download | emacs-fcb68f70a4a3e003f543dd44cad370743f41fbbb.tar.gz emacs-fcb68f70a4a3e003f543dd44cad370743f41fbbb.zip | |
(completion-try-completion, completion-all-completions):
Remove ill-defined (and mistakenly installed and luckily never used nor
documented) `completion-styles' property.
(completion-initials-expand, completion-initials-all-completions)
(completion-initials-try-completion): New functions.
(completion-styles-alist): Add doc to each entry.
Add new `initials' entry.
| -rw-r--r-- | etc/NEWS | 2 | ||||
| -rw-r--r-- | lisp/ChangeLog | 11 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 103 |
3 files changed, 83 insertions, 33 deletions
| @@ -34,6 +34,8 @@ This might not work on all platforms. | |||
| 34 | 34 | ||
| 35 | * Changes in Emacs 23.2 | 35 | * Changes in Emacs 23.2 |
| 36 | 36 | ||
| 37 | ** New completion-style `initials' to complete M-x lch to list-command-history. | ||
| 38 | |||
| 37 | ** Unibyte sessions are declared obsolete. | 39 | ** Unibyte sessions are declared obsolete. |
| 38 | I.e. the use of the environment variable EMACS_UNIBYTE, or command line | 40 | I.e. the use of the environment variable EMACS_UNIBYTE, or command line |
| 39 | arguments --unibyte, --multibyte, --no-multibyte, and --no-unibyte | 41 | arguments --unibyte, --multibyte, --no-multibyte, and --no-unibyte |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a7c9a5695ec..54a86f560b1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2009-09-01 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * minibuffer.el (completion-try-completion) | ||
| 4 | (completion-all-completions): Remove ill-defined (and | ||
| 5 | mistakenly installed and luckily never used nor documented) | ||
| 6 | `completion-styles' property. | ||
| 7 | (completion-initials-expand, completion-initials-all-completions) | ||
| 8 | (completion-initials-try-completion): New functions. | ||
| 9 | (completion-styles-alist): Add doc to each entry. | ||
| 10 | Add new `initials' entry. | ||
| 11 | |||
| 1 | 2009-09-01 Nick Roberts <nickrob@snap.net.nz> | 12 | 2009-09-01 Nick Roberts <nickrob@snap.net.nz> |
| 2 | 13 | ||
| 3 | * progmodes/gdb-mi.el (gdb-var-create-handler): Remove redundant | 14 | * progmodes/gdb-mi.el (gdb-var-create-handler): Remove redundant |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 5ab3e412232..ec1e1ddd37b 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -315,16 +315,33 @@ the second failed attempt to complete." | |||
| 315 | :group 'minibuffer) | 315 | :group 'minibuffer) |
| 316 | 316 | ||
| 317 | (defvar completion-styles-alist | 317 | (defvar completion-styles-alist |
| 318 | '((basic completion-basic-try-completion completion-basic-all-completions) | 318 | '((emacs21 |
| 319 | (emacs22 completion-emacs22-try-completion completion-emacs22-all-completions) | 319 | completion-emacs21-try-completion completion-emacs21-all-completions |
| 320 | (emacs21 completion-emacs21-try-completion completion-emacs21-all-completions) | 320 | "Simple prefix-based completion.") |
| 321 | (emacs22 | ||
| 322 | completion-emacs22-try-completion completion-emacs22-all-completions | ||
| 323 | "Prefix completion that only operates on the text before point.") | ||
| 324 | (basic | ||
| 325 | completion-basic-try-completion completion-basic-all-completions | ||
| 326 | "Completion of the prefix before point and the suffix after point.") | ||
| 321 | (partial-completion | 327 | (partial-completion |
| 322 | completion-pcm-try-completion completion-pcm-all-completions)) | 328 | completion-pcm-try-completion completion-pcm-all-completions |
| 329 | "Completion of multiple words, each one taken as a prefix. | ||
| 330 | E.g. M-x l-c-h can complete to list-command-history | ||
| 331 | and C-x C-f /u/m/s to /usr/monnier/src.") | ||
| 332 | (initials | ||
| 333 | completion-initials-try-completion completion-initials-all-completions | ||
| 334 | "Completion of acronyms and initialisms. | ||
| 335 | E.g. can complete M-x lch to list-command-history | ||
| 336 | and C-x C-f ~/sew to ~/src/emacs/work.")) | ||
| 323 | "List of available completion styles. | 337 | "List of available completion styles. |
| 324 | Each element has the form (NAME TRY-COMPLETION ALL-COMPLETIONS) | 338 | Each element has the form (NAME TRY-COMPLETION ALL-COMPLETIONS DOC): |
| 325 | where NAME is the name that should be used in `completion-styles', | 339 | where NAME is the name that should be used in `completion-styles', |
| 326 | TRY-COMPLETION is the function that does the completion, and | 340 | TRY-COMPLETION is the function that does the completion (it should |
| 327 | ALL-COMPLETIONS is the function that lists the completions.") | 341 | follow the same calling convention as `completion-try-completion'), |
| 342 | ALL-COMPLETIONS is the function that lists the completions (it should | ||
| 343 | follow the calling convention of `completion-all-completions'), | ||
| 344 | and DOC describes the way this style of completion works.") | ||
| 328 | 345 | ||
| 329 | (defcustom completion-styles '(basic partial-completion emacs22) | 346 | (defcustom completion-styles '(basic partial-completion emacs22) |
| 330 | "List of completion styles to use. | 347 | "List of completion styles to use. |
| @@ -342,19 +359,10 @@ The return value can be either nil to indicate that there is no completion, | |||
| 342 | t to indicate that STRING is the only possible completion, | 359 | t to indicate that STRING is the only possible completion, |
| 343 | or a pair (STRING . NEWPOINT) of the completed result string together with | 360 | or a pair (STRING . NEWPOINT) of the completed result string together with |
| 344 | a new position for point." | 361 | a new position for point." |
| 345 | ;; The property `completion-styles' indicates that this functional | 362 | (completion--some (lambda (style) |
| 346 | ;; completion-table claims to take care of completion styles itself. | 363 | (funcall (nth 1 (assq style completion-styles-alist)) |
| 347 | ;; [I.e. It will most likely call us back at some point. ] | 364 | string table pred point)) |
| 348 | (if (and (symbolp table) (get table 'completion-styles)) | 365 | completion-styles)) |
| 349 | ;; Extended semantics for functional completion-tables: | ||
| 350 | ;; They accept a 4th argument `point' and when called with action=nil | ||
| 351 | ;; and this 4th argument (a position inside `string'), they should | ||
| 352 | ;; return instead of a string a pair (STRING . NEWPOINT). | ||
| 353 | (funcall table string pred nil point) | ||
| 354 | (completion--some (lambda (style) | ||
| 355 | (funcall (nth 1 (assq style completion-styles-alist)) | ||
| 356 | string table pred point)) | ||
| 357 | completion-styles))) | ||
| 358 | 366 | ||
| 359 | (defun completion-all-completions (string table pred point) | 367 | (defun completion-all-completions (string table pred point) |
| 360 | "List the possible completions of STRING in completion table TABLE. | 368 | "List the possible completions of STRING in completion table TABLE. |
| @@ -364,19 +372,10 @@ The return value is a list of completions and may contain the base-size | |||
| 364 | in the last `cdr'." | 372 | in the last `cdr'." |
| 365 | ;; FIXME: We need to additionally return completion-extra-size (similar | 373 | ;; FIXME: We need to additionally return completion-extra-size (similar |
| 366 | ;; to completion-base-size but for the text after point). | 374 | ;; to completion-base-size but for the text after point). |
| 367 | ;; The property `completion-styles' indicates that this functional | 375 | (completion--some (lambda (style) |
| 368 | ;; completion-table claims to take care of completion styles itself. | 376 | (funcall (nth 2 (assq style completion-styles-alist)) |
| 369 | ;; [I.e. It will most likely call us back at some point. ] | 377 | string table pred point)) |
| 370 | (if (and (symbolp table) (get table 'completion-styles)) | 378 | completion-styles)) |
| 371 | ;; Extended semantics for functional completion-tables: | ||
| 372 | ;; They accept a 4th argument `point' and when called with action=t | ||
| 373 | ;; and this 4th argument (a position inside `string'), they may | ||
| 374 | ;; return BASE-SIZE in the last `cdr'. | ||
| 375 | (funcall table string pred t point) | ||
| 376 | (completion--some (lambda (style) | ||
| 377 | (funcall (nth 2 (assq style completion-styles-alist)) | ||
| 378 | string table pred point)) | ||
| 379 | completion-styles))) | ||
| 380 | 379 | ||
| 381 | (defun minibuffer--bitset (modified completions exact) | 380 | (defun minibuffer--bitset (modified completions exact) |
| 382 | (logior (if modified 4 0) | 381 | (logior (if modified 4 0) |
| @@ -1769,6 +1768,44 @@ filter out additional entries (because TABLE migth not obey PRED)." | |||
| 1769 | 'completion-pcm--filename-try-filter)) | 1768 | 'completion-pcm--filename-try-filter)) |
| 1770 | (completion-pcm--merge-try pattern all prefix suffix))) | 1769 | (completion-pcm--merge-try pattern all prefix suffix))) |
| 1771 | 1770 | ||
| 1771 | ;;; Initials completion | ||
| 1772 | ;; Complete /ums to /usr/monnier/src or lch to list-command-history. | ||
| 1773 | |||
| 1774 | (defun completion-initials-expand (str table pred) | ||
| 1775 | (unless (or (zerop (length str)) | ||
| 1776 | (string-match completion-pcm--delim-wild-regex string)) | ||
| 1777 | (let ((bounds (completion-boundaries str table pred ""))) | ||
| 1778 | (if (zerop (car bounds)) | ||
| 1779 | (mapconcat 'string str "-") | ||
| 1780 | ;; If there's a boundary, it's trickier. The main use-case | ||
| 1781 | ;; we consider here is file-name completion. We'd like | ||
| 1782 | ;; to expand ~/eee to ~/e/e/e and /eee to /e/e/e. | ||
| 1783 | ;; But at the same time, we don't want /usr/share/ae to expand | ||
| 1784 | ;; to /usr/share/a/e just because we mistyped "ae" for "ar", | ||
| 1785 | ;; so we probably don't want initials to touch anything that | ||
| 1786 | ;; looks like /usr/share/foo. As a heuristic, we just check that | ||
| 1787 | ;; the text before the boundary char is at most 1 char. | ||
| 1788 | ;; This allows both ~/eee and /eee and not much more. | ||
| 1789 | ;; FIXME: It sadly also disallows the use of ~/eee when that's | ||
| 1790 | ;; embedded within something else (e.g. "(~/eee" in Info node | ||
| 1791 | ;; completion or "ancestor:/eee" in bzr-revision completion). | ||
| 1792 | (when (< (car bounds) 3) | ||
| 1793 | (let ((sep (substring str (1- (car bounds)) (car bounds)))) | ||
| 1794 | ;; FIXME: the above string-match checks the whole string, whereas | ||
| 1795 | ;; we end up only caring about the after-boundary part. | ||
| 1796 | (concat (substring str 0 (car bounds)) | ||
| 1797 | (mapconcat 'string (substring str (car bounds)) sep)))))))) | ||
| 1798 | |||
| 1799 | (defun completion-initials-all-completions (string table pred point) | ||
| 1800 | (let ((newstr (completion-initials-expand string table pred))) | ||
| 1801 | (when newstr | ||
| 1802 | (completion-pcm-all-completions newstr table pred (length newstr))))) | ||
| 1803 | |||
| 1804 | (defun completion-initials-try-completion (string table pred point) | ||
| 1805 | (let ((newstr (completion-initials-expand string table pred))) | ||
| 1806 | (when newstr | ||
| 1807 | (completion-pcm-try-completion newstr table pred (length newstr))))) | ||
| 1808 | |||
| 1772 | 1809 | ||
| 1773 | (provide 'minibuffer) | 1810 | (provide 'minibuffer) |
| 1774 | 1811 | ||