-
Notifications
You must be signed in to change notification settings - Fork 4
/
paw-org.el
83 lines (72 loc) · 2.92 KB
/
paw-org.el
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
82
83
;;; paw-org.el -*- lexical-binding: t; -*-
(require 'paw-vars)
(require 'ol)
(org-link-set-parameters
"paw"
:follow #'paw-org-link-view-note
:face 'paw-link-face)
(defun paw-org-link-copy ()
"Copy the marked items as paw org links."
(interactive)
(let* ((marked-entries (paw-find-marked-candidates))
(entries (or marked-entries (list (get-text-property (point) 'paw-entry)))))
(kill-new
(with-temp-buffer
(dolist (entry entries)
(let* ((origin-word (alist-get 'word entry))
(word (paw-get-real-word origin-word)))
(insert (format "[[paw:%s][%s]]\n" origin-word word))
(message "Copied: \"%s\" as paw org link." word)))
(buffer-string)))
;; remove overlays and text properties
(paw-clear-marks)))
;;;###autoload
(defun paw-org-link-find-note (word arg)
"Follow paw org links."
(let ((entry (paw-candidate-by-id word)))
(if entry
(if arg
;; (paw-goto-dashboard (car entry))
(paw-find-origin (car entry))
(paw-find-note (car entry) t))
(message "No this entry."))))
;;;###autoload
(defun paw-org-link-view-note (word _)
"Follow paw org link."
(let ((entry (car (paw-candidate-by-word word) ))
(paw-view-note-show-type 'buffer))
(if entry
(paw-view-note entry)
(paw-view-note (paw-new-entry word) :no-pushp t :buffer-name paw-view-note-sub-buffer-name))))
(defcustom paw-org-protocol-display-function 'switch-to-buffer
"The function to display the note buffer."
:type 'function
:group 'paw)
(defun paw-org-protocol (data)
(let* ((note (plist-get data :note))
(url (plist-get data :url))
(title (plist-get data :title))
(word (plist-get data :body))
(entry (or (car (paw-candidate-by-word word))
(car (paw-candidate-by-word (downcase word))))))
(paw-view-note (or entry (paw-new-entry word
:origin_type "browser"
:serverp 3
:content (json-encode data)
:origin_path url
:origin_point title
:lang (paw-check-language word)
:context note ) )
;; :buffer-name (format "*Paw: %s*" title)
:buffer-name paw-view-note-buffer-name
:display-func paw-org-protocol-display-function)
nil))
(defun paw-org-setup-org-protocol()
(require 'org-protocol)
(add-to-list 'org-protocol-protocol-alist '("paw"
:protocol "paw"
:function paw-org-protocol
:kill-client t)))
;; setup org protocol for user
(paw-org-setup-org-protocol)
(provide 'paw-org)