From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-orgmode@gnu.org
Subject: Saving some kitten, plus some questions along the way
Date: Sat, 18 May 2024 11:22:04 -0400 [thread overview]
Message-ID: <jwv7cfrno8s.fsf-monnier+emacs@gnu.org> (raw)
[-- 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.
next reply other threads:[~2024-05-18 15:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-18 15:22 Stefan Monnier [this message]
2024-05-19 11:56 ` Saving some kitten, plus some questions along the way 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
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=jwv7cfrno8s.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-orgmode@gnu.org \
/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).