helpful

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

commit 3a7fdc25f548b277ff3db3a541cd10930eb46f4e
parent 98f5f20e201453040e82102603ed1f1ce6699a67
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sat, 22 Sep 2018 00:00:59 +0100

Ensure we can go to definitions when the buffer is narrowed

Fixes #158

Diffstat:
MCHANGELOG.md | 3+++
Mhelpful.el | 17+++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -9,6 +9,9 @@ Fixed an issue with Remacs compatibility. Fixed an issue with the prompt when setting variables whose current value was nil or a keyword. +Fixed an issue with going to definitions when the source buffer was +narrowed. + # v0.13 Buffer-local variables are now highlighted, and it's possible to see diff --git a/helpful.el b/helpful.el @@ -419,6 +419,14 @@ or disable if already enabled." 'follow-link t 'help-echo "Navigate to definition") +(defun helpful--goto-char-widen (pos) + "Move point to POS in the current buffer. +If narrowing is in effect, widen if POS isn't in the narrowed area." + (when (or (< pos (point-min)) + (> pos (point-max))) + (widen)) + (goto-char pos)) + (defun helpful--navigate (button) "Navigate to the path this BUTTON represents." (find-file (substring-no-properties (button-get button 'path))) @@ -426,7 +434,7 @@ or disable if already enabled." ;; http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=f7c4bad17d83297ee9a1b57552b1944020f23aea (-when-let (pos (get-text-property button 'position (marker-buffer button))) - (goto-char pos))) + (helpful--goto-char-widen pos))) (defun helpful--navigate-button (text path &optional pos) "Return a button that opens PATH and puts point at POS." @@ -449,7 +457,7 @@ or disable if already enabled." (pos (button-get button 'position))) (switch-to-buffer buf) (when pos - (goto-char pos)))) + (helpful--goto-char-widen pos)))) (defun helpful--buffer-button (buffer &optional pos) "Return a button that switches to BUFFER and puts point at POS." @@ -2333,10 +2341,7 @@ imenu." (setq pos (+ pos offset))))) (find-file path) - (when (or (< pos (point-min)) - (> pos (point-max))) - (widen)) - (goto-char pos) + (helpful--goto-char-widen pos) (recenter 0) (save-excursion (let ((defun-end (scan-sexps (point) 1)))