From e27aa38c8d4e37c33e9031530ddcca4ae42f32bc Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 3 Apr 2021 01:14:33 +0800 Subject: 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. --- view-conf.el | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'view-conf.el') 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 -- cgit v1.2.3-18-g5258