Skip to content

Commit

Permalink
Add consult-preview-excluded-files (Fix #621)
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Aug 4, 2022
1 parent b9c5d9e commit aaba2b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- =consult-grep/git-grep/ripgrep=: Add =--fixed-strings= support
- =consult-grep=: Respect =grep-find-ignored-directories/files=
- =consult-org-heading=: Add tags to completion candidates
- Add =consult-preview-excluded-files=

* Version 0.18 (2022-05-25)

Expand Down
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ an overview of all Consult variables and functions with their descriptions.
| consult-narrow-key | Narrowing prefix key during completion |
| consult-preview-key | Keys which triggers preview |
| consult-preview-allowed-hooks | List of =find-file= hooks to enable during preview |
| consult-preview-excluded-files | Regexps matched against file names during preview |
| consult-preview-max-count | Maximum number of files to keep open during preview |
| consult-preview-max-size | Files larger than this size are not previewed |
| consult-preview-raw-size | Files larger than this size are previewed in raw form |
Expand Down
10 changes: 8 additions & 2 deletions consult.el
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ The dynamically computed arguments are appended."
"Number of files to keep open at once during preview."
:type 'integer)

(defcustom consult-preview-excluded-files nil
"List of regexps matched against names of files, which are not previewed."
:type '(repeat regexp))

(defcustom consult-preview-allowed-hooks
'(global-font-lock-mode-check-buffers
save-place-find-file-hook)
Expand Down Expand Up @@ -1114,8 +1118,10 @@ ORIG is the original function, HOOKS the arguments."

(defun consult--find-file-temporarily (name)
"Open file NAME temporarily for preview."
;; file-attributes may throw permission denied error
(when-let* ((attrs (ignore-errors (file-attributes name)))
(when-let* (((not (seq-find (lambda (x) (string-match-p x name))
consult-preview-excluded-files)))
;; file-attributes may throw permission denied error
(attrs (ignore-errors (file-attributes name)))
(size (file-attribute-size attrs)))
(if (> size consult-preview-max-size)
(progn
Expand Down

0 comments on commit aaba2b0

Please sign in to comment.