emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Marco Wahl <marcowahlsoft@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: Using lexical-binding
Date: Tue, 09 Mar 2021 00:35:06 -0500	[thread overview]
Message-ID: <8735x4c2k5.fsf@kyleam.com> (raw)
In-Reply-To: <jwv4khnap6r.fsf-monnier+emacs@gnu.org>

Looking at this one more time before applying, I noticed a couple of
backward compatibility issues.

Stefan Monnier writes:

> Subject: [PATCH] * lisp/org-agenda.el: Use lexical-binding
[...]
> +	        (pcase type
> +	          ('agenda
> +	           (org-agenda-list current-prefix-arg))

Unfortunately Org's minimum Emacs version is still Emacs 24.3.  I'd like
to drop Emacs 24 support soon, but that hasn't been discussed or
announced.

And...

> +  (let* ((gprops (nth 1 series))
> +         (gvars (mapcar #'car gprops))
> +         (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
> +    (cl-progv gvars gvals (org-agenda-prepare name))
> +    ;; We need to reset agenda markers here, because when constructing a
> +    ;; block agenda, the individual blocks do not do that.
> +    (org-agenda-reset-markers)
> +    (with-suppressed-warnings ((lexical match))

... I believe with-suppressed-warnings isn't available until Emacs 27.1,
right?

Any objections to me squashing the below changes into your patch?

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 001ca4b1b..d08cab061 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2938,30 +2938,30 @@ (defun org-agenda (&optional arg keys restriction)
 	          (mapcar #'car lprops)
 	          (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
 	        (pcase type
-	          ('agenda
+	          (`agenda
 	           (org-agenda-list current-prefix-arg))
-	          ('agenda*
+	          (`agenda*
 	           (org-agenda-list current-prefix-arg nil nil t))
-	          ('alltodo
+	          (`alltodo
 	           (org-todo-list current-prefix-arg))
-	          ('search
+	          (`search
 	           (org-search-view current-prefix-arg org-match nil))
-	          ('stuck
+	          (`stuck
 	           (org-agenda-list-stuck-projects current-prefix-arg))
-	          ('tags
+	          (`tags
 	           (org-tags-view current-prefix-arg org-match))
-	          ('tags-todo
+	          (`tags-todo
 	           (org-tags-view '(4) org-match))
-	          ('todo
+	          (`todo
 		   (org-todo-list org-match))
-		  ('tags-tree
+		  (`tags-tree
 		   (org-check-for-org-mode)
 		   (org-match-sparse-tree current-prefix-arg org-match))
-		  ('todo-tree
+		  (`todo-tree
 		   (org-check-for-org-mode)
 		   (org-occur (concat "^" org-outline-regexp "[ \t]*"
 				      (regexp-quote org-match) "\\>")))
-		  ('occur-tree
+		  (`occur-tree
 		   (org-check-for-org-mode)
 		   (org-occur org-match))
 		  ((pred functionp)
@@ -3263,7 +3263,7 @@ (defun org-agenda-run-series (name series)
     ;; We need to reset agenda markers here, because when constructing a
     ;; block agenda, the individual blocks do not do that.
     (org-agenda-reset-markers)
-    (with-suppressed-warnings ((lexical match))
+    (org-with-suppressed-warnings ((lexical match))
       (defvar match))          ;Used via the `eval' below.
     (let* ((org-agenda-multi t)
 	   ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
@@ -3285,21 +3285,21 @@ (defun org-agenda-run-series (name series)
               (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
           (cl-progv (append gvars lvars) (append gvals lvals)
 	    (pcase type
-	      ('agenda
+	      (`agenda
 	       (call-interactively 'org-agenda-list))
-	      ('agenda*
+	      (`agenda*
 	       (funcall 'org-agenda-list nil nil t))
-	      ('alltodo
+	      (`alltodo
 	       (call-interactively 'org-todo-list))
-	      ('search
+	      (`search
 	       (org-search-view current-prefix-arg match nil))
-	      ('stuck
+	      (`stuck
 	       (call-interactively 'org-agenda-list-stuck-projects))
-	      ('tags
+	      (`tags
 	       (org-tags-view current-prefix-arg match))
-	      ('tags-todo
+	      (`tags-todo
 	       (org-tags-view '(4) match))
-	      ('todo
+	      (`todo
 	       (org-todo-list match))
 	      ((pred fboundp)
 	       (funcall type match))
@@ -5363,7 +5363,7 @@ (defun org-diary (&rest args)
 The function expects the lisp variables `entry' and `date' to be provided
 by the caller, because this is how the calendar works.  Don't use this
 function from a program - use `org-agenda-get-day-entries' instead."
-  (with-suppressed-warnings ((lexical date entry)) (defvar date) (defvar entry))
+  (org-with-suppressed-warnings ((lexical date entry)) (defvar date) (defvar entry))
   (when (> (- (float-time)
 	      org-agenda-last-marker-time)
 	   5)
@@ -5678,7 +5678,7 @@ (defun org-agenda-get-timestamps (&optional deadlines)
   "Return the date stamp information for agenda display.
 Optional argument DEADLINES is a list of deadline items to be
 displayed in agenda view."
-  (with-suppressed-warnings ((lexical date)) (defvar date))
+  (org-with-suppressed-warnings ((lexical date)) (defvar date))
   (let* ((props (list 'face 'org-agenda-calendar-event
 		      'org-not-done-regexp org-not-done-regexp
 		      'org-todo-regexp org-todo-regexp
@@ -5821,7 +5821,7 @@ (defun org-agenda-get-timestamps (&optional deadlines)
 (defun org-agenda-get-sexps ()
   "Return the sexp information for agenda display."
   (require 'diary-lib)
-  (with-suppressed-warnings ((lexical date entry)) (defvar date) (defvar entry))
+  (org-with-suppressed-warnings ((lexical date entry)) (defvar date) (defvar entry))
   (let* ((props (list 'face 'org-agenda-calendar-sexp
 		      'mouse-face 'highlight
 		      'help-echo
@@ -5910,7 +5910,7 @@ (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
 `holidays', then any date that is known by the Emacs calendar to be a
 holiday will also be skipped.  If SKIP-WEEKS arguments are holiday strings,
 then those holidays will be skipped."
-  (with-suppressed-warnings ((lexical date entry)) (defvar date) (defvar entry))
+  (org-with-suppressed-warnings ((lexical date entry)) (defvar date) (defvar entry))
   (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
 	 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
 	 (d (calendar-absolute-from-gregorian date))
@@ -5930,7 +5930,7 @@ (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
 (defalias 'org-get-closed #'org-agenda-get-progress)
 (defun org-agenda-get-progress ()
   "Return the logged TODO entries for agenda display."
-  (with-suppressed-warnings ((lexical date)) (defvar date))
+  (org-with-suppressed-warnings ((lexical date)) (defvar date))
   (let* ((props (list 'mouse-face 'highlight
 		      'org-not-done-regexp org-not-done-regexp
 		      'org-todo-regexp org-todo-regexp
@@ -6162,7 +6162,7 @@ (defun org-agenda-get-deadlines (&optional with-hour)
   "Return the deadline information for agenda display.
 When WITH-HOUR is non-nil, only return deadlines with an hour
 specification like [h]h:mm."
-  (with-suppressed-warnings ((lexical date)) (defvar date))
+  (org-with-suppressed-warnings ((lexical date)) (defvar date))
   (let* ((props (list 'mouse-face 'highlight
 		      'org-not-done-regexp org-not-done-regexp
 		      'org-todo-regexp org-todo-regexp
@@ -6321,7 +6321,7 @@ (defun org-agenda-get-scheduled (&optional deadlines with-hour)
 Optional argument DEADLINES is a list of deadline items to be
 displayed in agenda view.  When WITH-HOUR is non-nil, only return
 scheduled items with an hour specification like [h]h:mm."
-  (with-suppressed-warnings ((lexical date)) (defvar date))
+  (org-with-suppressed-warnings ((lexical date)) (defvar date))
   (let* ((props (list 'org-not-done-regexp org-not-done-regexp
 		      'org-todo-regexp org-todo-regexp
 		      'org-complex-heading-regexp org-complex-heading-regexp
@@ -6522,7 +6522,7 @@ (defun org-agenda-get-scheduled (&optional deadlines with-hour)
 
 (defun org-agenda-get-blocks ()
   "Return the date-range information for agenda display."
-  (with-suppressed-warnings ((lexical date)) (defvar date))
+  (org-with-suppressed-warnings ((lexical date)) (defvar date))
   (let* ((props (list 'face nil
 		      'org-not-done-regexp org-not-done-regexp
 		      'org-todo-regexp org-todo-regexp
@@ -6691,7 +6691,7 @@ (defun org-agenda-format-item (extra txt &optional level category tags dotime
 		 org-agenda-show-inherited-tags
 		 org-agenda-hide-tags-regexp))
 
-      (with-suppressed-warnings
+      (org-with-suppressed-warnings
 	  ((lexical breadcrumbs category category-icon effort extra
 	            level tag time))
 	;; `time', `tag', `effort' are needed for the eval of the prefix format.
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 63f0a0acb..92fdef0a0 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -629,6 +629,12 @@ (defun org-unlogged-message (&rest args)
   (let ((message-log-max nil))
     (apply #'message args)))
 
+(if (fboundp 'with-suppressed-warnings)  ; Introduced in Emacs 27.1.
+    (defalias 'org-with-suppressed-warnings 'with-suppressed-warnings)
+  (defmacro org-with-suppressed-warnings (_warnings &rest body)
+    (declare (debug (sexp &optional body)) (indent 1))
+    `(progn ,@body)))
+
 (defmacro org-dlet (binders &rest body)
   "Like `let*' but using dynamic scoping."
   (declare (indent 1) (debug let))
@@ -636,7 +642,7 @@ (defmacro org-dlet (binders &rest body)
                         (if (consp binder) (car binder) binder))
                       binders)))
     `(progn
-       (with-suppressed-warnings ((lexical ,@vars))
+       (org-with-suppressed-warnings ((lexical ,@vars))
          ,@(mapcar (lambda (var) `(defvar ,var)) vars))
        (let* ,binders ,@body))))
 


  reply	other threads:[~2021-03-09  5:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-23 21:11 Using lexical-binding Stefan Monnier
2021-02-24  0:26 ` Kyle Meyer
2021-02-24  3:44   ` Kyle Meyer
2021-02-24  4:01     ` Samuel Wales
2021-02-24  4:33   ` Stefan Monnier
2021-02-25  5:42     ` Kyle Meyer
2021-02-25  5:41 ` Kyle Meyer
2021-03-04  6:03   ` Kyle Meyer
2021-03-04  9:11     ` Marco Wahl
2021-03-06 16:10     ` Stefan Monnier
2021-03-06 17:08       ` Kyle Meyer
2021-03-06 22:33         ` Stefan Monnier
2021-03-09  5:35           ` Kyle Meyer [this message]
2021-03-09 14:09             ` Stefan Monnier
2021-03-10  4:16               ` Kyle Meyer
2021-03-10 16:32                 ` Stefan Monnier
2021-03-19 16:23                 ` Greg Minshall
2021-03-20  3:34                   ` Greg Minshall
2021-03-20  4:48                   ` Kyle Meyer
2021-03-20  5:33                     ` Greg Minshall
2021-03-21 16:04                       ` Kyle Meyer
2021-03-21 17:14                         ` Greg Minshall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735x4c2k5.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=marcowahlsoft@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).