-
Notifications
You must be signed in to change notification settings - Fork 0
/
ol-library-article.el
55 lines (46 loc) · 2.14 KB
/
ol-library-article.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
;;; ol-library-article-*
(require 'ol-library-core)
(defcustom ol-library-article-dir "~/articles"
"The path to be used for article-links."
:group 'ol-library
:type 'directory
:safe t)
(defcustom ol-library-article-regexp (concat "\\`[^.].*\\." (regexp-opt (list "pdf" "epub" "doc" "docx")) "\\'")
"Regular expression to match files for `ol-library-article-store-link'"
:group 'ol-library
:type 'regexp
:safe t)
(defcustom ol-library-article-to-path-function-list '(ol-library-plain-folder-format
ol-library-year-folder-format)
"List of functions parsing a article string into a folder-path.
The first function in this list defines the preferred function
which will be used when creating new attachment folders. All
functions of this list will be tried when looking for articles."
:group 'ol-library
:type '(repeat (function :tag "Function with articlename as input"))
:safe t)
(defun ol-library-article--collect ()
"Create collection of articles."
(ol-library-collect ol-library-article-dir
ol-library-article-regexp))
(defun ol-library-article--expand (article)
"Expand an article into a path.
Based on `ol-library-article-to-path-function-list' and
`ol-library-article-dir'."
(ol-library-dir-from-library-object article
ol-library-article-to-path-function-list
ol-library-article-dir))
(defun ol-library-article-follow (article arg)
"Open ARTICLE attachment.
See `org-open-file' for details about ARG."
(org-link-open-as-file (ol-library-article--expand article) arg))
(defun ol-library-article-complete-link ()
"Advise the user with the available files in the attachment directory."
(if (file-exists-p ol-library-article-dir)
(concat "article:" (completing-read "Article: " (ol-library-article--collect)))
(error "No article directory exist")))
;;; org-link-set-parameters
(org-link-set-parameters "article"
:follow #'ol-library-article-follow
:complete #'ol-library-article-complete-link)
(provide 'ol-library-article)