emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] PATCH: Fix malformed "message" links produced by org-mac-link.el


From: Alan Schmitt
Subject: Re: [O] PATCH: Fix malformed "message" links produced by org-mac-link.el
Date: Thu, 09 Oct 2014 14:15:41 +0200
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (darwin)

Hello Steve,

On 2014-09-25 08:14, Alan Schmitt <address@hidden> writes:

> On 2014-09-24 20:56, Steve Purcell <address@hidden> writes:
>
>> On 24 Sep 2014, at 20:01, Alan Schmitt <address@hidden> wrote:
>>
>>> This was the case here: the string returned by the AppleScript had
>>> quotes (and it still does).
>>> 
>>> For instance, with the message you mention, the call to
>>> org-as-get-selected-mail returns this (doing a debug):
>>> 
>>> Result: "\"message://address@hidden::split::Private beta invitation for 
>>> Emacs Q&A site - Area 51 - Stack Exchange\””
>>
>>
>> I definitely don’t get quotes in the result of org-as-get-selected-mail.
>
>
>
>> Not sure how to proceed, then…
>
> It seems that the difference is with getting quotes or not. How about
> changing org-as-get-selected-mail to make sure there is no quote? We
> could for instance test whether the first and last characters are
> quotes, and remove them if they are.

Would this work for you?

Alan

From c6c1a05894e6fb1698d1a12bb2dc6a47874169f6 Mon Sep 17 00:00:00 2001
From: Alan Schmitt <address@hidden>
Date: Thu, 9 Oct 2014 14:12:05 +0200
Subject: [PATCH] org-mac-link.el: Fix malformed message links

* contrib/lisp/org-mac-link.el (org-mac-message-get-links): Fix and use the 
`org-mac-paste-applescript-links' helper.

The existing code inserted links which should have been "[[message:ABC][the 
subject]]"
as "[[essage:ABC][the subjec]]".

Based on a patch by Steve Purcell <address@hidden>.
---
 contrib/lisp/org-mac-link.el | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/contrib/lisp/org-mac-link.el b/contrib/lisp/org-mac-link.el
index 979fb18..e1ab56d 100644
--- a/contrib/lisp/org-mac-link.el
+++ b/contrib/lisp/org-mac-link.el
@@ -234,11 +234,15 @@ When done, go grab the link, and insert it at point."
 (defun org-mac-paste-applescript-links (as-link-list)
   "Paste in a list of links from an applescript handler.
 The links are of the form <link>::split::<name>."
-  (let* ((link-list
+  (let* ((noquote-as-link-list 
+         (if (string-prefix-p "\"" as-link-list) 
+             (substring as-link-list 1 -1) 
+           as-link-list))
+        (link-list
           (mapcar (lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x)
                                  (setq x (match-string 1 x)))
                    x)
-                 (split-string as-link-list "[\r\n]+")))
+                 (split-string noquote-as-link-list "[\r\n]+")))
          split-link URL description orglink orglink-insert rtn orglink-list)
     (while link-list
       (setq split-link (split-string (pop link-list) "::split::"))
@@ -828,27 +832,11 @@ The Org-syntax text will be pushed to the kill ring, and 
also returned."
   (interactive "sLink to (s)elected or (f)lagged messages: ")
   (setq select-or-flag (or select-or-flag "s"))
   (message "AppleScript: searching mailboxes...")
-  (let* ((as-link-list
-          (if (string= select-or-flag "s")
-              (org-as-get-selected-mail)
-           (if (string= select-or-flag "f")
-               (org-as-get-flagged-mail)
-             (error "Please select \"s\" or \"f\""))))
-         (link-list
-          (mapcar
-           (lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x) (setq x 
(match-string 1 x))) x)
-           (split-string (substring as-link-list 1 -1) "[\r\n]+")))
-         split-link URL description orglink orglink-insert rtn orglink-list)
-    (while link-list
-      (setq split-link (split-string (pop link-list) "::split::"))
-      (setq URL (car split-link))
-      (setq description (cadr split-link))
-      (when (not (string= URL ""))
-        (setq orglink (org-make-link-string URL description))
-        (push orglink orglink-list)))
-    (setq rtn (mapconcat 'identity orglink-list "\n"))
-    (kill-new rtn)
-    rtn))
+  (org-mac-paste-applescript-links
+   (cond
+    ((string= select-or-flag "s") (org-as-get-selected-mail))
+    ((string= select-or-flag "f") (org-as-get-flagged-mail))
+    (t (error "Please select \"s\" or \"f\"")))))
 
 (defun org-mac-message-insert-selected ()
   "Insert a link to the messages currently selected in Mail.app.
-- 
2.1.2


-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]