diff options
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/icomplete.el | 63 |
2 files changed, 55 insertions, 15 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f104a4dfe3a..4976d5b9410 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2013-02-13 Jambunathan K <kjambunathan@gmail.com> | ||
| 2 | |||
| 3 | * icomplete.el (icomplete-hide-common-prefix): New user option. | ||
| 4 | (icomplete-first-match): New face. | ||
| 5 | (icomplete-completions): Correct handling of "complete but not | ||
| 6 | unique" (Bug#12638). | ||
| 7 | |||
| 1 | 2013-02-13 YE Qianchuan <stool.ye@gmail.com> (tiny change) | 8 | 2013-02-13 YE Qianchuan <stool.ye@gmail.com> (tiny change) |
| 2 | 9 | ||
| 3 | * descr-text.el (describe-char): Display the script (bug#13698). | 10 | * descr-text.el (describe-char): Display the script (bug#13698). |
diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 8e4dd69e199..1f9b4a3afe6 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el | |||
| @@ -76,6 +76,18 @@ | |||
| 76 | :type 'string | 76 | :type 'string |
| 77 | :version "24.4") | 77 | :version "24.4") |
| 78 | 78 | ||
| 79 | (defcustom icomplete-hide-common-prefix t | ||
| 80 | "When non-nil, hide common prefix from completion candidates. | ||
| 81 | When nil, show candidates in full." | ||
| 82 | :type 'boolean | ||
| 83 | :version "24.4" | ||
| 84 | :group 'icomplete) | ||
| 85 | |||
| 86 | (defface icomplete-first-match '((t :weight bold)) | ||
| 87 | "Face used by icomplete for highlighting first match." | ||
| 88 | :version "24.4" | ||
| 89 | :group 'icomplete) | ||
| 90 | |||
| 79 | ;;;_* User Customization variables | 91 | ;;;_* User Customization variables |
| 80 | (defcustom icomplete-prospects-height | 92 | (defcustom icomplete-prospects-height |
| 81 | ;; 20 is an estimated common size for the prompt + minibuffer content, to | 93 | ;; 20 is an estimated common size for the prompt + minibuffer content, to |
| @@ -344,7 +356,8 @@ are exhibited within the square braces.)" | |||
| 344 | (t (concat "…" (substring most compare)))) | 356 | (t (concat "…" (substring most compare)))) |
| 345 | close-bracket))) | 357 | close-bracket))) |
| 346 | ;;"-prospects" - more than one candidate | 358 | ;;"-prospects" - more than one candidate |
| 347 | (prospects-len (+ (length determ) | 359 | (prospects-len (+ (string-width |
| 360 | (or determ (concat open-bracket close-bracket))) | ||
| 348 | (string-width icomplete-separator) | 361 | (string-width icomplete-separator) |
| 349 | 3 ;; take {…} into account | 362 | 3 ;; take {…} into account |
| 350 | (string-width (buffer-string)))) | 363 | (string-width (buffer-string)))) |
| @@ -355,6 +368,8 @@ are exhibited within the square braces.)" | |||
| 355 | ;; one line, increase the allowable space accordingly. | 368 | ;; one line, increase the allowable space accordingly. |
| 356 | (/ prospects-len (window-width))) | 369 | (/ prospects-len (window-width))) |
| 357 | (window-width))) | 370 | (window-width))) |
| 371 | (prefix (when icomplete-hide-common-prefix | ||
| 372 | (try-completion "" comps))) | ||
| 358 | (prefix-len | 373 | (prefix-len |
| 359 | ;; Find the common prefix among `comps'. | 374 | ;; Find the common prefix among `comps'. |
| 360 | ;; We can't use the optimization below because its assumptions | 375 | ;; We can't use the optimization below because its assumptions |
| @@ -364,37 +379,55 @@ are exhibited within the square braces.)" | |||
| 364 | ;; ;; Common case. | 379 | ;; ;; Common case. |
| 365 | ;; (length most) | 380 | ;; (length most) |
| 366 | ;; Else, use try-completion. | 381 | ;; Else, use try-completion. |
| 367 | (let ((comps-prefix (try-completion "" comps))) | 382 | (and (stringp prefix) (length prefix))) ;;) |
| 368 | (and (stringp comps-prefix) | 383 | prospects comp limit) |
| 369 | (length comps-prefix)))) ;;) | ||
| 370 | |||
| 371 | prospects most-is-exact comp limit) | ||
| 372 | (if (eq most-try t) ;; (or (null (cdr comps)) | 384 | (if (eq most-try t) ;; (or (null (cdr comps)) |
| 373 | (setq prospects nil) | 385 | (setq prospects nil) |
| 386 | (when (member name comps) | ||
| 387 | ;; NAME is complete but not unique. This scenario poses | ||
| 388 | ;; following UI issues: | ||
| 389 | ;; | ||
| 390 | ;; - When `icomplete-hide-common-prefix' is non-nil, NAME | ||
| 391 | ;; is stripped empty. This would make the entry | ||
| 392 | ;; inconspicuous. | ||
| 393 | ;; | ||
| 394 | ;; - Due to sorting of completions, NAME may not be the | ||
| 395 | ;; first of the prospects and could be hidden deep in | ||
| 396 | ;; the displayed string. | ||
| 397 | ;; | ||
| 398 | ;; - Because of `icomplete-prospects-height' , NAME may | ||
| 399 | ;; not even be displayed to the user. | ||
| 400 | ;; | ||
| 401 | ;; To circumvent all the above problems, provide a visual | ||
| 402 | ;; cue to the user via an "empty string" in the try | ||
| 403 | ;; completion field. | ||
| 404 | (setq determ (concat open-bracket "" close-bracket))) | ||
| 405 | ;; Compute prospects for display. | ||
| 374 | (while (and comps (not limit)) | 406 | (while (and comps (not limit)) |
| 375 | (setq comp | 407 | (setq comp |
| 376 | (if prefix-len (substring (car comps) prefix-len) (car comps)) | 408 | (if prefix-len (substring (car comps) prefix-len) (car comps)) |
| 377 | comps (cdr comps)) | 409 | comps (cdr comps)) |
| 378 | (cond ((string-equal comp "") (setq most-is-exact t)) | 410 | (setq prospects-len |
| 379 | ((member comp prospects)) | ||
| 380 | (t (setq prospects-len | ||
| 381 | (+ (string-width comp) | 411 | (+ (string-width comp) |
| 382 | (string-width icomplete-separator) | 412 | (string-width icomplete-separator) |
| 383 | prospects-len)) | 413 | prospects-len)) |
| 384 | (if (< prospects-len prospects-max) | 414 | (if (< prospects-len prospects-max) |
| 385 | (push comp prospects) | 415 | (push comp prospects) |
| 386 | (setq limit t)))))) | 416 | (setq limit t)))) |
| 417 | (setq prospects (nreverse prospects)) | ||
| 418 | ;; Decorate first of the prospects. | ||
| 419 | (when prospects | ||
| 420 | (let ((first (copy-sequence (pop prospects)))) | ||
| 421 | (put-text-property 0 (length first) | ||
| 422 | 'face 'icomplete-first-match first) | ||
| 423 | (push first prospects))) | ||
| 387 | ;; Restore the base-size info, since completion-all-sorted-completions | 424 | ;; Restore the base-size info, since completion-all-sorted-completions |
| 388 | ;; is cached. | 425 | ;; is cached. |
| 389 | (if last (setcdr last base-size)) | 426 | (if last (setcdr last base-size)) |
| 390 | (if prospects | 427 | (if prospects |
| 391 | (concat determ | 428 | (concat determ |
| 392 | "{" | 429 | "{" |
| 393 | (and most-is-exact | 430 | (mapconcat 'identity prospects icomplete-separator) |
| 394 | (substring icomplete-separator | ||
| 395 | (string-match "[^ ]" icomplete-separator))) | ||
| 396 | (mapconcat 'identity (nreverse prospects) | ||
| 397 | icomplete-separator) | ||
| 398 | (and limit (concat icomplete-separator "…")) | 431 | (and limit (concat icomplete-separator "…")) |
| 399 | "}") | 432 | "}") |
| 400 | (concat determ " [Matched]")))))) | 433 | (concat determ " [Matched]")))))) |