Browse Source

Emacs: Upgrade org-roam from v1 to v2

master
Riyyi 2 years ago
parent
commit
d0447731da
  1. 124
      .config/emacs/config.org

124
.config/emacs/config.org

@ -81,7 +81,6 @@
- [[#lsp-functions][LSP Functions]]
- [[#neotree-functions][Neotree Functions]]
- [[#org-functions][Org Functions]]
- [[#org-roam-functions][Org Roam Functions]]
- [[#projectile-functions][Projectile Functions]]
- [[#selectrum-functions][Selectrum Functions]]
- [[#which-key-functions][Which-Key Functions]]
@ -368,7 +367,6 @@ Places buffers as tabs in a bar at the top.
helpful-mode
mu4e-view-mode
neotree-mode
org-roam-backlinks-mode
shell-mode)
. centaur-tabs-local-mode)
:config
@ -417,24 +415,58 @@ Setup =org-roam=.
#+BEGIN_SRC emacs-lisp
(use-package org-roam
:hook (emacs-startup . org-roam-mode)
:hook (org-roam-backlinks-mode . dot/hook-disable-line-numbers)
:hook (org-roam-backlinks-mode . dot/hook-disable-mode-line)
:defer 5
:init
(setq org-roam-v2-ack t)
:config
(setq org-image-actual-width nil)
(setq org-roam-completion-system 'default)
(setq org-image-actual-width nil) ;; TODO: Move to org section
(setq org-roam-db-location (expand-file-name "org-roam.db" dot-cache-dir))
(setq org-roam-directory (expand-file-name "./" org-directory))
;; Exclude Syncthing backup directory
(setq org-roam-file-exclude-regexp "\\.stversions")
(setq org-roam-title-to-slug-function #'dot/org-roam-title-to-slug)
(setq org-roam-verbose nil)
;; Templates used when creating a new file
(setq org-roam-capture-templates
'(("d" "default" plain #'org-roam-capture--get-point
'(("d" "default" plain
"%?"
:file-name "%<%Y%m%d%H%M%S>-${slug}" :head "#+TITLE: ${title}\n#+ROAM_TAGS: %^{Roam tags}\n" :unnarrowed t))))
:target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+TITLE: ${title}\n#+FILETAGS: %^{File tags}\n")
:unnarrowed t)))
(defun dot/org-roam-node-insert-immediate (arg &rest args)
(interactive "P")
(let ((args (push arg args))
(org-roam-capture-templates (list (append (car org-roam-capture-templates)
'(:immediate-finish t)))))
(apply #'org-roam-node-insert args)))
(cl-defmethod org-roam-node-slug ((node org-roam-node))
"Return the slug of NODE, strip out common words."
(let* ((title (org-roam-node-title node))
(words (split-string title " "))
(common-words '("a" "an" "and" "as" "at" "by" "is" "it" "of" "the" "to"))
(title (string-join (seq-remove (lambda (element) (member element common-words)) words) "_"))
(pairs '(("c\\+\\+" . "cpp") ;; convert c++ -> cpp
("c#" . "cs") ;; convert c# -> cs
("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric
("__*" . "_") ;; remove sequential underscores
("^_" . "") ;; remove starting underscore
("_$" . "")))) ;; remove ending underscore
(cl-flet* ((cl-replace (title pair)
(replace-regexp-in-string (car pair) (cdr pair) title)))
(downcase (-reduce-from #'cl-replace title pairs)))))
;; Right-align org-roam-node-tags in the completion menu without a length limit
;; Source: https://github.com/org-roam/org-roam/issues/1775#issue-971157225
(setq org-roam-node-display-template "${title} ${tags:0}")
(setq org-roam-node-annotation-function #'dot/org-roam-annotate-tag)
(defun dot/org-roam-annotate-tag (node)
(let ((tags (mapconcat 'identity (org-roam-node-tags node) " #")))
(unless (string-empty-p tags)
(concat
(propertize " " 'display `(space :align-to (- right ,(+ 2 (length tags)))))
(propertize (concat "#" tags) 'face 'bold)))))
(org-roam-setup))
#+END_SRC
Enable [[https://www.orgroam.com/manual.html#Roam-Protocol][Roam Protocol]], needed to process =org-protocol://= links
@ -447,9 +479,10 @@ Enable [[https://www.orgroam.com/manual.html#Roam-Protocol][Roam Protocol]], nee
;; Templates used when creating a new file from a bookmark
(setq org-roam-capture-ref-templates
'(("r" "ref" plain #'org-roam-capture--get-point
'(("r" "ref" plain
"%?"
:file-name "${slug}" :head "#+TITLE: ${title}\n#+ROAM_KEY: ${ref}\n\n${body}" :unnarrowed t))))
:target (file+head "${slug}.org" "#+TITLE: ${title}\n \n${body}")
:unnarrowed t))))
#+END_SRC
The roam-ref protocol bookmarks to add:
@ -462,27 +495,17 @@ javascript:location.href =
+ '&body=' + encodeURIComponent(window.getSelection())
#+END_SRC
Setup =org-roam-server=.
Setup =org-roam-ui=, runs at http://127.0.0.1:35901.
#+BEGIN_SRC emacs-lisp
(use-package simple-httpd
:after org-roam)
(use-package org-roam-server
:after (org-roam simple-httpd)
(use-package org-roam-ui
:after org-roam
;; :hook (emacs-startup . org-roam-ui-mode)
:config
(setq org-roam-server-host "127.0.0.1")
(setq org-roam-server-port 8080)
(setq org-roam-server-network-arrows "from")
(setq org-roam-server-style
(concat
"button#toggle-preview { margin: 4px; }"
"div#view-menu { margin: 4px; }"
"div#controls { right: 4px; left: 4px; bottom: 4px; }"
"button#toggle-list-type-button { margin: 0 4px; }"
"label#colormode { transform: translate(-25%, 0); }"
"label.toggle-off.btn-sm { padding-left: 0px; }"
)))
(setq org-roam-ui-follow t)
(setq org-roam-ui-open-on-start t)
(setq org-roam-ui-sync-theme nil) ;; FIXME: Make this work (org-roam-ui-get-theme)
(setq org-roam-ui-update-on-save t))
#+END_SRC
Easily searchable .org files via Deft.
@ -1658,18 +1681,6 @@ If point is on:
)))
#+END_SRC
*** Org Roam Functions
#+BEGIN_SRC emacs-lisp
(defun dot/org-roam-title-to-slug (title)
"Convert TITLE to a filename-suitable slug, strip out common words."
(let* ((common-words '("a" "an" "and" "as" "at" "by" "is" "it" "of" "the" "to"))
(title (replace-regexp-in-string "\\(c\\+\\+\\)" "cpp" title))
(title (replace-regexp-in-string "\\(c\\#\\)" "cs" title))
(words (split-string (org-roam--title-to-slug title) "\_")))
(string-join (seq-remove (lambda (element) (member element common-words)) words) "_")))
#+END_SRC
*** Projectile Functions
#+BEGIN_SRC emacs-lisp
@ -1939,6 +1950,10 @@ Set keybinds to functionality of installed packages.
(define-key magit-log-select-mode-map (kbd "M-c") #'magit-log-select-pick)
(define-key magit-log-select-mode-map (kbd "M-k") #'magit-log-select-quit))
;; Org-roam
(with-eval-after-load 'org-roam
(define-key org-roam-mode-map [down-mouse-1] #'org-roam-visit-thing))
;; Minibuffer completion selection
(general-def minibuffer-local-map
"M-h" #'abort-recursive-edit
@ -2195,18 +2210,17 @@ General.el ~leader key binds.
"i y" '(yas-insert-snippet :which-key "Insert yasnippet")
;; Notes
"n" '(:ignore t :which-key "notes")
"n a" '(org-agenda :which-key "Org agenda")
"n r" '(:ignore t :which-key "org-roam")
"n r b" '(org-roam-switch-to-buffer :which-key "Switch buffer")
"n r c" '(org-roam-capture :which-key "Capture")
"n r C" '(org-roam-db-build-cache :which-key "Build cache")
"n r f" '(org-roam-find-file :which-key "Find file")
"n r g" '(org-roam-graph-show :which-key "Show graph")
"n r i" '(org-roam-insert :which-key "Insert")
"n r I" '(org-roam-insert-immediate :which-key "Insert (without capture)")
"n r r" '(org-roam :which-key "Toggle side-buffer")
"n r s" '(org-roam-server-mode :which-key "Toggle server")
"n" '(:ignore t :which-key "notes")
"n a" '(org-agenda :which-key "Org agenda")
"n r" '(:ignore t :which-key "org-roam")
"n r c" '(org-roam-capture :which-key "Capture")
"n r C" '(org-roam-db-sync :which-key "Build cache")
"n r f" '(org-roam-node-find :which-key "Find node")
"n r g" '(org-roam-graph :which-key "Show graph")
"n r i" '(org-roam-node-insert :which-key "Insert")
"n r I" '(dot/org-roam-node-insert-immediate :which-key "Insert (without capture)")
"n r r" '(org-roam-buffer-toggle :which-key "Toggle buffer")
"n r s" '(org-roam-ui-mode :which-key "Toggle server")
;; Projectile
"p" '(:keymap projectile-command-map :package projectile :which-key "projectile")

Loading…
Cancel
Save