-;;;_ = icomplete-pre-command-hook
-(defvar icomplete-pre-command-hook nil
- "Incremental-minibuffer-completion pre-command-hook.
-
-Is run in minibuffer before user input when `icomplete-mode' is non-nil.
-Use `icomplete-mode' function to set it up properly for incremental
-minibuffer completion.")
-(add-hook 'icomplete-pre-command-hook 'icomplete-tidy)
-;;;_ = icomplete-post-command-hook
-(defvar icomplete-post-command-hook nil
- "Incremental-minibuffer-completion post-command-hook.
-
-Is run in minibuffer after user input when `icomplete-mode' is non-nil.
-Use `icomplete-mode' function to set it up properly for incremental
-minibuffer completion.")
-(add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
-
-(defun icomplete-get-keys (func-name)
- "Return strings naming keys bound to FUNC-NAME, or nil if none.
-Examines the prior, not current, buffer, presuming that current buffer
-is minibuffer."
- (when (commandp func-name)
- (save-excursion
- (let* ((sym (intern func-name))
- (buf (other-buffer nil t))
- (keys (with-current-buffer buf (where-is-internal sym))))
- (when keys
- (concat "<"
- (mapconcat 'key-description
- (sort keys
- #'(lambda (x y)
- (< (length x) (length y))))
- ", ")
- ">"))))))
-;;;_ = icomplete-with-completion-tables
-(defvar icomplete-with-completion-tables '(internal-complete-buffer)
- "Specialized completion tables with which icomplete should operate.
-
-Icomplete does not operate with any specialized completion tables
-except those on this list.")
+(defun icomplete-pre-command-hook ()
+ (let ((non-essential t))
+ (icomplete-tidy)))
+
+(defun icomplete-post-command-hook ()
+ (let ((non-essential t)) ;E.g. don't prompt for password!
+ (icomplete-exhibit)))
+
+(defvar icomplete-minibuffer-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map [?\M-\t] 'minibuffer-force-complete)
+ (define-key map [?\C-j] 'minibuffer-force-complete-and-exit)
+ (define-key map [?\C-.] 'icomplete-forward-completions)
+ (define-key map [?\C-,] 'icomplete-backward-completions)
+ map)
+ "Keymap used by `icomplete-mode' in the minibuffer.")
+
+(defun icomplete-forward-completions ()
+ "Step forward completions by one entry.
+Second entry becomes the first and can be selected with
+`minibuffer-force-complete-and-exit'."
+ (interactive)
+ (let* ((beg (icomplete--field-beg))
+ (end (icomplete--field-end))
+ (comps (completion-all-sorted-completions beg end))
+ (last (last comps)))
+ (when comps
+ (setcdr last (cons (car comps) (cdr last)))
+ (completion--cache-all-sorted-completions beg end (cdr comps)))))
+
+(defun icomplete-backward-completions ()
+ "Step backward completions by one entry.
+Last entry becomes the first and can be selected with
+`minibuffer-force-complete-and-exit'."
+ (interactive)
+ (let* ((beg (icomplete--field-beg))
+ (end (icomplete--field-end))
+ (comps (completion-all-sorted-completions beg end))
+ (last-but-one (last comps 2))
+ (last (cdr last-but-one)))
+ (when (consp last) ; At least two elements in comps
+ (setcdr last-but-one (cdr last))
+ (push (car last) comps)
+ (completion--cache-all-sorted-completions beg end comps))))