From e98b4b8517b786ee3e5d4086d6b3017a23d7d2cc Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Wed, 23 Sep 2020 00:05:14 -0700 Subject: WIP: more specific symbol extraction Based on #235 and #163. --- helpful.el | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/helpful.el b/helpful.el index 322754f..bc4ea24 100644 --- a/helpful.el +++ b/helpful.el @@ -2688,11 +2688,36 @@ See also `helpful-callable' and `helpful-variable'." (funcall helpful-switch-buffer-function (helpful--buffer symbol nil)) (helpful-update)) +(defun helpful--variable-at-point () + (let ((var (variable-at-point))) + (when (helpful--variable-p var) + var))) + +(defun helpful--function-at-point () + (let ((sym (symbol-at-point)) + (enclosing-sym (function-called-at-point))) + (if (fboundp sym) + sym + enclosing-sym))) + +(defun helpful--symbol-at-point () + "Find the most relevant symbol at or around point. +Returns nil if nothing found." + (let ((var (variable-at-point)) + (sym (symbol-at-point)) + (fun-sym (function-called-at-point))) + (when (zerop var) + (setq var nil)) + (cond + ((helpful--bound-p var) var) + ((helpful--bound-p sym) sym) + ((helpful--bound-p fun-sym) fun-sym)))) + ;;;###autoload (defun helpful-at-point () "Show help for the symbol at point." (interactive) - (-if-let (symbol (symbol-at-point)) + (-if-let (symbol (helpful--symbol-at-point)) (helpful-symbol symbol) (user-error "There is no symbol at point."))) -- cgit v1.0