From 55704c31109c278f03d4a1e9c84770d88781d976 Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 25 Mar 2021 17:52:35 +0000 Subject: new message: org link (and use it consistently: notmuch, recoll, etc.) --- consult.org | 12 +----------- init.org | 30 ++---------------------------- lib/doc/jao-recoll.el | 9 +++++++-- lib/net/jao-maildir.el | 28 ++++++++++++++++++++++++++++ lib/org/jao-org-links.el | 12 ++++++++++++ 5 files changed, 50 insertions(+), 41 deletions(-) diff --git a/consult.org b/consult.org index bcd5aac..8254ea4 100644 --- a/consult.org +++ b/consult.org @@ -109,16 +109,6 @@ #+begin_src emacs-lisp (jao-load-path "consult-recoll") - (defun jao-recoll-open-mail (fname) - (let ((group (jao-notmuch-file-to-group fname)) - (id (with-temp-buffer - (insert-file fname) - (goto-char (point-min)) - (message-mode) - (not-modified) - (message-fetch-field "Message-ID")))) - (when (and group id) (org-gnus-follow-link group id)))) - (defun jao-recoll-format (title url mtype) (let* ((u (replace-regexp-in-string "/home/jao/" "" url)) (u (replace-regexp-in-string "\\(doc\\|org/doc\\|var/mail\\)/" "" u))) @@ -130,7 +120,7 @@ (use-package consult-recoll :init (setq consult-recoll-open-fns '(("application/pdf" . jao-open-doc) - ("message/rfc822" . jao-recoll-open-mail)) + ("message/rfc822" . jao-org-links-open-mail)) consult-recoll-format-candidate #'jao-recoll-format) :bind (("C-c R" . #'consult-recoll))) diff --git a/init.org b/init.org index b0b77f9..9f96349 100644 --- a/init.org +++ b/init.org @@ -1889,38 +1889,12 @@ :bind (:map notmuch-show-mode-map ("C-c C-c" . jao-notmuch-goto-message-in-gnus)))) #+END_SRC -***** Go notmuch -> gnus (and use notmuch as default search) +***** notmuch -> gnus #+begin_src emacs-lisp - (defun jao-notmuch-file-to-group (file) - "Calculate the Gnus group name from the given file name. - - Example: - - IN: /home/jao/var/mail/jao/foo/cur/1259184569.M4818P3384.localhost,W=6921:2,S - OUT: nnimap:jao/foo - - IN: /home/jao/var/mail/gmane/foo/bar/100 - OUT: nntp+localhost:gmane.foo.bar - - IN: /home/jao/var/mail/bigml/cur/1259176906.M17483P24679.localhost,W=2488:2,S - OUT:nnimap:bigml/inbox" - (let* ((g (directory-file-name (file-name-directory file))) - (g (replace-regexp-in-string "/home/jao/var/mail/" "" g)) - (nntp (string-match-p "^\\(gmane\\|gwene\\)/" g)) - (g (if nntp - (concat "nntp+localhost:" g) - (replace-regexp-in-string "^\\([^/]+\\)/" "nnimap:\\1/" - (file-name-directory g) t))) - (g (if nntp (replace-regexp-in-string "/" "." g) g)) - (g (replace-regexp-in-string "[/.]$" "" g))) - (cond ((string-match ":$" g) (concat g "inbox")) - (nntp g) - (t (replace-regexp-in-string ":\\." ":" g))))) - (defun jao-notmuch-goto-message-in-gnus () "Open a summary buffer containing the current notmuch article." (interactive) - (let ((group (jao-notmuch-file-to-group (notmuch-show-get-filename))) + (let ((group (jao-maildir-file-to-group (notmuch-show-get-filename))) (message-id (replace-regexp-in-string "^id:" "" (notmuch-show-get-message-id)))) diff --git a/lib/doc/jao-recoll.el b/lib/doc/jao-recoll.el index be77100..7c64c7d 100644 --- a/lib/doc/jao-recoll.el +++ b/lib/doc/jao-recoll.el @@ -57,8 +57,13 @@ buffer using org mode." (forward-line 1)) (open-line 1) (while (search-forward-regexp jao-recoll--file-regexp nil t) - (setq lnk (concat "doc:" (file-name-nondirectory (match-string 2)))) - (replace-match "* [[\\2][\\3]] (\\1)") + (setq lnk + (cond ((string= (match-string 1) "application/pdf") + (concat "doc:" (file-name-nondirectory (match-string 2)))) + ((string= (match-string 1) "message/rfc822") + (concat "message:" (substring (match-string 2) 7))) + (t (match-string 2)))) + (replace-match (format "* [[%s][\\3]] (\\1)" lnk)) (forward-line) (let ((kill-whole-line t)) (kill-line)) (while (and (not (eobp)) (not (looking-at-p "/SNIPPETS"))) diff --git a/lib/net/jao-maildir.el b/lib/net/jao-maildir.el index d68fbe0..d7cd4d6 100644 --- a/lib/net/jao-maildir.el +++ b/lib/net/jao-maildir.el @@ -34,6 +34,7 @@ (defvar jao-maildir-echo-p t) (defvar jao-maildir-tracked-maildirs nil) (defvar jao-maildir-info-string "") +(defvar jao-maildir-home (expand-file-name "~/var/mail")) (defgroup jao-maildir-faces nil "Faces" :group 'faces) @@ -150,6 +151,33 @@ (t (error "Invalid mode-line value"))) (jao-maildir--setup-watches cb)) +;;;###autoload +(defun jao-maildir-file-to-group (file) + "Calculate the Gnus group name from the given file name. +Example: + + IN: /home/jao/var/mail/jao/foo/cur/1259184569.M4818P3384.localhost,W=6921:2,S + OUT: nnimap:jao/foo + + IN: /home/jao/var/mail/gmane/foo/bar/100 + OUT: nntp+localhost:gmane.foo.bar + + IN: /home/jao/var/mail/bigml/cur/1259176906.M17483P24679.localhost,W=2488:2,S + OUT:nnimap:bigml/inbox" + (let* ((g (directory-file-name (file-name-directory file))) + (g (replace-regexp-in-string (file-name-as-directory jao-maildir-home) + "" g)) + (nntp (string-match-p "^\\(gmane\\|gwene\\)/" g)) + (g (if nntp + (concat "nntp+localhost:" g) + (replace-regexp-in-string "^\\([^/]+\\)/" "nnimap:\\1/" + (file-name-directory g) t))) + (g (if nntp (replace-regexp-in-string "/" "." g) g)) + (g (replace-regexp-in-string "[/.]$" "" g))) + (cond ((string-match ":$" g) (concat g "inbox")) + (nntp g) + (t (replace-regexp-in-string ":\\." ":" g))))) + (provide 'jao-maildir) ;;; jao-maildir.el ends here diff --git a/lib/org/jao-org-links.el b/lib/org/jao-org-links.el index 21bf27c..f8080f5 100644 --- a/lib/org/jao-org-links.el +++ b/lib/org/jao-org-links.el @@ -1,4 +1,5 @@ (require 'jao-org-utils) +(require 'jao-maildir) (require 'pdf-info) (defvar jao-org--sink-dir "./") @@ -77,6 +78,16 @@ (setq outline (cdr outline))) (replace-regexp-in-string "[[:blank:]]+" " " cur-title))) +(defun jao-org-links-open-mail (fname) + (let ((group (jao-maildir-file-to-group fname)) + (id (with-temp-buffer + (insert-file fname) + (goto-char (point-min)) + (message-mode) + (not-modified) + (message-fetch-field "Message-ID")))) + (when (and group id) (org-gnus-follow-link group id)))) + ;;;###autoload (defvar jao-org-links-pdf-store-fun nil) @@ -107,6 +118,7 @@ :follow #'jao-org-links--follow-doc :complete #'jao-org-links--complete-doc :store #'jao-org-links--store-pdf-link) + (org-link-set-parameters "message" :follow #'jao-org-links-open-mail) (setq jao-org--sink-dir (file-name-as-directory sink-dir))) ;;;###autoload -- cgit v1.2.3