@@ -807,7 +807,6 @@ Expose Emacs with my packages as a top-level package (~<<flake-packages>>~).
807807 org-drill
808808 org-ref
809809 org-roam
810- org-roam-bibtex
811810 org-super-agenda
812811 paren-face
813812 pass
@@ -853,6 +852,30 @@ Expose Emacs with my packages as a top-level package (~<<flake-packages>>~).
853852 # not available in melpa
854853 epkgs.elpaPackages.valign
855854
855+ (epkgs.melpaBuild rec {
856+ pname = "org-roam-bibtex";
857+ version = "20210714";
858+ src = pkgs.fetchFromGitHub {
859+ owner = "org-roam";
860+ repo = "org-roam-bibtex";
861+ rev = "c7f7cb0dc24d11b00ab5ce4de9705461fb1c5581";
862+ sha256 = "sha256-iy+TH23BeIPpVOOpmyTX5OA4lix51xqkYc2Tob3cBhk=";
863+ };
864+ packageRequires = [ epkgs.melpaPackages.org-roam epkgs.melpaPackages.bibtex-completion epkgs.melpaPackages.org-ref ];
865+
866+ recipe = pkgs.writeText "recipe" ''
867+ (org-roam-bibtex
868+ :repo "org-roam/org-roam-bibtex"
869+ :fetcher github
870+ :files ("*.el"))
871+ '';
872+
873+ meta = {
874+ description = "Connector between Org-roam, BibTeX-completion, and Org-ref";
875+ license = pkgs.lib.licenses.gpl3;
876+ };
877+ })
878+
856879 (epkgs.melpaBuild rec {
857880 pname = "org-fc";
858881 version = "20201121";
@@ -4112,55 +4135,76 @@ Better line wrapping. (Use proper wrap-prefix in lists, etc.)
41124135(use-package org-roam
41134136 :after org
41144137 :diminish
4115- :hook
4116- (after-init . org-roam-mode)
4117-
41184138 :general
41194139 (s-leader-def
4120- "n r" #'org-roam
4121- "n f" #'org-roam-find-file
4122- "n b" #'org-roam-switch-to-buffer)
4140+ "n r" #'org-roam-buffer-toggle
4141+ "n f" #'org-roam-node-find)
41234142 (:keymaps 'org-mode-map
41244143 :states '(insert visual)
4125- "C-c i" #'org-roam-insert
4144+ "C-c i" #'org-roam-node- insert
41264145 ;; C-i is interpreted as TAB
4127- "C-c TAB" #'org-roam-insert)
4146+ "C-c TAB" #'org-roam-node-insert)
4147+
4148+ :init
4149+ (setq org-roam-v2-ack t)
41284150
41294151 :config
41304152 (require 'org-roam-protocol)
41314153
41324154 (setq org-roam-directory (concat rasen/org-directory "/roam")
41334155 ;; move `org-roam-db-location' off roam directory, so syncthing does not sync it
4134- org-roam-db-location (expand-file-name "cache/org-roam.db" user-emacs-directory)
4135- org-roam-index-file "index.org")
4156+ org-roam-db-location (expand-file-name "cache/org-roam.db" user-emacs-directory))
41364157
4137- ;; Submitted at https://github.com/org-roam/org-roam/pull/851
4138- (defun org-roam--extract-tags-first-directory (file)
4139- "Extract tags from path FILE. The first directory component after `org-roam-directory' is used as a tag."
4140- (when-let ((dir-relative (file-name-directory
4141- (file-relative-name file org-roam-directory))))
4142- (list (car (f-split dir-relative)))))
4158+ (setq org-roam-db-node-include-function
4159+ (defun rasen/org-roam-include ()
4160+ ;; exclude org-fc headlines from org-roam
4161+ (not (member "fc" (org-get-tags)))))
41434162
4144- (setq org-roam-tag-sources '(prop first-directory))
4163+ (setq org-roam-mode-section-functions
4164+ (list #'org-roam-backlinks-section
4165+ #'org-roam-reflinks-section
4166+ #'org-roam-unlinked-references-section))
41454167
4168+ (defun rasen/capture-tsid (node)
4169+ "A hack definition to workaround that org-roam passes a node argument."
4170+ (rasen/tsid))
41464171 (defconst rasen/slip-boxes
41474172 '(;; Default slip-box with permanent notes
4148- ("d" "default" "")
4173+ ("d" "default" "" "${rasen/capture-tsid}" )
41494174
41504175 ;; "Life project"—everything that doesn't fit in other slip
41514176 ;; boxes. Examples are: my gratitude journal, small projects,
41524177 ;; article drafts, idea list.
4153- ("l" "life" "life/")
4178+ ("l" "life" "life/" "${rasen/capture-tsid}" )
41544179
41554180 ;; Work notes
4156- ("r" "ring" "ring/")
4181+ ("r" "ring" "ring/" "${rasen/capture-tsid}" )
41574182
41584183 ;; Posts
4159- ("p" "posts" "posts/")
4184+ ("p" "posts" "posts/" "${slug}" "#+DATE: %<%Y-%m-%d>\n#+LAST_MODIFIED: \n#+PUBLISHED: false" )
41604185
41614186 ;; Literature notes
4162- ("" "literature" "biblio/"))
4163- "My Zettelkasten slip boxes. Format is a list of (capture-key name directory).")
4187+ ("b" "bibliograpic" "biblio/" "${citekey}" "#+LAST_MODIFIED: \n#+DATE: %<%Y-%m-%d>\n"))
4188+ "My slip boxes. Format is a list of (capture-key name directory filename extra-template).")
4189+
4190+ ;; one capture template per slip-box
4191+ (setq org-roam-capture-templates
4192+ (mapcar (lambda (x)
4193+ (let ((key (nth 0 x))
4194+ (name (nth 1 x))
4195+ (dir (nth 2 x))
4196+ (filename (nth 3 x))
4197+ (extra-template (nth 4 x)))
4198+ `(,key ,name plain "%?"
4199+ :if-new (file+head
4200+ ,(concat dir filename ".org")
4201+ ,(concat "#+TITLE: ${title}\n"
4202+ extra-template))
4203+ :immediate-finish t
4204+ :unnarrowed t)))
4205+ rasen/slip-boxes))
4206+
4207+ (org-roam-setup)
41644208
41654209 (defun rasen/roam-rename (new-name)
41664210 "Move file to NEW-NAME. `org-roam' takes care of adjusting all links."
@@ -4189,18 +4233,26 @@ Better line wrapping. (Use proper wrap-prefix in lists, etc.)
41894233 (seq-filter (lambda (x) (not (string-empty-p x)))
41904234 (mapcar (lambda (x) (nth 2 x)) rasen/slip-boxes)))
41914235
4192- ;; one capture template per slip-box
4193- (setq org-roam-capture-templates
4194- (mapcar (lambda (x)
4195- (let ((key (nth 0 x))
4196- (name (nth 1 x))
4197- (dir (nth 2 x)))
4198- `(,key ,name plain (function org-roam--capture-get-point) "%?"
4199- :file-name ,(concat dir "%(rasen/tsid)")
4200- :head "#+TITLE: ${title}\n"
4201- :immediate-finish t
4202- :unnarrowed t)))
4203- rasen/slip-boxes))
4236+ (cl-defmethod org-roam-node-filetitle ((node org-roam-node))
4237+ "Return the file TITLE for the node."
4238+ (org-roam-get-keyword "TITLE" (org-roam-node-file node)))
4239+ (cl-defmethod org-roam-node-hierarchy ((node org-roam-node))
4240+ "Return the hierarchy for the node."
4241+ (let ((title (org-roam-node-title node))
4242+ (olp (org-roam-node-olp node))
4243+ (level (org-roam-node-level node))
4244+ (directories (org-roam-node-directories node))
4245+ (filetitle (org-roam-node-filetitle node)))
4246+ (concat
4247+ (if directories (format "(%s) " directories))
4248+ (if (> level 0) (concat filetitle " > "))
4249+ (if (> level 1) (concat (string-join olp " > ") " > "))
4250+ title)))
4251+ (cl-defmethod org-roam-node-directories ((node org-roam-node))
4252+ (if-let ((dirs (file-name-directory (file-relative-name (org-roam-node-file node) org-roam-directory))))
4253+ (string-join (f-split dirs) "/")
4254+ nil))
4255+ (setq org-roam-node-display-template "${hierarchy:*} ${tags:10}")
42044256
42054257 ;; better defaults for graph view
42064258 ;; (setq org-roam-graph-executable (executable-find "dot"))
@@ -4216,34 +4268,58 @@ Better line wrapping. (Use proper wrap-prefix in lists, etc.)
42164268 (setq org-roam-graph-node-extra-config '(("shape" . "rectangle")))
42174269 (setq org-roam-graph-edge-extra-config '(("dir" . "back")))
42184270
4219- ;; patch function to use kebab-case in file names
4220- (el-patch-defun org-roam--title-to-slug (title)
4221- "Convert TITLE to a filename-suitable slug."
4222- (cl-flet* ((nonspacing-mark-p (char)
4223- (eq 'Mn (get-char-code-property char 'general-category)))
4224- (strip-nonspacing-marks (s)
4225- (apply #'string (seq-remove #'nonspacing-mark-p
4226- (ucs-normalize-NFD-string s))))
4227- (cl-replace (title pair)
4228- (replace-regexp-in-string (car pair) (cdr pair) title)))
4229- (let* ((pairs `(el-patch-swap (("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric
4230- ("__*" . "_") ;; remove sequential underscores
4231- ("^_" . "") ;; remove starting underscore
4232- ("_$" . "")) ;; remove ending underscore
4233- (("[^[:alnum:][:digit:]]" . "-") ;; convert anything not alphanumeric
4234- ("--*" . "-") ;; remove sequential dashes
4235- ("^-" . "") ;; remove starting dash
4236- ("-$" . "")))) ;; remove ending dash
4237- (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
4238- (downcase slug))))
4271+ ;; patch function to use kebab-case in slug
4272+ (el-patch-defun org-roam-node-slug (node)
4273+ "Return the slug of NODE."
4274+ (let ((title (org-roam-node-title node))
4275+ (slug-trim-chars '(;; Combining Diacritical Marks https://www.unicode.org/charts/PDF/U0300.pdf
4276+ 768 ; U+0300 COMBINING GRAVE ACCENT
4277+ 769 ; U+0301 COMBINING ACUTE ACCENT
4278+ 770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
4279+ 771 ; U+0303 COMBINING TILDE
4280+ 772 ; U+0304 COMBINING MACRON
4281+ 774 ; U+0306 COMBINING BREVE
4282+ 775 ; U+0307 COMBINING DOT ABOVE
4283+ 776 ; U+0308 COMBINING DIAERESIS
4284+ 777 ; U+0309 COMBINING HOOK ABOVE
4285+ 778 ; U+030A COMBINING RING ABOVE
4286+ 780 ; U+030C COMBINING CARON
4287+ 795 ; U+031B COMBINING HORN
4288+ 803 ; U+0323 COMBINING DOT BELOW
4289+ 804 ; U+0324 COMBINING DIAERESIS BELOW
4290+ 805 ; U+0325 COMBINING RING BELOW
4291+ 807 ; U+0327 COMBINING CEDILLA
4292+ 813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
4293+ 814 ; U+032E COMBINING BREVE BELOW
4294+ 816 ; U+0330 COMBINING TILDE BELOW
4295+ 817 ; U+0331 COMBINING MACRON BELOW
4296+ )))
4297+ (cl-flet* ((nonspacing-mark-p (char)
4298+ (memq char slug-trim-chars))
4299+ (strip-nonspacing-marks (s)
4300+ (ucs-normalize-NFC-string
4301+ (apply #'string (seq-remove #'nonspacing-mark-p
4302+ (ucs-normalize-NFD-string s)))))
4303+ (cl-replace (title pair)
4304+ (replace-regexp-in-string (car pair) (cdr pair) title)))
4305+ (let* ((pairs `(el-patch-swap (("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric
4306+ ("__*" . "_") ;; remove sequential underscores
4307+ ("^_" . "") ;; remove starting underscore
4308+ ("_$" . "")) ;; remove ending underscore
4309+ (("[^[:alnum:][:digit:]]" . "-") ;; convert anything not alphanumeric
4310+ ("--*" . "-") ;; remove sequential dashes
4311+ ("^-" . "") ;; remove starting dash
4312+ ("-$" . "")))) ;; remove ending dash
4313+ (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
4314+ (downcase slug)))))
42394315
42404316 (defun rasen/refile-weight ()
42414317 "Refile current item as weight log."
42424318 (interactive)
42434319 (save-excursion
42444320 (save-window-excursion
42454321 (rasen/org-copy-log-entry t)
4246- (org-roam- find-file "(life) My Weight" nil nil t )
4322+ (find-file (concat org-roam-directory "/life/20200620011908.org") )
42474323 (goto-char (point-max))
42484324 (yank))))
42494325
@@ -4259,7 +4335,7 @@ Better line wrapping. (Use proper wrap-prefix in lists, etc.)
42594335 (org-cut-subtree)
42604336 (current-kill 1)
42614337
4262- (org-roam- find-file "(life) My Gratitude Journal" nil nil t )
4338+ (find-file (concat org-roam-directory "/life/20200620010632.org") )
42634339 (org-datetree-find-date-create
42644340 (calendar-gregorian-from-absolute
42654341 (time-to-days (org-read-date nil t created))))
@@ -4370,16 +4446,16 @@ Citations and bibliography tools for org-mode.
43704446 :diminish
43714447 :hook (org-roam-mode . org-roam-bibtex-mode)
43724448 :config
4373- (setq orb-templates
4374- `(("r" "ref" plain #'org-roam-capture--get-point ""
4375- :file-name "biblio/${slug}"
4376- :head
4377- ,(concat "#+TITLE: ${title}\n"
4378- "#+ROAM_KEY: ${ref}\n"
4379- "#+LAST_MODIFIED: \n"
4380- "#+DATE: %<%Y-%m-%dT%H:%M:%S>\n")
4381- :immediate-finish t
4382- :unnarrowed t ))))
4449+ ;; https://github.com/org-roam/org-roam-bibtex/pull/194
4450+ (el-patch-defun orb--add-ref ()
4451+ "Add citeky as Org-roam ref to the current buffer.
4452+ To be used in `org-roam-capture-new-node-hook'."
4453+ (save-excursion
4454+ (el-patch-let (($do (org-roam-add-property orb--current-citekey "ROAM_REFS")))
4455+ (el-patch-swap
4456+ $do
4457+ (if orb--current-citekey
4458+ $do)) ))))
43834459#+end_src
43844460** toc-org
43854461Generate Table of Contents for this file.
0 commit comments