Searching for Notes
Inspired by Manuel Uberti’s essay on returning to grep, I’ve decided to go the opposite way, and do a better integration with the text search engines I have already installed on my laptops.
On my Mac, Apple’s Spotlight feature has a command line interface, mdfind which accepts queries that can limit the search to particular types of files (like org-mode text files) in a particular directory, but can search the entire file for the matches. Why is this important, if I am looking for files that contain two words, but the words are on separate lines, grep
has a problem locating them.
On my Linux system, the recoll system works similarly (see these details). My goal is to have a single Emacs interface to both programs, but that can format the output with grep-mode
so that I can easily select, and pull up a file.
Searching based on Filename
Interface to the locate
function.
Searching based on Contents
Using grep
requires an ambitious regular expression and that the contents of the text files that you wish to search, exist on a single line. Not always an option with org-mode text files.
(defun locate-my-org-files (search-string) (let ((tech (concat (getenv "HOME") "/technical")) (pers (concat (getenv "HOME") "/personal")) (note (concat (getenv "HOME") "/projects")) (note (concat (getenv "HOME") "/Notes")) (jrnl (concat (getenv "HOME") "/journal"))) (-flatten (list "mdfind" (if (file-exists-p tech) (list "-onlyin" tech)) (if (file-exists-p pers) (list "-onlyin" pers)) (if (file-exists-p note) (list "-onlyin" note)) (if (file-exists-p jrnl) (list "-onlyin" jrnl)) "-interpret" search-string)))) (setq locate-make-command-line 'locate-my-org-files)