branch: master commit efd74b8b8b86d21f900355b2d633800738c445a3 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
counsel.el (counsel-find-file): Extend `find-file' * counsel.el (counsel-find-file): Forward to `find-file', with Ivy completion. `ivy-next-line-and-call' as well as `ivy-resume' should work. (counsel--find-file-matcher): New defun. (counsel-find-file-ignore-regexp): Regexp of files to ignore. Fixes #122 Recommended binding: (global-set-key (kbd "C-x C-f") 'counsel-find-file) Peek at files with "C-M-n" and "C-M-p". Input a leading dot to see all files. --- counsel.el | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-) diff --git a/counsel.el b/counsel.el index 5538831..aae7c72 100644 --- a/counsel.el +++ b/counsel.el @@ -259,6 +259,34 @@ :action #'counsel-git-grep-action :unwind #'swiper--cleanup))) +(defun counsel-find-file () + "Forward to `find-file'." + (interactive) + (ivy-read "Find file: " 'read-file-name-internal + :matcher #'counsel--find-file-matcher + :action + (lambda (x) + (find-file (expand-file-name x ivy--directory))))) + +(defcustom counsel-find-file-ignore-regexp "\\(?:\\`[#.]\\)\\|\\(?:[#~]\\'\\)" + "A regexp of files to ignore while in `counsel-find-file'. +These files are un-ignored if `ivy-text' matches them. +The common way to show all files is to start `ivy-text' with a dot.") + +(defun counsel--find-file-matcher (regexp candidates) + "Return REGEXP-matching CANDIDATES. +Skip some dotfiles unless `ivy-text' requires them." + (let ((res (cl-remove-if-not + (lambda (x) + (string-match regexp x)) + candidates))) + (if (string-match counsel-find-file-ignore-regexp ivy-text) + res + (cl-remove-if + (lambda (x) + (string-match counsel-find-file-ignore-regexp x)) + res)))) + (defun counsel-git-grep-matcher (regexp candidates) (or (and (equal regexp ivy--old-re) ivy--old-cands)