I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #+TITLE: Roam
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle roam.el :comments org
  5. #+PROPERTY: header-args :results silent :eval no-export :comments org
  6. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  7. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  8. Plain-text knowledge management system.
  9. * Setup
  10. Make sure ~sqlite~ is available on your system:
  11. #+begin_src shell
  12. RUN apt install sqlite
  13. #+end_src
  14. * Config
  15. Configure ~org-roam~, a plain-text knowledge management system for Emacs built on top of ~org-mode~. Here's a quick recap of the main principles:
  16. + Notes can be arbitrarily referened
  17. + Contexts created by linking topics and notes
  18. #+begin_src emacs-lisp
  19. (use-package org-roam
  20. :hook (after-init . org-roam-mode) ;; Lauch roam at startup, big performance cost.
  21. :custom (org-roam-encrypt-files t) ;; Encrypt all roam captures.
  22. (org-roam-directory org-directory)
  23. (org-roam-capture-templates '())
  24. (org-roam-dailies-capture-templates '()))
  25. #+end_src
  26. ** Files
  27. The default behaviour of ~org-roam~ when creating a title slug is to replace any non alpha numerical (whitespace) to ~_~. I wanted to change this to use ~_~ and have done so here in my own definition. The only substantial difference from the original definition is the character used.
  28. + Define a new ~title-to-slug~ function
  29. + Override ~org-roam-title-to-slug-function~
  30. #+begin_src emacs-lisp
  31. (with-eval-after-load 'org-roam
  32. (require 'cl-lib)
  33. (defun dotfiles/title-to-slug (title)
  34. "Convert TITLE to a filename-suitable slug."
  35. (cl-flet* ((nonspacing-mark-p (char)
  36. (eq 'Mn (get-char-code-property char 'general-category)))
  37. (strip-nonspacing-marks (s)
  38. (apply #'string (seq-remove #'nonspacing-mark-p
  39. (ucs-normalize-NFD-string s))))
  40. (cl-replace (title pair)
  41. (replace-regexp-in-string (car pair) (cdr pair) title)))
  42. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-") ;; Convert anything not alphanumeric.
  43. ("--*" . "-") ;; Remove sequential dashes.
  44. ("^-" . "") ;; Remove starting dashes.
  45. ("-$" . ""))) ;; Remove ending dashes.
  46. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  47. (downcase slug))))
  48. (setq org-roam-title-to-slug-function #'dotfiles/title-to-slug))
  49. #+end_src
  50. ** Visualizer
  51. Use the ~org-roam-server~ web application to visualize the ~org-roam~ database. It's available whenever the editor is running at http://localhost:8080.
  52. #+begin_src emacs-lisp
  53. (use-package org-roam-server
  54. :after org-roam
  55. :hook (org-roam-mode . org-roam-server-mode))
  56. #+end_src
  57. ** Dailies
  58. Use the ~daily~ note feature of ~org-roam~ to capture daily notes. Create the default capture template with some preconfigured headers.
  59. #+begin_src emacs-lisp
  60. (with-eval-after-load 'org-roam
  61. (add-to-list 'org-roam-dailies-capture-templates
  62. '("d" "Default" entry (function org-roam-capture--get-point)
  63. "* %?"
  64. :file-name "docs/daily/%<%Y-%m-%d>"
  65. :head
  66. "
  67. ,#+TITLE: %<%Y-%m-%d>
  68. ,#+AUTHOR: Christopher James Hayward
  69. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  70. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  71. ")))
  72. #+end_src
  73. * Templates
  74. Collection of capture templates for various contexts. Here is one for a generic document.
  75. #+begin_src emacs-lisp
  76. (with-eval-after-load 'org-roam
  77. (add-to-list 'org-roam-capture-templates
  78. '("d" "Default" entry (function org-roam-capture--get-point)
  79. "%?"
  80. :file-name "docs/${slug}"
  81. :unnarrowed t
  82. :head
  83. "
  84. ,#+TITLE: ${title}
  85. ,#+AUTHOR: Christopher James Hayward
  86. ,#+EMAIL: chris@chrishayward.xyz
  87. ")))
  88. #+end_src
  89. ** Course
  90. Capture template for a new course. Capture with =SPC r c c=.
  91. #+begin_src emacs-lisp
  92. (with-eval-after-load 'org-roam
  93. (add-to-list 'org-roam-capture-templates
  94. '("c" "Course" plain (function org-roam-capture--get-point)
  95. "%?"
  96. :file-name "docs/courses/${slug}"
  97. :unnarrowed t
  98. :head
  99. "
  100. ,#+TITLE: ${title}
  101. ,#+SUBTITLE:
  102. ,#+AUTHOR: Christopher James Hayward
  103. ,#+EMAIL: chris@chrishayward.xyz
  104. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  105. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  106. ")))
  107. #+end_src
  108. * Shortcuts
  109. Configure custom keybindings for ~org-roam~ behind =SPC r=:
  110. + Find with =f=
  111. + Insert with =i=
  112. + Buffer with =b=
  113. + Capture with =c=
  114. #+begin_src emacs-lisp
  115. (dotfiles/leader
  116. "r" '(:ignore t :which-key "Roam")
  117. "ri" '(org-roam-insert :which-key "Insert")
  118. "rf" '(org-roam-find-file :which-key "Find")
  119. "rc" '(org-roam-capture :which-key "Capture")
  120. "rb" '(org-roam-buffer-toggle-display :which-key "Buffer"))
  121. #+end_src
  122. Place keybindings for daily notes behind =SPC r d=:
  123. + Date with =d=
  124. + Today with =t=
  125. + Tomorrow with =m=
  126. + Yesterday with =y=
  127. #+begin_src emacs-lisp
  128. (dotfiles/leader
  129. "rd" '(:ignore t :which-key "Dailies")
  130. "rdd" '(org-roam-dailies-find-date :which-key "Date")
  131. "rdt" '(org-roam-dailies-find-today :which-key "Today")
  132. "rdm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  133. "rdy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))
  134. #+end_src
  135. * Footnotes