Browse Source

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.
Bastien 5 months ago
parent
commit
ceb8086301
3 changed files with 26 additions and 34 deletions
  1. 1 17
      lisp/org-agenda.el
  2. 24 0
      lisp/org-macs.el
  3. 1 17
      lisp/ox.el

+ 1 - 17
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

+ 24 - 0
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)

+ 1 - 17
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))