GNU bug report logs - #27801
26.0.50; Dired: Use relative file names when DIR-OR-LIST is a cons

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Mon, 24 Jul 2017 03:31:01 UTC

Severity: wishlist

Tags: wontfix

Found in version 26.0.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 27801 in the body.
You can then email your comments to 27801 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#27801; Package emacs. (Mon, 24 Jul 2017 03:31:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tino Calancha <tino.calancha <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 24 Jul 2017 03:31:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50; Dired: Use relative file names when DIR-OR-LIST is a cons
Date: Mon, 24 Jul 2017 12:29:48 +0900
Severity: wishlist

emacs -Q /tmp

;; Following form shows the full file name in the Dired buffer.
(let* ((dir source-directory)
       (file1 (expand-file-name "lisp/subr.el" dir))
       (file2 (expand-file-name "src/data.c" dir)))
  (dired (list dir file1 file2)))

;; Usually, Dired just shows the relative file name to
;; 'default-directory'.  That is more clear, specially for
;; long file names.

--8<-----------------------------cut here---------------start------------->8---
commit 192c9b0179adbe4ae65d956f064eb9c2197a0a01
Author: Tino Calancha <tino.calancha <at> gmail.com>
Date:   Mon Jul 24 12:25:24 2017 +0900

    Dired: Use relative file names when DIR-OR-LIST is a cons
    
    * lisp/dired.el (dired-internal-noselect): Use relative file
    names when DIR-OR-LIST is a cons.
    * test/lisp/dired-tests.el (dired-test-bug27801): Add test.

diff --git a/lisp/dired.el b/lisp/dired.el
index 9d500a9f52..718c2b8cf9 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -926,6 +926,11 @@ dired-internal-noselect
 	    ;; if it was the name of a directory at all.
 	    (file-name-directory dirname))
       (or switches (setq switches dired-listing-switches))
+      ;; If `dir-or-list' is a cons, use file names relative
+      ;; to default-directory.
+      (when (and (consp dir-or-list) (file-name-absolute-p (cadr dir-or-list)))
+        (setf (cdr dir-or-list)
+              (mapcar #'file-relative-name (cdr dir-or-list))))
       (if mode (funcall mode)
         (dired-mode dir-or-list switches))
       ;; default-directory and dired-actual-switches are set now
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 69331457c0..4241609ec6 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -175,5 +175,25 @@
           (should (looking-at "src")))
       (when (buffer-live-p buf) (kill-buffer buf)))))
 
+(ert-deftest dired-test-bug27801 ()
+  "Test for http://debbugs.gnu.org/27801 ."
+  (let* ((dir (make-temp-file "bug27801" 'dir))
+         (foo (expand-file-name "foo" dir))
+         (bar (expand-file-name "bar" dir))
+         (f1 (expand-file-name "file" foo))
+         (f2 (expand-file-name "file" bar))
+         buf)
+    (unwind-protect
+        (progn
+          (make-directory foo)
+          (make-directory bar)
+          (with-temp-file f1 nil)
+          (with-temp-file f2 nil)
+          (setq buf (dired (list dir f1 f2)))
+          (dired-goto-file f1)
+          (should (looking-at "foo/file$")))
+      (when (buffer-live-p buf) (kill-buffer buf))
+      (delete-directory dir t))))
+
 (provide 'dired-tests)
 ;; dired-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-07-23
Repository revision: 1f450f1d3531cb53ebe50744c85c90141fce7ad0




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27801; Package emacs. (Mon, 24 Jul 2017 03:49:02 GMT) Full text and rfc822 format available.

Message #8 received at 27801 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Tino Calancha <tino.calancha <at> gmail.com>, 27801 <at> debbugs.gnu.org
Subject: RE: bug#27801: 26.0.50; Dired: Use relative file names when
 DIR-OR-LIST is a cons
Date: Sun, 23 Jul 2017 20:47:51 -0700 (PDT)
> ;; Following form shows the full file name in the Dired buffer.
> (let* ((dir source-directory)
>        (file1 (expand-file-name "lisp/subr.el" dir))
>        (file2 (expand-file-name "src/data.c" dir)))
>   (dired (list dir file1 file2)))
> 
> ;; Usually, Dired just shows the relative file name to
> ;; 'default-directory'.  That is more clear, specially for
> ;; long file names.

Sorry, but I've only read this bug report quickly - no time now.

If you are suggesting that when DIR-OR-LIST is a cons the
file names shown should be relative then I think I disagree
strongly.

The typical use case for a cons DIR-OR-LIST is a list
of files from anywhere, in which case absolute file
names are appropriate.

Again, sorry if I've read too quickly and misunderstood.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27801; Package emacs. (Mon, 24 Jul 2017 04:17:01 GMT) Full text and rfc822 format available.

Message #11 received at 27801 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 27801 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
Subject: RE: bug#27801: 26.0.50;
 Dired: Use relative file names when DIR-OR-LIST is a cons
Date: Mon, 24 Jul 2017 13:16:40 +0900 (JST)

On Sun, 23 Jul 2017, Drew Adams wrote:

>> ;; Following form shows the full file name in the Dired buffer.
>> (let* ((dir source-directory)
>>        (file1 (expand-file-name "lisp/subr.el" dir))
>>        (file2 (expand-file-name "src/data.c" dir)))
>>   (dired (list dir file1 file2)))
>>
>> ;; Usually, Dired just shows the relative file name to
>> ;; 'default-directory'.  That is more clear, specially for
>> ;; long file names.
>
> Sorry, but I've only read this bug report quickly - no time now.
>
> If you are suggesting that when DIR-OR-LIST is a cons the
> file names shown should be relative then I think I disagree
> strongly.
>
> The typical use case for a cons DIR-OR-LIST is a list
> of files from anywhere, in which case absolute file
> names are appropriate.
I am OK with adding a new variable `foo' so that i can get
this behavior if i locally bind `foo' to a non-nil value.

This idea comes while i am trying to implement Bug#27631; to
have this feature working with 'ls-lisp' my implementation
do something like:

1) Collect all matches with `find-lisp' in a variable FILES.
   (This is just a first approach to the problem; for large
   number of matches would be better to not store the matches
   in a list).

2) [Suppose DIR is the default-directory i the Dired buffer]
   Then call:
(dired (list DIR FILES))

;; My implementation works as with GNU ls; the only difference is
;; that 2) shows full file names in the Dired buffer.  I rather
;; prefer is the output has same format regarless on if the user
;; use `ls-lisp' or not.

With the var `foo' mentioned above, we could change 2) with:
3)

 (let ((foo t))
   (dired (list DIR FILES)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27801; Package emacs. (Mon, 24 Jul 2017 05:06:01 GMT) Full text and rfc822 format available.

Message #14 received at 27801 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 27801 <at> debbugs.gnu.org
Subject: RE: bug#27801: 26.0.50; Dired: Use relative file names when
 DIR-OR-LIST is a cons
Date: Sun, 23 Jul 2017 22:05:47 -0700 (PDT)
> >> ;; Following form shows the full file name in the Dired buffer.
> >> (let* ((dir source-directory)
> >>        (file1 (expand-file-name "lisp/subr.el" dir))
> >>        (file2 (expand-file-name "src/data.c" dir)))
> >>   (dired (list dir file1 file2)))
> >>
> >> ;; Usually, Dired just shows the relative file name to
> >> ;; 'default-directory'. That is more clear, specially for
> >> ;; long file names.
> >
> > Sorry, but I've only read this bug report quickly - no time
> > now.  If you are suggesting that when DIR-OR-LIST is a cons
> > the file names shown should be relative then I think I
> > disagree strongly.
> >
> > The typical use case for a cons DIR-OR-LIST is a list
> > of files from anywhere, in which case absolute file
> > names are appropriate.
>
> I am OK with adding a new variable `foo' so that i can get
> this behavior if i locally bind `foo' to a non-nil value.

I don't see why you need that.

> This idea comes while i am trying to implement Bug#27631; to
> have this feature working with 'ls-lisp' my implementation
> do something like:
> 
> 1) Collect all matches with `find-lisp' in a variable FILES.

(What is `find-lisp'?  I don't see it in Emacs 25.2 or earlier.
But I see 4 functions whose names start with `find-lisp-'.)

>     (This is just a first approach to the problem; for large
>     number of matches would be better to not store the matches
>     in a list).
> 
> 2) [Suppose DIR is the default-directory i the Dired buffer]
>     Then call: (dired (list DIR FILES))
> 
> My implementation works as with GNU ls; the only difference is
> that 2) shows full file names in the Dired buffer.  I rather
> prefer is the output has same format regarless on if the user
> use `ls-lisp' or not.
> 
> With the var `foo' mentioned above, we could change 2) with:
> 3) (let ((foo t)) (dired (list DIR FILES)))

Again, sorry, but I don't really have time to look into this
now.  Two quick comments though, which might be misguided:

1. IIUC, bug #27631 is not a bug.  It is an enhancement request,
for a new feature.  That's not a reason to change a longstanding,
essentially unrelated, behavior that is very general and very
useful.

2. If you call (dired (list DIR FILES)) and you want FILES
to be relative rather than absolute, why can't you just
(for your particular use case) use something like
(dired (list DIR (mapcar #'dired-make-relative FILES)))?
What am I missing?

Possibly you would want to pass DIR or some other directory to
`dired-make-relative' ; dunno.  Or maybe `file-relative-name'
would be more appropriate for your use case; dunno.

I don't understand why you would propose changing `dired'
so that a cons argument is interpreted in some new, more
restrictive way.

I say "more restrictive" because currently you can get
absolute or relative file names, just by passing the
forms of names that you want.  You can even get a mix
of absolute and relative names - that's sometimes handy.

Dired should be able to list file names in either or
both forms.  I see no reason that it shouldn't.

I don't see why you would need to add a variable, as
you describe, instead of just passing the file names
you want in the form(s) that you want.  But I'm probably
missing something in what you're suggesting.




Added tag(s) wontfix. Request was from Tino Calancha <tino.calancha <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 24 Jul 2017 05:37:02 GMT) Full text and rfc822 format available.

Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Mon, 24 Jul 2017 05:38:01 GMT) Full text and rfc822 format available.

Notification sent to Tino Calancha <tino.calancha <at> gmail.com>:
bug acknowledged by developer. (Mon, 24 Jul 2017 05:38:02 GMT) Full text and rfc822 format available.

Message #21 received at 27801-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 27801-done <at> debbugs.gnu.org
Cc: Drew Adams <drew.adams <at> oracle.com>
Subject: Re: bug#27801: 26.0.50;
 Dired: Use relative file names when DIR-OR-LIST is a cons
Date: Mon, 24 Jul 2017 14:37:36 +0900
Drew Adams <drew.adams <at> oracle.com> writes:

> 2. If you call (dired (list DIR FILES)) and you want FILES
> to be relative rather than absolute, why can't you just
> (for your particular use case) use something like
> (dired (list DIR (mapcar #'dired-make-relative FILES)))?
> What am I missing?
Your right.  Thank you!
This is the proper way to do it: pass a list with
the relative names.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 21 Aug 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 129 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.