From: Tokuya Kameshima <kametoku@gmail.com>
To: emacs-orgmode@gnu.org
Cc: kametoku@gmail.com
Subject: new version of org-mew.el
Date: Mon, 25 Feb 2013 20:36:52 +0900 (JST) [thread overview]
Message-ID: <20130225.203652.1880414702745010956.kametoku@gmail.com> (raw)
[-- Attachment #1: Type: Text/Plain, Size: 1935 bytes --]
Hi,
The attached is the new version of org-mew.el with several new features.
I would appreciate it if some of Mew users could try this.
If this is fine, I would like Bastien to incorporate it to the git repo.
The changes are as follows:
org-mew-store-link
- Works in mew message mode as well as mew summary mode.
org-mew-open
- Locates the message in the inbox folder given by `org-mew-inbox-folder'
if the message is not found in the link's folder.
- Uses id.db to search the message if the message is not found or the
folder is not specified by the link. You can disable this by
setting `org-mew-use-id-db' to nil.
org-mew-search - new function
- Shows all entries related to the message using `org-search-view'.
See the docstring for details.
org-mew-capture - new function
- Guesses the capture template from the folder name and invoke
`org-capture'. See the docstring for details.
----
My daily workflow using these features is something like this.
~/.mew.el:
(define-key mew-summary-mode-map "'" 'org-mew-search)
(eval-after-load "mew-summary"
'(define-key mew-summary-mode-map "\C-o" 'org-mew-capture))
1. In the Mew's inbox folder, I take a glance at new messages to find
a message that requires any action.
2. If the message is a reply from somebody and associated with the
existing orgmode entry, type M-x org-mew-search (or press ['] key
simply) to find the entry. If I can find the entry successfully
and think I should start the task right now, start the task by M-x
org-agenda-clock-in.
3. If the message is a brand-new message, type M-x org-mew-capture,
enter the refile folder, and the buffer to capture the message is
shown up (without selecting the template by hand!). And I fill the
template and type C-c C-c to complete the capture. Note that I
have configured `org-capture-templates' so that the captured entry
has a link to the message.
Thanks,
--Tokuya
[-- Attachment #2: org-mew.el --]
[-- Type: Text/Plain, Size: 12811 bytes --]
;;; org-mew.el --- Support for links to Mew messages from within Org-mode
;; Copyright (C) 2008-2013 Free Software Foundation, Inc.
;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;; This file implements links to Mew messages from within Org-mode.
;; Org-mode loads this module by default - if this is not what you want,
;; configure the variable `org-modules'.
;;; Code:
(require 'org)
(defgroup org-mew nil
"Options concerning the Mew link."
:tag "Org Startup"
:group 'org-link)
(defcustom org-mew-link-to-refile-destination t
"Create a link to the refile destination if the message is marked as refile."
:group 'org-mew
:type 'boolean)
(defcustom org-mew-inbox-folder nil
"The folder where new messages are incorporated.
If `org-mew-inbox-folder' is non-nil, `org-mew-open' locates the message
in this inbox folder as well as the folder specified by the link."
:group 'org-mew
:type 'string)
(defcustom org-mew-use-id-db t
"Use ID database to locate the message if id.db is created."
:group 'org-mew
:type 'boolean)
(defcustom org-mew-subject-alist
(list (cons (concat "^\\(?:\\(?:re\\|fwd?\\): *\\)*"
"\\(?:[[(][a-z0-9._-]+[:,]? [0-9]+[])]\\)? *"
"\\(?:\\(?:re\\|fwd?\\): *\\)*"
"\\(.*\\)[ \t]*")
1))
"Alist of subject regular expression and matched group number for search."
:group 'org-mew
:type '(repeat (cons (regexp) (integer))))
(defcustom org-mew-capture-inbox-folders nil
"List of the inbox folders whose messages need refile marked before capture.
`org-mew-capture' will ask you to put the refile mark on the message
if the message's folder is any of these folders and the message is not marked.
Nil means `org-mew-capture' never ask you destination folders before capture."
:group 'org-mew
:type '(repeat string))
(defcustom org-mew-capture-guess-alist nil
"Alist of the regular expression of the folder name and the capture
template selection keys.
For example,
'((\"^%emacs-orgmode$\" . \"o\")
(\"\" . \"t\"))
the messages in \"%emacs-orgmode\" folder will be captured with
the capture template associated with \"o\" key, and any other
messages will be captured with the capture template associated
with \"t\" key."
:group 'org-mew
:type '(repeat (cons regexp string)))
;; Declare external functions and variables
(declare-function mew-cache-hit "ext:mew-cache" (fld msg &optional must-hit))
(declare-function mew-case-folder "ext:mew-func" (case folder))
(declare-function mew-folder-path-to-folder
"ext:mew-func" (path &optional has-proto))
(declare-function mew-folder-remotep "ext:mew-func" (folder))
(declare-function mew-folder-virtualp "ext:mew-func" (folder))
(declare-function mew-header-get-value "ext:mew-header"
(field &optional as-list))
(declare-function mew-init "ext:mew" ())
(declare-function mew-refile-get "ext:mew-refile" (msg))
(declare-function mew-sinfo-get-case "ext:mew-summary" ())
(declare-function mew-summary-diag-global "ext:mew-thread" (id opt who))
(declare-function mew-summary-display "ext:mew-summary2" (&optional redisplay))
(declare-function mew-summary-folder-name "ext:mew-syntax" (&optional ext))
(declare-function mew-summary-get-mark "ext:mew-mark" ())
(declare-function mew-summary-message-number2 "ext:mew-syntax" ())
(declare-function mew-summary-pick-with-mewl "ext:mew-pick"
(pattern folder src-msgs))
(declare-function mew-summary-refile "ext:mew-refile" (&optional report))
(declare-function mew-summary-search-msg "ext:mew-const" (msg))
(declare-function mew-summary-set-message-buffer "ext:mew-summary3" (fld msg))
(declare-function mew-summary-visit-folder "ext:mew-summary4"
(folder &optional goend no-ls))
(declare-function mew-window-push "ext:mew" ())
(defvar mew-init-p)
(defvar mew-mark-afterstep-spec)
(defvar mew-summary-goto-line-then-display)
;; Install the link type
(org-add-link-type "mew" 'org-mew-open)
(add-hook 'org-store-link-functions 'org-mew-store-link)
;; Implementation
(defun org-mew-store-link ()
"Store a link to a Mew folder or message."
(save-window-excursion
(if (eq major-mode 'mew-message-mode)
(mew-message-goto-summary))
(when (memq major-mode '(mew-summary-mode mew-virtual-mode))
(let ((msgnum (mew-summary-message-number2))
(folder-name (org-mew-folder-name)))
(if (fboundp 'mew-summary-set-message-buffer)
(mew-summary-set-message-buffer folder-name msgnum)
(set-buffer (mew-cache-hit folder-name msgnum t)))
(let* ((message-id (mew-header-get-value "Message-Id:"))
(from (mew-header-get-value "From:"))
(to (mew-header-get-value "To:"))
(date (mew-header-get-value "Date:"))
(date-ts (and date (format-time-string
(org-time-stamp-format t)
(date-to-time date))))
(date-ts-ia (and date (format-time-string
(org-time-stamp-format t t)
(date-to-time date))))
(subject (mew-header-get-value "Subject:"))
desc link)
(org-store-link-props :type "mew" :from from :to to
:subject subject :message-id message-id)
(when date
(org-add-link-props :date date :date-timestamp date-ts
:date-timestamp-inactive date-ts-ia))
(setq message-id (org-remove-angle-brackets message-id))
(setq desc (org-email-link-description))
(setq link (concat "mew:" folder-name "#" message-id))
(org-add-link-props :link link :description desc)
link)))))
(defun org-mew-folder-name ()
"Return the folder name of the current message."
(save-window-excursion
(if (eq major-mode 'mew-message-mode)
(mew-message-goto-summary))
(let* ((msgnum (mew-summary-message-number2))
(mark-info (mew-summary-get-mark)))
(if (and org-mew-link-to-refile-destination
(eq mark-info ?o)) ; marked as refile
(nth 1 (mew-refile-get msgnum))
(let ((folder-or-path (mew-summary-folder-name)))
(mew-folder-path-to-folder folder-or-path t))))))
(defun org-mew-open (path)
"Follow the Mew message link specified by PATH."
(let (folder message-id)
(cond ((string-match "\\`\\(+.*\\)+\\+\\([0-9]+\\)\\'" path) ; for Bastien's
(setq folder (match-string 1 path))
(setq message-id (match-string 2 path)))
((string-match "\\`\\(\\(%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path)
(setq folder (match-string 1 path))
(setq message-id (match-string 4 path)))
((and org-mew-use-id-db (string-match "\\`#\\(.+\\)" path))
(setq folder nil)
(setq message-id (match-string 1 path)))
(t (error "Error in Mew link")))
(require 'mew)
(mew-window-push)
(unless mew-init-p (mew-init))
(if (null folder)
(progn
(mew t)
(org-mew-open-by-message-id message-id))
(or (org-mew-follow-link folder message-id)
(and org-mew-inbox-folder (not (string= org-mew-inbox-folder folder))
(org-mew-follow-link org-mew-inbox-folder message-id))
(and org-mew-use-id-db
(org-mew-open-by-message-id message-id))
(error "Message not found")))))
(defun org-mew-follow-link (folder message-id)
(unless (org-mew-folder-eixsts-p folder)
(error "No such folder or wrong folder %s" folder))
(mew-summary-visit-folder folder)
(when message-id
(let ((msgnum (org-mew-get-msgnum folder message-id)))
(when (mew-summary-search-msg msgnum)
(if mew-summary-goto-line-then-display
(mew-summary-display))
t))))
(defun org-mew-folder-eixsts-p (folder)
(let ((dir (mew-expand-folder folder)))
(cond
((mew-folder-virtualp folder) (get-buffer folder))
((null dir) nil)
((mew-folder-remotep (mew-case:folder-folder folder)) t)
(t (file-directory-p dir)))))
(defun org-mew-get-msgnum (folder message-id)
(if (string-match "\\`[0-9]+\\'" message-id)
message-id
(let* ((pattern (concat "message-id=" message-id))
(msgs (mew-summary-pick-with-mewl pattern folder nil)))
(car msgs))))
(defun org-mew-open-by-message-id (message-id)
"Open message using ID database."
(let ((result (mew-summary-diag-global (format "<%s>" message-id)
"-p" "Message")))
(unless (eq result t)
(error "Message not found"))))
;; In ~/.mew.el, add the following line:
;; (define-key mew-summary-mode-map "'" 'org-mew-search)
(defun org-mew-search (&optional arg)
"Show all entries related to the message using `org-search-view'.
It shows entries which contains the message ID, the reference
IDs, or the subject of the message.
With C-u prefix, search for the entries that contains the message
ID or any of the reference IDs. With C-u C-u prefix, search for
the message ID or the last reference ID.
The search phase for the subject is extracted with
`org-mew-subject-alist', which defines the regular expression of
the subject and the group number to extract. You can get rid of
\"Re:\" and some other prefix from the subject text."
(interactive "P")
(when (memq major-mode '(mew-summary-mode mew-virtual-mode))
(let ((last-reference-only (equal arg '(16)))
(by-subject (null arg))
(msgnum (mew-summary-message-number2))
(folder-name (mew-summary-folder-name))
subject message-id references id-list)
(save-window-excursion
(if (fboundp 'mew-summary-set-message-buffer)
(mew-summary-set-message-buffer folder-name msgnum)
(set-buffer (mew-cache-hit folder-name msgnum t)))
(setq subject (mew-header-get-value "Subject:"))
(setq message-id (mew-header-get-value "Message-Id:"))
(setq references (mew-header-get-value "References:")))
(setq id-list (mapcar (lambda (id) (org-remove-angle-brackets id))
(mew-idstr-to-id-list references)))
(if last-reference-only
(setq id-list (last id-list))
(if message-id
(setq id-list (cons (org-remove-angle-brackets message-id)
id-list))))
(when (and by-subject (stringp subject))
(catch 'matched
(mapc (lambda (elem)
(let ((regexp (car elem))
(num (cdr elem)))
(when (string-match regexp subject)
(setq subject (match-string num subject))
(throw 'matched t))))
org-mew-subject-alist))
(setq id-list (cons subject id-list)))
(cond ((null id-list)
(error "No message ID to search."))
((equal (length id-list) 1)
(org-search-view nil (car id-list)))
(t
(org-search-view nil (format "{\\(%s\\)}"
(mapconcat 'regexp-quote
id-list "\\|"))))))
(delete-other-windows)))
(defun org-mew-capture (arg)
"Guess the capture template from the folder name and invoke `org-capture'.
This selects a capture template in `org-capture-templates' by
searching for capture template selection keys defined in
`org-mew-capture-guess-alist' which are associated with the
regular expression that matches the message's folder name, and
then invokes `org-capture'.
If the message's folder is a inbox folder, you are prompted to
put the refile mark on the message and the capture template is
guessed from the refile destination folder. You can customize
the inbox folders by `org-mew-capture-inbox-folders'.
If ARG is non-nil, this does not guess the capture template but
asks you to select the capture template."
(interactive "P")
(or (not (member (org-mew-folder-name)
org-mew-capture-inbox-folders))
(eq (mew-summary-get-mark) ?o)
(save-window-excursion
(if (eq major-mode 'mew-message-mode)
(mew-message-goto-summary))
(let ((mew-mark-afterstep-spec '((?o 0 0 0 0 0 0 0))))
(mew-summary-refile)))
(error "No refile folder selected."))
(let* ((org-mew-link-to-refile-destination t)
(folder-name (org-mew-folder-name))
(keys (if arg
nil
(org-mew-capture-guess-selection-keys folder-name))))
(org-capture nil keys)))
(defun org-mew-capture-guess-selection-keys (folder-name)
(catch 'found
(let ((alist org-mew-capture-guess-alist))
(while alist
(let ((elem (car alist)))
(if (string-match (car elem) folder-name)
(throw 'found (cdr elem))))
(setq alist (cdr alist))))))
(provide 'org-mew)
;;; org-mew.el ends here
next reply other threads:[~2013-02-25 11:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 11:36 Tokuya Kameshima [this message]
2013-02-26 22:30 ` new version of org-mew.el Bastien
2013-02-27 9:26 ` Achim Gratz
2013-02-27 9:30 ` Bastien
2013-02-27 20:09 ` Achim Gratz
2013-02-27 22:28 ` Bastien
2013-02-27 22:46 ` Achim Gratz
2013-03-11 15:44 ` Tokuya Kameshima
2013-03-11 15:54 ` Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130225.203652.1880414702745010956.kametoku@gmail.com \
--to=kametoku@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.