[Orgmode] Re: Store link upon sending a message
Hi Bastien, Bastien bastien.gue...@wikimedia.fr wrote: Ulf Stegemann ulf-n...@zeitform.de writes: (defun ulf-message-send-and-org-gnus-store-link (optional arg) This is something I've been trying to achieve for very long! Great you found a solution. A minor suggestion: the function should make sure the buffer is not killed after the message is sent. I added (message-kill-buffer-on-exit nil) like this: good point, thanks for adding it. I also added an entry in org-hacks.org. Okay, thanks! Ulf ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: Store link upon sending a message
Hi Ulf, Ulf Stegemann ulf-n...@zeitform.de writes: (defun ulf-message-send-and-org-gnus-store-link (optional arg) This is something I've been trying to achieve for very long! Great you found a solution. A minor suggestion: the function should make sure the buffer is not killed after the message is sent. I added (message-kill-buffer-on-exit nil) like this: --8---cut here---start-8--- (defun ulf-message-send-and-org-gnus-store-link (optional arg) Send message with `message-send-and-exit' and store org link to message copy. If multiple groups appear in the Gcc header, the link refers to the copy in the last group. (interactive P) (save-excursion (save-restriction (message-narrow-to-headers) (let ((gcc (car (last (message-unquote-tokens (message-tokenize-header (mail-fetch-field gcc nil t) ,) (buf (current-buffer)) (message-kill-buffer-on-exit nil) id to from subject desc link newsgroup xarchive) (message-send-and-exit arg) (or ;; gcc group found ... (and gcc (save-current-buffer (progn (set-buffer buf) (setq id (org-remove-angle-brackets (mail-fetch-field Message-ID))) (setq to (mail-fetch-field To)) (setq from (mail-fetch-field From)) (setq subject (mail-fetch-field Subject (org-store-link-props :type gnus :from from :subject subject :message-id id :group gcc :to to) (setq desc (org-email-link-description)) (setq link (org-gnus-article-link gcc newsgroup id xarchive)) (setq org-stored-links (cons (list link desc) org-stored-links))) ;; no gcc group found ... (message Can not create Org link: No Gcc header found.)) --8---cut here---end---8--- I also added an entry in org-hacks.org. Thanks! -- Bastien ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: Store link upon sending a message
I came back to the matter of storing an org link to a copy of a message upon sending that message. The function below does just that and proves to be quite useful together with a sensible key binding (if you use Gnus and Gcc that is). --8--cut herestart8--- (defun ulf-message-send-and-org-gnus-store-link (optional arg) Send message with `message-send-and-exit' and store org link to message copy. If multiple groups appear in the Gcc header, the link refers to the copy in the last group. (interactive P) (save-excursion (save-restriction (message-narrow-to-headers) (let ((gcc (car (last (message-unquote-tokens (message-tokenize-header (mail-fetch-field gcc nil t) ,) (buf (current-buffer)) id to from subject desc link newsgroup xarchive) (message-send-and-exit arg) (or ;; gcc group found ... (and gcc (save-current-buffer (progn (set-buffer buf) (setq id (org-remove-angle-brackets (mail-fetch-field Message-ID))) (setq to (mail-fetch-field To)) (setq from (mail-fetch-field From)) (setq subject (mail-fetch-field Subject (org-store-link-props :type gnus :from from :subject subject :message-id id :group gcc :to to) (setq desc (org-email-link-description)) (setq link (org-gnus-article-link gcc newsgroup id xarchive)) (setq org-stored-links (cons (list link desc) org-stored-links))) ;; no gcc group found ... (message Can not create Org link: No Gcc header found.)) (define-key message-mode-map [(control c) (control meta c)] 'ulf-message-send-and-org-gnus-store-link) --8--cut here-end-8--- Ulf ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: Store link upon sending a message
Ulf Stegemann ulf-n...@zeitform.de writes: I came back to the matter of storing an org link to a copy of a message upon sending that message. The function below does just that and proves to be quite useful together with a sensible key binding (if you use Gnus and Gcc that is). Very nice! Works very well. Thanks. Instead of binding this to a command sequence, is there any hook we can attach the function to so that it's invoked for every message I send (I'm somewhat of a gnus noob unfortunately although I'm learning...)? I ask because I alternative between =C-c C-c= and =C-c C-j= for sending emails and I would need to provide two alternatives to incorporate your function. Thanks again, eric -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 23.2.1 : using Org-mode version 7.3 (release_7.3.42.g0fd5ec) ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: Store link upon sending a message
Eric S. Fraga ucec...@ucl.ac.uk wrote: Ulf Stegemann ulf-n...@zeitform.de writes: I came back to the matter of storing an org link to a copy of a message upon sending that message. The function below does just that and proves to be quite useful together with a sensible key binding (if you use Gnus and Gcc that is). Very nice! Works very well. Thanks. Instead of binding this to a command sequence, is there any hook we can attach the function to so that it's invoked for every message I send (I'm somewhat of a gnus noob unfortunately although I'm learning...)? I ask because I alternative between =C-c C-c= and =C-c C-j= for sending emails and I would need to provide two alternatives to incorporate your function. hmmm, never thought of this, probably because I never use `gnus-delay-article'. You could try to put the function into `message-send-hook' (but you should remove the call to `message-send-and-exit' first). I don't know if this would work as I don't know if the Gcc magic (incl. removal of Gcc header) is done before or after that hook. If the Gcc header has been removed when `message-send-hook' is called than you'll have to look for a different hook to use. If the Gcc header is still present, it should probably work as expected but note that in that case the org link will be created before the actual copying of the message took place. If something goes wrong with the latter this will leave you with a bogus org link (which, however, is probably not much of a problem). Ulf ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: Store link upon sending a message
Ulf Stegemann ulf-n...@zeitform.de writes: Eric S. Fraga ucec...@ucl.ac.uk wrote: Ulf Stegemann ulf-n...@zeitform.de writes: I came back to the matter of storing an org link to a copy of a message upon sending that message. The function below does just that and proves to be quite useful together with a sensible key binding (if you use Gnus and Gcc that is). Very nice! Works very well. Thanks. Instead of binding this to a command sequence, is there any hook we can attach the function to so that it's invoked for every message I send (I'm somewhat of a gnus noob unfortunately although I'm learning...)? I ask because I alternative between =C-c C-c= and =C-c C-j= for sending emails and I would need to provide two alternatives to incorporate your function. hmmm, never thought of this, probably because I never use `gnus-delay-article'. You could try to put the function into `message-send-hook' (but you should remove the call to `message-send-and-exit' first). I don't know if this would work as I don't know if the Gcc magic (incl. removal of Gcc header) is done before or after that hook. If the Gcc header has been removed when `message-send-hook' is called than you'll have to look for a different hook to use. If the Gcc header is still present, it should probably work as expected but note that in that case the org link will be created before the actual copying of the message took place. If something goes wrong with the latter this will leave you with a bogus org link (which, however, is probably not much of a problem). Thanks. I realised after sending my earlier message that this is going to be quite complicated. There's no point in storing a link when the message is actually sent (after all, that will be sometime later). I would want to store the link when I send the message to the delay queue (so that I can do something with the link, of course) so there really need to be two versions of your function. Should be doable. I'll think about it some more. In any case, most of my emails are sent immediately so your function is very useful already. Thanks again, eric -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 23.2.1 : using Org-mode version 7.3 (release_7.3.42.g0fd5ec) ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: Store link upon sending a message
Ulf Stegemann ulf-n...@zeitform.de wrote: Eric S. Fraga ucec...@ucl.ac.uk wrote: Ulf Stegemann ulf-n...@zeitform.de writes: I came back to the matter of storing an org link to a copy of a message upon sending that message. The function below does just that and proves to be quite useful together with a sensible key binding (if you use Gnus and Gcc that is). Very nice! Works very well. Thanks. Instead of binding this to a command sequence, is there any hook we can attach the function to so that it's invoked for every message I send (I'm somewhat of a gnus noob unfortunately although I'm learning...)? I ask because I alternative between =C-c C-c= and =C-c C-j= for sending emails and I would need to provide two alternatives to incorporate your function. hmmm, never thought of this, probably because I never use `gnus-delay-article'. You could try to put the function into `message-send-hook' (but you should remove the call to `message-send-and-exit' first). I don't know if this would work as I don't know if the Gcc magic (incl. removal of Gcc header) is done before or after that hook. If the Gcc header has been removed when `message-send-hook' is called than you'll have to look for a different hook to use. If the Gcc header is still present, it should probably work as expected but note that in that case the org link will be created before the actual copying of the message took place. If something goes wrong with the latter this will leave you with a bogus org link (which, however, is probably not much of a problem). If the hook approach does not work you could also advise `gnus-inews-do-gcc', the function that actually creates the message copies ... ... or you could replace `gnus-inews-do-gcc', e.g. replace the call to `message-send-and-exit' in `ulf-message-send-and-org-gnus-store-link' with something like `gnus-inews-do-gcc-orig' and save it as e.g. `my-gnus-gcc-and-org-store-link'. Then you could do something like (fset 'gnus-inews-do-gcc-orig (symbol-function 'gnus-inews-do-gcc)) (fset 'gnus-inews-do-gcc 'my-gnus-gcc-and-org-store-link) ... but that's all untested ;) Ulf ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: Store link upon sending a message
Ulf Stegemann ulf-n...@zeitform.de writes: [...] If the hook approach does not work you could also advise `gnus-inews-do-gcc', the function that actually creates the message copies ... ... or you could replace `gnus-inews-do-gcc', e.g. replace the call to `message-send-and-exit' in `ulf-message-send-and-org-gnus-store-link' with something like `gnus-inews-do-gcc-orig' and save it as e.g. `my-gnus-gcc-and-org-store-link'. Then you could do something like (fset 'gnus-inews-do-gcc-orig (symbol-function 'gnus-inews-do-gcc)) (fset 'gnus-inews-do-gcc 'my-gnus-gcc-and-org-store-link) ... but that's all untested ;) two very good suggestions. Thanks! I'll try to play with these over the weekend if I get a chance. -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 23.2.1 : using Org-mode version 7.3 (release_7.3.42.g0fd5ec) ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: Store link upon sending a message
Eric S. Fraga ucec...@ucl.ac.uk wrote: Thanks. I realised after sending my earlier message that this is going to be quite complicated. There's no point in storing a link when the message is actually sent (after all, that will be sometime later). I would want to store the link when I send the message to the delay queue (so that I can do something with the link, of course) so there really need to be two versions of your function. Should be doable. I'll think about it some more. ah, now I seem to understand. With your scenario I'd probably remove the call to `message-send-and-exit' from `ulf-message-send-and-org-gnus-store-link' and advise both `message-send-and-exit' and `gnus-delay-article' to run the modified function before execution. This would leave you with a stored link right after a `C-c C-c' and `C-c C-j'. But in case of the latter, the org link will be bogus until the message has actually been sent. Could that be a way to go for you? Ulf ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: Store link upon sending a message
Ulf Stegemann ulf-n...@zeitform.de writes: It often happens to me that I send a message (Gnus) and need to keep a reference of the mail just sent as link in an org file. [...] It would of course be much nicer if the org link could be stored automagically upon sending the message (or more precisely upon creating the copy of the message). In Gnus, just like in other Emacs applications, there is a lot of hooks and I am quite sure there is one we could use. I am going to investigate the problem soon as I also need the feature you descibed. As I'm not very familiar with the Gnus code I'll probably have to ask at the Gnus towers if it's possible to get hold of the group and article number AFAIR, message-id is used for org links rather than the articla number. of the last Gcc message created. But maybe someone around here has a partly or completely different idea how to achieve the described behaviour? Which simplifies the problem quite a lot because we need to be able to see the buffer just before sending or copying it to Gcc folder. All the information is there. -- Miłego dnia, Łukasz Stelmach ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: Store link upon sending a message
Łukasz Stelmach lukasz.stelm...@iem.pw.edu.pl wrote: Ulf Stegemann ulf-n...@zeitform.de writes: [snipped 15 lines] AFAIR, message-id is used for org links rather than the articla number. ah, right, that's at least what raw gnus-article links look like. I remember vaguely that this was different in the past and I obviously hadn't checked again. of the last Gcc message created. But maybe someone around here has a partly or completely different idea how to achieve the described behaviour? Which simplifies the problem quite a lot because we need to be able to see the buffer just before sending or copying it to Gcc folder. All the information is there. Yes, this makes things a lot easier :) IIUC we just need to parse the Gcc header for the group(s), grab the message-id and put things together. We should however keep in mind that we need to parse the Gcc header _before_ `gnus-inews-do-gcc' copies the message as the Gcc header is removed in the process. But the org link should probably be built _after_ `gnus-inews-do-gcc' to avoid bogus org links in case the Gcc fails. Additionally, it's probably not necessary to create a link for every group in Gcc but only for one (first one?). Furthermore, storing an org link should only happen when somehow requested by the user and not on every send. Although prefix args of `message-send' and friends already serve a different purpose that nevertheless seems to be trivial. Ulf ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode