mirror of
https://github.com/org-roam/org-roam
synced 2025-09-30 17:00:56 -05:00
(bugfix): populate database after org-roam--make-new-file (#208)
This commit is contained in:
42
org-roam.el
42
org-roam.el
@@ -351,7 +351,6 @@ It uses TITLE and the current timestamp to form a unique title."
|
|||||||
(cadr (assoc (completing-read "Template: " org-roam-templates)
|
(cadr (assoc (completing-read "Template: " org-roam-templates)
|
||||||
org-roam-templates)))))
|
org-roam-templates)))))
|
||||||
|
|
||||||
|
|
||||||
(defun org-roam--make-new-file (&optional info)
|
(defun org-roam--make-new-file (&optional info)
|
||||||
(let ((template (org-roam--get-template (cdr (assoc 'template info))))
|
(let ((template (org-roam--get-template (cdr (assoc 'template info))))
|
||||||
(title (or (cdr (assoc 'title info))
|
(title (or (cdr (assoc 'title info))
|
||||||
@@ -359,16 +358,16 @@ It uses TITLE and the current timestamp to form a unique title."
|
|||||||
file-name-fn file-path)
|
file-name-fn file-path)
|
||||||
(fset 'file-name-fn (plist-get template :file))
|
(fset 'file-name-fn (plist-get template :file))
|
||||||
(setq file-path (org-roam--new-file-path (file-name-fn title) t))
|
(setq file-path (org-roam--new-file-path (file-name-fn title) t))
|
||||||
(setq info (cons (cons 'slug (org-roam--title-to-slug title)) info))
|
(push (cons 'slug (org-roam--title-to-slug title)) info)
|
||||||
(if (file-exists-p file-path)
|
(unless (file-exists-p file-path)
|
||||||
file-path
|
|
||||||
(org-roam--touch-file file-path)
|
(org-roam--touch-file file-path)
|
||||||
(write-region
|
(write-region
|
||||||
(s-format (plist-get template :content)
|
(s-format (plist-get template :content)
|
||||||
'aget
|
'aget
|
||||||
info)
|
info)
|
||||||
nil file-path nil)
|
nil file-path nil))
|
||||||
file-path)))
|
(org-roam--db-update-file file-path)
|
||||||
|
file-path))
|
||||||
|
|
||||||
;;; Inserting org-roam links
|
;;; Inserting org-roam links
|
||||||
(defun org-roam-insert (prefix)
|
(defun org-roam-insert (prefix)
|
||||||
@@ -553,13 +552,18 @@ INFO is an alist containing additional information."
|
|||||||
(when-let ((links (org-roam--extract-links)))
|
(when-let ((links (org-roam--extract-links)))
|
||||||
(org-roam--db-insert-links links))))
|
(org-roam--db-insert-links links))))
|
||||||
|
|
||||||
(defun org-roam--db-update-buffer-file ()
|
(defun org-roam--db-update-file (&optional file-path)
|
||||||
"Update org-roam caches for the current buffer file."
|
"Update org-roam caches for the FILE-PATH."
|
||||||
(save-excursion
|
(let (buf)
|
||||||
(org-roam--db-update-titles)
|
(if file-path
|
||||||
(org-roam--db-update-refs)
|
(setq buf (find-file-noselect file-path))
|
||||||
(org-roam--update-cache-links)
|
(setq buf (current-buffer)))
|
||||||
(org-roam--maybe-update-buffer :redisplay t)))
|
(with-current-buffer buf
|
||||||
|
(save-excursion
|
||||||
|
(org-roam--db-update-titles)
|
||||||
|
(org-roam--db-update-refs)
|
||||||
|
(org-roam--update-cache-links)
|
||||||
|
(org-roam--maybe-update-buffer :redisplay t)))))
|
||||||
|
|
||||||
;;; Org-roam daily notes
|
;;; Org-roam daily notes
|
||||||
(defun org-roam--file-for-time (time)
|
(defun org-roam--file-for-time (time)
|
||||||
@@ -766,7 +770,7 @@ Applies `org-roam-link-face' if PATH correponds to a Roam file."
|
|||||||
(when (org-roam--org-roam-file-p)
|
(when (org-roam--org-roam-file-p)
|
||||||
(setq org-roam-last-window (get-buffer-window))
|
(setq org-roam-last-window (get-buffer-window))
|
||||||
(add-hook 'post-command-hook #'org-roam--maybe-update-buffer nil t)
|
(add-hook 'post-command-hook #'org-roam--maybe-update-buffer nil t)
|
||||||
(add-hook 'after-save-hook #'org-roam--db-update-buffer-file nil t)
|
(add-hook 'after-save-hook #'org-roam--db-update-file nil t)
|
||||||
(org-roam--setup-file-links)
|
(org-roam--setup-file-links)
|
||||||
(org-roam--maybe-update-buffer :redisplay nil)))
|
(org-roam--maybe-update-buffer :redisplay nil)))
|
||||||
|
|
||||||
@@ -828,12 +832,8 @@ This sets `file:' Org links to have the org-link face."
|
|||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (re-search-forward named-regex nil t)
|
(while (re-search-forward named-regex nil t)
|
||||||
(replace-match (format "[[file:%s][\\1]]" relative-path))))
|
(replace-match (format "[[file:%s][\\1]]" relative-path))))
|
||||||
(save-window-excursion
|
(org-roam--db-update-file file-from)))
|
||||||
(find-file file-from)
|
(org-roam--db-update-file new-path))))
|
||||||
(org-roam--db-update-buffer-file))))
|
|
||||||
(save-window-excursion
|
|
||||||
(find-file new-path)
|
|
||||||
(org-roam--db-update-buffer-file)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode org-roam-mode
|
(define-minor-mode org-roam-mode
|
||||||
@@ -866,7 +866,7 @@ If ARG is `toggle', toggle `org-roam-mode'. Otherwise, behave as if called inter
|
|||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(org-roam--teardown-file-links)
|
(org-roam--teardown-file-links)
|
||||||
(remove-hook 'post-command-hook #'org-roam--maybe-update-buffer t)
|
(remove-hook 'post-command-hook #'org-roam--maybe-update-buffer t)
|
||||||
(remove-hook 'after-save-hook #'org-roam--db-update-buffer-file t))))))
|
(remove-hook 'after-save-hook #'org-roam--db-update-file t))))))
|
||||||
|
|
||||||
;;; Show/hide the org-roam buffer
|
;;; Show/hide the org-roam buffer
|
||||||
(define-inline org-roam--current-visibility ()
|
(define-inline org-roam--current-visibility ()
|
||||||
|
Reference in New Issue
Block a user