emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] put `org-attach-after-change-hook` at the end of org-attach
@ 2024-08-29  3:36 Christopher M. Miles
  2024-09-22 16:27 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Christopher M. Miles @ 2024-08-29  3:36 UTC (permalink / raw)
  To: Org mode mailing list


[-- Attachment #1.1: Type: text/plain, Size: 147 bytes --]


lisp/org-attach.el (org-attach-attach): Put org-attach-after-change-hook
at the end to make sure user can access attach link in org-store-links.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org-attach.el-put-org-attach-after-change-hook-at-th.patch --]
[-- Type: text/x-patch, Size: 1584 bytes --]

From f21ef819ab6670f1ed64a731d5d7b5fb29119f33 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Thu, 29 Aug 2024 11:31:53 +0800
Subject: [PATCH] org-attach.el: put org-attach-after-change-hook at the end

lisp/org-attach.el (org-attach-attach): Put org-attach-after-change-hook
at the end to make sure user can access attach link in org-store-links.
---
 lisp/org-attach.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 7a03d170e..d43cbc74c 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -615,8 +615,6 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
             (url-copy-file file attach-file)
           (error "The remote resource %S is considered unsafe, and will not be downloaded"
                  file))))
-      (run-hook-with-args 'org-attach-after-change-hook attach-dir)
-      (org-attach-tag)
       (cond ((eq org-attach-store-link-p 'attached)
 	     (push (list (concat "attachment:" (file-name-nondirectory attach-file))
 			 (file-name-nondirectory attach-file))
@@ -629,6 +627,8 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
 	     (push (list (concat "file:" attach-file)
 			 (file-name-nondirectory attach-file))
 		   org-stored-links)))
+      (run-hook-with-args 'org-attach-after-change-hook attach-dir)
+      (org-attach-tag)
       (if visit-dir
           (dired attach-dir)
         (message "File %S is now an attachment" basename)))))
-- 
2.39.3 (Apple Git-146)


[-- Attachment #1.3: Type: text/plain, Size: 267 bytes --]


-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* Re: [PATCH] put `org-attach-after-change-hook` at the end of org-attach
  2024-08-29  3:36 [PATCH] put `org-attach-after-change-hook` at the end of org-attach Christopher M. Miles
@ 2024-09-22 16:27 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2024-09-22 16:27 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode mailing list

"Christopher M. Miles" <numbchild@gmail.com> writes:

> Subject: [PATCH] org-attach.el: put org-attach-after-change-hook at the end
>
> lisp/org-attach.el (org-attach-attach): Put org-attach-after-change-hook
> at the end to make sure user can access attach link in org-store-links.

I have no problem with the change, but I'd like to point out that link
may or may not be present in the list of stored links depending on
`org-attach-store-link-p'. So, checking stored links from the hook is
unreliable.

And remember that `org-attach-after-change-hook' may be called in other
scenarios; not necessarily when a new file is attached.

Instead, it might make more sense to pass the information about file
changes (if available) to the hook itself directly.
For example, we may obsolete `org-attach-after-change-hook' and introduce
`org-attach-after-change-functions'.  Then, we pass attachment dir +
list of changed files to that new abnormal hook.
WDYT?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2024-09-22 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29  3:36 [PATCH] put `org-attach-after-change-hook` at the end of org-attach Christopher M. Miles
2024-09-22 16:27 ` Ihor Radchenko

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).