From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id UNaBJd7HSGZeDAAAe85BDQ:P1 (envelope-from ) for ; Sat, 18 May 2024 17:23:10 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id UNaBJd7HSGZeDAAAe85BDQ (envelope-from ) for ; Sat, 18 May 2024 17:23:10 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=iro.umontreal.ca header.s=mail header.b=O0iACBau; dmarc=pass (policy=quarantine) header.from=iro.umontreal.ca; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1716045790; a=rsa-sha256; cv=none; b=rn5TnYqr95/BdIkVd48nLeFia02/SSJgDz4MVytrq6MLGzZyx705ymIxW1eAxVZVVG5nyb eFVI93xKNpRslC1SVErZZLAO6AtCMBtkUgxgpGTayzZngtf1OYldXnPmnuJqC88FTs7KTR qzf6cDFDYxiJoJS7myizcs47Aq0hhjIiV/E2Q5cqNGfasSoC1XvIApwyJAoC+DpGh7b89R OYJL4+h/NKdmjE9LByg9LrQZtNzZ3DbIjPq/4SuL6v80/8GgHBOVxqY98odIwgO9V8FgnQ FOKzhNQDTvSg+Li6NsVnh09f2rJcYlakrwoFNA40LUYyoi3hZhG+RIpGyIgwUQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=iro.umontreal.ca header.s=mail header.b=O0iACBau; dmarc=pass (policy=quarantine) header.from=iro.umontreal.ca; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1716045790; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=QQg/l2sqt9gTNr/cAMVL/tcq+aq7nIlOVU18R22Mva8=; b=Mp4RIyjR/2gDzzK5x5xwSF/rtwrvQVwoxP9DTyaxSr8vXnSddkoYbaNMSd5Pzle+x+yOCG W32vYXrgZHYLmeHjqo283OushTvUgGugTGVxyE4mAwivc0gxAYydJpefbG/oCGVDfZ77iL xyUpifLirQL8xtkqz/Tiow/3d7EhSZgMPp9lP+wUfZSkC15SvVB8+qd0uO4yTuO87B0K+D KXOkcuZA46QdOBToEHeNpFt2tXZpsGgYHYNab7moBtQMgmsVD5pC13Kzsk4EtfNZDSPaE5 aKa+SpHr2N39yBulYMzpx4ZvSDFhRN/kKxx3jsLqKVldqT1sbA1XIMP9fgxxjQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8B9D51DC17 for ; Sat, 18 May 2024 17:23:09 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s8Lt0-0001LD-18; Sat, 18 May 2024 11:22:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8Lsv-0001JN-63 for emacs-orgmode@gnu.org; Sat, 18 May 2024 11:22:10 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8Lst-0004HC-Cm for emacs-orgmode@gnu.org; Sat, 18 May 2024 11:22:08 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 055C6100061; Sat, 18 May 2024 11:22:06 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1716045724; bh=XWueTpzugSRBGyr7EZBumcIRh6lCR7Fa+Oj1BRtTLd4=; h=From:To:Subject:Date:From; b=O0iACBauCKRKdJqXxWI6NlGwxxsI2+4eD53JYG7G9FATrBqte6hH08JWA+OkYGJ5W xRYyFyq9+Lri0FVZYr2PS1aQFNTht/XhYZAntsrmhLmMFR2xPu6CWnFA5a9qvUxdRp c3sfQvdlMTM8w/qIC1Zi6eHmtoEpfDRfzb71Pz/RORolrfB1Fl7zqG7mLPzwqrzWGF +JqmpoS1kgRv1gUu4+Zjp9NB8j8K2SasRv933y6ksc8F3PJCmr2Cw+QTjZqBnLy2B9 pXoAbYtXc4ghvcWZB8jnC1ekmraPdSLDuZQX7tprhv4f/OiMTxcyq7bTYX2Yu8q5qa BtM3k5dFpdD9w== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A0483100035; Sat, 18 May 2024 11:22:04 -0400 (EDT) Received: from pastel (unknown [45.72.201.215]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 6321E1205CC; Sat, 18 May 2024 11:22:04 -0400 (EDT) From: Stefan Monnier To: emacs-orgmode@gnu.org Subject: Saving some kitten, plus some questions along the way Message-ID: Date: Sat, 18 May 2024 11:22:04 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 8B9D51DC17 X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -11.08 X-Spam-Score: -11.08 X-TUID: rqQ4HsPU5ke9 --=-=-= Content-Type: text/markdown; charset=UTF-8 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=org.patch 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. --=-=-=--