aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-12-06 23:42:56 +0000
committerWilfred Hughes <me@wilfred.me.uk>2017-12-06 23:42:56 +0000
commit909ead2ee2439bd8fc64121a8e1b0c952efbbd79 (patch)
treea8147a8392a8dfc9e77ccb352c351ba727d68cba
parent3a13f04969b9f58a037a68f08c05730075956830 (diff)
Allow moving with TAB and S-TAB
Fixes #5
-rw-r--r--helpful.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/helpful.el b/helpful.el
index 6bf7214..ca9086f 100644
--- a/helpful.el
+++ b/helpful.el
@@ -900,8 +900,42 @@ See also `helpful-callable' and `helpful-variable'."
(find-file path)
(goto-char pos))))
+(defun helpful--forward-button (direction)
+ "Move point the next/previous button."
+ (let ((step (if (< direction 0) -1 1)))
+ ;; Step over the current button, if any.
+ (while (and
+ (not (if (< direction 0) (bobp) (eobp)))
+ (get-text-property (point) 'button))
+ (forward-char step))
+ ;; Move forward until we hit a button.
+ (while (and
+ (not (if (< direction 0) (bobp) (eobp)))
+ (not (get-text-property (point) 'button)))
+ (forward-char step))
+ ;; Ensure we're on the first char of the button.
+ (while (and
+ (not (if (< direction 0) (bobp) (eobp)))
+ (get-text-property (point) 'button))
+ (forward-char -1))
+ (unless (bobp)
+ (forward-char 1))))
+
+(defun helpful-forward-button ()
+ "Move point forward to the next button."
+ (interactive)
+ (helpful--forward-button 1))
+
+(defun helpful-backward-button ()
+ "Move point backward to the next button."
+ (interactive)
+ (helpful--forward-button -1))
+
(define-key helpful-mode-map (kbd "g") #'helpful-update)
(define-key helpful-mode-map (kbd "RET") #'helpful-visit-reference)
+(define-key helpful-mode-map (kbd "TAB") #'helpful-forward-button)
+(define-key helpful-mode-map (kbd "<backtab>") #'helpful-backward-button)
+
(provide 'helpful)
;;; helpful.el ends here