From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joseph Vidal-Rosset Subject: org-links for Gnus in imap with Gmail (for a convenient todo.org list) Date: Thu, 25 Jul 2019 18:24:15 +0200 Message-ID: <5d39d7af.1c69fb81.2893e.8fde@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:33680) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqgXU-0008Fz-Ek for emacs-orgmode@gnu.org; Thu, 25 Jul 2019 12:24:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqgXS-0000mX-Sp for emacs-orgmode@gnu.org; Thu, 25 Jul 2019 12:24:20 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:51087) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hqgXS-0000kq-Hg for emacs-orgmode@gnu.org; Thu, 25 Jul 2019 12:24:18 -0400 Received: by mail-wm1-x334.google.com with SMTP id v15so45574523wml.0 for ; Thu, 25 Jul 2019 09:24:18 -0700 (PDT) Received: from debian ([2a01:e0a:21e:7710:2508:36ad:a518:bffb]) by smtp.gmail.com with ESMTPSA id x185sm39322026wmg.46.2019.07.25.09.24.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jul 2019 09:24:15 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode list Hello, Documentation to create a todo.org list that provides links to email as tasks is not seldom on the web. I recommend for example [[http://pragmaticemacs.com/]]. But for gnus-imap-gmail users, it is more difficult to get the same thing. Here is a the lines of code in my setup (user.el in Kitchin's scimax) that work for gnus in imap: #+BEGIN_SRC elisp ;;capture todo items using C-c c t (define-key global-map (kbd "C-c c") 'org-capture) (setq org-capture-templates '(("t" "todo" entry (file+headline "~/Dropbox/Orgzly/todo.org" "Tasks") "* TODO [#A] %?\n [[~/Dropbox/Orgzly/links.org::%(org-insert-time-stamp (org-read-date nil t \"%:date\"))]] \n* %(org-insert-time-stamp (org-read-date nil t \"%:date\")) %a "))) (defun hs/replace () (interactive) (goto-char 1) (let ((search-invisible t)) (replace-string "gnus:INBOX#" "gnus:%5BGmail%5D/Tous les messages#"))) (define-key global-map (kbd "C-c r") 'hs/replace) (add-hook 'org-capture-prepare-finalize-hook 'hs/replace) (defun my/refile (file headline &optional arg) (let ((pos (save-excursion (find-file file) (org-find-exact-headline-in-buffer headline)))) (org-refile arg nil (list headline file nil pos))) (switch-to-buffer (current-buffer))) (defhydra jo/org-refile-hydra (:foreign-keys run) "Refile" ("l" (my/refile "~/Dropbox/Orgzly/links.org" "Links") "Links") ("j" org-refile-goto-last-stored "Jump to last refile") ("q" nil "cancel")) ;; Or whatever you want your keybinding to be (global-set-key (kbd " r") 'jo/org-refile-hydra/body) (global-set-key (kbd " a") 'org-archive-subtree) ;;refile https://blog.aaronbieber.com/2017/03/19/organizing-notes-with-refile.html (setq org-refile-targets '((org-agenda-files :maxlevel . 2))) (setq org-refile-use-outline-path 'file) (setq org-outline-path-complete-in-steps nil) (setq org-refile-allow-creating-parent-nodes 'confirm) (setq org-refile-targets '((nil :maxlevel . 2) (org-agenda-files :maxlevel . 2))) (setq org-outline-path-complete-in-steps nil) ; Refile in a single go (setq org-refile-use-outline-path t) ; Show full paths for refiling (setq org-refile-targets (quote (("todo.org" :maxlevel . 2) ("links.org" :level . 2) ))) #+END_SRC with any file open in emacs, like for example this email, C-c c t gives the following result that I paste below: #+BEGIN_SRC elisp ** TODO [#A] [[~/Dropbox/Orgzly/links.org::<2019-07-25 jeu.>]] ** <2019-07-25 jeu.> [[file:~/News/drafts/drafts/129]] #+END_SRC Because I like to see my todo list with conky on my wallpaper, I refile the second link into links.org and it is now easy to get immediately from todo.org the correct entry that have the appropriate link in links.org. In Gnus, it is the same thing. For example C-c c t in reading the last email that I received from John Kitchin provides: #+BEGIN_SRC elisp ** TODO [#A] [[~/Dropbox/Orgzly/links.org::<2019-07-25 jeu.>]] ** <2019-07-25 jeu.> [[gnus:INBOX#CAJ51ETqLcFTeZvPYg0AuzZL2HGwVGCOewKem8OkZnLL-ES59-g@mail.gmail.com][Email from John Kitchin: Re: scimax question]] #+END_SRC But I need to change the mention of INBOX in the link to John's email. Hence the function hs/replace via C-c r with the cursor on the link that gives the wanted result: #+BEGIN_SRC elisp ** TODO [#A] [[~/Dropbox/Orgzly/links.org::<2019-07-25 jeu.>]] ** <2019-07-25 jeu.> [[gnus:%5BGmail%5D/Tous les messages#CAJ51ETqLcFTeZvPYg0AuzZL2HGwVGCOewKem8OkZnLL-ES59-g@mail.gmail.com][Email from John Kitchin: Re: scimax question]] #+END_SRC and then the email can be archived in Tous les messages, Gnus will find it, via imap.gmail.com . That's it. I hope some of you will find this useful. Let me know. Of course the code must be adapted according to the language of the gmail user, it goes without saying. (In refiling, I do not succeed to get other level that level one for sections, but it is a detail. ) Best wishes, -- Jo.