+roam-plus.el 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. ;;; +roam.el --- Description -*- lexical-binding: t; -*-
  2. ;;
  3. ;; Copyright (C) 2023 Colin Powell
  4. ;;
  5. ;; Author: Colin Powell <colin@unbl.ink>
  6. ;; Maintainer: Colin Powell <colin@unbl.ink>
  7. ;; Created: November 14, 2023
  8. ;; Modified: November 14, 2023
  9. ;; Version: 0.0.1
  10. ;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
  11. ;; Homepage: https://github.com/powellc/+pdf-page-nums
  12. ;; Package-Requires: ((emacs "24.3"))
  13. ;;
  14. ;; This file is not part of GNU Emacs.
  15. ;;
  16. ;;; Commentary:
  17. ;;
  18. ;; Description
  19. ;;
  20. ;;; Code:
  21. (provide '+roam-plus)
  22. (use-package! org-roam
  23. :after org
  24. :init
  25. (setq org-roam-directory (concat org-directory "/Org-roam/")
  26. org-roam-completion-everywhere nil
  27. ;;Functions tags are special types of tags which tells what the node are for
  28. ;;In the future, this should probably be replaced by categories
  29. hp/org-roam-function-tags '("compilation" "argument" "journal" "concept" "tool" "data" "bio" "literature" "event" "website"))
  30. :config
  31. ;; Org-roam interface
  32. (cl-defmethod org-roam-node-hierarchy ((node org-roam-node))
  33. "Return the node's TITLE, as well as it's HIERACHY."
  34. (let* ((title (org-roam-node-title node))
  35. (olp (mapcar (lambda (s) (if (> (length s) 10) (concat (substring s 0 10) "...") s)) (org-roam-node-olp node)))
  36. (level (org-roam-node-level node))
  37. (filetitle (org-roam-get-keyword "TITLE" (org-roam-node-file node)))
  38. (filetitle-or-name (if filetitle filetitle (file-name-nondirectory (org-roam-node-file node))))
  39. (shortentitle (if (> (length filetitle-or-name) 20) (concat (substring filetitle-or-name 0 20) "...") filetitle-or-name))
  40. (separator (concat " " (nerd-icons-octicon "nf-oct-chevron_right") " ")))
  41. (cond
  42. ((= level 1) (concat (propertize (format "=level:%d=" level) 'display
  43. (nerd-icons-faicon "nf-fa-file" :face 'nerd-icons-dyellow))
  44. (propertize shortentitle 'face 'org-roam-olp) separator title))
  45. ((= level 2) (concat (propertize (format "=level:%d=" level) 'display
  46. (nerd-icons-faicon "nf-fa-file" :face 'nerd-icons-dsilver))
  47. (propertize (concat shortentitle separator (string-join olp separator)) 'face 'org-roam-olp)
  48. separator title))
  49. ((> level 2) (concat (propertize (format "=level:%d=" level) 'display
  50. (nerd-icons-faicon "nf-fa-file" :face 'org-roam-olp))
  51. (propertize (concat shortentitle separator (string-join olp separator)) 'face 'org-roam-olp) separator title))
  52. (t (concat (propertize (format "=level:%d=" level) 'display
  53. (nerd-icons-faicon "nf-fa-file" :face 'nerd-icons-yellow))
  54. (if filetitle title (propertize filetitle-or-name 'face 'nerd-icons-dyellow)))))))
  55. (cl-defmethod org-roam-node-functiontag ((node org-roam-node))
  56. "Return the FUNCTION TAG for each node. These tags are intended to be unique to each file, and represent the note's function.
  57. journal data literature"
  58. (let* ((tags (seq-filter (lambda (tag) (not (string= tag "ATTACH"))) (org-roam-node-tags node))))
  59. (concat
  60. ;; Argument or compilation
  61. (cond
  62. ((member "argument" tags)
  63. (propertize "=f:argument=" 'display
  64. (nerd-icons-mdicon "nf-md-forum" :face 'nerd-icons-dred)))
  65. ((member "compilation" tags)
  66. (propertize "=f:compilation=" 'display
  67. (nerd-icons-mdicon "nf-md-format_list_text" :face 'nerd-icons-dyellow)))
  68. (t (propertize "=f:empty=" 'display
  69. (nerd-icons-codicon "nf-cod-remove" :face 'org-hide))))
  70. ;; concept, bio, data or event
  71. (cond
  72. ((member "concept" tags)
  73. (propertize "=f:concept=" 'display
  74. (nerd-icons-mdicon "nf-md-blur" :face 'nerd-icons-dblue)))
  75. ((member "tool" tags)
  76. (propertize "=f:tool=" 'display
  77. (nerd-icons-mdicon "nf-md-tools" :face 'nerd-icons-dblue)))
  78. ((member "bio" tags)
  79. (propertize "=f:bio=" 'display
  80. (nerd-icons-octicon "nf-oct-people" :face 'nerd-icons-dblue)))
  81. ((member "event" tags)
  82. (propertize "=f:event=" 'display
  83. (nerd-icons-codicon "nf-cod-symbol_event" :face 'nerd-icons-dblue)))
  84. ((member "data" tags)
  85. (propertize "=f:data=" 'display
  86. (nerd-icons-mdicon "nf-md-chart_arc" :face 'nerd-icons-dblue)))
  87. (t (propertize "=f:nothing=" 'display
  88. (nerd-icons-codicon "nf-cod-remove" :face 'org-hide))))
  89. ;; literature
  90. (cond
  91. ((member "literature" tags)
  92. (propertize "=f:literature=" 'display
  93. (nerd-icons-mdicon "nf-md-bookshelf" :face 'nerd-icons-dcyan)))
  94. ((member "website" tags)
  95. (propertize "=f:website=" 'display
  96. (nerd-icons-mdicon "nf-md-web" :face 'nerd-icons-dsilver)))
  97. (t (propertize "=f:nothing=" 'display
  98. (nerd-icons-codicon "nf-cod-remove" :face 'org-hide))))
  99. ;; journal
  100. )))
  101. (cl-defmethod org-roam-node-othertags ((node org-roam-node))
  102. "Return the OTHER TAGS of each notes."
  103. (let* ((tags (seq-filter (lambda (tag) (not (string= tag "ATTACH"))) (org-roam-node-tags node)))
  104. (specialtags hp/org-roam-function-tags)
  105. (othertags (seq-difference tags specialtags 'string=)))
  106. (propertize
  107. (string-join
  108. (append '(" ") othertags)
  109. (propertize "#" 'display
  110. (nerd-icons-faicon "nf-fa-hashtag" :face 'nerd-icons-dgreen)))
  111. 'face 'nerd-icons-dgreen)))
  112. (cl-defmethod org-roam-node-backlinkscount ((node org-roam-node))
  113. (let* ((count (caar (org-roam-db-query
  114. [:select (funcall count source)
  115. :from links
  116. :where (= dest $s1)
  117. :and (= type "id")]
  118. (org-roam-node-id node)))))
  119. (if (> count 0)
  120. (concat (propertize "=has:backlinks=" 'display
  121. (nerd-icons-mdicon "nf-md-link" :face 'nerd-icons-blue)) (format "%d" count))
  122. (concat " " (propertize "=not-backlinks=" 'display
  123. (nerd-icons-mdicon "nf-md-link" :face 'org-hide)) " "))))
  124. (cl-defmethod org-roam-node-directories ((node org-roam-node))
  125. (if-let ((dirs (file-name-directory (file-relative-name (org-roam-node-file node) org-roam-directory))))
  126. (concat
  127. (if (string= "journal/" dirs)
  128. (nerd-icons-mdicon "nf-md-fountain_pen_tip" :face 'nerd-icons-dsilver)
  129. (nerd-icons-mdicon "nf-md-folder" :face 'nerd-icons-dsilver))
  130. (propertize (string-join (f-split dirs) "/") 'face 'nerd-icons-dsilver) " ")
  131. ""))
  132. (defun +marginalia--time-colorful (time)
  133. (let* ((seconds (float-time (time-subtract (current-time) time)))
  134. (color (doom-blend
  135. (face-attribute 'marginalia-on :foreground nil t)
  136. (face-attribute 'marginalia-off :foreground nil t)
  137. (/ 1.0 (log (+ 3 (/ (+ 1 seconds) 345600.0)))))))
  138. ;; 1 - log(3 + 1/(days + 1)) % grey
  139. (propertize (marginalia--time time) 'face (list :foreground color :slant 'italic))))
  140. (setq org-roam-node-display-template
  141. (concat "${backlinkscount:16} ${functiontag} ${directories}${hierarchy}${othertags} ")
  142. org-roam-node-annotation-function
  143. (lambda (node) (+marginalia--time-colorful (org-roam-node-file-mtime node))))
  144. )