emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7fea1a3: Make icomplete-tidy-shadowed-file-names less aggressive


From: Joo Tvora
Subject: master 7fea1a3: Make icomplete-tidy-shadowed-file-names less aggressive
Date: Fri, 15 Nov 2019 15:31:43 -0500 (EST)

branch: master
commit 7fea1a3f2656c69f4de99d092680f7a917d8426f
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    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.
---
 lisp/icomplete.el | 107 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 55 insertions(+), 52 deletions(-)

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index a732d4c..8410ca5 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -69,7 +69,7 @@ When nil, show candidates in full."
   :version "24.4")
 
 (defvar icomplete-tidy-shadowed-file-names nil
-  "If non-nil, delete superflous parts of input file names.
+  "If non-nil, automatically delete superflous parts of file names.
 For example, if the user types ~/ after a long path name,
 everything preceding the ~/ is discarded so the interactive
 selection process starts again from the user's $HOME.")
@@ -463,58 +463,61 @@ Should be run via minibuffer `post-command-hook'.
 See `icomplete-mode' and `minibuffer-setup-hook'."
   (when (and icomplete-mode
              (icomplete-simple-completing-p)) ;Shouldn't be necessary.
-    (save-excursion
-      (goto-char (point-max))
+    (let ((saved-point (point)))
+      (save-excursion
+        (goto-char (point-max))
                                         ; Insert the match-status information:
-      (when (and (or icomplete-show-matches-on-no-input
-                     (> (icomplete--field-end) (icomplete--field-beg)))
-                 (or
-                  ;; Don't bother with delay after certain number of chars:
-                  (> (- (point) (icomplete--field-beg))
-                     icomplete-max-delay-chars)
-                  ;; Don't delay if the completions are known.
-                  completion-all-sorted-completions
-                  ;; Don't delay if alternatives number is small enough:
-                  (and (sequencep (icomplete--completion-table))
-                       (< (length (icomplete--completion-table))
-                          icomplete-delay-completions-threshold))
-                  ;; Delay - give some grace time for next keystroke, before
-                 ;; embarking on computing completions:
-                 (sit-for icomplete-compute-delay)))
-        (when (and
-               icomplete-tidy-shadowed-file-names
-               (eq (alist-get 'category
-                              (cdr (completion--field-metadata
-                                    (icomplete--field-beg))))
-                   'file)
-               rfn-eshadow-overlay (overlay-buffer rfn-eshadow-overlay)
-               (or (>= (- (point) (overlay-end rfn-eshadow-overlay)) 2)
-                   (eq ?/ (char-before (- (point) 2)))))
-          (delete-region (overlay-start rfn-eshadow-overlay)
-                         (overlay-end rfn-eshadow-overlay)) )
-       (let* ((field-string (icomplete--field-string))
-               ;; Not sure why, but such requests seem to come
-               ;; every once in a while.  It's not fully
-               ;; deterministic but `C-x C-f M-DEL M-DEL ...'
-               ;; seems to trigger it fairly often!
-               (while-no-input-ignore-events '(selection-request))
-               (text (while-no-input
-                       (icomplete-completions
-                        field-string
-                        (icomplete--completion-table)
-                        (icomplete--completion-predicate)
-                        (if (window-minibuffer-p)
-                            (not minibuffer-completion-confirm)))))
-               (buffer-undo-list t)
-               deactivate-mark)
-         ;; Do nothing if while-no-input was aborted.
-          (when (stringp text)
-            (move-overlay icomplete-overlay (point) (point) (current-buffer))
-            ;; The current C cursor code doesn't know to use the overlay's
-            ;; marker's stickiness to figure out whether to place the cursor
-            ;; before or after the string, so let's spoon-feed it the pos.
-            (put-text-property 0 1 'cursor t text)
-            (overlay-put icomplete-overlay 'after-string text)))))))
+        (when (and (or icomplete-show-matches-on-no-input
+                       (> (icomplete--field-end) (icomplete--field-beg)))
+                   (or
+                    ;; Don't bother with delay after certain number of chars:
+                    (> (- (point) (icomplete--field-beg))
+                       icomplete-max-delay-chars)
+                    ;; Don't delay if the completions are known.
+                    completion-all-sorted-completions
+                    ;; Don't delay if alternatives number is small enough:
+                    (and (sequencep (icomplete--completion-table))
+                         (< (length (icomplete--completion-table))
+                            icomplete-delay-completions-threshold))
+                    ;; Delay - give some grace time for next keystroke, before
+                    ;; embarking on computing completions:
+                    (sit-for icomplete-compute-delay)))
+          (when (and
+                 icomplete-tidy-shadowed-file-names
+                 (eq (alist-get 'category
+                                (cdr (completion--field-metadata
+                                      (icomplete--field-beg))))
+                     'file)
+                 rfn-eshadow-overlay (overlay-buffer rfn-eshadow-overlay)
+                 (eq this-command 'self-insert-command)
+                 (= saved-point (icomplete--field-end))
+                 (or (>= (- (point) (overlay-end rfn-eshadow-overlay)) 2)
+                     (eq ?/ (char-before (- (point) 2)))))
+            (delete-region (overlay-start rfn-eshadow-overlay)
+                           (overlay-end rfn-eshadow-overlay)) )
+          (let* ((field-string (icomplete--field-string))
+                 ;; Not sure why, but such requests seem to come
+                 ;; every once in a while.  It's not fully
+                 ;; deterministic but `C-x C-f M-DEL M-DEL ...'
+                 ;; seems to trigger it fairly often!
+                 (while-no-input-ignore-events '(selection-request))
+                 (text (while-no-input
+                         (icomplete-completions
+                          field-string
+                          (icomplete--completion-table)
+                          (icomplete--completion-predicate)
+                          (if (window-minibuffer-p)
+                              (not minibuffer-completion-confirm)))))
+                 (buffer-undo-list t)
+                 deactivate-mark)
+            ;; Do nothing if while-no-input was aborted.
+            (when (stringp text)
+              (move-overlay icomplete-overlay (point) (point) (current-buffer))
+              ;; The current C cursor code doesn't know to use the overlay's
+              ;; marker's stickiness to figure out whether to place the cursor
+              ;; before or after the string, so let's spoon-feed it the pos.
+              (put-text-property 0 1 'cursor t text)
+              (overlay-put icomplete-overlay 'after-string text))))))))
 
 ;;;_ > icomplete-completions (name candidates predicate require-match)
 (defun icomplete-completions (name candidates predicate require-match)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]