-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-deft-title.el
34 lines (29 loc) · 1.35 KB
/
my-deft-title.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
(defun my-deft/strip-quotes (str)
(cond ((string-match "\"\\(.+\\)\"" str) (match-string 1 str))
((string-match "'\\(.+\\)'" str) (match-string 1 str))
(t str)))
(defun my-deft/parse-title-from-front-matter-data (str)
(if (string-match "^title: \\(.+\\)" str)
(let* ((title-text (my-deft/strip-quotes (match-string 1 str)))
(is-draft (string-match "^draft: true" str)))
(concat (if is-draft "[DRAFT] " "") title-text))))
(defun my-deft/deft-file-relative-directory (filename)
(file-name-directory (file-relative-name filename deft-directory)))
(defun my-deft/title-prefix-from-file-name (filename)
(let ((reldir (my-deft/deft-file-relative-directory filename)))
(if reldir
(concat (directory-file-name reldir) " > "))))
(defun my-deft/parse-title-with-directory-prepended (orig &rest args)
(let ((str (nth 1 args))
(filename (car args)))
(concat
(my-deft/title-prefix-from-file-name filename)
(let ((nondir (file-name-nondirectory filename)))
(if (or (string-prefix-p "README" nondir)
(string-suffix-p ".txt" filename))
nondir
(if (string-prefix-p "---\n" str)
(my-deft/parse-title-from-front-matter-data
(car (split-string (substring str 4) "\n---\n")))
(apply orig args)))))))
(provide 'my-deft-title)