aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJoão Távora2019-11-15 20:27:18 +0000
committerJoão Távora2019-11-15 20:27:18 +0000
commit7fea1a3f2656c69f4de99d092680f7a917d8426f (patch)
tree50365d45d9bfd6afe2890146e465106cd52d40aa /lisp
parent87347a5bbc2f044c51feea8d513fb1dcefa6f50e (diff)
downloademacs-7fea1a3f2656c69f4de99d092680f7a917d8426f.tar.gz
emacs-7fea1a3f2656c69f4de99d092680f7a917d8426f.zip
Make icomplete-tidy-shadowed-file-names less aggressive
When using this option and editing input, some transient situations may arise that lead to file-name shadowing, but that shouldn't necessarily lead to auto-delete behaviour, which will be suprising. In '/foo/x/bar', if the user deletes the 'x', shadowing occurs, but probably shouldn't. So, somewhat like ido-mode, only auto-tidy shadowed file names if the user is inserting text at end of input. * lisp/icomplete.el (icomplete-exhibit): Check this-command. (icomplete-tidy-shadowed-file-names): Tweak docstring.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/icomplete.el107
1 files changed, 55 insertions, 52 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index a732d4cc0d1..8410ca5c3e1 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -69,7 +69,7 @@ When nil, show candidates in full."
69 :version "24.4") 69 :version "24.4")
70 70
71(defvar icomplete-tidy-shadowed-file-names nil 71(defvar icomplete-tidy-shadowed-file-names nil
72 "If non-nil, delete superflous parts of input file names. 72 "If non-nil, automatically delete superflous parts of file names.
73For example, if the user types ~/ after a long path name, 73For example, if the user types ~/ after a long path name,
74everything preceding the ~/ is discarded so the interactive 74everything preceding the ~/ is discarded so the interactive
75selection process starts again from the user's $HOME.") 75selection process starts again from the user's $HOME.")
@@ -463,58 +463,61 @@ Should be run via minibuffer `post-command-hook'.
463See `icomplete-mode' and `minibuffer-setup-hook'." 463See `icomplete-mode' and `minibuffer-setup-hook'."
464 (when (and icomplete-mode 464 (when (and icomplete-mode
465 (icomplete-simple-completing-p)) ;Shouldn't be necessary. 465 (icomplete-simple-completing-p)) ;Shouldn't be necessary.
466 (save-excursion 466 (let ((saved-point (point)))
467 (goto-char (point-max)) 467 (save-excursion
468 (goto-char (point-max))
468 ; Insert the match-status information: 469 ; Insert the match-status information:
469 (when (and (or icomplete-show-matches-on-no-input 470 (when (and (or icomplete-show-matches-on-no-input
470 (> (icomplete--field-end) (icomplete--field-beg))) 471 (> (icomplete--field-end) (icomplete--field-beg)))
471 (or 472 (or
472 ;; Don't bother with delay after certain number of chars: 473 ;; Don't bother with delay after certain number of chars:
473 (> (- (point) (icomplete--field-beg)) 474 (> (- (point) (icomplete--field-beg))
474 icomplete-max-delay-chars) 475 icomplete-max-delay-chars)
475 ;; Don't delay if the completions are known. 476 ;; Don't delay if the completions are known.
476 completion-all-sorted-completions 477 completion-all-sorted-completions
477 ;; Don't delay if alternatives number is small enough: 478 ;; Don't delay if alternatives number is small enough:
478 (and (sequencep (icomplete--completion-table)) 479 (and (sequencep (icomplete--completion-table))
479 (< (length (icomplete--completion-table)) 480 (< (length (icomplete--completion-table))
480 icomplete-delay-completions-threshold)) 481 icomplete-delay-completions-threshold))
481 ;; Delay - give some grace time for next keystroke, before 482 ;; Delay - give some grace time for next keystroke, before
482 ;; embarking on computing completions: 483 ;; embarking on computing completions:
483 (sit-for icomplete-compute-delay))) 484 (sit-for icomplete-compute-delay)))
484 (when (and 485 (when (and
485 icomplete-tidy-shadowed-file-names 486 icomplete-tidy-shadowed-file-names
486 (eq (alist-get 'category 487 (eq (alist-get 'category
487 (cdr (completion--field-metadata 488 (cdr (completion--field-metadata
488 (icomplete--field-beg)))) 489 (icomplete--field-beg))))
489 'file) 490 'file)
490 rfn-eshadow-overlay (overlay-buffer rfn-eshadow-overlay) 491 rfn-eshadow-overlay (overlay-buffer rfn-eshadow-overlay)
491 (or (>= (- (point) (overlay-end rfn-eshadow-overlay)) 2) 492 (eq this-command 'self-insert-command)
492 (eq ?/ (char-before (- (point) 2))))) 493 (= saved-point (icomplete--field-end))
493 (delete-region (overlay-start rfn-eshadow-overlay) 494 (or (>= (- (point) (overlay-end rfn-eshadow-overlay)) 2)
494 (overlay-end rfn-eshadow-overlay)) ) 495 (eq ?/ (char-before (- (point) 2)))))
495 (let* ((field-string (icomplete--field-string)) 496 (delete-region (overlay-start rfn-eshadow-overlay)
496 ;; Not sure why, but such requests seem to come 497 (overlay-end rfn-eshadow-overlay)) )
497 ;; every once in a while. It's not fully 498 (let* ((field-string (icomplete--field-string))
498 ;; deterministic but `C-x C-f M-DEL M-DEL ...' 499 ;; Not sure why, but such requests seem to come
499 ;; seems to trigger it fairly often! 500 ;; every once in a while. It's not fully
500 (while-no-input-ignore-events '(selection-request)) 501 ;; deterministic but `C-x C-f M-DEL M-DEL ...'
501 (text (while-no-input 502 ;; seems to trigger it fairly often!
502 (icomplete-completions 503 (while-no-input-ignore-events '(selection-request))
503 field-string 504 (text (while-no-input
504 (icomplete--completion-table) 505 (icomplete-completions
505 (icomplete--completion-predicate) 506 field-string
506 (if (window-minibuffer-p) 507 (icomplete--completion-table)
507 (not minibuffer-completion-confirm))))) 508 (icomplete--completion-predicate)
508 (buffer-undo-list t) 509 (if (window-minibuffer-p)
509 deactivate-mark) 510 (not minibuffer-completion-confirm)))))
510 ;; Do nothing if while-no-input was aborted. 511 (buffer-undo-list t)
511 (when (stringp text) 512 deactivate-mark)
512 (move-overlay icomplete-overlay (point) (point) (current-buffer)) 513 ;; Do nothing if while-no-input was aborted.
513 ;; The current C cursor code doesn't know to use the overlay's 514 (when (stringp text)
514 ;; marker's stickiness to figure out whether to place the cursor 515 (move-overlay icomplete-overlay (point) (point) (current-buffer))
515 ;; before or after the string, so let's spoon-feed it the pos. 516 ;; The current C cursor code doesn't know to use the overlay's
516 (put-text-property 0 1 'cursor t text) 517 ;; marker's stickiness to figure out whether to place the cursor
517 (overlay-put icomplete-overlay 'after-string text))))))) 518 ;; before or after the string, so let's spoon-feed it the pos.
519 (put-text-property 0 1 'cursor t text)
520 (overlay-put icomplete-overlay 'after-string text))))))))
518 521
519;;;_ > icomplete-completions (name candidates predicate require-match) 522;;;_ > icomplete-completions (name candidates predicate require-match)
520(defun icomplete-completions (name candidates predicate require-match) 523(defun icomplete-completions (name candidates predicate require-match)