[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Saving some kitten, plus some questions along the way
From: |
Stefan Monnier |
Subject: |
Saving some kitten, plus some questions along the way |
Date: |
Sat, 18 May 2024 11:22:04 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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
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.
- Saving some kitten, plus some questions along the way,
Stefan Monnier <=
- Re: Saving some kitten, plus some questions along the way, Ihor Radchenko, 2024/05/19
- Re: Saving some kitten, plus some questions along the way, Stefan Monnier, 2024/05/19
- Re: Saving some kitten, plus some questions along the way, Ihor Radchenko, 2024/05/19
- Re: Saving some kitten, plus some questions along the way, Stefan Monnier, 2024/05/19
- Re: Saving some kitten, plus some questions along the way, Ihor Radchenko, 2024/05/20
- Re: Saving some kitten, plus some questions along the way, Max Nikulin, 2024/05/21