2021-05-14 05:04:21 +00:00
|
|
|
(defvar +wiki-directory "~/writings/wiki")
|
2021-07-21 08:28:07 +00:00
|
|
|
(defvar +wiki-notebook-name "notebook")
|
|
|
|
(defvar +wiki-notebook-directory (f-join +wiki-directory +wiki-notebook-name))
|
2023-08-24 02:29:32 +00:00
|
|
|
|
2021-05-14 05:04:21 +00:00
|
|
|
(defvar my/wiki-asset-directory-name "assets")
|
2023-08-24 02:29:32 +00:00
|
|
|
(defvar my/wiki-exercises-directory "challenges")
|
2021-05-14 05:04:21 +00:00
|
|
|
|
2022-10-25 08:49:00 +00:00
|
|
|
(defun my/is-in-wiki-directory (&optional filename)
|
|
|
|
"Return t if the file buffer is in the wiki directory."
|
|
|
|
(unless filename (setq filename (buffer-file-name)))
|
|
|
|
(if (and (not (string= (f-base filename)
|
2021-05-14 05:04:21 +00:00
|
|
|
my/wiki-asset-directory-name))
|
2022-10-25 08:49:00 +00:00
|
|
|
(f-descendant-of-p filename
|
2021-05-14 05:04:21 +00:00
|
|
|
(expand-file-name +wiki-directory)))
|
|
|
|
t
|
|
|
|
nil))
|
|
|
|
|
2023-08-24 02:29:32 +00:00
|
|
|
;; Automate updating timestamps on save.
|
|
|
|
(add-hook! 'before-save-hook 'time-stamp)
|
|
|
|
|
|
|
|
;; Custom keybindings
|
|
|
|
(map!
|
|
|
|
(:when (modulep! :tools wiki)
|
|
|
|
:leader
|
|
|
|
:prefix "nr" :desc "Create the asset folder" "m" #'my/create-assets-folder)
|
|
|
|
|
|
|
|
(:when (modulep! :editor format)
|
|
|
|
:n "g=" #'+format/buffer))
|
|
|
|
|
2022-10-25 08:49:00 +00:00
|
|
|
(defun my/get-assets-folder (&optional filename)
|
|
|
|
"Get the assets folder of the current Org mode document."
|
|
|
|
(unless filename (setq filename (buffer-file-name)))
|
|
|
|
(if (my/is-in-wiki-directory filename)
|
|
|
|
(f-join my/wiki-asset-directory-name (f-base filename))
|
2021-05-14 05:04:21 +00:00
|
|
|
nil))
|
|
|
|
|
2022-11-23 09:35:16 +00:00
|
|
|
(defun my/concat-assets-folder (&rest args)
|
2021-05-14 05:04:21 +00:00
|
|
|
"Concatenate PATH to the assets folder."
|
2022-11-23 09:35:16 +00:00
|
|
|
(apply #'f-join (my/get-assets-folder (buffer-file-name)) args))
|
2021-05-14 05:04:21 +00:00
|
|
|
|
2022-10-25 08:49:00 +00:00
|
|
|
(defun my/create-assets-folder (&optional filename)
|
2022-11-23 09:35:16 +00:00
|
|
|
"A quick convenient function to create the appropriate folder in the assets
|
|
|
|
folder with its buffer filename."
|
2021-05-14 05:04:21 +00:00
|
|
|
(interactive)
|
2022-10-25 08:49:00 +00:00
|
|
|
(unless filename (setq filename (buffer-file-name)))
|
2021-05-14 05:04:21 +00:00
|
|
|
(if (my/is-in-wiki-directory)
|
2022-10-25 08:49:00 +00:00
|
|
|
(let* ((target (f-base filename))
|
|
|
|
(target-dir (f-join my/wiki-asset-directory-name target)))
|
|
|
|
(apply #'f-mkdir (f-split target-dir))
|
|
|
|
(message "Directory '%s' has been created." target-dir))
|
2021-05-14 05:04:21 +00:00
|
|
|
(message "Not in the wiki directory.")))
|
|
|
|
|
2022-10-25 08:49:00 +00:00
|
|
|
(defun my/parse-links-in-org (&optional filename)
|
2021-11-07 10:42:50 +00:00
|
|
|
"Returns a list of links in an Org buffer."
|
2022-10-25 08:49:00 +00:00
|
|
|
(unless filename (setq filename (buffer-file-name)))
|
2021-11-07 10:42:50 +00:00
|
|
|
(let ((ast (with-temp-buffer
|
|
|
|
(insert-file-contents filename)
|
|
|
|
(org-mode)
|
|
|
|
(org-element-parse-buffer))))
|
|
|
|
(org-element-map ast 'link
|
|
|
|
(lambda (link)
|
|
|
|
(when (or (string= (org-element-property :type link) "http")
|
|
|
|
(string= (org-element-property :type link) "https"))
|
|
|
|
(org-element-property :path link))))))
|
|
|
|
|
2021-05-14 05:04:21 +00:00
|
|
|
(defun my/anki-editor-delete-note ()
|
|
|
|
"Request AnkiConnect for deleting a note at point."
|
|
|
|
(interactive)
|
|
|
|
(let ((queue (anki-editor--anki-connect-invoke-queue)))
|
|
|
|
(funcall queue
|
|
|
|
'deleteNotes
|
|
|
|
`((notes . ,(list (org-entry-get (point) anki-editor-prop-note-id)))))
|
|
|
|
(org-entry-delete (point) anki-editor-prop-note-id)))
|
|
|
|
|
2021-06-06 06:10:03 +00:00
|
|
|
(setq
|
2021-07-21 08:28:07 +00:00
|
|
|
org-roam-v2-ack 't
|
2022-07-29 15:13:07 +00:00
|
|
|
|
2023-08-23 14:08:00 +00:00
|
|
|
org-roam-directory "~/library/writings/wiki"
|
|
|
|
org-roam-dailies-directory (f-join org-roam-directory "daily")
|
|
|
|
org-roam-db-location (f-join org-roam-directory "org-roam.db")
|
|
|
|
org-agenda-files '("~/library/writings/wiki/inbox")
|
|
|
|
|
|
|
|
;; Setting up the bibliography-related stuff for this notebook.
|
|
|
|
org-cite-global-bibliography (f-join +wiki-directory "references.bib")
|
2022-10-25 08:49:00 +00:00
|
|
|
citar-notes-paths `(,+wiki-directory)
|
|
|
|
citar-library-paths '("~/library/references" "~/Zotero")
|
2023-08-23 14:08:00 +00:00
|
|
|
citar-bibliography (f-join +wiki-directory "references.bib")
|
|
|
|
citar-notes-paths `(,+wiki-directory)
|
2022-10-25 08:49:00 +00:00
|
|
|
|
2023-08-23 14:08:00 +00:00
|
|
|
;; The capture templates for org-roam.
|
2022-11-23 09:35:16 +00:00
|
|
|
org-roam-capture-templates `(("e" "evergreen" plain
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +wiki-directory "templates" "default.org"))
|
2021-11-07 10:42:50 +00:00
|
|
|
:target
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +wiki-notebook-directory "%<%Y-%m-%d-%H-%M-%S>.org"))
|
2021-06-06 06:10:03 +00:00
|
|
|
:unnarrowed t)
|
|
|
|
|
2022-11-23 09:35:16 +00:00
|
|
|
("c" "cards" plain
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +wiki-directory "templates" "anki.org"))
|
2021-11-07 10:42:50 +00:00
|
|
|
:target
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +anki-cards-directory-name "%<%Y>.org"))
|
2022-10-25 08:49:00 +00:00
|
|
|
:unnarrowed t
|
|
|
|
:empty-lines 2)
|
2021-06-06 06:10:03 +00:00
|
|
|
|
2022-11-23 09:35:16 +00:00
|
|
|
("l" "literature" plain
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +wiki-directory "templates" "default.org"))
|
2021-11-07 10:42:50 +00:00
|
|
|
:target
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +wiki-notebook-directory "literature.${slug}.org"))
|
2021-06-06 06:10:03 +00:00
|
|
|
:unnarrowed t)
|
|
|
|
|
2022-11-23 09:35:16 +00:00
|
|
|
("L" "literature reference" plain
|
2021-11-07 10:42:50 +00:00
|
|
|
(file ,(f-join +wiki-directory "templates" "literature.org"))
|
|
|
|
:target
|
|
|
|
(file ,(f-join +wiki-notebook-directory "literature.${citekey}.org"))
|
|
|
|
:unnarrowed t)
|
|
|
|
|
2022-11-23 09:35:40 +00:00
|
|
|
("j" "journals" plain
|
|
|
|
(file ,(f-join +wiki-directory "templates" "journal.org"))
|
|
|
|
:target
|
|
|
|
(file ,(f-join +wiki-notebook-directory "journals.${slug}.org"))
|
|
|
|
:unnarrowed t)
|
|
|
|
|
2021-06-06 06:10:03 +00:00
|
|
|
("d" "dailies" entry "* %?"
|
2021-11-07 10:42:50 +00:00
|
|
|
:target
|
2021-06-06 06:10:03 +00:00
|
|
|
(file+head ,(expand-file-name "%<%Y-%m-%d>.org" org-roam-dailies-directory) "#+title: %<%Y-%m-%d>\n"))
|
|
|
|
|
2022-11-23 09:35:16 +00:00
|
|
|
("s" "structured" plain
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +wiki-directory "templates" "default.org"))
|
2021-11-07 10:42:50 +00:00
|
|
|
:target
|
2022-07-29 15:13:07 +00:00
|
|
|
(file ,(f-join +wiki-notebook-directory "${slug}.org"))
|
2021-06-06 06:10:03 +00:00
|
|
|
:unnarrowed t)))
|
2022-11-23 09:35:16 +00:00
|
|
|
|
|
|
|
(eval-after-load "org-roam"
|
|
|
|
'(cl-defmethod org-roam-node-slug ((node org-roam-node))
|
|
|
|
"Override of the original org-roam slug function by replacing the
|
|
|
|
underscore with dashes."
|
|
|
|
(let ((title (org-roam-node-title node))
|
|
|
|
(slug-trim-chars '(;; Combining Diacritical Marks https://www.unicode.org/charts/PDF/U0300.pdf
|
|
|
|
768 ; U+0300 COMBINING GRAVE ACCENT
|
|
|
|
769 ; U+0301 COMBINING ACUTE ACCENT
|
|
|
|
770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
|
|
|
|
771 ; U+0303 COMBINING TILDE
|
|
|
|
772 ; U+0304 COMBINING MACRON
|
|
|
|
774 ; U+0306 COMBINING BREVE
|
|
|
|
775 ; U+0307 COMBINING DOT ABOVE
|
|
|
|
776 ; U+0308 COMBINING DIAERESIS
|
|
|
|
777 ; U+0309 COMBINING HOOK ABOVE
|
|
|
|
778 ; U+030A COMBINING RING ABOVE
|
|
|
|
779 ; U+030B COMBINING DOUBLE ACUTE ACCENT
|
|
|
|
780 ; U+030C COMBINING CARON
|
|
|
|
795 ; U+031B COMBINING HORN
|
|
|
|
803 ; U+0323 COMBINING DOT BELOW
|
|
|
|
804 ; U+0324 COMBINING DIAERESIS BELOW
|
|
|
|
805 ; U+0325 COMBINING RING BELOW
|
|
|
|
807 ; U+0327 COMBINING CEDILLA
|
|
|
|
813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
|
|
|
|
814 ; U+032E COMBINING BREVE BELOW
|
|
|
|
816 ; U+0330 COMBINING TILDE BELOW
|
|
|
|
817 ; U+0331 COMBINING MACRON BELOW
|
|
|
|
)))
|
|
|
|
(cl-flet* ((nonspacing-mark-p (char) (memq char slug-trim-chars))
|
|
|
|
(strip-nonspacing-marks (s) (string-glyph-compose
|
|
|
|
(apply #'string
|
|
|
|
(seq-remove #'nonspacing-mark-p
|
|
|
|
(string-glyph-decompose s)))))
|
|
|
|
(cl-replace (title pair) (replace-regexp-in-string (car pair) (cdr pair) title)))
|
|
|
|
(let* ((pairs `(("[^[:alnum:][:digit:]]" . "-") ;; convert anything not alphanumeric
|
|
|
|
("--*" . "-") ;; remove sequential dashes
|
|
|
|
("^_" . "") ;; remove starting dashes
|
|
|
|
("_$" . ""))) ;; remove ending dashes
|
|
|
|
(slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
|
|
|
|
(downcase slug))))))
|
|
|
|
|
|
|
|
(eval-after-load "org-roam"
|
|
|
|
'(setq
|
|
|
|
org-roam-node-display-template
|
|
|
|
(format "${doom-hierarchy:*} %s %s"
|
|
|
|
(propertize "${doom-tags:15}" 'face 'org-tag)
|
|
|
|
(propertize "${file:60}" 'face 'font-lock-default-face))))
|
2021-05-14 05:04:21 +00:00
|
|
|
;;; config.el ends here
|