diff --git a/consult.el b/consult.el index 05508edc..11d7e62b 100644 --- a/consult.el +++ b/consult.el @@ -3080,6 +3080,39 @@ See `consult-grep' for more details regarding the asynchronous search." :add-history (concat consult-async-default-split (thing-at-point 'symbol)) :history '(:input consult--man-history)))) +(defun consult--hippie-expand-completions (&optional hippie-expand-function) + "Return list of completions generated by `hippie-expand'." + (save-excursion + (with-silent-modifications + (let ((this-command 'consult--hippie-expand-completions) + (last-command last-command) + (hippie-expand-function (or hippie-expand-function 'hippie-expand))) + (cl-letf (((symbol-function #'ding) #'ignore) + ((symbol-function #'message) #'ignore)) + (while (progn + (funcall hippie-expand-function nil) + (setq last-command 'consult--hippie-expand-completions) + (not (equal he-num -1))))) + ;; Provide the options in the order in which they are normally generated. + (delete he-search-string (reverse he-tried-table)))))) + +(defun consult--hippie-expand (hippie-expand-function) + "Offer completion using the specified hippie-expand function." + (let* ((options (consult--hippie-expand-completions hippie-expand-function))) + (if options + (progn + (if (> (safe-length options) 1) + (setq selection (completing-read "Completions: " options)) + (setq selection (car options))) + (if selection + (he-substitute-string selection t))) + (message "No expansion found")))) + +(defun consult-hippie () + "Offer completion for the word at point." + (interactive) + (consult--hippie-expand 'hippie-expand)) + ;;;; Integration with the default completion system (defun consult--default-completion-candidate ()