summaryrefslogtreecommitdiff
path: root/comb
diff options
context:
space:
mode:
Diffstat (limited to 'comb')
-rw-r--r--comb/orderless-conf.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/comb/orderless-conf.el b/comb/orderless-conf.el
index 2d669a4..a86e40e 100644
--- a/comb/orderless-conf.el
+++ b/comb/orderless-conf.el
@@ -37,3 +37,45 @@
(cond
((= (aref pattern 0) ?,)
(cons 'orderless-strict-leading-initialism (substring pattern 1))))))
+
+
+(defvar durand-headlong-entered-minibuffer-p nil
+ "Whether or not we have entered minibuffer.
+
+This is used for determining if we shall exit the minibuffer when
+there is only one candidate left.")
+
+;;;###autoload
+(defun durand-headlong-minibuffer-setup-hook ()
+ "The entry for the completion to be headlong.
+Simply add this function to `minibuffer-setup-hook'."
+ ;; NOTE: When we run this function we first enter minibuffer, so we
+ ;; set a variable to its appropriate value.
+ (set 'durand-headlong-entered-minibuffer-p nil)
+ (add-hook 'post-command-hook 'durand-headlong-post-command-hook t)
+ (add-hook 'minibuffer-exit-hook 'durand-headlong-minibuffer-exit-hook))
+
+;;;###autoload
+(defun durand-headlong-post-command-hook ()
+ "Exit the minibuffer if there is only one candidate left.
+
+In practice, when we first enter minibuffer, there is some
+abnormal behaviour, so we only check when we have entered the
+minibuffer as usual."
+ (let ((comps (completion-all-completions
+ (minibuffer-contents)
+ minibuffer-completion-table minibuffer-completion-predicate
+ (- (point) (minibuffer-prompt-end)))))
+ (cond
+ ((and durand-headlong-entered-minibuffer-p
+ comps
+ (not (consp (cdr comps))))
+ (minibuffer-force-complete-and-exit))
+ (t (set 'durand-headlong-entered-minibuffer-p t)))))
+
+;;;###autoload
+(defun durand-headlong-minibuffer-exit-hook ()
+ "Remove the hooks we added."
+ (remove-hook 'post-command-hook 'durand-headlong-post-command-hook)
+ (remove-hook 'minibuffer-setup-hook 'durand-headlong-minibuffer-setup-hook)
+ (remove-hook 'minibuffer-exit-hook 'durand-headlong-minibuffer-exit-hook))