From 849b1e4aa8a5089943c0254e68db4a0bc40371d9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 19 Sep 2025 00:47:57 -0400 Subject: [PATCH] feat(org): org-roam-insert spacing in normal mode Fix: #8513 --- modules/lang/org/contrib/roam2.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/lang/org/contrib/roam2.el b/modules/lang/org/contrib/roam2.el index ad11b37ea..96f3220eb 100644 --- a/modules/lang/org/contrib/roam2.el +++ b/modules/lang/org/contrib/roam2.el @@ -47,6 +47,21 @@ In case of failure, fail gracefully." (advice-remove 'org-roam-db-query #'+org-roam-try-init-db-a) (org-roam-db-sync)) + (defadvice! +org-roam-node-insert-after-point-a (fn &rest args) + "If in evil normal mode and cursor is on a whitespace character, insert the +link after the whitespace rather than before. If at EOL, add a space before +inserting the link." + :around #'org-roam-node-insert + (if (and (bound-and-true-p evil-local-mode) + (not (evil-insert-state-p)) + (or (looking-at-p "[[:blank:]]") + (evil-eolp))) + (evil-with-state 'insert + (unless (eolp) (forward-char)) + (if (evil-eolp) (insert " ")) + (apply fn args)) + (apply fn args))) + (setq org-roam-directory (thread-first (or org-roam-directory "roam") (expand-file-name org-directory)