emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH]: Add elisp snippet to worg/org-contrib/org-mac.org
@ 2021-05-02 20:53 Tim Visher
  2021-05-03  4:05 ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Visher @ 2021-05-02 20:53 UTC (permalink / raw)
  To: Emacs Org Mode mailing list


[-- Attachment #1.1: Type: text/plain, Size: 6859 bytes --]

Hello,

At the recommendation of Tim Cross
<https://lists.gnu.org/archive/html/emacs-orgmode/2021-04/msg00813.html> I've
prepared a patch to worg to include the elisp that I recently sent to the
list that I've been using to create TODO items based on the currently
selected macOS Mail.app message.

Let me know if there's anything I can do to help get it applied.

From d1a7818593aee6bcb6de5c6837c506905a64f723 Mon Sep 17 00:00:00 2001
From: Tim Visher <tim@stitchdata.com> <tim%40stitchdata.com>
Date: Sun, 2 May 2021 16:34:24 -0400
Subject: [PATCH] org-mac: Add org-mac-mail-link section and elisp
---
 org-contrib/org-mac-mail-link.org | 147 ++++++++++++++++++++++++++++++
 org-mac.org                       |   5 +
 2 files changed, 152 insertions(+)
 create mode 100644 org-contrib/org-mac-mail-link.org
diff --git a/org-contrib/org-mac-mail-link.org
b/org-contrib/org-mac-mail-link.orgnew file mode 100644index
00000000..6e7f9c52--- /dev/null+++
b/org-contrib/org-mac-mail-link.org@@ -0,0 +1,147 @@+#+TITLE:
org-mac-mail-link.el -- Create and handle links to the selected
Mail.app message+#+OPTIONS:   ^:{} author:Tim Visher+#+STARTUP: odd++#
This file is released by its authors and contributors under the GNU+#
Free Documentation license v1.3 or later, code examples are released+#
under the GNU General Public License v3 or
later.++[[file:index.org][{Back to Worg's contibutions index}]]++*
Overview++  This code will allow you to capture a TODO item based on
the+  currently selected Mail.app message using =org-capture=.++*
Installation++  You should simply copy the source code from this
document into your+  init file and edit it as you see fit.++* Usage++
Activate =org-capture= however you see fit (=M-x org-capture= works+
just fine) and then whack the keychord you have set up to activate+
the capture template.++* Code++  #+begin_src elisp+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+
 ;;; Capture template for the currently selected Mail.app message+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++
 (defun org-mac-mail-link-get-selected-message-subject+      ()+
(with-temp-buffer+      (call-process+       "osascript" nil t nil+
   "-e" "tell application \"Mail\" to get subject of item 1 of
(selection as list)")+      (buffer-substring-no-properties
(point-min) (- (point-max) 1))))++  (defun
org-mac-mail-link-get-selected-message-id+      ()+
(with-temp-buffer+      (call-process+       "osascript" nil t nil+
   "-e" "tell application \"Mail\" to get message id of item 1 of
(selection as list)")+      ;; This additional encoding specifically
of =/= is because Mail.app+      ;; claims to be unable to find a
message if it's ID contains unencoded+      ;; slashes.+
(browse-url-url-encode-chars+       (buffer-substring-no-properties
(point-min) (- (point-max) 1))+       "[/]")))++  (defun
org-mac-mail-link-get-link-string+      ()+    (let ((subject
(org-mac-mail-link-get-selected-message-subject))+
(message-id (org-mac-mail-link-get-selected-message-id)))+
(org-link-make-string (format "message:%s" message-id)+
            subject)))++  (defun
org-mac-mail-link-get-body-quote-template-element+      ()+    (let
((body (setq body (with-temp-buffer+
(call-process+                              "osascript" nil t nil+
                         "-e" "tell application \"Mail\" to get
content of item 1 of (selection as list)")+
 (buffer-substring-no-properties (point-min) (- (point-max) 1))))))+
   (format "++    ,#+begin_quote+  %s+    ,#+end_quote"+
(string-join+               ;; Remove duplicate empty lines+
    (seq-reduce+                (lambda (acc next)+
(if (string= next (or (car (last acc)) ""))+                      acc+
                   (append acc (list next))))+                ;;
Indent each line by two spaces for inclusion in the quote+
   (mapcar (lambda (string)+                          (let ((string
(string-trim string)))+                            (if (string= ""
string)+                                string+
      (format "  %s" string))))+                        (split-string
body "\n"))+                '())+               "\n"))))++  (require
'org-capture)++  ;;; You may also wish to use the Customize interface
for this variable+  ;;; which is quite nice.+  (setq
org-capture-templates+        ;; These 2-item entries are only
necessary if you want to nest the+        ;; capture template under a
keychord.+        '(("t" "TODO")+          ("tc" "TODO Current")+
    ("tcm" "TODO Current Mail" entry+           ;; If you maintain
your TODO list in a single file this will+           ;; place the
resulting org-capture template expansion under the+           ;;
'Inbox' heading. You may want to modify this.+           ;;+
;; The resulting heading looks something like+           ;;+
;; ** TODO [[message:<encoded messageID>][subject]]+           ;;+
      ;;    [2021-05-02 Sun 16:22]+           ;;+           ;;
#+begin_quote+           ;;    Unwrapped+           ;;+           ;;
 Body+           ;;+           ;;    Text+           ;;
#+end_quote+           (file+headline "~/your-org-todo.org" "Inbox")+
         "* TODO %(org-mac-mail-link-get-link-string)++
%U%(org-mac-mail-link-get-body-quote-template-element)" :prepend t
:immediate-finish t)))++
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+
 ;;; Use =C-c C= as your org-capture keybinding+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++
 (eval-after-load 'org+    '(org-defkey org-mode-map (kbd "C-c C")
#'org-capture))++
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+
 ;;; Teach org about opening message links+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++
 (defun org-mac-mail-link-open-link+      (mid _)+    (start-process
"open-link" nil "open" (format "message://%%3C%s%%3E"+
                                 mid)))++  (defun
org-mac-mail-link-add-message-links+      ()+
(org-link-set-parameters+     "message" :follow
#'org-mac-mail-link-open-link))++  (eval-after-load 'org+
'(org-mac-mail-link-add-message-links))++  #+end_srcdiff --git
a/org-mac.org b/org-mac.orgindex 1cb5392b..2addd5f0 100644---
a/org-mac.org+++ b/org-mac.org@@ -33,6 +33,11 @@ applications other
than Emacs...
    insert it as a hyperlink at point in an org-mode document. Written
    by /Anthony Lander/.
+** org-mac-mail-link -- Hyperlink to messages in Mail.app+   A small
elisp file that addresses linking to Mail.app messages+   directly via
the =org-capture= system. For wider application+   support check out
[[file:org-contrib/org-mac-link.org][org-mac-link]].+
 * For use outside Emacs

   Push information from the current application into org-mode.--
2.30.1


Cheers!

--

In Christ,

Timmy V.

https://blog.twonegatives.com
http://five.sentenc.es

[-- Attachment #1.2: Type: text/html, Size: 28570 bytes --]

[-- Attachment #2: 0001-org-mac-Add-org-mac-mail-link-section-and-elisp.patch --]
[-- Type: application/octet-stream, Size: 6808 bytes --]

From d1a7818593aee6bcb6de5c6837c506905a64f723 Mon Sep 17 00:00:00 2001
From: Tim Visher <tim@stitchdata.com>
Date: Sun, 2 May 2021 16:34:24 -0400
Subject: [PATCH] org-mac: Add org-mac-mail-link section and elisp

---
 org-contrib/org-mac-mail-link.org | 147 ++++++++++++++++++++++++++++++
 org-mac.org                       |   5 +
 2 files changed, 152 insertions(+)
 create mode 100644 org-contrib/org-mac-mail-link.org

diff --git a/org-contrib/org-mac-mail-link.org b/org-contrib/org-mac-mail-link.org
new file mode 100644
index 00000000..6e7f9c52
--- /dev/null
+++ b/org-contrib/org-mac-mail-link.org
@@ -0,0 +1,147 @@
+#+TITLE:     org-mac-mail-link.el -- Create and handle links to the selected Mail.app message
+#+OPTIONS:   ^:{} author:Tim Visher
+#+STARTUP: odd
+
+# This file is released by its authors and contributors under the GNU
+# Free Documentation license v1.3 or later, code examples are released
+# under the GNU General Public License v3 or later.
+
+[[file:index.org][{Back to Worg's contibutions index}]]
+
+* Overview
+
+  This code will allow you to capture a TODO item based on the
+  currently selected Mail.app message using =org-capture=.
+
+* Installation
+
+  You should simply copy the source code from this document into your
+  init file and edit it as you see fit.
+
+* Usage
+
+  Activate =org-capture= however you see fit (=M-x org-capture= works
+  just fine) and then whack the keychord you have set up to activate
+  the capture template.
+
+* Code
+
+  #+begin_src elisp
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+  ;;; Capture template for the currently selected Mail.app message
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+  (defun org-mac-mail-link-get-selected-message-subject
+      ()
+    (with-temp-buffer
+      (call-process
+       "osascript" nil t nil
+       "-e" "tell application \"Mail\" to get subject of item 1 of (selection as list)")
+      (buffer-substring-no-properties (point-min) (- (point-max) 1))))
+
+  (defun org-mac-mail-link-get-selected-message-id
+      ()
+    (with-temp-buffer
+      (call-process
+       "osascript" nil t nil
+       "-e" "tell application \"Mail\" to get message id of item 1 of (selection as list)")
+      ;; This additional encoding specifically of =/= is because Mail.app
+      ;; claims to be unable to find a message if it's ID contains unencoded
+      ;; slashes.
+      (browse-url-url-encode-chars
+       (buffer-substring-no-properties (point-min) (- (point-max) 1))
+       "[/]")))
+
+  (defun org-mac-mail-link-get-link-string
+      ()
+    (let ((subject (org-mac-mail-link-get-selected-message-subject))
+          (message-id (org-mac-mail-link-get-selected-message-id)))
+      (org-link-make-string (format "message:%s" message-id)
+                            subject)))
+
+  (defun org-mac-mail-link-get-body-quote-template-element
+      ()
+    (let ((body (setq body (with-temp-buffer
+                             (call-process
+                              "osascript" nil t nil
+                              "-e" "tell application \"Mail\" to get content of item 1 of (selection as list)")
+                             (buffer-substring-no-properties (point-min) (- (point-max) 1))))))
+      (format "
+
+    ,#+begin_quote
+  %s
+    ,#+end_quote"
+              (string-join
+               ;; Remove duplicate empty lines
+               (seq-reduce
+                (lambda (acc next)
+                  (if (string= next (or (car (last acc)) ""))
+                      acc
+                    (append acc (list next))))
+                ;; Indent each line by two spaces for inclusion in the quote
+                (mapcar (lambda (string)
+                          (let ((string (string-trim string)))
+                            (if (string= "" string)
+                                string
+                              (format "  %s" string))))
+                        (split-string body "\n"))
+                '())
+               "\n"))))
+
+  (require 'org-capture)
+
+  ;;; You may also wish to use the Customize interface for this variable
+  ;;; which is quite nice.
+  (setq org-capture-templates
+        ;; These 2-item entries are only necessary if you want to nest the
+        ;; capture template under a keychord.
+        '(("t" "TODO")
+          ("tc" "TODO Current")
+          ("tcm" "TODO Current Mail" entry
+           ;; If you maintain your TODO list in a single file this will
+           ;; place the resulting org-capture template expansion under the
+           ;; 'Inbox' heading. You may want to modify this.
+           ;;
+           ;; The resulting heading looks something like
+           ;;
+           ;; ** TODO [[message:<encoded messageID>][subject]]
+           ;;
+           ;;    [2021-05-02 Sun 16:22]
+           ;;
+           ;;    #+begin_quote
+           ;;    Unwrapped
+           ;;
+           ;;    Body
+           ;;
+           ;;    Text
+           ;;    #+end_quote
+           (file+headline "~/your-org-todo.org" "Inbox")
+           "* TODO %(org-mac-mail-link-get-link-string)
+
+    %U%(org-mac-mail-link-get-body-quote-template-element)" :prepend t :immediate-finish t)))
+
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+  ;;; Use =C-c C= as your org-capture keybinding
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+  (eval-after-load 'org
+    '(org-defkey org-mode-map (kbd "C-c C") #'org-capture))
+
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+  ;;; Teach org about opening message links
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+  (defun org-mac-mail-link-open-link
+      (mid _)
+    (start-process "open-link" nil "open" (format "message://%%3C%s%%3E"
+                                                  mid)))
+
+  (defun org-mac-mail-link-add-message-links
+      ()
+    (org-link-set-parameters
+     "message" :follow #'org-mac-mail-link-open-link))
+
+  (eval-after-load 'org
+    '(org-mac-mail-link-add-message-links))
+
+  #+end_src
diff --git a/org-mac.org b/org-mac.org
index 1cb5392b..2addd5f0 100644
--- a/org-mac.org
+++ b/org-mac.org
@@ -33,6 +33,11 @@ applications other than Emacs...
    insert it as a hyperlink at point in an org-mode document. Written
    by /Anthony Lander/.
 
+** org-mac-mail-link -- Hyperlink to messages in Mail.app
+   A small elisp file that addresses linking to Mail.app messages
+   directly via the =org-capture= system. For wider application
+   support check out [[file:org-contrib/org-mac-link.org][org-mac-link]].
+
 * For use outside Emacs
 
   Push information from the current application into org-mode.
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH]: Add elisp snippet to worg/org-contrib/org-mac.org
  2021-05-02 20:53 [PATCH]: Add elisp snippet to worg/org-contrib/org-mac.org Tim Visher
@ 2021-05-03  4:05 ` Bastien
  2021-05-03 12:30   ` Tim Visher
  0 siblings, 1 reply; 5+ messages in thread
From: Bastien @ 2021-05-03  4:05 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

Hi Tim,

Tim Visher <tim.visher@gmail.com> writes:

> At the recommendation of Tim Cross I've prepared a patch to worg to
> include the elisp that I recently sent to the list that I've been
> using to create TODO items based on the currently selected macOS
> Mail.app message.
>
> Let me know if there's anything I can do to help get it applied.

Applied in Worg, thanks a lot.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH]: Add elisp snippet to worg/org-contrib/org-mac.org
  2021-05-03  4:05 ` Bastien
@ 2021-05-03 12:30   ` Tim Visher
  2021-05-03 12:58     ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Visher @ 2021-05-03 12:30 UTC (permalink / raw)
  To: Bastien; +Cc: Emacs Org Mode mailing list


[-- Attachment #1.1: Type: text/plain, Size: 1787 bytes --]

Hi Bastien,

On Mon, May 3, 2021 at 12:05 AM Bastien <bzg@gnu.org> wrote:

>
> Tim Visher <tim.visher@gmail.com> writes:
>
> > At the recommendation of Tim Cross I've prepared a patch to worg to
> > include the elisp that I recently sent to the list that I've been
> > using to create TODO items based on the currently selected macOS
> > Mail.app message.
> >
> > Let me know if there's anything I can do to help get it applied.
>
> Applied in Worg, thanks a lot.
>

Thanks for the quick apply!

I'm surprised but I failed to notice that I never actually finished the
hyperlink to the new org-mac-mail-link.org file from org-mac.org. I only
saw it when I went to the site <https://orgmode.org/worg/org-mac.html> to
check out the fruits of our labors. (-‸ლ)

Here's a quick patch that fixes that up:

From 5a363a927f67d2c8571085110ce336872a073fac Mon Sep 17 00:00:00 2001
From: Tim Visher <tim@stitchdata.com> <tim%40stitchdata.com>
Date: Mon, 3 May 2021 08:25:46 -0400
Subject: [PATCH] org-mac: Fix link to org-mac-mail-link from org-mac
---
 org-mac.org | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/org-mac.org b/org-mac.orgindex 2addd5f0..b7c334fd
100644--- a/org-mac.org+++ b/org-mac.org@@ -33,7 +33,7 @@ applications
other than Emacs...
    insert it as a hyperlink at point in an org-mode document. Written
    by /Anthony Lander/.
-** org-mac-mail-link -- Hyperlink to messages in Mail.app+**
[[file:org-contrib/org-mac-mail-link.org][org-mac-mail-link]] --
Hyperlink to messages in Mail.app
    A small elisp file that addresses linking to Mail.app messages
    directly via the =org-capture= system. For wider application
    support check out [[file:org-contrib/org-mac-link.org][org-mac-link]].--
2.30.1

[-- Attachment #1.2: Type: text/html, Size: 4204 bytes --]

[-- Attachment #2: 0001-org-mac-Fix-link-to-org-mac-mail-link-from-org-mac.patch --]
[-- Type: application/octet-stream, Size: 925 bytes --]

From 5a363a927f67d2c8571085110ce336872a073fac Mon Sep 17 00:00:00 2001
From: Tim Visher <tim@stitchdata.com>
Date: Mon, 3 May 2021 08:25:46 -0400
Subject: [PATCH] org-mac: Fix link to org-mac-mail-link from org-mac

---
 org-mac.org | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/org-mac.org b/org-mac.org
index 2addd5f0..b7c334fd 100644
--- a/org-mac.org
+++ b/org-mac.org
@@ -33,7 +33,7 @@ applications other than Emacs...
    insert it as a hyperlink at point in an org-mode document. Written
    by /Anthony Lander/.
 
-** org-mac-mail-link -- Hyperlink to messages in Mail.app
+** [[file:org-contrib/org-mac-mail-link.org][org-mac-mail-link]] -- Hyperlink to messages in Mail.app
    A small elisp file that addresses linking to Mail.app messages
    directly via the =org-capture= system. For wider application
    support check out [[file:org-contrib/org-mac-link.org][org-mac-link]].
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH]: Add elisp snippet to worg/org-contrib/org-mac.org
  2021-05-03 12:30   ` Tim Visher
@ 2021-05-03 12:58     ` Bastien
  2021-05-03 13:05       ` Tim Visher
  0 siblings, 1 reply; 5+ messages in thread
From: Bastien @ 2021-05-03 12:58 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

Hi Tim,

Tim Visher <tim.visher@gmail.com> writes:

> Here's a quick patch that fixes that up:

Applied, thanks.  If you want to contribute more to Worg, please 
send me the username you want in private and I'll create an account
for you on code.orgmode.org.

Thanks!

-- 
 Bastien


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH]: Add elisp snippet to worg/org-contrib/org-mac.org
  2021-05-03 12:58     ` Bastien
@ 2021-05-03 13:05       ` Tim Visher
  0 siblings, 0 replies; 5+ messages in thread
From: Tim Visher @ 2021-05-03 13:05 UTC (permalink / raw)
  To: Bastien; +Cc: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 350 bytes --]

On Mon, May 3, 2021 at 8:58 AM Bastien <bzg@gnu.org> wrote:

> Tim Visher <tim.visher@gmail.com> writes:
>
> > Here's a quick patch that fixes that up:
>
> Applied, thanks.  If you want to contribute more to Worg, please
> send me the username you want in private and I'll create an account
> for you on code.orgmode.org.
>

Thanks for the apply! :)

[-- Attachment #2: Type: text/html, Size: 793 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-03 13:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-02 20:53 [PATCH]: Add elisp snippet to worg/org-contrib/org-mac.org Tim Visher
2021-05-03  4:05 ` Bastien
2021-05-03 12:30   ` Tim Visher
2021-05-03 12:58     ` Bastien
2021-05-03 13:05       ` Tim Visher

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).