mirror of
https://github.com/correl/dotfiles.git
synced 2024-11-21 19:18:41 +00:00
[emacs] Add more slipbox selection functions
This commit is contained in:
parent
16d79e64ad
commit
7059aed9a0
1 changed files with 44 additions and 15 deletions
|
@ -979,37 +979,66 @@ keep them tidy.
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defvar my/org-roam-slipbox-directory (expand-file-name "~/roam"))
|
(defvar my/org-roam-slipbox-directory (expand-file-name "~/roam"))
|
||||||
|
|
||||||
|
(defun my/slipbox-directories ()
|
||||||
|
(f-directories my/org-roam-slipbox-directory))
|
||||||
|
|
||||||
|
(defun my/slipbox-names ()
|
||||||
|
(-map #'f-filename (my/slipbox-directories)))
|
||||||
|
|
||||||
|
(defun my/slipbox--directory (slipbox)
|
||||||
|
(f-join my/org-roam-slipbox-directory slipbox))
|
||||||
|
|
||||||
|
(defun my/slipbox--database (slipbox)
|
||||||
|
(f-join my/org-roam-slipbox-directory (s-concat slipbox ".db")))
|
||||||
|
|
||||||
|
(defmacro my/with-slipbox (slipbox &rest body)
|
||||||
|
`(let ((org-roam-directory (my/slipbox--directory ,slipbox))
|
||||||
|
(org-roam-db-location (my/slipbox--database ,slipbox)))
|
||||||
|
,@body))
|
||||||
|
|
||||||
(defun my/org-roam-slipbox-node-find ()
|
(defun my/org-roam-slipbox-node-find ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((slipbox (completing-read "Slipbox" (-map #'f-filename (f-directories my/org-roam-slipbox-directory)))))
|
(let ((slipbox (completing-read "Slipbox: " (my/slipbox-names))))
|
||||||
(setq org-roam-directory (f-join my/org-roam-slipbox-directory slipbox)
|
(setq org-roam-directory (my/slipbox--directory slipbox)
|
||||||
org-roam-db-location (f-join my/org-roam-slipbox-directory (s-concat slipbox ".db")))
|
org-roam-db-location (my/slipbox--database slipbox))
|
||||||
(unless (f-exists? org-roam-db-location)
|
(unless (f-exists? org-roam-db-location)
|
||||||
(org-roam-db-sync))
|
(org-roam-db-sync))
|
||||||
(org-roam-node-find)))
|
(org-roam-node-find)))
|
||||||
|
|
||||||
(defun my/org-roam-slipbox-db-sync ()
|
(defun my/org-roam-slipbox-db-sync ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(-each (-map #'f-filename (f-directories my/org-roam-slipbox-directory))
|
(--each (my/slipbox-names)
|
||||||
(lambda (slipbox)
|
(my/with-slipbox it (org-roam-db-sync))))
|
||||||
(let ((org-roam-directory (f-join my/org-roam-slipbox-directory slipbox))
|
|
||||||
(org-roam-db-location (f-join my/org-roam-slipbox-directory (s-concat slipbox ".db"))))
|
(defun my/slipbox-select (slipbox)
|
||||||
(org-roam-db-sync)))))
|
(interactive
|
||||||
|
(list (completing-read "Slipbox: " (my/slipbox-names))))
|
||||||
|
(unless (member slipbox (my/slipbox-names))
|
||||||
|
(error "Unknown slipbox %s" slipbox))
|
||||||
|
(setq org-roam-directory (my/slipbox--directory slipbox)
|
||||||
|
org-roam-db-location (my/slipbox--database slipbox))
|
||||||
|
(unless (f-exists? org-roam-db-location)
|
||||||
|
(org-roam-db-sync))
|
||||||
|
slipbox)
|
||||||
|
|
||||||
(map! :leader
|
(map! :leader
|
||||||
(:prefix-map ("n" . "notes")
|
(:prefix-map ("n" . "notes")
|
||||||
(:prefix ("r" . "roam")
|
(:prefix ("r" . "roam")
|
||||||
:desc "Find file in slipbox" "F" #'my/org-roam-slipbox-node-find)))
|
:desc "Select slipbox" "c" #'my/slipbox-select)))
|
||||||
|
|
||||||
(map! :leader
|
(map! :leader
|
||||||
(:prefix-map ("n" . "notes")
|
(:prefix-map ("n" . "notes")
|
||||||
(:prefix ("r" . "roam")
|
(:prefix ("r" . "roam")
|
||||||
:desc "Synchronize all slipbox databases" "S" #'my/org-roam-slipbox-db-sync)))
|
:desc "Find file in slipbox" "F" #'my/org-roam-slipbox-node-find)))
|
||||||
|
|
||||||
|
(map! :leader
|
||||||
|
(:prefix-map ("n" . "notes")
|
||||||
|
(:prefix ("r" . "roam")
|
||||||
|
:desc "Synchronize all slipbox databases" "S" #'my/org-roam-slipbox-db-sync)))
|
||||||
|
|
||||||
;; Set a default org-roam directory from the available slipboxes
|
;; Set a default org-roam directory from the available slipboxes
|
||||||
(if-let (slipbox (-first-item (-map #'f-filename (f-directories my/org-roam-slipbox-directory))))
|
(if-let (slipbox (-first-item (my/slipbox-names)))
|
||||||
(setq org-roam-directory (f-join my/org-roam-slipbox-directory slipbox)
|
(my/slipbox-select slipbox))
|
||||||
org-roam-db-location (f-join my/org-roam-slipbox-directory (s-concat slipbox ".db"))))
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
*** Sidebar
|
*** Sidebar
|
||||||
|
|
Loading…
Reference in a new issue