Skip to content

Instantly share code, notes, and snippets.

@odomanov
Last active May 4, 2022 03:58
Show Gist options
  • Select an option

  • Save odomanov/73e85bc6163557482b1a7aef55c1bad3 to your computer and use it in GitHub Desktop.

Select an option

Save odomanov/73e85bc6163557482b1a7aef55c1bad3 to your computer and use it in GitHub Desktop.
Emacs setup for org-roam-ui
;; For Org-roam version 2.
;; Links should be defined in Org mode (see below)
;; (defface org-roam-link-major
;; '((t (:inherit org-link
;; :foreground "Indian Red"
;; )))
;; "Face for 'major' links."
;; :group 'org-roam-faces)
(defface org-roam-link-minor
'((t (:inherit org-link
;:foreground "MediumSeaGreen"
:foreground "SlateGray"
)))
"Face for 'minor' links."
:group 'org-roam-faces)
;; (defface org-roam-link-pointer
;; '((t (:inherit org-link
;; :foreground "BlueViolet"
;; )))
;; "Face for 'pointer' links."
;; :group 'org-roam-faces)
(defun org-roam-insert-link-type (link-type &rest args)
"Insert a link of type LINK-TYPE."
(interactive "P")
(org-roam-node-insert nil link-type))
(defun org-roam--make-link-at-point-tagged (tag)
"Adds the :tag TAG to the link at point.
TODO: check the correctness."
(let ((context (org-element-context)))
(when (eq (org-element-type context) 'link)
(when (equal (org-element-property :type context) "id")
(let* ((path (org-element-property :path context))
(desc-begin (org-element-property :contents-begin context))
(desc-end (org-element-property :contents-end context))
(link-begin (org-element-property :begin context))
(link-end (org-element-property :end context))
(desc (buffer-substring-no-properties desc-begin desc-end))
(newlink (concat "[[id:" path "|:tag " (symbol-name tag) "][" desc "]]")))
(delete-region link-begin link-end)
(insert newlink))))))
(require 'org-roam-link-properties)
(use-package org-roam
:commands org-roam-node-read--completions
:straight (org-roam :type git :host github :repo "org-roam/org-roam"
:fork (:host github :repo "odomanov/org-roam"))
:after org-roam-link-properties
:init
(setq org-roam-v2-ack t)
:custom
(org-roam-directory (concat YD-directory "org-roam-v2/"))
(org-roam-db-location (concat org-roam-directory (system-name) ".db"))
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n i" . org-roam-node-insert))
:config
(org-roam-db-autosync-enable)
;; (require 'org-roam-protocol)
(setq org-roam-graph-viewer
(lambda (file)
(let ((org-roam-graph-viewer
(cond ((equal system-type 'windows-nt)
(concat scripts-directory "firefoxOLEG.cmd"))
(t "firefox"))))
(org-roam-graph--open (concat "file://" file)))))
(setq org-roam-graph-executable "c:/Apps/Graphviz/bin/dot.exe")
;; (setq org-roam-db-update-method 'immediate)
;; (org-roam-setup) ;obsolete in v2
)
;; org-roam-ui
(use-package websocket
:after org-roam)
(use-package simple-httpd
:after org-roam)
(use-package org-roam-ui
:straight (org-roam-ui :type git :host github :repo "/org-roam/org-roam-ui"
:files ("*.el" "out")
:fork (:host github :repo "odomanov/org-roam-ui"
:branch "main" :files ("*.el" "out")))
:after org-roam
;; normally we'd recommend hooking orui after org-roam, but since org-roam does not have
;; a hookable mode anymore, you're advised to pick something yourself
;; if you don't care about startup time, use
;; :hook (after-init . org-roam-ui-mode)
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-update-on-save t
org-roam-ui-open-on-start t))
;; hydra
(defun odm/repair-ids ()
"Repair possibly missing IDs"
(interactive)
(org-id-update-id-locations
(directory-files-recursively org-roam-directory ".org$\\|.org.gpg$")))
(defhydra hydra-org-roam (:color blue :columns 3)
"Org-roam v.2 commands"
("l" org-roam-buffer-toggle "Org-roam buffer on/off")
("f" org-roam-node-find "Find file")
("d" delete-file-and-buffer "Delete current file")
("c" org-roam-db-sync "Build cache (repeat twice!)")
("g" org-roam-graph "Graph")
("s" org-roam-ui-mode "Server start/stop")
("e" org-roam-buffer-display-dedicated "Dedicated buffer")
("a" org-roam-alias-add "Add alias")
("A" org-roam-alias-remove "Remove alias")
("r" org-roam-ref-add "Add ref")
("R" org-roam-ref-remove "Remove ref")
("<f8>" org-roam-node-insert "Insert link (blue)" :color teal)
("t" (org-roam--make-link-at-point-tagged 'minor) "Make link minor")
("i" (org-roam--make-link-at-point-tagged 'index) "Make link index")
("p" odm/repair-ids "Repair IDs")
;; ("<f8>" (org-roam-insert-link-type "major") "Insert major link (red)" :color teal)
;; ("m" (org-roam-insert-link-type "minor") "Insert minor link (green)" :color teal)
;; ("x" (org-roam-insert-link-type "pointer") "Insert pointer link (gray)" :color teal)
;; cyrillic
("д" org-roam-buffer-toggle nil)
("а" org-roam-node-find nil)
("в" delete-file-and-buffer nil)
("с" org-roam-db-sync nil)
("п" org-roam-graph nil)
("ы" org-roam-ui-mode nil)
("у" org-roam-buffer-display-dedicated nil)
("ф" org-roam-alias-add nil)
("Ф" org-roam-alias-remove nil)
("к" org-roam-ref-add nil)
("К" org-roam-ref-remove nil)
("е" (org-roam--make-link-at-point-tagged 'minor) nil)
("ш" (org-roam--make-link-at-point-tagged 'index) nil)
("з" odm/repair-ids nil)
;; ("ш" org-roam-node-insert nil)
;; ("ь" (org-roam-insert-link-type "minor") nil)
;; ("ч" (org-roam-insert-link-type "pointer") nil)
(" <escape>" nil "quit")
)
(bind-key "<f8>" 'hydra-org-roam/body)
(defconst helm-source-org-roam
'((name . "Org Roam Files")
(candidates . org-roam-node-read--completions)
(type . file)
(action . (("Open" . (lambda (x)
(org-roam-node-visit x nil 'force))))))
"For Helm-mini.")
(defun link-activate-id (start end path bracketp)
(save-excursion
(goto-char start)
(let* ((link (org-element-link-parser))
(extra (org-element-property :extra-attrs link)))
(pcase (plist-get extra :tag)
('index
(put-text-property start (1+ start) 'display "(I)")) ;⟫Ⓘ
('major
(put-text-property start (1+ start) 'display "◆")) ;◆➤◀◁▶▷▲△▼▽
('minor
;; (put-text-property start (1+ start) 'display "◇") ;⇒➩↘▷◁▽◇
(add-face-text-property start end 'org-roam-link-minor))))))
(defun org-roam-export-link-id (link description format channel)
"Export an 'id' link from Org files."
(message-log "EXPORT:%s" link)
(let ((desc (or description link)))
(pcase format
('html
(message-log "FILE-P=%s (%s)" org-roam--org-roam-file-p (concat (expand-file-name org-roam-directory) link))
(when (org-roam--org-roam-file-p (concat (expand-file-name org-roam-directory) link))
(let ((html-link (concat (file-name-sans-extension link) ".html")))
(if org-roam-server-authenticate
(format "<a class=\"major\" href=%s?token=%s>➤%s</a>"
html-link org-roam-server-token desc)
(format "<a class=\"major\" href=%s>➤%s</a>" html-link desc)))))
(_ link))))
(org-link-set-parameters "id"
:follow #'org-id-open
;; :export #'org-roam-export-link-id
;; :export nil
;:face #'org-roam-id-face
:face 'org-link
:activate-func 'link-activate-id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment