helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit 954d4e8eaa61ab7573c591acb90f8f04797ead16
parent c5a5965017606fa703cdfabdac1441483ad72e9c
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Tue, 20 Feb 2018 19:57:38 +0000

Support functions defined in non-file buffers

Diffstat:
MCHANGELOG.md | 3+++
Mhelpful.el | 28++++++++++++++++++++++++----
2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -6,6 +6,9 @@ a plain symbol. Fixed an issue where we would show function source code for variables where we can't find the variable definition. +Fixed a crash on functions defined in a buffer that isn't backed by a +file. We now provide a button to navigate to that buffer. + # v0.7 Helpful buffers now start with a summary of what you're looking at, diff --git a/helpful.el b/helpful.el @@ -411,6 +411,23 @@ or disable if already enabled." 'path path 'position pos)) +(define-button-type 'helpful-buffer-button + 'action #'helpful--switch-to-buffer + 'buffer nil + 'follow-link t + 'help-echo "Switch to this buffer") + +(defun helpful--switch-to-buffer (button) + "Navigate to the buffer this BUTTON represents." + (switch-to-buffer (button-get button 'buffer))) + +(defun helpful--buffer-button (buffer) + "Return a button that opens PATH and puts point at POS." + (helpful--button + (buffer-name buffer) + 'helpful-buffer-button + 'buffer buffer)) + (define-button-type 'helpful-customize-button 'action #'helpful--customize 'symbol nil @@ -1289,10 +1306,13 @@ OBJ may be a symbol or a compiled function object." (cond (buf (let ((path (buffer-file-name buf))) - (format - "defined in %s" - (helpful--navigate-button - (file-name-nondirectory path) path pos)))) + (if path + (format + "defined in %s" + (helpful--navigate-button + (file-name-nondirectory path) path pos)) + (format "defined in buffer %s" + (helpful--buffer-button buf))))) (primitive-p "defined in C source code") (t