-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphi-omnifocus.el
More file actions
81 lines (65 loc) · 3.09 KB
/
phi-omnifocus.el
File metadata and controls
81 lines (65 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;;; phi-omnifocus.el --- Integration with OmniFocus for Org and Markdown
;; Author: Bruno Conte <bruno@brunoc.com.br>
;; Version: 0.1
;; Created: 2023-10-01
;; Keywords: org, markdown, omnifocus
;; URL: https://github.com/brunocbr/phi-notes/phi-omnifocus.el
;; This file is not part of GNU Emacs.
;; This program 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.
;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This package allows you to send task headers from Org or
;; Markdown files to OmniFocus using the x-callback URL scheme.
;;; Code:
(defgroup phi-omnifocus nil
"Integration with OmniFocus."
:prefix "phi-omnifocus-"
:group 'external)
(defcustom phi-omnifocus-x-callback-url "omnifocus://x-callback-url/"
"Base URL for x-callback calls to OmniFocus."
:type 'string
:group 'phi-omnifocus)
(defun phi-omnifocus-send-task ()
"Sends the task under the cursor to OmniFocus, supporting Org mode and Markdown."
(interactive)
(let ((task-text (phi-omnifocus-get-task-text))
(current-url (when (and (boundp 'phi-mode) phi-mode)
(phi-get-current-note-url))))
(if task-text
(let* ((note (when current-url (concat "Source: " current-url)))
(url (format "%sadd?name=%s¬e=%s"
phi-omnifocus-x-callback-url
(url-encode-url task-text)
(url-encode-url note))))
(browse-url url))
(message "No task found on the current line."))))
(defun phi-omnifocus-sanitize-task-text (line)
"Sanitize LINE by removing Markdown list markers and tags like #todo #abcd."
(let ((sanitized-line line))
;; Remove Markdown list markers
(setq sanitized-line (replace-regexp-in-string "^\\s-*[-+*]\\s-*" "" sanitized-line))
(setq sanitized-line (replace-regexp-in-string "^\\s-*\\[\\s-*\\]\\s-*" "" sanitized-line)) ; Remove unmarked tasks
(setq sanitized-line (replace-regexp-in-string "^\\s-*\\[X]\\s-*" "" sanitized-line)) ; Remove marked tasks
;; Remove tags
(setq sanitized-line (replace-regexp-in-string "#[A-Za-z0-9_]+" "" sanitized-line))
;; Trim whitespace
(string-trim sanitized-line)))
(defun phi-omnifocus-get-task-text ()
"Gets the task text based on the current mode (Org or Text/Markdown)."
(if (equal major-mode 'org-mode)
(if (org-at-heading-p)
(org-get-heading t t)
nil)
(let ((line (thing-at-point 'line t)))
(phi-omnifocus-sanitize-task-text line))))
(global-set-key (kbd "C-c o") 'phi-omnifocus-send-task)
(provide 'phi-omnifocus)
;;; phi-omnifocus.el ends here