forked from hasu/notdeft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notdeft-example.el
112 lines (98 loc) · 4.2 KB
/
notdeft-example.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
;; Autoloads for NotDeft commands.
(require 'notdeft-autoloads)
;; Full path of "notdeft-xapian" executable.
(let ((x
(let ((default-directory
(file-name-directory
(file-truename (locate-library "notdeft")))))
(file-truename "xapian/notdeft-xapian"))))
(setq notdeft-xapian-program
(and (file-executable-p x) x)))
;; As an alternative to the above, you can try building and
;; configuring "notdeft-xapian" on demand, but on most systems this
;; will not succeed out of the box.
;(add-hook 'notdeft-load-hook 'notdeft-xapian-make-program-when-uncurrent)
(defun run-local-variables-mode-hooks ()
"Run hooks for `major-mode' with locals set.
Like `run-mode-hooks', but run later, with any buffer and
directory local variables set."
(run-hooks (intern (concat (symbol-name major-mode)
"-local-variables-hook"))))
(add-hook 'hack-local-variables-hook 'run-local-variables-mode-hooks)
;; A variable determining whether to enable minor mode.
(defcustom notdeft-note-mode-auto-enable nil
"Whether to enable NotDeft Note minor mode for a buffer."
:type 'boolean
:safe 'booleanp)
(make-variable-buffer-local 'notdeft-note-mode-auto-enable)
;; Define a hook for conditionally enabling the NotDeft minor mode.
(defun default-notdeft-hook ()
"Conditionally enable `notdeft-note-mode'.
Enable when the buffer local variable
`notdeft-note-mode-auto-enable' is set to a non-nil value."
(when notdeft-note-mode-auto-enable
(notdeft-note-mode 1)))
;; Have Org mode files respect the flag. A hook like this should be
;; set for all NotDeft note file types, and no others.
(add-hook 'org-mode-local-variables-hook 'default-notdeft-hook)
(defun my-notdeft-add-directory-local-variables ()
"Add `notdeft-note-mode-auto-enable' flag.
Add it for all `notdeft-directories'."
(interactive)
(require 'notdeft) ;; for `notdeft-directories'
(dolist (dir notdeft-directories)
(make-directory dir t)
(let ((default-directory dir))
(add-dir-local-variable nil 'notdeft-note-mode-auto-enable t))))
;; Org mode "deft:" and "notdeft:" link support.
(eval-after-load 'org
(lambda ()
(let ((ver (ignore-errors
(car (version-to-list org-version)))))
(require (if (and ver (< ver 9))
'notdeft-org8
'notdeft-org9)))))
;; Add global bindings for NotDeft. To do that, bind a custom keymap
;; that inherits from NotDeft's, one that we can use to override and
;; add to the predefined set of bindings.
(require 'notdeft-global)
(defvar my-notdeft-global-map
(let ((map (make-sparse-keymap)))
(define-key map [(a) (d) (l) (v)]
#'my-notdeft-add-directory-local-variables)
(define-key map [(l)] #'notdeft-org-link-existing-note) ;; l for link
(define-key map [(n)] #'notdeft-org-link-new-file) ;; n for new
(define-key map [(s)] #'org-store-link) ;; s for store
(define-key map [(S)] #'notdeft-org-store-deft-link) ;; s for store
(define-key map [(*)] #'notdeft-org-open-heading-as-query)
(set-keymap-parent map 'notdeft-global-map)
map)
"Custom keymap for accessing NotDeft functionality.
\\{my-notdeft-global-map}")
(fset 'my-notdeft-global-map my-notdeft-global-map)
(global-set-key [f6] 'my-notdeft-global-map)
;; Add Org-specific bindings that are also usable in a NotDeft buffer.
(add-hook 'notdeft-load-hook
(lambda ()
(define-key notdeft-mode-map (kbd "C-c S")
#'notdeft-org-store-deft-link)))
(require 'hydra nil t)
(when (featurep 'hydra)
;; Augment `notdeft-mode' bindings with a hydra.
(autoload 'notdeft-mode-hydra/body "notdeft-mode-hydra" nil t)
(add-hook 'notdeft-load-hook
(lambda ()
(define-key notdeft-mode-map (kbd "C-c h")
#'notdeft-mode-hydra/body)))
;; Augment the global NotDeft keymap with a hydra also.
(autoload 'notdeft-global-hydra/body "notdeft-global-hydra" nil t)
(define-key my-notdeft-global-map [(h)] #'notdeft-global-hydra/body))
(require 'ivy nil t)
(when (featurep 'ivy)
;; Do minibuffer note selection by search and then Ivy choice list.
(require 'notdeft-ivy)
(add-to-list 'ivy-re-builders-alist
'(notdeft-ivy-completing-read . ivy--regex-ignore-order))
(setq notdeft-completing-read-function 'notdeft-ivy-completing-read)
(setq notdeft-select-note-file-by-search t)
(setq notdeft-select-note-file-all t))