unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] change dired--find-possibly-alternative-file behaviour.
@ 2023-02-25 19:43 Felix
  2023-02-26  5:26 ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Felix @ 2023-02-25 19:43 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 995 bytes --]


I find dired--find-possibly-alternative-file a bit
confusing if dired-kill-when-opening-new-dired-buffer is set to t.

It's fine if the active window is the only window that shows that dired
buffer, but if there are multiple windows showing dired buffers, it's
likely that the user wanted to have those windows showing dired buffers.
If those buffers happen to show the same directory, opening another
directory with dired-find-file will kill the buffer, and change the
shown buffer in both windows.

Before dired-kill-when-opening-new-dired-buffer, to copy/move a file to
another directory, i could open a dired buffer, split the window, in
one of the windows (both showing the same dired buffer) navigate to
another directory and copy the file (with the dired-dwim-target).

In my personal configuration, i changed
dired--find-possibly-alternative-file to not kill the buffer if
it's shown in another window. I'm not shure if this would fit
every workflow, but for me it feels more logical.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired.patch --]
[-- Type: text/x-patch, Size: 570 bytes --]

diff --git a/lisp/dired.el b/lisp/dired.el
index 76499d0f520..620508bef4f 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2728,7 +2728,8 @@ dired-find-file
 (defun dired--find-possibly-alternative-file (file)
   "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
   (if (and dired-kill-when-opening-new-dired-buffer
-           (file-directory-p file))
+           (file-directory-p file)
+           (= (length (get-buffer-window-list)) 1))
       (progn
         (set-buffer-modified-p nil)
         (dired--find-file #'find-alternate-file file))

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-25 19:43 [PATCH] change dired--find-possibly-alternative-file behaviour Felix
@ 2023-02-26  5:26 ` Eli Zaretskii
  2023-02-26  6:07   ` Felix
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2023-02-26  5:26 UTC (permalink / raw)
  To: Felix; +Cc: emacs-devel

> From: Felix <felix.dick@web.de>
> Date: Sat, 25 Feb 2023 20:43:57 +0100
> 
> diff --git a/lisp/dired.el b/lisp/dired.el
> index 76499d0f520..620508bef4f 100644
> --- a/lisp/dired.el
> +++ b/lisp/dired.el
> @@ -2728,7 +2728,8 @@ dired-find-file
>  (defun dired--find-possibly-alternative-file (file)
>    "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
>    (if (and dired-kill-when-opening-new-dired-buffer
> -           (file-directory-p file))
> +           (file-directory-p file)
> +           (= (length (get-buffer-window-list)) 1))
>        (progn
>          (set-buffer-modified-p nil)
>          (dired--find-file #'find-alternate-file file))

What if get-buffer-window-list returns nil?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  5:26 ` Eli Zaretskii
@ 2023-02-26  6:07   ` Felix
  2023-02-26  6:29     ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Felix @ 2023-02-26  6:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


Eli Zaretskii <eliz@gnu.org> writes:

>> From: Felix <felix.dick@web.de>
>> Date: Sat, 25 Feb 2023 20:43:57 +0100
>>
>> diff --git a/lisp/dired.el b/lisp/dired.el
>> index 76499d0f520..620508bef4f 100644
>> --- a/lisp/dired.el
>> +++ b/lisp/dired.el
>> @@ -2728,7 +2728,8 @@ dired-find-file
>>  (defun dired--find-possibly-alternative-file (file)
>>    "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
>>    (if (and dired-kill-when-opening-new-dired-buffer
>> -           (file-directory-p file))
>> +           (file-directory-p file)
>> +           (= (length (get-buffer-window-list)) 1))
>>        (progn
>>          (set-buffer-modified-p nil)
>>          (dired--find-file #'find-alternate-file file))
>
> What if get-buffer-window-list returns nil?

The optional argument BUFFER-OR-NAME of get-buffer-window-list defaults
to the current buffer, shouldn't that garantee that it never returns
nil?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  6:07   ` Felix
@ 2023-02-26  6:29     ` Eli Zaretskii
  2023-02-26  6:32       ` Felix
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2023-02-26  6:29 UTC (permalink / raw)
  To: Felix; +Cc: emacs-devel

> From: Felix <felix.dick@web.de>
> Cc: emacs-devel@gnu.org
> Date: Sun, 26 Feb 2023 07:07:10 +0100
> 
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Felix <felix.dick@web.de>
> >> Date: Sat, 25 Feb 2023 20:43:57 +0100
> >>
> >> diff --git a/lisp/dired.el b/lisp/dired.el
> >> index 76499d0f520..620508bef4f 100644
> >> --- a/lisp/dired.el
> >> +++ b/lisp/dired.el
> >> @@ -2728,7 +2728,8 @@ dired-find-file
> >>  (defun dired--find-possibly-alternative-file (file)
> >>    "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
> >>    (if (and dired-kill-when-opening-new-dired-buffer
> >> -           (file-directory-p file))
> >> +           (file-directory-p file)
> >> +           (= (length (get-buffer-window-list)) 1))
> >>        (progn
> >>          (set-buffer-modified-p nil)
> >>          (dired--find-file #'find-alternate-file file))
> >
> > What if get-buffer-window-list returns nil?
> 
> The optional argument BUFFER-OR-NAME of get-buffer-window-list defaults
> to the current buffer, shouldn't that garantee that it never returns
> nil?

Only if the current buffer is displayed in some window.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  6:29     ` Eli Zaretskii
@ 2023-02-26  6:32       ` Felix
  2023-02-26  7:00         ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Felix @ 2023-02-26  6:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


Eli Zaretskii <eliz@gnu.org> writes:

>> From: Felix <felix.dick@web.de>
>> Cc: emacs-devel@gnu.org
>> Date: Sun, 26 Feb 2023 07:07:10 +0100
>>
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> From: Felix <felix.dick@web.de>
>> >> Date: Sat, 25 Feb 2023 20:43:57 +0100
>> >>
>> >> diff --git a/lisp/dired.el b/lisp/dired.el
>> >> index 76499d0f520..620508bef4f 100644
>> >> --- a/lisp/dired.el
>> >> +++ b/lisp/dired.el
>> >> @@ -2728,7 +2728,8 @@ dired-find-file
>> >>  (defun dired--find-possibly-alternative-file (file)
>> >>    "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
>> >>    (if (and dired-kill-when-opening-new-dired-buffer
>> >> -           (file-directory-p file))
>> >> +           (file-directory-p file)
>> >> +           (= (length (get-buffer-window-list)) 1))
>> >>        (progn
>> >>          (set-buffer-modified-p nil)
>> >>          (dired--find-file #'find-alternate-file file))
>> >
>> > What if get-buffer-window-list returns nil?
>>
>> The optional argument BUFFER-OR-NAME of get-buffer-window-list defaults
>> to the current buffer, shouldn't that garantee that it never returns
>> nil?
>
> Only if the current buffer is displayed in some window.

If get-buffer-window-list returns nil for any case, (length nil) returns 0.
In that case the if condition is false and dired--find-file will not
kill any buffer.
Is there a possible case where the function is called from dired buffer,
and get-buffer-window-list returns nil?
In that case the buffer would stay alive!

dired--find-possibly-alternative-file is only used in 2 places
dired-find-file and in dired-up-directory.
I thought those functions are only useful inside dired buffer windows.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  6:32       ` Felix
@ 2023-02-26  7:00         ` Eli Zaretskii
  2023-02-26  7:01           ` Felix
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2023-02-26  7:00 UTC (permalink / raw)
  To: Felix; +Cc: emacs-devel

> From: Felix <felix.dick@web.de>
> Cc: emacs-devel@gnu.org
> Date: Sun, 26 Feb 2023 07:32:27 +0100
> 
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Felix <felix.dick@web.de>
> >> Cc: emacs-devel@gnu.org
> >> Date: Sun, 26 Feb 2023 07:07:10 +0100
> >>
> >>
> >> Eli Zaretskii <eliz@gnu.org> writes:
> >>
> >> >> From: Felix <felix.dick@web.de>
> >> >> Date: Sat, 25 Feb 2023 20:43:57 +0100
> >> >>
> >> >> diff --git a/lisp/dired.el b/lisp/dired.el
> >> >> index 76499d0f520..620508bef4f 100644
> >> >> --- a/lisp/dired.el
> >> >> +++ b/lisp/dired.el
> >> >> @@ -2728,7 +2728,8 @@ dired-find-file
> >> >>  (defun dired--find-possibly-alternative-file (file)
> >> >>    "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
> >> >>    (if (and dired-kill-when-opening-new-dired-buffer
> >> >> -           (file-directory-p file))
> >> >> +           (file-directory-p file)
> >> >> +           (= (length (get-buffer-window-list)) 1))
> >> >>        (progn
> >> >>          (set-buffer-modified-p nil)
> >> >>          (dired--find-file #'find-alternate-file file))
> >> >
> >> > What if get-buffer-window-list returns nil?
> >>
> >> The optional argument BUFFER-OR-NAME of get-buffer-window-list defaults
> >> to the current buffer, shouldn't that garantee that it never returns
> >> nil?
> >
> > Only if the current buffer is displayed in some window.
> 
> If get-buffer-window-list returns nil for any case, (length nil) returns 0.
> In that case the if condition is false and dired--find-file will not
> kill any buffer.
> Is there a possible case where the function is called from dired buffer,
> and get-buffer-window-list returns nil?
> In that case the buffer would stay alive!
> 
> dired--find-possibly-alternative-file is only used in 2 places
> dired-find-file and in dired-up-directory.
> I thought those functions are only useful inside dired buffer windows.

I just asked that question to make sure we are not introducing a
regression here.  If you are certain that situation cannot cause any
trouble, I'm okay with that conclusion.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  7:00         ` Eli Zaretskii
@ 2023-02-26  7:01           ` Felix
  2023-02-26  7:22             ` Felix
  2023-02-26  8:09             ` Eli Zaretskii
  0 siblings, 2 replies; 12+ messages in thread
From: Felix @ 2023-02-26  7:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


Eli Zaretskii <eliz@gnu.org> writes:

>> From: Felix <felix.dick@web.de>
>> Cc: emacs-devel@gnu.org
>> Date: Sun, 26 Feb 2023 07:32:27 +0100
>>
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> From: Felix <felix.dick@web.de>
>> >> Cc: emacs-devel@gnu.org
>> >> Date: Sun, 26 Feb 2023 07:07:10 +0100
>> >>
>> >>
>> >> Eli Zaretskii <eliz@gnu.org> writes:
>> >>
>> >> >> From: Felix <felix.dick@web.de>
>> >> >> Date: Sat, 25 Feb 2023 20:43:57 +0100
>> >> >>
>> >> >> diff --git a/lisp/dired.el b/lisp/dired.el
>> >> >> index 76499d0f520..620508bef4f 100644
>> >> >> --- a/lisp/dired.el
>> >> >> +++ b/lisp/dired.el
>> >> >> @@ -2728,7 +2728,8 @@ dired-find-file
>> >> >>  (defun dired--find-possibly-alternative-file (file)
>> >> >>    "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
>> >> >>    (if (and dired-kill-when-opening-new-dired-buffer
>> >> >> -           (file-directory-p file))
>> >> >> +           (file-directory-p file)
>> >> >> +           (= (length (get-buffer-window-list)) 1))
>> >> >>        (progn
>> >> >>          (set-buffer-modified-p nil)
>> >> >>          (dired--find-file #'find-alternate-file file))
>> >> >
>> >> > What if get-buffer-window-list returns nil?
>> >>
>> >> The optional argument BUFFER-OR-NAME of get-buffer-window-list defaults
>> >> to the current buffer, shouldn't that garantee that it never returns
>> >> nil?
>> >
>> > Only if the current buffer is displayed in some window.
>>
>> If get-buffer-window-list returns nil for any case, (length nil) returns 0.
>> In that case the if condition is false and dired--find-file will not
>> kill any buffer.
>> Is there a possible case where the function is called from dired buffer,
>> and get-buffer-window-list returns nil?
>> In that case the buffer would stay alive!
>>
>> dired--find-possibly-alternative-file is only used in 2 places
>> dired-find-file and in dired-up-directory.
>> I thought those functions are only useful inside dired buffer windows.
>
> I just asked that question to make sure we are not introducing a
> regression here.  If you are certain that situation cannot cause any
> trouble, I'm okay with that conclusion.

Just to be absolutely save,
(= (length (get-buffer-window-list)) 1))
could be changed to
(> (length (get-buffer-window-list)) 1))

>> I thought those functions are only useful inside dired buffer windows.

is that not the case? If not (length (get-buffer-window-list)) will
count the windows that are displaying the current buffer whatever that
is, and kill or not kill a dired buffer depending on the result.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  7:01           ` Felix
@ 2023-02-26  7:22             ` Felix
  2023-02-26  8:10               ` Eli Zaretskii
  2023-02-26  8:09             ` Eli Zaretskii
  1 sibling, 1 reply; 12+ messages in thread
From: Felix @ 2023-02-26  7:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


Felix <felix.dick@web.de> writes:

>
> Just to be absolutely save,
> (= (length (get-buffer-window-list)) 1))
> could be changed to

 (< (length (get-buffer-window-list)) 2))

of course.

Should i resend the patch?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  7:01           ` Felix
  2023-02-26  7:22             ` Felix
@ 2023-02-26  8:09             ` Eli Zaretskii
  1 sibling, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2023-02-26  8:09 UTC (permalink / raw)
  To: Felix; +Cc: emacs-devel

> From: Felix <felix.dick@web.de>
> Cc: emacs-devel@gnu.org
> Date: Sun, 26 Feb 2023 08:01:01 +0100
> 
> >> I thought those functions are only useful inside dired buffer windows.
> 
> is that not the case?

I don't know, sorry.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  7:22             ` Felix
@ 2023-02-26  8:10               ` Eli Zaretskii
  2023-02-26 13:14                 ` Felix
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2023-02-26  8:10 UTC (permalink / raw)
  To: Felix; +Cc: emacs-devel

> From: Felix <felix.dick@web.de>
> Cc:  emacs-devel@gnu.org
> Date: Sun, 26 Feb 2023 08:22:12 +0100
> 
> 
> Felix <felix.dick@web.de> writes:
> 
> >
> > Just to be absolutely save,
> > (= (length (get-buffer-window-list)) 1))
> > could be changed to
> 
>  (< (length (get-buffer-window-list)) 2))
> 
> of course.
> 
> Should i resend the patch?

It's safer if you do, thanks.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26  8:10               ` Eli Zaretskii
@ 2023-02-26 13:14                 ` Felix
  2023-02-28 14:12                   ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Felix @ 2023-02-26 13:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 431 bytes --]


Eli Zaretskii <eliz@gnu.org> writes:

>> From: Felix <felix.dick@web.de>
>> Cc:  emacs-devel@gnu.org
>> Date: Sun, 26 Feb 2023 08:22:12 +0100
>>
>>
>> Felix <felix.dick@web.de> writes:
>>
>> >
>> > Just to be absolutely save,
>> > (= (length (get-buffer-window-list)) 1))
>> > could be changed to
>>
>>  (< (length (get-buffer-window-list)) 2))
>>
>> of course.
>>
>> Should i resend the patch?
>
> It's safer if you do, thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired.patch --]
[-- Type: text/x-patch, Size: 527 bytes --]

index 76499d0f520..55a5bbd9800 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2728,7 +2728,8 @@ dired-find-file
 (defun dired--find-possibly-alternative-file (file)
   "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
   (if (and dired-kill-when-opening-new-dired-buffer
-           (file-directory-p file))
+           (file-directory-p file)
+           (< (length (get-buffer-window-list)) 2))
       (progn
         (set-buffer-modified-p nil)
         (dired--find-file #'find-alternate-file file))

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] change dired--find-possibly-alternative-file behaviour.
  2023-02-26 13:14                 ` Felix
@ 2023-02-28 14:12                   ` Eli Zaretskii
  0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2023-02-28 14:12 UTC (permalink / raw)
  To: Felix; +Cc: emacs-devel

> From: Felix <felix.dick@web.de>
> Cc: emacs-devel@gnu.org
> Date: Sun, 26 Feb 2023 14:14:59 +0100
> 
> >> Should i resend the patch?
> >
> > It's safer if you do, thanks.
> 

Thanks, installed.



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-02-28 14:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-25 19:43 [PATCH] change dired--find-possibly-alternative-file behaviour Felix
2023-02-26  5:26 ` Eli Zaretskii
2023-02-26  6:07   ` Felix
2023-02-26  6:29     ` Eli Zaretskii
2023-02-26  6:32       ` Felix
2023-02-26  7:00         ` Eli Zaretskii
2023-02-26  7:01           ` Felix
2023-02-26  7:22             ` Felix
2023-02-26  8:10               ` Eli Zaretskii
2023-02-26 13:14                 ` Felix
2023-02-28 14:12                   ` Eli Zaretskii
2023-02-26  8:09             ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).