emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: David Maus <dmaus@ictsoc.de>
To: org-mode <emacs-orgmode@gnu.org>
Subject: [patch] org-wl: Code cleanup and enhancements
Date: Fri, 07 May 2010 17:36:15 +0200	[thread overview]
Message-ID: <87632zafm8.wl%dmaus@ictsoc.de> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 621 bytes --]

Attached patch for org-wl.el contains some code cleanup and two
enhancements:

  1. Store and open link to Wanderlust folders.

  2. Store link to Wanderlust message while visiting the message
     buffer.

     Up to now it was only possible to store a link to a message when
     point was in the message summary.

@Carsten: This patch also contains the update for ChangeLog.  I hope
merging different ChangeLog entries works out of the box.  I.e. there
will be two other patches with an updated ChangeLog as well.

HTH
 -- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #1.1.2: org-wl-cleanup-features.diff --]
[-- Type: application/octet-stream, Size: 9293 bytes --]

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 88d477e..426ac21 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
+2010-05-07  David Maus  <dmaus@ictsoc.de>
+
+	* org-wl.el (org-wl-message-field): New function.  Return
+	content of header field in message entity.
+	(org-wl-store-link): Call `org-wl-store-link-folder' or
+	`org-wl-store-link-message' depending on major-mode.
+	(org-wl-store-link-folder): New function.  Store link to
+	Wanderlust folder.
+	(org-wl-store-link-message): New function.  Store link to
+	Wanderlust message.
+	(org-wl-store-link-message): Store link to message while
+	visiting message.
+	(org-wl-open): Don't try to jump to message when opening a
+	folder link.
+
 2010-05-07  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-table.el (org-table-recalculate-buffer-tables)
diff --git a/lisp/org-wl.el b/lisp/org-wl.el
index 0534342..4a76904 100644
--- a/lisp/org-wl.el
+++ b/lisp/org-wl.el
@@ -86,9 +86,14 @@ googlegroups otherwise."
 (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
 (declare-function wl-folder-goto-folder-subr "ext:wl-folder"
 		  (&optional folder sticky))
+(declare-function wl-folder-get-petname "ext:wl-folder" (name))
+(declare-function wl-folder-get-entity-from-buffer "ext:wl-folder"
+		  (&optional getid))
+(declare-function wl-folder-buffer-group-p "ext:wl-folder")
 (defvar wl-init)
 (defvar wl-summary-buffer-elmo-folder)
 (defvar wl-summary-buffer-folder-name)
+(defvar wl-folder-group-regexp)
 
 (defconst org-wl-folder-types
   '(("%" . imap) ("-" . nntp) ("+" . mh) ("=" . spool)
@@ -96,7 +101,6 @@ googlegroups otherwise."
     ("*" . multi) ("/" . filter) ("|" . pipe) ("'" . internal))
   "List of folder indicators. See Wanderlust manual, section 3.")
 
-
 ;; Install the link type
 (org-add-link-type "wl" 'org-wl-open)
 (add-hook 'org-store-link-functions 'org-wl-store-link)
@@ -123,79 +127,102 @@ folder name determines the the folder type."
 	      nil))))
     type))
 
+(defun org-wl-message-field (field entity)
+  "Return content of FIELD in ENTITY.
+FIELD is a symbol of a rfc822 message header field.
+ENTITY is a message entity."
+  (let ((content (elmo-message-entity-field entity field)))
+    (if (listp content) (car content) content)))
+
 (defun org-wl-store-link ()
- "Store a link to a WL folder or message."
- (when (eq major-mode 'wl-summary-mode)
-   (let* ((msgnum (wl-summary-message-number))
-	   (mark-info (wl-summary-registered-temp-mark msgnum))
-	   (folder-name
-	    (if (and org-wl-link-to-refile-destination
-		     mark-info
-		     (equal (nth 1 mark-info) "o")) ; marked as refile
-		(nth 2 mark-info)
-	      wl-summary-buffer-folder-name))
-	   (folder-type (org-wl-folder-type folder-name))
-	   (message-id (elmo-message-field wl-summary-buffer-elmo-folder
-					   msgnum 'message-id))
-	   (wl-message-entity
-	    (if (fboundp 'elmo-message-entity)
-		(elmo-message-entity
-		 wl-summary-buffer-elmo-folder msgnum)
-	      (elmo-msgdb-overview-get-entity
-	       msgnum (wl-summary-buffer-msgdb))))
-	   (from (let ((from-field (elmo-message-entity-field wl-message-entity
-							      'from)))
-		   (if (listp from-field)
-		       (car from-field)
-		     from-field)))
-	   (to (let ((to-field (elmo-message-entity-field wl-message-entity
-							  'to)))
-		 (if (listp to-field)
-		     (car to-field)
-		   to-field)))
-	   (xref (let ((xref-field (elmo-message-entity-field wl-message-entity
-							      'xref)))
-		   (if (listp xref-field)
-		       (car xref-field)
-		     xref-field)))
-	   (subject (let (wl-thr-indent-string wl-parent-message-entity)
-		      (wl-summary-line-subject)))
-	   desc link)
-
-     ;; remove text properties of subject string to avoid possible bug
-     ;; when formatting the subject
-     ;; (Emacs bug #5306, fixed)
-     (set-text-properties 0 (length subject) nil subject)
-
-     ;; maybe remove filter condition
-     (when (and (eq folder-type 'filter) org-wl-link-remove-filter)
-       (while (eq (org-wl-folder-type folder-name) 'filter)
-	 (setq folder-name
-	       (replace-regexp-in-string "^/[^/]+/" "" folder-name))))
-
-     ;; maybe create http link
-     (cond
-      ((and (eq folder-type 'shimbun) org-wl-shimbun-prefer-web-links xref)
-       (org-store-link-props :type "http" :link xref :description subject
-			     :from from :to to :message-id message-id
-			     :subject subject))
-      ((and (eq folder-type 'nntp) org-wl-nntp-prefer-web-links)
-       (setq link (format
-		   (if (string-match "gmane\\." folder-name)
-		       "http://mid.gmane.org/%s"
-		     "http://groups.google.com/groups/search?as_umsgid=%s")
-		   (org-fixup-message-id-for-http message-id)))
-       (org-store-link-props :type "http" :link link :description subject
-			     :from from :to to :message-id message-id
-			     :subject subject))
-      (t
-       (org-store-link-props :type "wl" :from from :to to
-			     :subject subject :message-id message-id)
-       (setq message-id (org-remove-angle-brackets message-id))
-       (setq desc (org-email-link-description))
-       (setq link (org-make-link "wl:" folder-name "#" message-id))
-       (org-add-link-props :link link :description desc)))
-     (or link xref))))
+  "Store a link to a WL message or folder."
+  (cond
+   ((memq major-mode '(wl-summary-mode mime-view-mode))
+    (org-wl-store-link-message))
+   ((eq major-mode 'wl-folder-mode)
+    (org-wl-store-link-folder))
+   (t
+    nil)))
+
+(defun org-wl-store-link-folder ()
+  "Store a link to a WL folder."
+  (let* ((folder (wl-folder-get-entity-from-buffer))
+	 (petname (wl-folder-get-petname folder))
+	 (link (org-make-link "wl:" folder)))
+    (save-excursion
+      (beginning-of-line)
+      (if (and (wl-folder-buffer-group-p)
+	       (looking-at wl-folder-group-regexp))
+	  (error "Cannot store link to folder group: %s" folder))
+      (org-store-link-props :type "wl" :description petname
+			    :link link)
+      link)))
+
+(defun org-wl-store-link-message ()
+  "Store a link to a WL message."
+  (save-excursion
+    (let ((buf (if (eq major-mode 'wl-summary-mode)
+		   (current-buffer)
+		 (and (boundp 'wl-message-buffer-cur-summary-buffer)
+		      wl-message-buffer-cur-summary-buffer))))
+      (when buf
+	(with-current-buffer buf
+	  (let* ((msgnum (wl-summary-message-number))
+		 (mark-info (wl-summary-registered-temp-mark msgnum))
+		 (folder-name
+		  (if (and org-wl-link-to-refile-destination
+			   mark-info
+			   (equal (nth 1 mark-info) "o")) ; marked as refile
+		      (nth 2 mark-info)
+		    wl-summary-buffer-folder-name))
+		 (folder-type (org-wl-folder-type folder-name))
+		 (wl-message-entity
+		  (if (fboundp 'elmo-message-entity)
+		      (elmo-message-entity
+		       wl-summary-buffer-elmo-folder msgnum)
+		    (elmo-msgdb-overview-get-entity
+		     msgnum (wl-summary-buffer-msgdb))))
+		 (message-id (org-wl-message-field 'message-id wl-message-entity))
+		 (from (org-wl-message-field 'from wl-message-entity))
+		 (to (org-wl-message-field 'to wl-message-entity))
+		 (xref (org-wl-message-field 'xref wl-message-entity))
+		 (subject (org-wl-message-field 'subject wl-message-entity))
+		 desc link)
+
+	    ;; remove text properties of subject string to avoid possible bug
+	    ;; when formatting the subject
+	    ;; (Emacs bug #5306, fixed)
+	    (set-text-properties 0 (length subject) nil subject)
+
+	    ;; maybe remove filter condition
+	    (when (and (eq folder-type 'filter) org-wl-link-remove-filter)
+	      (while (eq (org-wl-folder-type folder-name) 'filter)
+		(setq folder-name
+		      (replace-regexp-in-string "^/[^/]+/" "" folder-name))))
+
+	    ;; maybe create http link
+	    (cond
+	     ((and (eq folder-type 'shimbun) org-wl-shimbun-prefer-web-links xref)
+	      (org-store-link-props :type "http" :link xref :description subject
+				    :from from :to to :message-id message-id
+				    :subject subject))
+	     ((and (eq folder-type 'nntp) org-wl-nntp-prefer-web-links)
+	      (setq link (format
+			  (if (string-match "gmane\\." folder-name)
+			      "http://mid.gmane.org/%s"
+			    "http://groups.google.com/groups/search?as_umsgid=%s")
+			  (org-fixup-message-id-for-http message-id)))
+	      (org-store-link-props :type "http" :link link :description subject
+				    :from from :to to :message-id message-id
+				    :subject subject))
+	     (t
+	      (org-store-link-props :type "wl" :from from :to to
+				    :subject subject :message-id message-id)
+	      (setq message-id (org-remove-angle-brackets message-id))
+	      (setq desc (org-email-link-description))
+	      (setq link (org-make-link "wl:" folder-name "#" message-id))
+	      (org-add-link-props :link link :description desc)))
+	    (or link xref)))))))
 
 (defun org-wl-open (path)
   "Follow the WL message link specified by PATH.
@@ -228,9 +255,9 @@ for namazu index."
 	;; beginning of the current line.  So, restore the point
 	;; in the old buffer.
 	(goto-char old-point))
-     (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
-						  article))
-	   (wl-summary-redisplay)))))
+     (and article (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
+							 article))
+	  (wl-summary-redisplay)))))
 
 (provide 'org-wl)
 

[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

             reply	other threads:[~2010-05-07 16:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-07 15:36 David Maus [this message]
2010-05-08  5:33 ` [patch] org-wl: Code cleanup and enhancements Carsten Dominik
2010-05-08 12:25   ` David Maus

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87632zafm8.wl%dmaus@ictsoc.de \
    --to=dmaus@ictsoc.de \
    --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 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).