-
Notifications
You must be signed in to change notification settings - Fork 0
/
orp-ok-mode.el
57 lines (49 loc) · 1.95 KB
/
orp-ok-mode.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
;;; orp-ok-mode.el --- Plugin for org-roam-mode -*- lexical-binding: t -*-
;;
;; Copyright (C) 2024 Taro Sato
;;
;;; License:
;;
;; 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:
;;
;; This module provides a plugin for `org-roam-mode'.
;;
;;; Code:
(require 'org-roam)
(defun orp-ok-create-missing-directories (file)
"Create parent directories of FILE if missing."
(let* ((file (expand-file-name file))
(parent-directory (file-name-directory file)))
(and (not (file-remote-p file))
(string-prefix-p org-roam-directory file)
(not (file-directory-p parent-directory))
(make-directory parent-directory 'parents))))
(defun orp-ok-mode--create-missing-directories ()
"Automatically create missing directories when creating a file.
This hook removes the prompt for the directory creation during,
e.g., Org capture."
(let ((file buffer-file-name))
(orp-ok-create-missing-directories file)))
(add-hook 'find-file-not-found-functions
#'orp-ok-mode--create-missing-directories)
(defun rename-file--ok-create-missing-directories
(_ newname &optional _)
"Create missing directories when creating NEWNAME on `rename-file'."
(orp-ok-create-missing-directories newname))
(advice-add 'rename-file
:before #'rename-file--ok-create-missing-directories)
(provide 'orp-ok-mode)
;;; orp-ok-mode.el ends here