From ceb80863015840d91f21283ab435a4dcbc584f0b Mon Sep 17 00:00:00 2001 From: Bastien Date: Mon, 10 Feb 2020 23:22:51 +0100 Subject: [PATCH] Small refactoring * lisp/org-macs.el (org-scroll): New function. * lisp/ox.el (org-export--dispatch-action): * lisp/org-agenda.el (org-agenda-get-restriction-and-command): Use the new function. --- lisp/org-agenda.el | 18 +----------------- lisp/org-macs.el | 24 ++++++++++++++++++++++++ lisp/ox.el | 18 +----------------- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index d03923e41..68b790745 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -3134,23 +3134,7 @@ s Search for keywords M Like m, but only TODO entries "")) (setq c (read-char-exclusive))) until (not (memq c '(14 16 ?\s ?\d))) - do (cl-case c - (14 (if (not (pos-visible-in-window-p (point-max))) - (ignore-errors (scroll-up 1)) - (message "End of buffer") - (sit-for 1))) - (16 (if (not (pos-visible-in-window-p (point-min))) - (ignore-errors (scroll-down 1)) - (message "Beginning of buffer") - (sit-for 1))) - (?\s (if (not (pos-visible-in-window-p (point-max))) - (scroll-up nil) - (message "End of buffer") - (sit-for 1))) - (?\d (if (not (pos-visible-in-window-p (point-min))) - (scroll-down nil) - (message "Beginning of buffer") - (sit-for 1))))) + do (org-scroll c)) (message "") (cond diff --git a/lisp/org-macs.el b/lisp/org-macs.el index c1aef0c4d..0d7c2c616 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -1202,6 +1202,30 @@ Return 0. if S is not recognized as a valid value." ((string-match org-ts-regexp0 s) (org-2ft s)) (t 0.))))) +(defun org-scroll (key) + "Receive KEY and scroll the current window accordingly." + (cl-case key + ;; C-n + (14 (if (not (pos-visible-in-window-p (point-max))) + (ignore-errors (scroll-up 1)) + (message "End of buffer") + (sit-for 1))) + ;; C-p + (16 (if (not (pos-visible-in-window-p (point-min))) + (ignore-errors (scroll-down 1)) + (message "Beginning of buffer") + (sit-for 1))) + ;; SPC + (?\s (if (not (pos-visible-in-window-p (point-max))) + (scroll-up nil) + (message "End of buffer") + (sit-for 1))) + ;; DEL + (?\d (if (not (pos-visible-in-window-p (point-min))) + (scroll-down nil) + (message "Beginning of buffer") + (sit-for 1))))) + (provide 'org-macs) diff --git a/lisp/ox.el b/lisp/ox.el index 22cf1d53a..c3ecb664f 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -6904,23 +6904,7 @@ options as CDR." (while (and (setq key (read-char-exclusive prompt)) (not expertp) (memq key '(14 16 ?\s ?\d))) - (cl-case key - (14 (if (not (pos-visible-in-window-p (point-max))) - (ignore-errors (scroll-up 1)) - (message "End of buffer") - (sit-for 1))) - (16 (if (not (pos-visible-in-window-p (point-min))) - (ignore-errors (scroll-down 1)) - (message "Beginning of buffer") - (sit-for 1))) - (?\s (if (not (pos-visible-in-window-p (point-max))) - (scroll-up nil) - (message "End of buffer") - (sit-for 1))) - (?\d (if (not (pos-visible-in-window-p (point-min))) - (scroll-down nil) - (message "Beginning of buffer") - (sit-for 1))))) + (org-scroll key)) (cond ;; Ignore undefined associations. ((not (memq key allowed-keys))