From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id 0GtUCwIjQWYE/QAAqHPOHw:P1 (envelope-from ) for ; Sun, 12 May 2024 22:13:54 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 0GtUCwIjQWYE/QAAqHPOHw (envelope-from ) for ; Sun, 12 May 2024 22:13:54 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1715544834; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=UBvh7q+ZDAW0yglSJjTWOOZf7CygTbdXRWzd0u2R904=; b=j4M0vErteUeZpzo9+c2DGgJ5cUb48CUrTmLxbNLQkInti61PE2gL4i1iQpSe1B9diY9RpC AR9ltD21poNk+Htw7f6d4mJGEBByb6zpA261YFAp1+fQ9hHfqwl9JNmWMlyQRTNRFzm3S/ o/PNL6ZxU1XTNwWYxS9jF4RJhOL/fNV60hy/GnGMq/HrSFGKv5pl1Av2GTAOwsRDHyavw2 0zz+9F5TJ7NqAX67v62O95mLmxsE7qtOi8T7kvKHmk2wOE8t9gWq0gDZulGkr3u2H5/wjr SwM5kPLFztro9vfM1HiNbu6uZb8ZyGt8EzdfrjDl5LbjkECQeXp3runI2MoglQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1715544834; a=rsa-sha256; cv=none; b=dUAuVW9zwn8iFVYsCN8AqJHwre98MjN6k72OpU17/igJu3kdF2s8xx2J0ORAPUVttK8/3c +HMyU+NbRFIqBJrjB4agiYQ7o5lV3Nw8tsV+onIqW2bBv5gtZz8d2ZoY2CheiVJ9OC6+Ky rayJf+POgs1pelinjEiK135XHlyImzrZo/zfIR1a6AZJfUntWfYXkUbM8zLlLWBJPAA+59 e3JL2acxsJaI7Yc86qnYr59C4cVKXpUUUc0EsE4rXkH0JvHlY5XkCApAvxZTsO1F0uSNmd DUgA5Ro1eHic9A6cvZiXqxYXQzANeS8T6IUyDZxclnIguADWfDtf/eHZktRzzg== 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 B887910DE6 for ; Sun, 12 May 2024 22:13:53 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6FZI-0004iW-Vo; Sun, 12 May 2024 16:13:13 -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 1s6FZC-0004cY-4O for emacs-orgmode@gnu.org; Sun, 12 May 2024 16:13:08 -0400 Received: from 62-210-209-184.rev.poneytelecom.eu ([62.210.209.184] helo=sula.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s6FYw-0004e7-CI for emacs-orgmode@gnu.org; Sun, 12 May 2024 16:13:05 -0400 Received: from localhost (anancy-653-1-9-249.w92-138.abo.wanadoo.fr [92.138.227.249]) by sula.io (Postfix) with ESMTPSA id 7607E5D419AC; Sun, 12 May 2024 22:12:42 +0200 (CEST) To: Ihor Radchenko Cc: emacs-orgmode list Subject: Re: [PATCH] Add org-after-note-stored-hook In-Reply-To: <8734qouw77.fsf@localhost> (Ihor Radchenko's message of "Sat, 11 May 2024 16:53:16 +0000") References: <8734qouw77.fsf@localhost> User-Agent: mu4e 1.12.4; emacs 29.3 Date: Sun, 12 May 2024 22:12:41 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=62.210.209.184; envelope-from=tyx+org@sula.io; helo=sula.io X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, RDNS_DYNAMIC=0.982, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, TVD_RCVD_IP=0.001 autolearn=no 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: , Reply-to: Joris Caravati From: Joris Caravati via "General discussions about Org-mode." Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.87 X-Spam-Score: -6.87 X-Migadu-Queue-Id: B887910DE6 X-Migadu-Scanner: mx13.migadu.com X-TUID: 5CuD/mJPShg8 --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Although, removing heading from inside > `org-after-todo-state-change-hook' is a bad idea - Org mode does not > expect the heading to disappear from under the cursor when this hook is > executed. I recommend using `org-trigger-hook' instead. Thanks for your help! I switched to `org-trigger-hook' without issue. > An easier way would be forcing note earlier by calling > `org-add-log-note' from your hook. I remember trying that before adding the hook (and I tried again today) but the problem with adding the note directly is that I only seem to manage storing the note where the task was before being archived, eg. with this (or any variants I could think of while making sense of what note functions do): #+begin_src elisp (when (member (plist-get properties ':to) '("CANCELLED" "READ")) (org-add-log-note) (my/org-roam-archive-to-today)) #+end_src which I find logical, since `org-store-log-note' is only called after =C-c C-c= is pressed, whereas the archival function is called just after the note buffer is created. So I still struggle to see how I could do without the hook (maybe if the archival function would return the position of the task after moving it, but that seems more complicated than just using the hook). > It will probably be better to run such new hooks right before (message "Note stored") > in `org-store-log-note'. A patch modified to match the suggested location for the `run-hooks' is attached. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-org.el-Add-org-after-note-stored-hook.patch >From 779d6b85acf9c30d7230bffccb2f98764372034a Mon Sep 17 00:00:00 2001 From: Joris Caravati Date: Sun, 12 May 2024 21:29:52 +0200 Subject: [PATCH] lisp/org.el: Add `org-after-note-stored-hook' * lisp/org.el: Add `org-after-note-stored-hook' which is called at the end of the `org-store-log-note' function. * etc/ORG-NEWS: Document the new hook. This change allows customization after a note is taken. One case where it is useful is when one wants to move a task after a state change but cannot do so in `org-after-todo-state-change' because the new state is configured to take a note (with '@' in `org-todo-keywords'). Setting this hook in `org-after-todo-state-change' allows to defer the move after the note is taken and prevents the note to be placed where the task was before being moved. TINYCHANGE --- etc/ORG-NEWS | 4 ++++ lisp/org.el | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 87b72ad12..4b7636765 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -1569,6 +1569,10 @@ optional argument =NEW-HEADING-CONTAINER= specifies where in the buffer it will be added. If not specified, new headings are created at level 1 at the end of the accessible part of the buffer, as before. +*** New hook [[doc::org-after-note-stored-hook][org-after-note-stored-hook]] + +This new hook runs when a note has been stored. + ** Miscellaneous *** =org-crypt.el= now applies initial visibility settings to decrypted entries diff --git a/lisp/org.el b/lisp/org.el index 598b4ca23..64f6d07ee 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -1990,6 +1990,9 @@ Lisp variable `org-state'." :group 'org-todo :type 'hook) +(defcustom org-after-note-stored-hook nil + "Hook which is run after a note was stored") + (defvar org-blocker-hook nil "Hook for functions that are allowed to block a state change. @@ -10845,6 +10848,7 @@ items are State notes." (unless (string-empty-p line) (indent-line-to ind) (insert-and-inherit line)))) + (run-hooks 'org-after-note-stored-hook) (message "Note stored") (org-back-to-heading t)))))) ;; Don't add undo information when called from `org-agenda-todo'. -- 2.44.0 --=-=-=--