From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Suckling Subject: Re: Problem with org-mac-message.el Date: Sat, 4 Apr 2009 08:18:27 +0100 Message-ID: <4DDA3A2E-81DA-4FAE-8D96-68D5E38E6667@gmail.com> References: Mime-Version: 1.0 (Apple Message framework v930.3) Content-Type: multipart/mixed; boundary=Apple-Mail-1-676786373 Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lq09H-00055j-14 for emacs-orgmode@gnu.org; Sat, 04 Apr 2009 03:18:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lq09C-00050r-95 for emacs-orgmode@gnu.org; Sat, 04 Apr 2009 03:18:38 -0400 Received: from [199.232.76.173] (port=60680 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lq09C-00050c-5K for emacs-orgmode@gnu.org; Sat, 04 Apr 2009 03:18:34 -0400 Received: from mx20.gnu.org ([199.232.41.8]:22426) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lq09B-0007XA-Jw for emacs-orgmode@gnu.org; Sat, 04 Apr 2009 03:18:33 -0400 Received: from mail-ew0-f160.google.com ([209.85.219.160]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Lq09A-00028q-6A for emacs-orgmode@gnu.org; Sat, 04 Apr 2009 03:18:32 -0400 Received: by ewy4 with SMTP id 4so1382984ewy.42 for ; Sat, 04 Apr 2009 00:18:29 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Carsten Dominik Cc: emacs-orgmode emacs-orgmode , Christopher Suckling --Apple-Mail-1-676786373 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On 3 Apr 2009, at 17:58, Carsten Dominik wrote: > > On Apr 3, 2009, at 4:49 PM, Christopher Suckling wrote: > >> >> On 1 Apr 2009, at 21:21, Ed Hirgelt wrote: >> >>> I've found that org-mac-message-get-link has a problem inserting >>> [["]] as the first item. >> >> I can't replicate this. Could you provide an example? >> >>> The following change makes it better... >> >> Unfortunately, this change breaks the code for all other >> possibilities, and, if I understand the problem correctly, simply >> omits a link that begins [[" >> >> My beginner's elisp is rather clumsy; I'm going to attempt to tidy >> up the code anyway, so I'll be on the lookout for your difficulty >> whilst I do so. > > I think I already fixed it..... > Thanks! I've never used mapcar before... I've made things more modular so that your changes are reflected in searches for both selected and flagged mail. In doing so, I may have been rather naughty - I've changed the function names so that they are consistent: (org-mac-message-insert-link) becomes (org-mac-message-insert-selected) (org-mac-create-flagged-mail) becomes (org-mac-message-insert-flagged) both of which call the function (org-mac-message-get-links) to do their stuff. If this is not on, then I'll resubmit the patch with the original function names. Otherwise, new documentation is primed for pushing to Worg. Best, Christopher --Apple-Mail-1-676786373 Content-Disposition: attachment; filename=org-mac-message.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="org-mac-message.patch" Content-Transfer-Encoding: 7bit diff --git a/lisp/org-mac-message.el b/lisp/org-mac-message.el index 87cdea5..720b7e5 100644 --- a/lisp/org-mac-message.el +++ b/lisp/org-mac-message.el @@ -42,7 +42,7 @@ ;; If you have Growl installed and would like more visual feedback ;; whilst AppleScript searches for messages, please uncomment lines -;; 125 to 130. +;; 114 to 119. ;;; Code: @@ -81,64 +81,25 @@ This will use the command `open' with the message URL." (start-process (concat "open message:" message-id) nil "open" (concat "message://<" (substring message-id 2) ">"))) -(defun org-mac-message-insert-link () - "Insert a link to the messages currently selected in Apple Mail. -This will use applescript to get the message-id and the subject of the -active mail in AppleMail and make a link out of it." - (interactive) - (org-mac-message-get-link) - (yank)) - -(defun org-mac-message-get-link () - "Insert a link to the messages currently selected in Apple Mail. -This will use applescript to get the message-id and the subject of the -active mail in AppleMail and make a link out of it." - (let* ((as-link-list - (do-applescript - (concat - "tell application \"Mail\"\n" - "set theLinkList to {}\n" - "set theSelection to selection\n" - "repeat with theMessage in theSelection\n" - "set theID to message id of theMessage\n" - "set theSubject to subject of theMessage\n" - "set theLink to \"message://\" & theID & \"::split::\" & theSubject & \"\n\"\n" - "copy theLink to end of theLinkList\n" - "end repeat\n" - "return theLinkList as string\n" - "end tell"))) - (link-list - (mapcar - (lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x) (setq x (match-string 1 x))) x) - (split-string as-link-list "[\r\n]+"))) - split-link - URL - description - orglink - orglink-insert - (orglink-list nil)) - (while link-list - (progn - (setq split-link (split-string (pop link-list) "::split::")) - (setq URL (car split-link)) - (setq description (cadr split-link)) - (if (not (string= URL "")) - (progn - (setq orglink (org-make-link-string URL description)) - (push orglink orglink-list))))) - (with-temp-buffer - (while orglink-list - (insert (concat (pop orglink-list)) "\n")) - (kill-region (point-min) (point-max)) - (current-kill 0)))) - -(defun org-mac-create-flagged-mail () - "Create links to flagged messages in a Mail.app account and -copy them to the kill ring" - (interactive) - (message "AppleScript: searching mailboxes...") - (let* ((as-link-list - (do-applescript +(defun as-get-selected-mail () + "AppleScript to create links to selected messages in Mail.app" + (do-applescript + (concat + "tell application \"Mail\"\n" + "set theLinkList to {}\n" + "set theSelection to selection\n" + "repeat with theMessage in theSelection\n" + "set theID to message id of theMessage\n" + "set theSubject to subject of theMessage\n" + "set theLink to \"message://\" & theID & \"::split::\" & theSubject & \"\n\"\n" + "copy theLink to end of theLinkList\n" + "end repeat\n" + "return theLinkList as string\n" + "end tell"))) + +(defun as-get-flagged-mail () + "AppleScript to create links to flagged messages in Mail.app" + (do-applescript (concat "tell application \"Mail\"\n" "set theMailboxes to every mailbox of account \"" org-mac-mail-account "\"\n" @@ -160,28 +121,53 @@ copy them to the kill ring" "end repeat\n" "return theLinkList as string\n" "end tell"))) - (link-list (split-string as-link-list "\n")) + +(defun org-mac-message-get-links (select-or-flag) + "Create links to the messages currently selected or flagged in +Mail.app. This will use AppleScript to get the message-id and +the subject of the message in Mail.app and make a link out +of it." + (interactive "sLink to (s)elected or (f)lagged messages: ") + (message "AppleScript: searching mailboxes...") + (let* ((as-link-list + (if (string= select-or-flag "s") + (as-get-selected-mail) + (if (string= select-or-flag "f") + (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 as-link-list "[\r\n]+"))) split-link URL description orglink + orglink-insert (orglink-list nil)) (while link-list - (progn - (setq split-link (split-string (pop link-list) "::split::")) - (setq URL (car split-link)) - (setq description (cadr split-link)) - (if (not (string= URL "")) - (progn - (setq orglink (org-make-link-string URL description)) - (push orglink orglink-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))) (with-temp-buffer (while orglink-list (insert (concat (pop orglink-list)) "\n")) (kill-region (point-min) (point-max)) - (message "Flagged messages copied to kill ring")))) + (current-kill 0))) + (message "Messages copied to kill-ring")) + +(defun org-mac-message-insert-selected () + "Insert a link to the messages currently selected in Apple Mail. +This will use applescript to get the message-id and the subject of the +active mail in AppleMail and make a link out of it." + (interactive) + (org-mac-message-get-links "s") + (yank)) -(defun org-mac-insert-flagged-mail (org-buffer org-heading) +(defun org-mac-message-insert-flagged (org-buffer org-heading) "Asks for an org buffer and a heading within it. If heading exists, delete all message:// links within heading's first level. If heading doesn't exist, create it at point-max. Insert @@ -199,17 +185,17 @@ list of message:// links to flagged mail after heading." (while (re-search-forward message-re (save-excursion (outline-next-heading)) t) (delete-region (match-beginning 0) (match-end 0))) - (org-mac-create-flagged-mail) + (org-mac-message-get-links "f") (yank)) (flush-lines "^$" (point) (outline-next-heading))) (insert "\n") - (org-mac-create-flagged-mail) + (org-mac-message-get-links "f") (yank)) (goto-char (point-max)) (insert "\n") (org-insert-heading) (insert (concat org-heading "\n")) - (org-mac-create-flagged-mail) + (org-mac-message-get-links "f") (yank))))) (provide 'org-mac-message) --Apple-Mail-1-676786373 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-1-676786373 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --Apple-Mail-1-676786373--