-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathol-tmsu.el
81 lines (63 loc) · 2.57 KB
/
ol-tmsu.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
;;; ol-tmsu.el --- Org-mode links to TMSU queries -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Wojciech Siewierski
;; Author: Wojciech Siewierski
;; URL: https://github.com/vifon/tmsu.el
;; Keywords: files, outlines, hypermedia
;; Version: 0.9
;; Package-Requires: ((emacs "28.1") (tmsu "0.9"))
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; org-mode links to TMSU queries.
;;; Code:
(require 'ol)
(eval-when-compile
(require 'subr-x))
(require 'tmsu-dired)
(defconst org-tmsu-link-regex
(rx (group (*? any))
"::"
(group (*? any))
(? "::"
(group (* any)))
eol)
"A regex matching an `org-mode' link this module generates.")
(defun org-tmsu-open-link (link &optional _arg)
"Implement the :follow handler for org LINKs saved from `tmsu-dired-query'.
See `org-link-parameters' for the details."
(string-match org-tmsu-link-regex link)
(let ((dir (match-string 1 link))
(query (match-string 2 link))
(flags (match-string 3 link)))
(tmsu-dired-query dir (split-string query ",") flags)))
(defun org-tmsu-store-link ()
"Implement the :store handler for org LINKs saved from `org-store-link'.
See `org-link-parameters' for the details."
(when (and (eq major-mode 'dired-mode)
(bound-and-true-p tmsu-dired-query-args))
(let* ((dir default-directory)
(query (string-join tmsu-dired-query-args ","))
(flags tmsu-dired-query-flags)
(link (if flags
(concat "tmsu:" dir "::" query "::" flags)
(concat "tmsu:" dir "::" query)))
(desc (funcall tmsu-dired-pretty-description-function)))
(org-link-store-props :type "tmsu"
:link link
:description desc
:directory dir
:query query))))
(org-link-set-parameters
"tmsu"
:follow #'org-tmsu-open-link
:store #'org-tmsu-store-link)
(provide 'ol-tmsu)
;;; ol-tmsu.el ends here