MacOS's Spotlight is more general than Org

And my org-find-file should be in the org configuration file.
This commit is contained in:
Howard Abrams 2023-01-16 09:48:10 -08:00
parent 31fdabd1e3
commit 0570a5f1fa
2 changed files with 26 additions and 14 deletions

View file

@ -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 a" '("load any" . find-file)
"f f" '("load" . consult-projectile-find-file) "f f" '("load" . consult-projectile-find-file)
"f F" '("load new window" . find-file-other-window) "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" . save-buffer)
"f S" '("save as" . write-buffer) "f S" '("save as" . write-buffer)
"f r" '("recent" . recentf-open-files) "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 8" '("load win-8" . ha-find-file-window-8)
"f 9" '("load win-9" . ha-find-file-window-9)) "f 9" '("load win-9" . ha-find-file-window-9))
#+end_src #+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 *** Buffer Operations
This section groups buffer-related operations under the "SPC b" sequence. This section groups buffer-related operations under the "SPC b" sequence.

View file

@ -243,12 +243,17 @@ Of course, I need an 'undo' feature when the meeting is over…
(winner-undo)) ; Put the windows back in place (winner-undo)) ; Put the windows back in place
#+end_src #+end_src
** Searching ** 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 #+begin_src emacs-lisp
(when (equal system-type 'darwin) (use-package org-find-file
(setq locate-command "mdfind")) :straight nil
:config
(ha-leader "f o" '("load org" . org-find-file)))
#+end_src #+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=. Lets 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. Lets create operating-system functions the command line for searching:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun ha-search-notes--macos (phrase path) (defun ha-search-notes--macos (phrase path)
"Return the indexed search system command on MACOS, mdfind. "Return the indexed search system command on MACOS, mdfind.
@ -269,9 +274,6 @@ And lets see how that works:
(ha-search-notes--macos "crossway stream" "~/Notes") (ha-search-notes--macos "crossway stream" "~/Notes")
#+end_src #+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. 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 #+begin_src emacs-lisp
(defun ha-search-notes--files (phrase path) (defun ha-search-notes--files (phrase path)
@ -315,12 +317,6 @@ Add a keybinding to the function:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(ha-leader "f n" '("find notes" . ha-search-notes)) (ha-leader "f n" '("find notes" . ha-search-notes))
#+end_src #+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 ** Misc
*** Babel Blocks *** Babel Blocks
I use [[https://orgmode.org/worg/org-contrib/babel/intro.html][org-babel]] (obviously) and dont need confirmation before evaluating a block: I use [[https://orgmode.org/worg/org-contrib/babel/intro.html][org-babel]] (obviously) and dont need confirmation before evaluating a block: