Browse Source

Backport commit 8d5dfafab from Emacs

While at it, I enabled lexical-binding in the affected files.

* lisp/org-agenda.el (org-let, org-let2): Move from org-macs and
use `declare`.

* lisp/org-macs.el (org-let, org-let2): Move these functions that are
inherently harmful to your karma to the only package that uses them.
(org-scroll): Use `pcase` to avoid `eval` and use more readable syntax
for those integers standing for events.

* lisp/org-element.el (org-element-map): Use `declare`.

Prefer `declare` over a `put` of `list-indent-function`.
8d5dfafab7dc40d4b74dc0b56d1b314fd8cac390
Stefan Monnier
Mon Feb 22 11:54:17 2021 -0500
Stefan Monnier 4 years ago
parent
commit
63da3ccfb4
3 changed files with 34 additions and 35 deletions
  1. 9 0
      lisp/org-agenda.el
  2. 1 1
      lisp/org-element.el
  3. 24 34
      lisp/org-macs.el

+ 9 - 0
lisp/org-agenda.el

@@ -3224,6 +3224,15 @@ s   Search for keywords                 M   Like m, but only TODO entries
 (defvar org-agenda-overriding-cmd nil)
 (defvar org-agenda-overriding-arguments nil)
 (defvar org-agenda-overriding-cmd-arguments nil)
+
+(defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
+  (declare (indent 1))
+  (eval (cons 'let (cons list body))))
+
+(defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
+  (declare (indent 2))
+  (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
+
 (defun org-agenda-run-series (name series)
   "Run agenda NAME as a SERIES of agenda commands."
   (org-let (nth 1 series) '(org-agenda-prepare name))

+ 1 - 1
lisp/org-element.el

@@ -4228,6 +4228,7 @@ looking into captions:
    (lambda (b)
      (and (org-element-map b \\='latex-snippet #\\='identity nil t) b))
    nil nil nil t)"
+  (declare (indent 2))
   ;; Ensure TYPES and NO-RECURSION are a list, even of one element.
   (let* ((types (if (listp types) types (list types)))
 	 (no-recursion (if (listp no-recursion) no-recursion
@@ -4321,7 +4322,6 @@ looking into captions:
 	(funcall --walk-tree data)
 	;; Return value in a proper order.
 	(nreverse --acc)))))
-(put 'org-element-map 'lisp-indent-function 2)
 
 ;; The following functions are internal parts of the parser.
 ;;

+ 24 - 34
lisp/org-macs.el

@@ -627,18 +627,10 @@ program is needed for, so that the error message can be more informative."
   (let ((message-log-max nil))
     (apply #'message args)))
 
-(defun org-let (list &rest body)
-  (eval (cons 'let (cons list body))))
-(put 'org-let 'lisp-indent-function 1)
-
-(defun org-let2 (list1 list2 &rest body)
-  (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
-(put 'org-let2 'lisp-indent-function 2)
-
 (defun org-eval (form)
   "Eval FORM and return result."
   (condition-case error
-      (eval form)
+      (eval form t)
     (error (format "%%![Error: %s]" error))))
 
 (defvar org-outline-regexp) ; defined in org.el
@@ -1242,31 +1234,29 @@ Return 0. if S is not recognized as a valid value."
 When ADDITIONAL-KEYS is not nil, also include SPC and DEL in the
 allowed keys for scrolling, as expected in the export dispatch
 window."
-  (let ((scrlup (if additional-keys '(?\s 22) 22))
-	(scrldn (if additional-keys `(?\d 134217846) 134217846)))
-    (eval
-     `(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 or
-	(,scrlup
-	 (if (not (pos-visible-in-window-p (point-max)))
-	     (scroll-up nil)
-	   (message "End of buffer")
-	   (sit-for 1)))
-	;; DEL
-	(,scrldn (if (not (pos-visible-in-window-p (point-min)))
-		     (scroll-down nil)
-		   (message "Beginning of buffer")
-		   (sit-for 1)))))))
+  (let ((scrlup (if additional-keys '(?\s ?\C-v) ?\C-v))
+	(scrldn (if additional-keys `(?\d ?\M-v) ?\M-v)))
+    (pcase key
+      (?\C-n (if (not (pos-visible-in-window-p (point-max)))
+	      (ignore-errors (scroll-up 1))
+	    (message "End of buffer")
+	    (sit-for 1)))
+      (?\C-p (if (not (pos-visible-in-window-p (point-min)))
+	      (ignore-errors (scroll-down 1))
+	    (message "Beginning of buffer")
+	    (sit-for 1)))
+      ;; SPC or
+      ((guard (memq key scrlup))
+       (if (not (pos-visible-in-window-p (point-max)))
+	   (scroll-up nil)
+	 (message "End of buffer")
+	 (sit-for 1)))
+      ;; DEL
+      ((guard (memq key scrldn))
+       (if (not (pos-visible-in-window-p (point-min)))
+	   (scroll-down nil)
+	 (message "Beginning of buffer")
+	 (sit-for 1))))))
 
 (provide 'org-macs)