Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure zk--id-list to take fuller advantage of passed zk-alist #61

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zk-desktop.el
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ To quickly change this setting, call `zk-desktop-add-toggle'."
;; replace titles
(goto-char (point-min))
(let* ((zk-alist (zk--alist))
(ids (zk--id-list)))
(ids (zk--id-list nil zk-alist)))
Copy link
Owner

@localauthor localauthor Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if str is nil, then zk--alist function is never called, and not used; the function just goes straight to zk--parse-file, right? Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the point of d6be688: if zk-alist is passed to zk--id-list, no matter whether str is nil or not, the function uses the passed zk-alist rather than redoing all the work with zk--parse-file.

(while (re-search-forward zk-id-regexp nil t)
(let* ((beg (line-beginning-position))
(end (line-end-position))
Expand Down
9 changes: 5 additions & 4 deletions zk-index.el
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,24 @@ items listed first.")
(defun zk-index-query-files ()
"Return narrowed list of notes, based on focus or search query."
(let* ((command this-command)
(zk-alist (zk--alist))
(scope (if (zk-index-narrowed-p (buffer-name))
(zk-index--current-id-list (buffer-name))
(setq zk-index-query-terms nil)
(zk--id-list)))
(zk--id-list nil zk-alist)))
(string (read-string (cond ((eq command 'zk-index-focus)
"Focus: ")
((eq command 'zk-index-search)
"Search: "))
nil 'zk-search-history))
(query (cond
((eq command 'zk-index-focus)
(zk--id-list string))
(zk--id-list string zk-alist))
((eq command 'zk-index-search)
(zk--grep-id-list string))))
(zk--grep-id-list string zk-alist))))
(ids (mapcar (lambda (x) (when (member x scope) x))
query))
(files (zk--parse-id 'file-path (remq nil ids))))
(files (zk--parse-id 'file-path (remq nil ids) zk-alist)))
(add-to-history 'zk-search-history string)
(when files
(let ((mode-line (zk-index-query-mode-line command string)))
Expand Down
16 changes: 8 additions & 8 deletions zk.el
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ The ID is created using `zk-id-time-string-format'."
Optional search for STR in note title, case-insenstive. Takes an
optional ZK-ALIST, for efficiency if `zk--id-list' is called in
an internal loop."
(if str
(if (or str zk-alist)
(let ((zk-alist (or zk-alist (zk--alist)))
(case-fold-search t)
(ids))
Expand All @@ -361,9 +361,10 @@ an internal loop."

(defun zk-id-p (id)
"Return t if ID is already in use as a zk-id."
(when (and (listp (zk--id-list))
(member id (zk--id-list)))
t))
(let ((zk-alist (zk--alist)))
(when (and (listp (zk--id-list nil zk-alist))
(member id (zk--id-list nil zk-alist)))
t)))

(defun zk--current-id ()
"Return the ID of zk note in current buffer."
Expand Down Expand Up @@ -508,9 +509,8 @@ in an internal loop."
(zk--singleton-p ids))
(car (zk--directory-files t (car ids))))
(t
(let* ((zk-alist (or zk-alist
(zk--alist)))
(zk-id-list (zk--id-list))
(let* ((zk-alist (or zk-alist (zk--alist)))
(zk-id-list (zk--id-list nil zk-alist))
(return
(cond ((eq target 'file-path)
(cond ((stringp ids)
Expand Down Expand Up @@ -828,7 +828,7 @@ Optionally call a custom function by setting the variable
(defun zk--links-in-note-list ()
"Return list of zk files that are linked from the current buffer."
(let* ((zk-alist (zk--alist))
(zk-ids (zk--id-list))
(zk-ids (zk--id-list nil zk-alist))
id-list)
(save-buffer)
(save-excursion
Expand Down