diff options
| author | João Távora | 2019-10-31 10:58:38 +0000 |
|---|---|---|
| committer | João Távora | 2019-11-02 02:38:45 +0000 |
| commit | 730e7da7ba6a4b545176ea246653928edb10cff4 (patch) | |
| tree | a59840095ba408f608167c8f3a522690f3aca4e0 | |
| parent | 0bb97ad8b89af91e296ea791f34b46963323ce7a (diff) | |
| download | emacs-730e7da7ba6a4b545176ea246653928edb10cff4.tar.gz emacs-730e7da7ba6a4b545176ea246653928edb10cff4.zip | |
New icomplete-tidy-shadowed-file-names variable
* lisp/icomplete.el (rfn-eshadow): Require it.
(icomplete-tidy-shadowed-file-names): New variable.
(icomplete-exhibit): Use icomplete-tidy-shadowed-file-names.
| -rw-r--r-- | lisp/icomplete.el | 105 |
1 files changed, 66 insertions, 39 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 47e47f895f0..8357fd900f0 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el | |||
| @@ -49,6 +49,8 @@ | |||
| 49 | 49 | ||
| 50 | ;;; Code: | 50 | ;;; Code: |
| 51 | 51 | ||
| 52 | (require 'rfn-eshadow) ; rfn-eshadow-overlay | ||
| 53 | |||
| 52 | (defgroup icomplete nil | 54 | (defgroup icomplete nil |
| 53 | "Show completions dynamically in minibuffer." | 55 | "Show completions dynamically in minibuffer." |
| 54 | :prefix "icomplete-" | 56 | :prefix "icomplete-" |
| @@ -66,6 +68,12 @@ When nil, show candidates in full." | |||
| 66 | :type 'boolean | 68 | :type 'boolean |
| 67 | :version "24.4") | 69 | :version "24.4") |
| 68 | 70 | ||
| 71 | (defvar icomplete-tidy-shadowed-file-names nil | ||
| 72 | "If non-nil, delete superflous parts of input file names. | ||
| 73 | For example, if the user types ~/ after a long path name, | ||
| 74 | everything preceding the ~/ is discarded so the interactive | ||
| 75 | selection process starts again from the user's $HOME.") | ||
| 76 | |||
| 69 | (defcustom icomplete-show-matches-on-no-input nil | 77 | (defcustom icomplete-show-matches-on-no-input nil |
| 70 | "When non-nil, show completions when first prompting for input." | 78 | "When non-nil, show completions when first prompting for input." |
| 71 | :type 'boolean | 79 | :type 'boolean |
| @@ -226,7 +234,11 @@ Last entry becomes the first and can be selected with | |||
| 226 | ;;; (define-key imap (kbd "C-d") 'icomplete-magic-ido-delete-char) | 234 | ;;; (define-key imap (kbd "C-d") 'icomplete-magic-ido-delete-char) |
| 227 | ;;; (define-key imap (kbd "RET") 'icomplete-magic-ido-ret) | 235 | ;;; (define-key imap (kbd "RET") 'icomplete-magic-ido-ret) |
| 228 | ;;; (define-key imap (kbd "DEL") 'icomplete-magic-ido-backward-updir)) | 236 | ;;; (define-key imap (kbd "DEL") 'icomplete-magic-ido-backward-updir)) |
| 229 | 237 | ;;; | |
| 238 | ;;; For more ido behaviour, you'll probably like this too: | ||
| 239 | ;;; | ||
| 240 | ;;; (setq icomplete-tidy-shadowed-file-names t) | ||
| 241 | ;;; | ||
| 230 | (defun icomplete-magic-ido-kill () | 242 | (defun icomplete-magic-ido-kill () |
| 231 | "Kill line or current completion, like `ido-mode'. | 243 | "Kill line or current completion, like `ido-mode'. |
| 232 | If killing to the end of line make sense, call `kill-line', | 244 | If killing to the end of line make sense, call `kill-line', |
| @@ -422,44 +434,59 @@ See `icomplete-mode' and `minibuffer-setup-hook'." | |||
| 422 | (save-excursion | 434 | (save-excursion |
| 423 | (goto-char (point-max)) | 435 | (goto-char (point-max)) |
| 424 | ; Insert the match-status information: | 436 | ; Insert the match-status information: |
| 425 | (if (and (or icomplete-show-matches-on-no-input | 437 | (when (and (or icomplete-show-matches-on-no-input |
| 426 | (> (icomplete--field-end) (icomplete--field-beg))) | 438 | (> (icomplete--field-end) (icomplete--field-beg))) |
| 427 | (or | 439 | (or |
| 428 | ;; Don't bother with delay after certain number of chars: | 440 | ;; Don't bother with delay after certain number of chars: |
| 429 | (> (- (point) (icomplete--field-beg)) | 441 | (> (- (point) (icomplete--field-beg)) |
| 430 | icomplete-max-delay-chars) | 442 | icomplete-max-delay-chars) |
| 431 | ;; Don't delay if the completions are known. | 443 | ;; Don't delay if the completions are known. |
| 432 | completion-all-sorted-completions | 444 | completion-all-sorted-completions |
| 433 | ;; Don't delay if alternatives number is small enough: | 445 | ;; Don't delay if alternatives number is small enough: |
| 434 | (and (sequencep (icomplete--completion-table)) | 446 | ;; Not sure why, but such requests seem to come |
| 435 | (< (length (icomplete--completion-table)) | 447 | ;; every once in a while. It's not fully |
| 436 | icomplete-delay-completions-threshold)) | 448 | ;; deterministic but `C-x C-f M-DEL M-DEL ...' |
| 437 | ;; Delay - give some grace time for next keystroke, before | 449 | ;; seems to trigger it fairly often! |
| 438 | ;; embarking on computing completions: | 450 | (while-no-input-ignore-events '(selection-request)) (and (sequencep (icomplete--completion-table)) |
| 439 | (sit-for icomplete-compute-delay))) | 451 | (< (length (icomplete--completion-table)) |
| 440 | (let* ((field-string (icomplete--field-string)) | 452 | icomplete-delay-completions-threshold)) |
| 441 | ;; Not sure why, but such requests seem to come | 453 | ;; Delay - give some grace time for next keystroke, before |
| 442 | ;; every once in a while. It's not fully | 454 | ;; embarking on computing completions: |
| 443 | ;; deterministic but `C-x C-f M-DEL M-DEL ...' | 455 | (sit-for icomplete-compute-delay))) |
| 444 | ;; seems to trigger it fairly often! | 456 | (when (and |
| 445 | (while-no-input-ignore-events '(selection-request)) | 457 | icomplete-tidy-shadowed-file-names |
| 446 | (text (while-no-input | 458 | (eq (alist-get 'category |
| 447 | (icomplete-completions | 459 | (cdr (completion--field-metadata |
| 448 | field-string | 460 | (icomplete--field-beg)))) |
| 449 | (icomplete--completion-table) | 461 | 'file) |
| 450 | (icomplete--completion-predicate) | 462 | rfn-eshadow-overlay (overlay-buffer rfn-eshadow-overlay) |
| 451 | (if (window-minibuffer-p) | 463 | (or (>= (- (point) (overlay-end rfn-eshadow-overlay)) 2) |
| 452 | (not minibuffer-completion-confirm))))) | 464 | (eq ?/ (char-before (- (point) 2))))) |
| 453 | (buffer-undo-list t) | 465 | (delete-region (overlay-start rfn-eshadow-overlay) |
| 454 | deactivate-mark) | 466 | (overlay-end rfn-eshadow-overlay)) ) |
| 455 | ;; Do nothing if while-no-input was aborted. | 467 | (let* ((field-string (icomplete--field-string)) |
| 456 | (when (stringp text) | 468 | ;; Not sure why, but such requests seem to come |
| 457 | (move-overlay icomplete-overlay (point) (point) (current-buffer)) | 469 | ;; every once in a while. It's not fully |
| 458 | ;; The current C cursor code doesn't know to use the overlay's | 470 | ;; deterministic but `C-x C-f M-DEL M-DEL ...' |
| 459 | ;; marker's stickiness to figure out whether to place the cursor | 471 | ;; seems to trigger it fairly often! |
| 460 | ;; before or after the string, so let's spoon-feed it the pos. | 472 | (while-no-input-ignore-events '(selection-request)) |
| 461 | (put-text-property 0 1 'cursor t text) | 473 | (text (while-no-input |
| 462 | (overlay-put icomplete-overlay 'after-string text))))))) | 474 | (icomplete-completions |
| 475 | field-string | ||
| 476 | (icomplete--completion-table) | ||
| 477 | (icomplete--completion-predicate) | ||
| 478 | (if (window-minibuffer-p) | ||
| 479 | (not minibuffer-completion-confirm))))) | ||
| 480 | (buffer-undo-list t) | ||
| 481 | deactivate-mark) | ||
| 482 | ;; Do nothing if while-no-input was aborted. | ||
| 483 | (when (stringp text) | ||
| 484 | (move-overlay icomplete-overlay (point) (point) (current-buffer)) | ||
| 485 | ;; The current C cursor code doesn't know to use the overlay's | ||
| 486 | ;; marker's stickiness to figure out whether to place the cursor | ||
| 487 | ;; before or after the string, so let's spoon-feed it the pos. | ||
| 488 | (put-text-property 0 1 'cursor t text) | ||
| 489 | (overlay-put icomplete-overlay 'after-string text))))))) | ||
| 463 | 490 | ||
| 464 | ;;;_ > icomplete-completions (name candidates predicate require-match) | 491 | ;;;_ > icomplete-completions (name candidates predicate require-match) |
| 465 | (defun icomplete-completions (name candidates predicate require-match) | 492 | (defun icomplete-completions (name candidates predicate require-match) |