mirror of
https://github.com/org-roam/org-roam
synced 2025-08-03 12:27:23 -05:00
Use a side window instead
This commit is contained in:
56
org-roam.el
56
org-roam.el
@ -10,12 +10,32 @@
|
|||||||
(defcustom org-roam-zettel-indicator "§"
|
(defcustom org-roam-zettel-indicator "§"
|
||||||
"Indicator in front of a zettel.")
|
"Indicator in front of a zettel.")
|
||||||
|
|
||||||
(defvar org-roam-backlinks-buffer "*org-roam-backlinks*"
|
(defvar org-roam-buffer "*org-roam*"
|
||||||
"Backlink buffer name.")
|
"Org-roam buffer name.")
|
||||||
|
|
||||||
|
(defcustom org-roam-position 'right
|
||||||
|
"Position of org-roam buffer.
|
||||||
|
|
||||||
|
Valid values are
|
||||||
|
* left,
|
||||||
|
* right."
|
||||||
|
:type '(choice (const left)
|
||||||
|
(const right))
|
||||||
|
:group 'org-roam)
|
||||||
|
|
||||||
(defvar org-roam-hash-backlinks nil
|
(defvar org-roam-hash-backlinks nil
|
||||||
"Cache containing backlinks for org-roam buffers.")
|
"Cache containing backlinks for org-roam buffers.")
|
||||||
|
|
||||||
|
(define-inline org-roam-current-visibility ()
|
||||||
|
"Return whether the current visibility state of the org-roam buffer.
|
||||||
|
Valid states are 'visible, 'exists and 'none."
|
||||||
|
(declare (side-effect-free t))
|
||||||
|
(inline-quote
|
||||||
|
(cond
|
||||||
|
((get-buffer-window org-roam-buffer) 'visible)
|
||||||
|
((get-buffer org-roam-buffer) 'exists)
|
||||||
|
(t 'none))))
|
||||||
|
|
||||||
(defun org-roam-insert (file-name)
|
(defun org-roam-insert (file-name)
|
||||||
"Finds a file, inserts it as a link with the base file name as the link name."
|
"Finds a file, inserts it as a link with the base file name as the link name."
|
||||||
(interactive (list (completing-read "File: " (deft-find-all-files-no-prefix))))
|
(interactive (list (completing-read "File: " (deft-find-all-files-no-prefix))))
|
||||||
@ -87,25 +107,14 @@ SLUG is the short file name, without a path or a file extension."
|
|||||||
(interactive)
|
(interactive)
|
||||||
(org-roam-new-file-named (format-time-string "%Y-%m-%d" (current-time))))
|
(org-roam-new-file-named (format-time-string "%Y-%m-%d" (current-time))))
|
||||||
|
|
||||||
(defun org-roam-backlinks-split ()
|
(defun org-roam-update ()
|
||||||
"Split window and show backlinks."
|
|
||||||
(when (= (length (window-list)) 1)
|
|
||||||
(split-window-right))
|
|
||||||
(other-window 1)
|
|
||||||
(switch-to-buffer org-roam-backlinks-buffer)
|
|
||||||
(other-window -1))
|
|
||||||
|
|
||||||
(defun org-roam-backlinks ()
|
|
||||||
(interactive)
|
(interactive)
|
||||||
"Show the backlinks for the current org-buffer."
|
"Show the backlinks for the current org-buffer."
|
||||||
(unless org-roam-hash-backlinks
|
(unless org-roam-hash-backlinks
|
||||||
(org-roam-build-backlinks))
|
(org-roam-build-backlinks))
|
||||||
(get-buffer-create org-roam-backlinks-buffer)
|
|
||||||
(unless (get-buffer-window org-roam-backlinks-buffer)
|
|
||||||
(org-roam-backlinks-split))
|
|
||||||
(let* ((file (file-name-nondirectory (buffer-file-name (current-buffer))))
|
(let* ((file (file-name-nondirectory (buffer-file-name (current-buffer))))
|
||||||
(backlinks (ht-get org-roam-hash-backlinks file)))
|
(backlinks (ht-get org-roam-hash-backlinks file)))
|
||||||
(with-current-buffer org-roam-backlinks-buffer
|
(with-current-buffer org-roam-buffer
|
||||||
(read-only-mode -1)
|
(read-only-mode -1)
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(org-mode)
|
(org-mode)
|
||||||
@ -117,4 +126,21 @@ SLUG is the short file name, without a path or a file extension."
|
|||||||
) backlinks)
|
) backlinks)
|
||||||
(read-only-mode +1))))
|
(read-only-mode +1))))
|
||||||
|
|
||||||
|
(defun org-roam ()
|
||||||
|
"Initialize org-roam."
|
||||||
|
(interactive)
|
||||||
|
(pcase (org-roam-current-visibility)
|
||||||
|
('visible nil)
|
||||||
|
('exists (org-roam-split))
|
||||||
|
('none (org-roam-split))))
|
||||||
|
|
||||||
|
(defun org-roam-split ()
|
||||||
|
(interactive)
|
||||||
|
(org-roam-setup-buffer)
|
||||||
|
(org-roam-update))
|
||||||
|
|
||||||
|
(defun org-roam-setup-buffer ()
|
||||||
|
(-> (get-buffer-create org-roam-buffer)
|
||||||
|
(display-buffer-in-side-window `((side . ,org-roam-position)))))
|
||||||
|
|
||||||
(provide 'org-roam)
|
(provide 'org-roam)
|
||||||
|
Reference in New Issue
Block a user