Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft: consult-hippie #175

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions consult.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down