[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 8717aa24d8: Refactor consult--find-file-tempora
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 8717aa24d8: Refactor consult--find-file-temporarily |
Date: |
Fri, 14 Oct 2022 12:57:25 -0400 (EDT) |
branch: externals/consult
commit 8717aa24d83bcde75fddbc669dd45218c1335e9c
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Refactor consult--find-file-temporarily
---
consult.el | 60 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/consult.el b/consult.el
index 25a68953ba..c1a7fa96d7 100644
--- a/consult.el
+++ b/consult.el
@@ -1197,37 +1197,17 @@ ORIG is the original function, HOOKS the arguments."
(apply orig hooks))
(apply orig hooks)))
-(defun consult--find-file-temporarily (name)
- "Open file NAME temporarily for preview."
+(defun consult--find-file-temporarily-1 (name)
+ "Open file NAME, helper function for `consult--find-file-temporarily'."
(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
- (message "File `%s' (%s) is too large for preview"
- name (file-size-human-readable size))
- nil)
- (let* ((vars (delq nil
- (mapcar
- (pcase-lambda (`(,k . ,v))
- (if (boundp k)
- (list k v (default-value k) (symbol-value k))
- (message "consult-preview-variables: The
variable `%s' is not bound" k)
- nil))
- consult-preview-variables)))
- (buf (unwind-protect
- (progn
- (advice-add #'run-hooks :around
#'consult--filter-find-file-hook)
- (pcase-dolist (`(,k ,v . ,_) vars)
- (set-default k v)
- (set k v))
- (find-file-noselect name 'nowarn (> size
consult-preview-raw-size)))
- (advice-remove #'run-hooks
#'consult--filter-find-file-hook)
- (pcase-dolist (`(,k ,_ ,d ,v) vars)
- (set-default k d)
- (set k v)))))
+ (format "File `%s' (%s) is too large for preview"
+ name (file-size-human-readable size))
+ (let ((buf (find-file-noselect name 'nowarn (> size
consult-preview-raw-size))))
(cond
((and (> size consult-preview-raw-size)
(with-current-buffer buf
@@ -1235,14 +1215,36 @@ ORIG is the original function, HOOKS the arguments."
(goto-char (point-min))
(search-forward "\0" nil 'noerror))))
(kill-buffer buf)
- (message "Binary file `%s' not previewed literally" name)
- nil)
+ (format "Binary file `%s' not previewed literally" name))
((ignore-errors (buffer-local-value 'so-long-detected-p buf))
(kill-buffer buf)
- (message "File `%s' with long lines not previewed" name)
- nil)
+ (format "File `%s' with long lines not previewed" name))
(t buf))))))
+(defun consult--find-file-temporarily (name)
+ "Open file NAME temporarily for preview."
+ (let ((vars (delq nil
+ (mapcar
+ (pcase-lambda (`(,k . ,v))
+ (if (boundp k)
+ (list k v (default-value k) (symbol-value k))
+ (message "consult-preview-variables: The variable
`%s' is not bound" k)
+ nil))
+ consult-preview-variables)))
+ buf)
+ (unwind-protect
+ (progn
+ (advice-add #'run-hooks :around #'consult--filter-find-file-hook)
+ (pcase-dolist (`(,k ,v . ,_) vars)
+ (set-default k v)
+ (set k v))
+ (setq buf (consult--find-file-temporarily-1 name)))
+ (advice-remove #'run-hooks #'consult--filter-find-file-hook)
+ (pcase-dolist (`(,k ,_ ,d ,v) vars)
+ (set-default k d)
+ (set k v)))
+ (if (stringp buf) (progn (message "%s" buf) nil) buf)))
+
(defun consult--temporary-files ()
"Return a function to open files temporarily for preview."
(let ((dir default-directory)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/consult 8717aa24d8: Refactor consult--find-file-temporarily,
ELPA Syncer <=