all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Saving some kitten, plus some questions along the way
@ 2024-05-18 15:22 Stefan Monnier
  2024-05-19 11:56 ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2024-05-18 15:22 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/markdown, Size: 414 bytes --]

The patch below replaces a use of `eval` with `apply`, but along the way
I wondered about some of the details of `org-eval-in-calendar` (see the
FIXMEs), the most important of them being: why doesn't it use
`with-selected-window`?

Assuming the change from `eval` to `apply` is OK, I'll upgrade my patch
with an appropriate commit message, but I'd first like to understand
better what's at stake.


        Stefan

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org.patch --]
[-- Type: text/x-diff, Size: 6935 bytes --]

diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index 50e05efa1b..fc5fd53aa8 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -89,7 +89,6 @@
 (declare-function org-emphasize "org" (&optional char))
 (declare-function org-end-of-line "org" (&optional n))
 (declare-function org-entry-put "org" (pom property value))
-(declare-function org-eval-in-calendar "org" (form &optional keepdate))
 (declare-function org-calendar-goto-today-or-insert-dot "org" ())
 (declare-function org-calendar-goto-today "org" ())
 (declare-function org-calendar-backward-month "org" ())
@@ -390,9 +389,9 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 ;;; Global bindings
 
 ;;;; Outline functions
-(define-key org-mode-map [menu-bar headings] 'undefined)
-(define-key org-mode-map [menu-bar hide] 'undefined)
-(define-key org-mode-map [menu-bar show] 'undefined)
+(define-key org-mode-map [menu-bar headings] #'undefined)
+(define-key org-mode-map [menu-bar hide] #'undefined)
+(define-key org-mode-map [menu-bar show] #'undefined)
 
 (define-key org-mode-map [remap outline-mark-subtree] #'org-mark-subtree)
 (define-key org-mode-map [remap outline-show-subtree] #'org-fold-show-subtree)
diff --git a/lisp/org.el b/lisp/org.el
index 4342ddd735..a95a67b829 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14009,13 +14009,15 @@ user."
 	      (setq cal-frame
 		    (window-frame (get-buffer-window calendar-buffer 'visible)))
 	      (select-frame cal-frame))
-	    (org-eval-in-calendar '(setq cursor-type nil) t)
+	    ;; FIXME: Could we use `with-current-buffer' or do we really
+	    ;; need the `move-overlay' that's in `org-funcall-in-calendar'?
+	    (org-funcall-in-calendar (lambda () (setq cursor-type nil)) t)
 	    (unwind-protect
 		(progn
 		  (calendar-forward-day (- (time-to-days org-def)
 					   (calendar-absolute-from-gregorian
 					    (calendar-current-date))))
-		  (org-eval-in-calendar nil t)
+		  (org-funcall-in-calendar #'ignore t)
 		  (let* ((old-map (current-local-map))
 			 (map (copy-keymap calendar-mode-map))
 			 (minibuffer-local-map
@@ -14398,13 +14400,14 @@ user function argument order change dependent on argument order."
     (`european (list arg2 arg1 arg3))
     (`iso (list arg2 arg3 arg1))))
 
-(defun org-eval-in-calendar (form &optional keepdate)
-  "Eval FORM in the calendar window and return to current window.
+(defun org-funcall-in-calendar (func &optional keepdate &rest args)
+  "Call FUNC in the calendar window and return to current window.
 Unless KEEPDATE is non-nil, update `org-ans2' to the cursor date."
   (let ((sf (selected-frame))
 	(sw (selected-window)))
+    ;; FIXME: Use `with-selected-window'?
     (select-window (get-buffer-window calendar-buffer t))
-    (eval form t)
+    (apply func args)
     (when (and (not keepdate) (calendar-cursor-to-date))
       (let* ((date (calendar-cursor-to-date))
 	     (time (org-encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
@@ -14413,6 +14416,10 @@ Unless KEEPDATE is non-nil, update `org-ans2' to the cursor date."
     (select-window sw)
     (select-frame-set-input-focus sf)))
 
+(defun org-eval-in-calendar (func &optional keepdate)
+  (declare (obsolete org-funcall-in-calendar "2024"))
+  (org-funcall-in-calendar (lambda () (eval form t)) keepdate))
+
 (defun org-calendar-goto-today-or-insert-dot ()
   "Go to the current date, or insert a dot.
 
@@ -14423,81 +14430,81 @@ insert \".\"."
   (if (looking-back "^[^:]+: "
 		    (let ((inhibit-field-text-motion t))
 		      (line-beginning-position)))
-      (org-eval-in-calendar '(calendar-goto-today))
+      (org-funcall-in-calendar #'calendar-goto-today)
     (insert ".")))
 
 (defun org-calendar-goto-today ()
   "Reposition the calendar window so the current date is visible."
   (interactive)
-  (org-eval-in-calendar '(calendar-goto-today)))
+  (org-funcall-in-calendar #'calendar-goto-today))
 
 (defun org-calendar-backward-month ()
   "Move the cursor backward by one month."
   (interactive)
-  (org-eval-in-calendar '(calendar-backward-month 1)))
+  (org-funcall-in-calendar #'calendar-backward-month nil 1))
 
 (defun org-calendar-forward-month ()
   "Move the cursor forward by one month."
   (interactive)
-  (org-eval-in-calendar '(calendar-forward-month 1)))
+  (org-funcall-in-calendar #'calendar-forward-month nil 1))
 
 (defun org-calendar-backward-year ()
   "Move the cursor backward by one year."
   (interactive)
-  (org-eval-in-calendar '(calendar-backward-year 1)))
+  (org-funcall-in-calendar #'calendar-backward-year nil 1))
 
 (defun org-calendar-forward-year ()
   "Move the cursor forward by one year."
   (interactive)
-  (org-eval-in-calendar '(calendar-forward-year 1)))
+  (org-funcall-in-calendar #'calendar-forward-year nil 1))
 
 (defun org-calendar-backward-week ()
   "Move the cursor backward by one week."
   (interactive)
-  (org-eval-in-calendar '(calendar-backward-week 1)))
+  (org-funcall-in-calendar #'calendar-backward-week nil 1))
 
 (defun org-calendar-forward-week ()
   "Move the cursor forward by one week."
   (interactive)
-  (org-eval-in-calendar '(calendar-forward-week 1)))
+  (org-funcall-in-calendar #'calendar-forward-week nil 1))
 
 (defun org-calendar-backward-day ()
   "Move the cursor backward by one day."
   (interactive)
-  (org-eval-in-calendar '(calendar-backward-day 1)))
+  (org-funcall-in-calendar #'calendar-backward-day nil 1))
 
 (defun org-calendar-forward-day ()
   "Move the cursor forward by one day."
   (interactive)
-  (org-eval-in-calendar '(calendar-forward-day 1)))
+  (org-funcall-in-calendar #'calendar-forward-day nil 1))
 
 (defun org-calendar-view-entries ()
   "Prepare and display a buffer with diary entries."
   (interactive)
-  (org-eval-in-calendar '(diary-view-entries))
+  (org-funcall-in-calendar #'diary-view-entries)
   (message ""))
 
 (defun org-calendar-scroll-month-left ()
   "Scroll the displayed calendar left by one month."
   (interactive)
-  (org-eval-in-calendar '(calendar-scroll-left 1)))
+  (org-funcall-in-calendar #'calendar-scroll-left nil 1))
 
 (defun org-calendar-scroll-month-right ()
   "Scroll the displayed calendar right by one month."
   (interactive)
-  (org-eval-in-calendar '(calendar-scroll-right 1)))
+  (org-funcall-in-calendar #'calendar-scroll-right nil 1))
 
 (defun org-calendar-scroll-three-months-left ()
   "Scroll the displayed calendar left by three months."
   (interactive)
-  (org-eval-in-calendar
-   '(calendar-scroll-left-three-months 1)))
+  (org-funcall-in-calendar
+   #'calendar-scroll-left-three-months nil 1))
 
 (defun org-calendar-scroll-three-months-right ()
   "Scroll the displayed calendar right by three months."
   (interactive)
-  (org-eval-in-calendar
-   '(calendar-scroll-right-three-months 1)))
+  (org-funcall-in-calendar
+   #'calendar-scroll-right-three-months nil 1))
 
 (defun org-calendar-select ()
   "Return to `org-read-date' with the date currently selected.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-06-15 14:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-18 15:22 Saving some kitten, plus some questions along the way Stefan Monnier
2024-05-19 11:56 ` Ihor Radchenko
2024-05-19 14:40   ` Stefan Monnier
2024-05-19 14:45     ` Ihor Radchenko
2024-05-19 21:24       ` Stefan Monnier
2024-05-20 11:10         ` Ihor Radchenko
2024-06-15 14:32           ` Ihor Radchenko
2024-05-21 10:55         ` Max Nikulin

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.