diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..78d29fc --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,4 @@ +;;; Directory Local Variables -*- no-byte-compile: t -*- +;;; For more information see (info "(emacs) Directory Variables") + +((emacs-lisp-mode . ((sentence-end-double-space . t)))) diff --git a/README.org b/README.org index 45efcd4..46c34a9 100644 --- a/README.org +++ b/README.org @@ -1,11 +1,11 @@ -#+title: ivy-quick-find-files.el +#+title: quick-find-files.el #+author: Lucien Cartier-Tilet #+email: lucien@phundrak.com * Introduction -~ivy-quick-find-files.el~ is a utility package for all of you out there -that often find themselves looking for the right file in the right -place, but you can’t be bothered to have a specific keybinding for -that particular file for one reason or another. +~quick-find-files.el~ is a utility package for all of you out there that +often find themselves looking for the right file in the right place, +but you can’t be bothered to have a specific keybinding for that +particular file for one reason or another. Now, you have a utility for finding files by directory with an associated extension! Let’s say you often open files with a ~.org~ @@ -22,37 +22,38 @@ for my various org files alone! Unmanageable! * Installation ** Prerequisites First of all, make sure either ~find~ (which is fairly standard, it -should be there by default) or [[https://github.com/sharkdp/fd][fd]] are installed on your system, as +should be there by default) or [[https://github.com/sharkdp/fd][~fd~]] are installed on your system, as this package relies on one or the other depending on your choices (~find~ by default). ** Local installation The vanilla way of installing this package would be to clone this repository somewhere in your Emacs’ ~load-path~, or add the following -line to your ~.emacs~ or ~init.el~: +line to your Emacs configuration: #+begin_src emacs-lisp - (add-to-list 'load-path "/path/to/ivy-quick-find-files.el") +(add-to-list 'load-path "/path/to/quick-find-files.el") #+end_src -Then add the following lines to your ~.emacs~ or ~init.el~: +Then add the following lines to your configuration: #+begin_src emacs-lisp - (require 'ivy-quick-find-files) +(require 'quick-find-files) #+end_src ** Straight + use-package My personnal choice in terms of installing packages is using straight -with use-package. If you are using it too, add the following code to -your ~.emacs~ or ~init.el~: +with use-package. Here is my own configuration of ~quick-find-files.el~: #+begin_src emacs-lisp - (use-package ivy-quick-find-files - :defer t - :ensure t - :straight (ivy-quick-find-files :type git - :host github - :repo "Phundrak/ivy-quick-find-files.el") - :config ; Depending on your preferences of course - (setq ivy-quick-find-files-program 'fd - ivy-quick-find-files-dirs-and-exts '(("~/org" . "org")))) +(use-package quick-find-files + :defer t + :ensure t + :straight (quick-find-files :type git + :host github + :repo "Phundrak/quick-find-files.el") + :config ; Depending on your preferences of course + (setq quick-find-files-program 'fd + ; I like ivy + quick-find-files-completing-read #'ivy-completing-read + quick-find-files-dirs-and-exts '(("~/org" . "org")))) #+end_src ** Other methods @@ -63,41 +64,28 @@ do, feel free to submit a PR with new instructions! * Customizing A couple of variables can be editer by the user in order to configure -~ivy-quick-find-files.el~: -- ~ivy-quick-find-files-program~ :: The program to use in order to find - your files. The two currently supported options are ~'find~ and ~'fd~. -- ~ivy-quick-find-files-fd-executable~ :: Specify the executable to use - when using the option ~'fd~. -- ~ivy-quick-find-files-find-executable~ :: Specify the executable to - use when using the option ~'find~. -- ~ivy-quick-find-files-dirs-and-exts~ :: List of pairs between - directories and extensions. For one directory, the program will be - searching recursively all files with the specified - extension. Possible value: +~quick-find-files.el~: +- ~quick-find-files-program~ :: The program to use in order to find your + files. The two currently supported options are ~'find~ and ~'fd~. +- ~quick-find-files-fd-executable~ :: Specify the executable to use when + using the option ~'fd~. +- ~quick-find-files-find-executable~ :: Specify the executable to use + when using the option ~'find~. +- ~quick-find-files-dirs-and-exts~ :: List of pairs between directories + and extensions. For one directory, the program will be searching + recursively all files with the specified extension. Possible value: #+begin_src emacs-lisp - '(("~/org" . "org") - ("/tmp" . "html") - ("~/code/C" . "h")) +'(("~/org" . "org") + ("/tmp" . "html") + ("~/code/C" . "h")) #+end_src This specific example will recursively search for all ~.org~ files in =~/org=, all ~.html~ files in ~/tmp~, and all ~.h~ files in =~/code/C=. -* I don’t want to use Ivy, I want to use -You can still use this package then! I made the function -~ivy-quick-find-files-list-files~ specifically for this kind of -situation. For instance, if you are an ido user, you could write an -~ido-quick-find-files-list-files~ function like so: -#+begin_src emacs-lisp - (defun my/ido-quick-find-files () - (interactive) - (find-file (ido-completing-read "Open file: " - (ivy-quick-find-files-list-files)))) -#+end_src - * Upcoming changes -Plans exist to customize the maximum depth at which ~find~ and ~fd~ are to -search for files. +- Plans exist to customize the maximum depth at which ~find~ and ~fd~ are to + search for files. -* License -~ivy-quick-find-files.el~ is available under the GNU GPL-3.0 -license. You can find the full text in [[file:LICENSE.md][LICENSE.md]]. +* License +~quick-find-files.el~ is available under the GNU GPL-3.0 license. You +can find the full text in [[file:LICENSE.md][LICENSE.md]]. diff --git a/ivy-quick-find-files.el b/quick-find-files.el similarity index 54% rename from ivy-quick-find-files.el rename to quick-find-files.el index 473eea3..720d778 100644 --- a/ivy-quick-find-files.el +++ b/quick-find-files.el @@ -1,10 +1,10 @@ -;;; ivy-quick-find-files.el --- Quickly find files in directories and by extension -*- lexical-binding: t -*- +;;; quick-find-files.el --- Quickly find files in directories and by extension -*- lexical-binding: t -*- ;; Author: Lucien Cartier-Tilet ;; Maintainer: Lucien Cartier-Tilet ;; Version: 0.1.0 -;; Package-Requires: ((emacs "24") (ivy "0.13")) -;; Homepage: https://labs.phundrak.com/phundrak/ivy-quick-find-files.el +;; Package-Requires: ((emacs "24")) +;; Homepage: https://labs.phundrak.com/phundrak/quick-find-files.el ;; This file is not part of GNU Emacs @@ -24,122 +24,133 @@ ;;; Commentary: -;;; Code: +;; quick-find-files.el is a utlity to quickly find files in a specific +;; directory, with maybe a specific file extension. It can use both +;; the shell utilities find and fd to quickly find your files and let +;; you select the file you’re looking for in a completing read +;; prompt. Refer to the README for more information. -(require 'ivy) +;;; Code: ; Group ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defgroup ivy-quick-find-files nil +(defgroup quick-find-files nil "Quickly find files by directory and extension." :group 'convenience - :prefix "ivy-quick-find-files-" - :link '(url-link :tag "Github" "https://github.com/phundrak/ivy-quick-find-files.el") - :link '(url-link :tag "Gitea" "https://labs.phundrak.com/phundrak/ivy-quick-find-files.el")) + :prefix "quick-find-files-" + :link '(url-link :tag "Github" "https://github.com/phundrak/quick-find-files.el") + :link '(url-link :tag "Gitea" "https://labs.phundrak.com/phundrak/quick-find-files.el")) ; Custom variables ;;;;;;;;;;;;;;;;;;;; -(defcustom ivy-quick-find-files-program (if (executable-find "fd") - 'fd - 'find) +(defcustom quick-find-files-program (if (executable-find "fd") + 'fd + 'find) "Program to find files on your system. By default, the value is 'fd, but you can change it to 'find too. For now, no other program is supported. -By default, ivy-quick-find-files will try to find fd or find in your -path. You can customize the executable to use with -`ivy-quick-find-files-fd-executable' and +By default, `quick-find-files' will try to find fd or find in +your path. You can customize the executable to use with +`quick-find-files-fd-executable' and `quind-find-files-find-executable'." - :group 'ivy-quick-find-files + :group 'quick-find-files :type 'symbol) -(defcustom ivy-quick-find-files-fd-executable (executable-find "fd") +(defcustom quick-find-files-fd-executable (executable-find "fd") "Executable name or path to the executable of fd." - :group 'ivy-quick-find-files + :group 'quick-find-files :type 'string) -(defcustom ivy-quick-find-files-find-executable (executable-find "find") +(defcustom quick-find-files-find-executable (executable-find "find") "Executable name or path to the executable of find." - :group 'ivy-quick-find-files + :group 'quick-find-files :type 'string) -(defcustom ivy-quick-find-files-dirs-and-exts '() +(defcustom quick-find-files-dirs-and-exts '() "List of pairs of directories and extensions. Each element should be a pair of a directory path and an extension, such as '((\"~/Documents/org/\" . \"org\"))" - :group 'ivy-quick-find-files + :group 'quick-find-files :type 'list) -(defcustom ivy-quick-find-files-fd-additional-options "" +(defcustom quick-find-files-fd-additional-options "" "Additional command-line options for fd." - :group 'ivy-quick-find-files + :group 'quick-find-files :type 'string) -(defcustom ivy-quick-find-files-find-additional-options "" +(defcustom quick-find-files-find-additional-options "" "Additional command-line options for find." - :group 'ivy-quick-find-files + :group 'quick-find-files :type 'string) +(defcustom quick-find-files-completing-read #'completing-read + "Completing read function. + +The function must accept a prompt as its first argument and the +collection of elements to choose from as its second argument." + :group 'quick-find-files) + ; Internal functions ;;;;;;;;;;;;;;;;;; -(defun ivy-quick-find-files--split-lines (str &optional omit-null) +(defun quick-find-files--split-lines (str &optional omit-null) "Split a multilines `STR' into a list of strings. If `OMIT-NULL' is non-null, ignore empty strings." (declare (side-effect-free t)) (split-string str "\\(\r\n\\|[\n\r]\\)" omit-null)) -(defun ivy-quick-find-files--find-files (dir ext) +(defun quick-find-files--find-files (dir ext) "Find files in directory DIR with extension EXT. -Use `fd' or `find' depending on `ivy-quick-find-files-program'. +Use fd or find depending on `quick-find-files-program'. Return files as a list of absolute paths." (declare (side-effect-free t)) - (ivy-quick-find-files--split-lines + (quick-find-files--split-lines (shell-command-to-string (format - (pcase ivy-quick-find-files-program + (pcase quick-find-files-program ('fd "fd . %s -e %s -c never %s") ('find "find %s -name \"*.%s\" %s") (otherwise (error "Find program %s not implemented" otherwise))) dir ext - (pcase ivy-quick-find-files-program - ('fd ivy-quick-find-files-fd-additional-options) - ('find ivy-quick-find-files-find-additional-options) + (pcase quick-find-files-program + ('fd quick-find-files-fd-additional-options) + ('find quick-find-files-find-additional-options) (otherwise (error "Find program %s not implemented" otherwise))))))) ; Public functions ;;;;;;;;;;;;;;;;;;;; ;;;###autoload -(defun ivy-quick-find-files-list-files () +(defun quick-find-files-list-files () "List files in directories and with specific extensions. The directories and extensions are specified in the variable -`ivy-quick-find-files-dirs-and-exts'. +`quick-find-files-dirs-and-exts'. Return a list of paths to files." (declare (side-effect-free t)) (mapcan (lambda (dir-ext) - (ivy-quick-find-files--find-files (car dir-ext) - (cdr dir-ext))) - ivy-quick-find-files-dirs-and-exts)) + (quick-find-files--find-files (car dir-ext) + (cdr dir-ext))) + quick-find-files-dirs-and-exts)) ;;;###autoload -(defun ivy-quick-find-files () +(defmacro quick-find-files() "Quickly find and open files in directories with specific extensions. Directories in which to look for files with specific extensions -are specified in `ivy-quick-find-files-dirs-and-exts'." +are specified in `quick-find-files-dirs-and-exts'." (interactive) - (find-file (ivy-completing-read "Open file: " - (ivy-quick-find-files-list-files)))) + `(find-file (,quick-find-files-completing-read "Open File: " + (quick-find-files-list-files)))) ; Provides ;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(provide 'ivy-quick-find-files) +(provide 'quick-find-files) -;;; ivy-quick-find-files.el ends here +;;; quick-find-files.el ends here