summaryrefslogtreecommitdiff
path: root/view-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-04-03 01:14:33 +0800
committerJSDurand <mmemmew@gmail.com>2021-04-03 01:14:33 +0800
commite27aa38c8d4e37c33e9031530ddcca4ae42f32bc (patch)
tree6eecadbf56ffef0fbb51938884577b988fd4ffe4 /view-conf.el
parent7023bc46c91f2223a1cba4b15cc41b3c2274e17b (diff)
Moving by paragraphs.
* view-conf.el (durand-scroll-next-paragraph): (durand-scroll-prev-paragraph): These functions were born while I wrote my little novel-reading package. And I grew used to this convenient functionality, so I want to add that here. (durand-focus-map): Bind in the focus map.
Diffstat (limited to 'view-conf.el')
-rw-r--r--view-conf.el39
1 files changed, 39 insertions, 0 deletions
diff --git a/view-conf.el b/view-conf.el
index f5dcda9..b58e04d 100644
--- a/view-conf.el
+++ b/view-conf.el
@@ -330,6 +330,43 @@ If ARG is non-nil, do the same for Bluetooth."
(define-key global-map (vector 3 ?w) #'durand-wifi-or-bluetooth)
+;;; moving by paragraphs
+
+;;;###autoload
+(defun durand-scroll-next-paragraph (&optional arg)
+ "Scroll so that the next ARG paragraph is at the top."
+ (interactive "p")
+ (let ((forward-p (> arg 0))
+ pos)
+ (save-excursion
+ (goto-char (window-start))
+ (cond
+ (forward-p
+ (while (> arg 0)
+ (cond
+ ((re-search-forward "^\\s-*$" (line-end-position) t)
+ (forward-line 1)))
+ (while (not (re-search-forward "^\\s-*$" (line-end-position) t))
+ (forward-line 1))
+ (setq arg (1- arg))))
+ (t
+ (while (< arg 0)
+ (cond
+ ((re-search-forward "^\\s-*$" (line-end-position) t)
+ (forward-line -1)))
+ (while (not (re-search-forward "^\\s-*$" (line-end-position) t))
+ (forward-line -1))
+ (setq arg (1+ arg)))))
+ (setq pos (point)))
+ (set-window-start (selected-window) pos)))
+
+;;;###autoload
+(defun durand-scroll-prev-paragraph (&optional arg)
+ "Scroll so that the previous ARG paragraph is at the top."
+ (interactive "p")
+ (cond ((numberp arg)) ((setq arg 1)))
+ (durand-scroll-next-paragraph (- arg)))
+
;;; focus mode
;;;###autoload
@@ -338,6 +375,8 @@ If ARG is non-nil, do the same for Bluetooth."
(define-key durand-focus-map (vector ?\s-v) #'view-mode)
(define-key durand-focus-map (vector ?\s-x) #'durand-focus)
+(define-key durand-focus-map (vector ?f) #'durand-scroll-next-paragraph)
+(define-key durand-focus-map (vector ?b) #'durand-scroll-prev-paragraph)
;;;###autoload
(define-minor-mode durand-focus