-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteward.el
47 lines (42 loc) · 2 KB
/
steward.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
(setq org-capture-templates
'(("z" "Zettelkasten Entry" entry (file create-zettelkasten-entry)
"* %?\nEntered on %U\n %i\n %a")
("f" "Fleeting Entry" entry (file create-fleeting-entry)
"* %?\nEntered on %U\n %i\n %a"))
)
(defun create-zettelkasten-entry ()
"Create a dated filename for zettelkasten identification purposes."
(let ((name (read-string "Enter the file name: ")))
(expand-file-name (format "%s_%s.org"
(format-time-string "%Y%m%d%H%M%S")
name)
"~/Development/notes/")))
(defun create-fleeting-entry ()
"Create a dated filename for zettelkasten identification purposes."
(let ((name (read-string "Enter the file name: ")))
(expand-file-name (format "%s_%s.org"
(format-time-string "%Y%m%d%H%M%S")
name)
"~/Development/notes/fleeting/")))
(defun get-undated-filenames (directory)
"Return a list of filenames in the given Directory."
(directory-files directory nil "^[^0-9].*\.org$" t))
;; create-new-name -> get current datetime if current_datetime exists, decrement and check again else append datetime to the old name with an underscore
;; get datetimes at beginning of each file that has one
;; (directory-files "~/Development/notes/" nil "^[0-9]\\{14\\}_.*\\.org" t)
(defun get-14-digit-prefixes-as-numbers (directory)
"Get a list of 14-digit prefixes as numbers from filenames in DIRECTORY."
(let* ((files (directory-files directory nil "^[0-9]\\{14\\}_.*\\.org" t))
(digits-list '()))
(dolist (file files digits-list)
(when (string-match "^\\([0-9]\\{14\\}\\)" file)
(push (string-to-number (match-string 1 file)) digits-list)))))
(defun rename-file-safe (old-name new-name)
"Rename file old-name to new-name safely."
(condition-case err
(progn
(when (file-exists-p new-name)
(error "File '%s' already exists" new-name))
(rename-file old-name new-name)
(message "File renamed from '%s' to '%s'" old-name new-name))
(error (message "Error renaming file: %s" (error-message-string err)))))