reddit / emacs

[elisp] when clause behaving differently inside hook

engineerwolf · 2022-01-28 15:15
Hello, I am trying to setup a `org-roam-capture-new-node-hook`, that will add a property to a daily/journal file automatically. while skipping other types of notes. here's the function I have (defun my/org-roam-dailies--daily-note-p (file) "Return t if FILE is an Org-roam daily-note, nil otherwise. If FILE is not specified, use the current buffer's file-path." (when-let ((path (expand-file-name file)) (directory (expand-file-name org-roam-dailies-directory org-roam-directory))) (setq path (expand-file-name path)) (f-descendant-of-p path directory))) When I call this normally, I get expected response. (when (my/org-roam-dailies--daily-note-p "/path/to/org/roam/daily/2022-01-26.org") "Cool") : Cool But when I call this from the custom hook function, (defun my/add-auto-props-to-org-roam-dailies () "Add properties to org-roam daily entry automatically" (unless (file-exists-p (buffer-file-name)) (when (my/org-roam-dailies--daily-note-p (buffer-file-name)) (unless (org-find-property "header-args:ledger") (org-roam-add-property (concat (file-name-as-directory (ledger-path-relative-to-org)) (file-name-base (buffer-file-name)) ".ledger") "header-args:ledger") (org-roam-add-property ":tangle" "header-args:ledger"))))) (add-hook! 'org-roam-capture-new-node-hook #'my/add-auto-props-to-org-roam-dailies) This does not seem to work as expected. The call to `my/org-roam-dailies--daily-note-p` seem to return nil for all files. Am I missing something here? if I remove the check (call for `my/org-roam-dailies--daily-note-p`), the property gets added correctly for all files, so rest of the code is working as intended. P.S. `ledger-path-relative-to-org` is a custom function that returns a relative path to where I expect the ledger files to get tangled.
nv-elisp · 2022-01-28 15:56
Instrument the function and step through it with edebug.
engineerwolf · 2022-01-28 16:10
Thanks. I had never used edbug before, and I could not get it working. any guide on that? but anyways I managed to get regular old `debug-on-entry` working. Looks like `org-roam` is doing something weird, when I set the variable `org-roam-dailies-directory`, the `org-roam-directory` is somewhere getting appended. hence the `(expand-file-name org-roam-dailies-directory org-roam-directory)` call returns something like `/path/to/org/roam/daily/daily`. I will file a bug with org-roam.
nv-elisp · 2022-01-28 17:18
> any guide on that? The documentation and manual