From 0570a5f1fa1ed4b82c34f7a778c4dd5906cb7853 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Mon, 16 Jan 2023 09:48:10 -0800 Subject: [PATCH] MacOS's Spotlight is more general than Org And my org-find-file should be in the org configuration file. --- ha-config.org | 18 +++++++++++++++++- ha-org.org | 22 +++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/ha-config.org b/ha-config.org index c371d94..cd37fd2 100644 --- a/ha-config.org +++ b/ha-config.org @@ -607,7 +607,7 @@ With these helper functions in place, I can create a leader collection for file- "f a" '("load any" . find-file) "f f" '("load" . consult-projectile-find-file) "f F" '("load new window" . find-file-other-window) - "f o" '("load org" . org-find-file) + "f l" '("locate" . locate) "f s" '("save" . save-buffer) "f S" '("save as" . write-buffer) "f r" '("recent" . recentf-open-files) @@ -628,6 +628,22 @@ With these helper functions in place, I can create a leader collection for file- "f 8" '("load win-8" . ha-find-file-window-8) "f 9" '("load win-9" . ha-find-file-window-9)) #+end_src + +On Unix systems, the =locate= command is faster than =find= when searching the whole system, since it uses a pre-computed database, and =find= is faster if you need to search a specific directory instead of the whole system. On the Mac, we need to change the =locate= command: + +#+begin_src emacs-lisp + (when (equal system-type 'darwin) + (setq locate-command "mdfind")) +#+end_src + +The advantage of =mdfind= is that is searches for filename /and/ its contents of your search string. + +Trying the [[https://github.com/benmaughan/spotlight.el][spotlight]] project, as it has a slick interface for selecting files: + +#+begin_src emacs-lisp + (use-package spotlight + :config (ha-leader "f /" '("search files" . spotlight))) +#+end_src *** Buffer Operations This section groups buffer-related operations under the "SPC b" sequence. diff --git a/ha-org.org b/ha-org.org index ba0056b..54b7d14 100644 --- a/ha-org.org +++ b/ha-org.org @@ -243,12 +243,17 @@ Of course, I need an 'undo' feature when the meeting is over… (winner-undo)) ; Put the windows back in place #+end_src ** Searching -On the Mac, we need to change the =locate= command: +Came up with a great way to search a project for Org-specific files, and wrote [[https://howardism.org/Technical/Emacs/org-find-file.html][an essay]] describing the approach and the code. The idea is that I can call =find-file=, but the list of files is not only the filename, but the Org =#+title:= as well as any tags located in the file. + #+begin_src emacs-lisp - (when (equal system-type 'darwin) - (setq locate-command "mdfind")) + (use-package org-find-file + :straight nil + :config + (ha-leader "f o" '("load org" . org-find-file))) #+end_src -Now that my paragraphs in an org file are on a single line, I need this less, but being able to use an /indexed search system/, like [[https://ss64.com/osx/mdfind.html][mdfind]] on Macos, or [[https://www.lesbonscomptes.com/recoll/][recoll]] on Linux, gives better results that line-oriented search systems, like =grep=. Let’s create operating-system functions the command line for searching: + +Now that my paragraphs in an org file are on a single line, I could use =rg= (or some other =grep= program), but being able to use an /indexed search system/, like [[https://ss64.com/osx/mdfind.html][mdfind]] on Macos, or [[https://www.lesbonscomptes.com/recoll/][recoll]] on Linux, gives better results than line-oriented search systems. Let’s create operating-system functions the command line for searching: + #+begin_src emacs-lisp (defun ha-search-notes--macos (phrase path) "Return the indexed search system command on MACOS, mdfind. @@ -269,9 +274,6 @@ And let’s see how that works: (ha-search-notes--macos "crossway stream" "~/Notes") #+end_src -#+RESULTS: -: mdfind -onlyin ~/Notes -interpret crossway stream - This function calls the above-mentioned operating-system-specific functions, but returns the matching files as a /single string/ (where single quotes wrap each file, and all joined together, separated by spaces). This function also allows me to /not-match/ backup files and whatnot. #+begin_src emacs-lisp (defun ha-search-notes--files (phrase path) @@ -315,12 +317,6 @@ Add a keybinding to the function: #+begin_src emacs-lisp (ha-leader "f n" '("find notes" . ha-search-notes)) #+end_src - -I might replace my code with the [[https://github.com/benmaughan/spotlight.el][spotlight]] project, as it has a slick interface for selecting files: -#+begin_src emacs-lisp - (use-package spotlight - :config (ha-leader "f /" '("search files" . spotlight))) -#+end_src ** Misc *** Babel Blocks I use [[https://orgmode.org/worg/org-contrib/babel/intro.html][org-babel]] (obviously) and don’t need confirmation before evaluating a block: