: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.")
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)