From 7490b4858c7dfdc42227e9600eaca61dfc5083dc Mon Sep 17 00:00:00 2001 From: Grant Rosson Date: Sun, 21 Nov 2021 02:13:47 +0200 Subject: [PATCH] Add functions to insert IDs or open files based on full text search Fix #29 and #101 --- zetteldeft.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/zetteldeft.el b/zetteldeft.el index 46f765c..463bcf1 100644 --- a/zetteldeft.el +++ b/zetteldeft.el @@ -316,6 +316,35 @@ Set `zetteldeft-home-id' to an ID string of your home note." (deft-find-all-files-no-prefix)))) (zetteldeft--insert-link (zetteldeft--lift-id file))) +(defun zetteldeft--full-search (string) + "Return list of deft files with STRING in full body of file." + (let ((result-files (zetteldeft--get-file-list string)) + (this-file (buffer-file-name))) + (when this-file + (setq result-files (delete this-file result-files))) + (setq completions + (mapcar (lambda (file) (cons (file-name-base file) (file-name-nondirectory file))) result-files)) + (cdr (assoc (completing-read (format "Files containing \"%s\": " string) completions) completions)))) + +;;;###autoload +(defun zetteldeft-full-search-id-insert (string) + "Insert ID of file from list of files containing STRING." + (interactive (list (read-string "Search string: "))) + (zetteldeft-find-file-id-insert (zetteldeft--full-search string))) + +;;;###autoload +(defun zetteldeft-full-search-full-title-insert (string) + "Insert title and ID of file from list of files containing +STRING." + (interactive (list (read-string "Search string: "))) + (zetteldeft-find-file-full-title-insert (zetteldeft--full-search string))) + +;;;###autoload +(defun zetteldeft-full-search-find-file (string) + "Open file containing STRING." + (interactive (list (read-string "Search string: "))) + (zetteldeft-find-file (zetteldeft--full-search string))) + (defcustom zetteldeft-backlink-prefix "# Backlink: " "Prefix string included before a back link. Formatted as `org-mode' comment by default."