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

evil-ex: elisp: eldoc #1410

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions evil-ex.el
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,39 @@ Otherwise behaves like `delete-backward-char'."
(insert result)
(exit-minibuffer))

(defun evil-ex--elisp-p ()
"Check if `evil-ex' is executing an elisp expression."
(string-prefix-p "(" (minibuffer-contents-no-properties)))

(defun evil-ex-elisp-completion-at-point ()
"Complete an `evil-ex' Elisp expression."
(when (and (fboundp 'elisp-completion-at-point)
(evil-ex--elisp-p))
(elisp-completion-at-point)))

(defun evil-ex-elisp-eldoc-function ()
"`eldoc' for `evil-ex' Elisp expressions.
Only provides an `eldoc' hint if the current `evil-ex' command is
an elisp expression."
(when (and (fboundp 'elisp-eldoc-documentation-function)
(evil-ex--elisp-p))
(elisp-eldoc-documentation-function)))

(defmacro evil-ex--eldoc-add (fn)
"Add FN to `eldoc'.
Handles older Emacsen that don't have `add-function'."
(if (fboundp 'add-function)
`(add-function :before-until (local 'eldoc-documentation-function) ,fn)
`(add-to-list (make-local-variable 'eldoc-documentation-functions) ,fn)))

(defmacro evil-ex--eldoc-remove (fn)
"Remove FN from `eldoc'.
See `evil-ex--eldoc-add'. FN must be a symbol."
(if (fboundp 'remove-function)
`(remove-function (local 'eldoc-documentation-function) ,fn)
`(set (make-local-variable 'eldoc-documentation-functions)
(delq ,fn eldoc-documentation-functions))))

(defun evil-ex-setup ()
"Initialize Ex minibuffer.
This function registers several hooks that are used for the
Expand All @@ -239,11 +272,12 @@ interactive actions during ex state."
(when evil-ex-previous-command
(add-hook 'pre-command-hook #'evil-ex-remove-default))
(remove-hook 'minibuffer-setup-hook #'evil-ex-setup)
(with-no-warnings
(make-variable-buffer-local 'completion-at-point-functions))
(setq completion-at-point-functions
'(evil-ex-command-completion-at-point
evil-ex-argument-completion-at-point)))
(set (make-local-variable 'completion-at-point-functions)
'(evil-ex-elisp-completion-at-point
evil-ex-command-completion-at-point
evil-ex-argument-completion-at-point))
(evil-ex--eldoc-add #'evil-ex-elisp-eldoc-function)
(eldoc-mode 1))
(put 'evil-ex-setup 'permanent-local-hook t)

(defun evil-ex-setup-and-update ()
Expand All @@ -261,7 +295,9 @@ Clean up everything set up by `evil-ex-setup'."
(let ((runner (evil-ex-argument-handler-runner
evil-ex-argument-handler)))
(when runner
(funcall runner 'stop)))))
(funcall runner 'stop))))
(evil-ex--eldoc-remove #'evil-ex-elisp-eldoc-function)
(eldoc-mode -1))
(put 'evil-ex-teardown 'permanent-local-hook t)

(defun evil-ex-remove-default ()
Expand Down