diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2018-09-22 00:00:59 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2018-09-22 00:00:59 +0100 |
| commit | 3a7fdc25f548b277ff3db3a541cd10930eb46f4e (patch) | |
| tree | 64bd1664c4b8cff924a70e2e919edbe41eb448cf | |
| parent | 98f5f20e201453040e82102603ed1f1ce6699a67 (diff) | |
Ensure we can go to definitions when the buffer is narrowed
Fixes #158
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | helpful.el | 17 |
2 files changed, 14 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc9b56..473eede 100644 --- 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 @@ -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))) |
