Skip to content

Instantly share code, notes, and snippets.

@dmgerman
dmgerman / extract-fields.el
Created June 25, 2024 02:01
Extract Fields from org-roam template
(defun org-roam-template-extract-fields (template)
"return a list with the names of the fields used
in the given template"
(let (
(result '())
(pos 0)
)
(while (string-match "\\${\\([^}]+\\)}" template pos)
;; position should be saved first, since
@dmgerman
dmgerman / org-roam-dangling-dyn-block.org
Last active June 8, 2024 20:17
dynamic block for listing Dangling links
(defun dmg-org-roam-danling-links  (&optional limit)
  (let (
        (lim (or limit 25))
        )
    (unless (integerp lim)
      (error "limit should be nil or an integer"))
    (org-roam-db-query
     (format 
@dmgerman
dmgerman / retrieve-fields.org
Last active May 28, 2024 21:07
Retrieve Fields of a node for a template

formatting fields for presentation

  • The way the nodes are processed for the template is very slow.
  • To test how slow, I replaced the code and returned the value of the field without any extra manipulation

    See below

  • With these changes, the take home:
@dmgerman
dmgerman / test-node-constructor.org
Created May 26, 2024 18:45
Test Node Constructor #org
(defun test-node-creation-original (rows)
    (cl-loop for row in rows
             append (pcase-let* ((`(,id ,file ,file-title ,level ,todo
                                        ,pos ,priority ,scheduled ,deadline
                                        ,title ,properties ,olp  ;;12
                                        ,atime ,mtime ,tags ,aliases ,refs)
                                  row)
                                 (all-titles (cons title aliases)))
                      (mapcar (lambda (temp-title)
@dmgerman
dmgerman / node-constructor.el
Last active May 24, 2024 05:24
New Node Constructor
(cl-defstruct (org-roam-node (:constructor org-roam-node-create)
(:constructor org-roam-node-create-from-db
(title aliases ; 2
id file file-title level todo ; 5
point priority scheduled deadline properties ;;5
olp file-atime file-mtime tags refs)) ;;5
(:copier nil))
"A heading or top level file with an assigned ID property."
file file-title file-hash file-atime file-mtime ;5
id level point todo priority ; 5
@dmgerman
dmgerman / testing-node-constructor.org
Last active May 21, 2024 22:24
test a constructor that does not take named parameters

add a constructor that does not take named parameters

(cl-defstruct (org-roam-node (:constructor org-roam-node-create)
                             (:constructor org-roam-node-create-from-db
                                           (title
                                            id file file-title level todo
                                            pos priority scheduled deadline 
                                            properties olp atime  mtime tags
                                            aliases refs))
@dmgerman
dmgerman / test-org-roam-db-query.el
Created May 21, 2024 17:27
Testing only Org Roam Db Query
(defun dmg-test-function ()
(org-roam-db-query
"SELECT
id,
file,
filetitle,
\"level\",
todo,
pos,
@dmgerman
dmgerman / test-db.sh
Created May 21, 2024 07:08
Test org-roam db
#!/bin/bash
time sqlite3 /tmp/org-roam.db | wc <<EOF
SELECT
id,
file,
filetitle,
"level",
todo,
pos,
@dmgerman
dmgerman / improved org-roam-node-list.el
Last active May 20, 2024 21:11
Improved Org Roam Node List
(defun org-roam-node-list ()
(let ((rows (org-roam-db-query
"SELECT
id,
file,
filetitle,
\"level\",
todo,
pos,
priority ,
@dmgerman
dmgerman / memoize-roam-read--to-candidate
Created May 19, 2024 08:49
Improve performance of org-roam-find-node
(setq dmg-roam-candidates-cache (make-hash-table :test 'equal))
(defun org-roam-node-read--to-candidate (node template)
"Return a minibuffer completion candidate given NODE.
TEMPLATE is the processed template used to format the entry."
(let* ((args (list node template))
(cached-result (gethash args dmg-roam-candidates-cache))
)
(if cached-result