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.

236 lines
7.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #+TITLE: Writing
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle writing.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. #+ATTR_ORG: :width 420px
  9. #+ATTR_HTML: :width 420px
  10. #+ATTR_LATEX: :width 420px
  11. [[../docs/images/2021-02-13-example-roam.png]]
  12. I am using *Org mode*[fn:1] extensively throughout my writing. Most of the improvements are done in the [[file:core.org][Core]] module, but all of the management, encryption, synchronization, and organization of all of my writing happens here.
  13. * Improvements
  14. Real time checking and one-shot methods to check and correct common spelling and grammatical errors.
  15. ** Spelling
  16. Configure *InteractiveSpell*[fn:6] as a backend with *FlySpell*[fn:7] for real time checking and highlighting.
  17. #+begin_src emacs-lisp
  18. (use-package ispell
  19. :after org
  20. :custom (ispell-dictionary dotfiles/lang))
  21. #+end_src
  22. Toggle highlighting within buffers with =SPC t s=.
  23. #+begin_src emacs-lisp
  24. (dotfiles/leader
  25. "ts" '(flyspell-buffer :which-key "Spelling"))
  26. #+end_src
  27. ** Grammar
  28. I use *Writegood*[fn:8] to find common writing problems such as cliches and poor wording. Grammarly for the peons!
  29. #+begin_src emacs-lisp
  30. (use-package writegood-mode
  31. :after org
  32. :config (writegood-mode))
  33. #+end_src
  34. Toggle *Writegood* mode with =SPC t w=.
  35. #+begin_src emacs-lisp
  36. (dotfiles/leader
  37. "tw" '(writegood-mode :which-key "Grammar"))
  38. #+end_src
  39. * Knowledge base
  40. Download and install *Org roam*[fn:4], a plain text knowledge management system for Emacs built on top of *Org mode*[fn:1].
  41. + Notes can be arbitrarily referenced
  42. + Contexts created by linking topics and notes
  43. + Install dependencies on *Debian/Ubuntu* systems
  44. + Configure custom keybindings for roam behind =SPC r=
  45. + Find with =f=
  46. + Insert with =i=
  47. + Buffer with =b=
  48. + Capture with =c=
  49. #+begin_src emacs-lisp
  50. (use-package org-roam
  51. :hook (after-init . org-roam-mode)
  52. :init (dotfiles/install "sqlite")
  53. :custom (org-roam-directory org-directory)
  54. (org-roam-capture-templates '())
  55. (org-roam-dailies-capture-templates '())
  56. :config (dotfiles/leader "r" '(:ignore t :which-key "Roam")
  57. "ri" '(org-roam-insert :which-key "Insert")
  58. "rf" '(org-roam-find-file :which-key "Find")
  59. "rc" '(org-roam-capture :which-key "Capture")
  60. "rb" '(org-roam-buffer-toggle-display :which-key "Buffer")))
  61. #+end_src
  62. ** File slugs
  63. 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.
  64. + Define a new ~title-to-slug~ function
  65. + Override ~org-roam-title-to-slug-function~
  66. #+begin_src emacs-lisp
  67. (with-eval-after-load 'org-roam
  68. (require 'cl-lib)
  69. (defun dotfiles/title-to-slug (title)
  70. "Convert TITLE to a filename-suitable slug."
  71. (cl-flet* ((nonspacing-mark-p (char)
  72. (eq 'Mn (get-char-code-property char 'general-category)))
  73. (strip-nonspacing-marks (s)
  74. (apply #'string (seq-remove #'nonspacing-mark-p
  75. (ucs-normalize-NFD-string s))))
  76. (cl-replace (title pair)
  77. (replace-regexp-in-string (car pair) (cdr pair) title)))
  78. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-") ;; Convert anything not alphanumeric.
  79. ("--*" . "-") ;; Remove sequential dashes.
  80. ("^-" . "") ;; Remove starting dashes.
  81. ("-$" . ""))) ;; Remove ending dashes.
  82. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  83. (downcase slug))))
  84. (setq org-roam-title-to-slug-function #'dotfiles/title-to-slug))
  85. #+end_src
  86. ** Web visualizer
  87. Including the extension *Org roam server*[fn:5] will run a web application that visualizes the *Org roam*[fn:4] database. Available whenever the editor is running at https://localhost:8080. The image at the top of this page is an example of the application running.
  88. #+begin_src emacs-lisp
  89. (use-package org-roam-server
  90. :hook (org-roam-mode . org-roam-server-mode))
  91. #+end_src
  92. ** Daily note taking
  93. Use the =daily= note feature of *Org roam*[fn:4] to capture daily notes. Create the default capture template with some preconfigured headers.
  94. #+begin_src emacs-lisp
  95. (with-eval-after-load 'org-roam
  96. (add-to-list 'org-roam-dailies-capture-templates
  97. '("d" "Default" entry (function org-roam-capture--get-point)
  98. "* %?"
  99. :file-name "docs/daily/%<%Y-%m-%d>"
  100. :head
  101. "
  102. ,#+TITLE: %<%Y-%m-%d>
  103. ,#+AUTHOR: Christopher James Hayward
  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. Place keybindings behind =SPC r d=.
  109. + Date with =d=
  110. + Today with =t=
  111. + Tomorrow with =m=
  112. + Yesterday with =y=
  113. #+begin_src emacs-lisp
  114. (dotfiles/leader
  115. "rd" '(:ignore t :which-key "Dailies")
  116. "rdd" '(org-roam-dailies-find-date :which-key "Date")
  117. "rdt" '(org-roam-dailies-find-today :which-key "Today")
  118. "rdm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  119. "rdy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))
  120. #+end_src
  121. ** Capture templates
  122. + Capture template for generic documents
  123. #+begin_src emacs-lisp
  124. (with-eval-after-load 'org-roam
  125. (add-to-list 'org-roam-capture-templates
  126. '("d" "Default" entry (function org-roam-capture--get-point)
  127. "%?"
  128. :file-name "docs/${slug}"
  129. :unnarrowed t
  130. :head
  131. "
  132. ,#+TITLE: ${title}
  133. ,#+AUTHOR: Christopher James Hayward
  134. ,#+EMAIL: chris@chrishayward.xyz
  135. ")))
  136. #+end_src
  137. Custom capture template for courses.
  138. + Capture a new buffer with =SPC r c c=
  139. #+begin_src emacs-lisp
  140. (with-eval-after-load 'org-roam
  141. (add-to-list 'org-roam-capture-templates
  142. '("c" "Course" plain (function org-roam-capture--get-point)
  143. "%?"
  144. :file-name "docs/courses/${slug}"
  145. :unnarrowed t
  146. :head
  147. "
  148. ,#+TITLE: ${title}
  149. ,#+SUBTITLE:
  150. ,#+AUTHOR: Christopher James Hayward
  151. ,#+EMAIL: chris@chrishayward.xyz
  152. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  153. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  154. ")))
  155. #+end_src
  156. ** Agenda integration
  157. #+ATTR_ORG: :width 420px
  158. #+ATTR_HTML: :width 420px
  159. #+ATTR_LATEX: :width 420px
  160. [[../docs/images/2021-02-13-example-agenda.gif]]
  161. More capture templates for *Org roam*[fn:4] are defined here in the context of specific domains and topics.
  162. + Configure agenda sources
  163. #+begin_src emacs-lisp
  164. (setq org-agenda-files '("~/.emacs.d/"
  165. "~/.emacs.d/docs/"
  166. "~/.emacs.d/docs/courses/"
  167. "~/.emacs.d/docs/daily/"
  168. "~/.emacs.d/docs/notes/"
  169. "~/.emacs.d/docs/posts/"
  170. "~/.emacs.d/docs/slides/"
  171. "~/.emacs.d/hosts/"
  172. "~/.emacs.d/modules/"))
  173. #+end_src
  174. + Open an agenda buffer with =SPC a=
  175. #+begin_src emacs-lisp
  176. (dotfiles/leader
  177. "a" '(org-agenda :which-key "Agenda"))
  178. #+end_src
  179. * Resources
  180. [fn:1] https://orgmode.org
  181. [fn:4] https://github.com/org-roam/org-roam
  182. [fn:5] https://github.com/org-roam/org-roam-server
  183. [fn:6] https://emacswiki.org/emacs/InteractiveSpell
  184. [fn:7] https://emacswiki.org/emacs/FlySpell
  185. [fn:8] https://github.com/bnbeckwith/writegood-mode