aboutsummaryrefslogtreecommitdiff
path: root/helpful.el
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2020-09-23 00:05:14 -0700
committerWilfred Hughes <me@wilfred.me.uk>2020-09-23 00:05:14 -0700
commite98b4b8517b786ee3e5d4086d6b3017a23d7d2cc (patch)
tree07a0b633ebd2e9f4fde66abbe10491df9b61e73d /helpful.el
parent27373703625fdf86fe0f71500767802a28350b9f (diff)
WIP: more specific symbol extractionsmarter-syms
Based on #235 and #163.
Diffstat (limited to 'helpful.el')
-rw-r--r--helpful.el27
1 files changed, 26 insertions, 1 deletions
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.")))