[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 0d518df9f8 1/4: Disassociate Dired buffers from
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 0d518df9f8 1/4: Disassociate Dired buffers from directory (Fix #639) |
Date: |
Thu, 1 Sep 2022 14:57:27 -0400 (EDT) |
branch: externals/consult
commit 0d518df9f816a55604db23e5dc71f9208b2666ff
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Disassociate Dired buffers from directory (Fix #639)
We set dired-directory to nil. This ensures that embark-act does not reuse
the
previewed (and incompletely initialized) Dired buffer. We already did the
same
for file buffers by setting buffer-file-name to nil, but missed that Dired
needs
special casing.
---
consult.el | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/consult.el b/consult.el
index a7e89e85f8..eb47a7ddef 100644
--- a/consult.el
+++ b/consult.el
@@ -1195,11 +1195,22 @@ ORIG is the original function, HOOKS the arguments."
(let ((default-directory dir))
(setq name (abbreviate-file-name (expand-file-name name)))
(or
- ;; get-file-buffer is only a small optimization here. It
- ;; may not find the actual buffer, for directories it
- ;; returns nil instead of returning the Dired buffer.
- (get-file-buffer name)
+ ;; Find existing fully initialized buffer (non-previewed). We have
+ ;; to check for fully initialized buffer before accessing the
+ ;; previewed buffers, since `embark-act' can open a buffer which
is
+ ;; currently previewed, such that we end up with two buffers for
+ ;; the same file - one previewed and only partially initialized
and
+ ;; one fully initialized. In this case we prefer the fully
+ ;; initialized buffer. For directories `get-file-buffer' returns
nil,
+ ;; therefore we have to special case Dired.
+ (if (and (string-suffix-p "/" name) (fboundp
'dired-find-buffer-nocreate))
+ (dired-find-buffer-nocreate name)
+ (get-file-buffer name))
+ ;; Find existing previewed buffer. Previewed buffers are not fully
+ ;; initialized (hooks are delayed) in order to ensure fast
preview.
(cdr (assoc name temporary-buffers))
+ ;; Finally, if no existing buffer has been found, open the file
for
+ ;; preview.
(when-let (buf (consult--find-file-temporarily name))
;; Only add new buffer if not already in the list
(unless (or (rassq buf temporary-buffers) (memq buf
orig-buffers))
@@ -1214,9 +1225,9 @@ ORIG is the original function, HOOKS the arguments."
(format "Preview:%s"
(file-name-nondirectory (directory-file-name
name)))
'unique))
- ;; The buffer disassociation is delayed to avoid breaking
- ;; modes like pdf-view-mode or doc-view-mode which rely on
- ;; buffer-file-name. Executing (set-visited-file-name nil)
+ ;; The buffer disassociation is delayed to avoid breaking
modes
+ ;; like `pdf-view-mode' or `doc-view-mode' which rely on
+ ;; `buffer-file-name'. Executing (set-visited-file-name nil)
;; early also prevents the major mode initialization.
(let ((hook (make-symbol
"consult--temporary-files-disassociate")))
(fset hook (lambda ()
@@ -1224,6 +1235,7 @@ ORIG is the original function, HOOKS the arguments."
(with-current-buffer buf
(remove-hook 'pre-command-hook hook)
(setq buffer-read-only t
+ dired-directory nil
buffer-file-name nil)))))
(add-hook 'pre-command-hook hook))
;; Only keep a few buffers alive