unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10607: Handle all the escapes used by ls -b
       [not found] <6o62fzm010.fsf@fencepost.gnu.org>
@ 2021-01-20 17:41 ` Lars Ingebrigtsen
  2023-04-04 18:52 ` bug#10607: bug-10607 Charles El Hourani
  1 sibling, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-01-20 17:41 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10607

Glenn Morris <rgm@gnu.org> writes:

> Emacs only partially handles (setq dired-listing-switches "-alb") at the
> moment. Ideally, should add handling for all possible file-name
> characters (eg \a = \a, etc). dired-goto-file needs this, possibly other
> places.

This problem is still present in Emacs 28.

Case to reproduce:

(progn
  (setq dired-listing-switches "-alb")
  (shell-command "touch /tmp/a\ab")
  (dired "/tmp/")
  (dired-goto-file "/tmp/a\ab"))

This will not go to the a^Gb file.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#10607: bug-10607
       [not found] <6o62fzm010.fsf@fencepost.gnu.org>
  2021-01-20 17:41 ` bug#10607: Handle all the escapes used by ls -b Lars Ingebrigtsen
@ 2023-04-04 18:52 ` Charles El Hourani
  2023-04-05  4:45   ` Eli Zaretskii
  1 sibling, 1 reply; 4+ messages in thread
From: Charles El Hourani @ 2023-04-04 18:52 UTC (permalink / raw)
  To: 10607


[-- Attachment #1.1: Type: text/plain, Size: 122 bytes --]

Here is a way to solve the issue by calling `ls` directly, without
re-implementing the "-b" functionality of ls in elisp.

[-- Attachment #1.2: Type: text/html, Size: 157 bytes --]

[-- Attachment #2: 0001-Fix-dired-goto-file-when-b-is-provided-to-ls-bug-106.patch --]
[-- Type: text/x-patch, Size: 3101 bytes --]

From 22962ffd84370ac05017ed05cca88286d010aa0e Mon Sep 17 00:00:00 2001
From: Charlie El Hourani <charlie.eh@gmail.com>
Date: Tue, 4 Apr 2023 21:26:07 +0300
Subject: [PATCH] Fix dired goto file when -b is provided to ls (bug#10607)

This fixes the goto file in dired mode for:
- files containing a control character
- and when dired uses ls with the "-b" flag

The goto file function calls 'ls' to give it the escaped name.
---
 lisp/dired.el            | 16 +++++++++-------
 test/lisp/dired-tests.el | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 8e3244356fe..a3117d8e553 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3522,13 +3522,15 @@ dired-goto-file-1
   (let (str)
     (setq str (string-replace "\^m" "\\^m"  file))
     (setq str (string-replace "\\" "\\\\" str))
-    (and (dired-switches-escape-p dired-actual-switches)
-	 (string-match-p "[ \t\n]" str)
-	 ;; FIXME: to fix this for embedded control characters etc, we
-	 ;; should escape everything that `ls -b' does.
-	 (setq str (string-replace " " "\\ "  str)
-	       str (string-replace "\t" "\\t" str)
-	       str (string-replace "\n" "\\n" str)))
+    (and (not (featurep 'ls-lisp))
+         (dired-switches-escape-p dired-actual-switches)
+         (let ((escaped-full-name
+                (with-output-to-string
+                  (call-process "ls" nil (list standard-output nil) nil
+                                "-bd" full-name))))
+           (when (not (string-blank-p escaped-full-name))
+             (setq str (file-name-nondirectory
+                        (car (split-string escaped-full-name)))))))
     (let ((found nil)
 	  ;; filenames are preceded by SPC, this makes the search faster
 	  ;; (e.g. for the filename "-").
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 347bdfc0d7b..c26ff8ec9ea 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -31,6 +31,28 @@ dired-autoload
     (symbol-function
      'dired-do-relsymlink))))
 
+(ert-deftest dired-test-bug10607 ()
+  "Test for https://debbugs.gnu.org/10607 ."
+  (let* ((dired-listing-switches "-alb")
+         (prefix "a\ab")
+         (prefixed-filename (make-temp-file prefix))
+         (regular-filename (make-temp-file ""))
+         buffers)
+    (push (dired (file-name-directory prefixed-filename)) buffers)
+    (unwind-protect
+        (progn
+          (dired-goto-file prefixed-filename)
+          (when (not (featurep 'ls-lisp))
+            (should (equal (dired-file-name-at-point)
+                           prefixed-filename)))
+          (dired-goto-file regular-filename)
+          (should (equal (dired-file-name-at-point)
+                         regular-filename)))
+      (dolist (buf buffers)
+        (when (buffer-live-p buf) (kill-buffer buf)))
+      (delete-file prefixed-filename)
+      (delete-file regular-filename))))
+
 (ert-deftest dired-test-bug22694 ()
   "Test for https://debbugs.gnu.org/22694 ."
   (let* ((dir       (expand-file-name "bug22694" default-directory))
-- 
2.34.1


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

* bug#10607: bug-10607
  2023-04-04 18:52 ` bug#10607: bug-10607 Charles El Hourani
@ 2023-04-05  4:45   ` Eli Zaretskii
  2023-04-06 16:45     ` Charles El Hourani
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2023-04-05  4:45 UTC (permalink / raw)
  To: Charles El Hourani; +Cc: 10607

> From: Charles El Hourani <charlie.eh@gmail.com>
> Date: Tue, 4 Apr 2023 21:52:39 +0300
> 
> Here is a way to solve the issue by calling `ls` directly, without re-implementing the "-b" functionality of ls in
> elisp.
> 
> From 22962ffd84370ac05017ed05cca88286d010aa0e Mon Sep 17 00:00:00 2001
> From: Charlie El Hourani <charlie.eh@gmail.com>
> Date: Tue, 4 Apr 2023 21:26:07 +0300
> Subject: [PATCH] Fix dired goto file when -b is provided to ls (bug#10607)
> 
> This fixes the goto file in dired mode for:
> - files containing a control character
> - and when dired uses ls with the "-b" flag
> 
> The goto file function calls 'ls' to give it the escaped name.

Thanks, but is it really a good idea to invoke a program each time we
move in Dired?  dired-goto-file is a function that is used very
frequently.

In any case, calling literally "ls" is not TRT, IMO, since the user
could have modified the value of insert-directory-program.





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

* bug#10607: bug-10607
  2023-04-05  4:45   ` Eli Zaretskii
@ 2023-04-06 16:45     ` Charles El Hourani
  0 siblings, 0 replies; 4+ messages in thread
From: Charles El Hourani @ 2023-04-06 16:45 UTC (permalink / raw)
  To: 10607

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

Practically, the concern I see in this additional `ls` call here is a
slowdown when dired is used for remote locations. It is an added delay to
the delay already incurred with read-file-name when called interactively.

On that note, dired-goto-file could just use the files already inserted in
the buffer to provide options to the user to pick from. That could obviate
the need to convert the read-file-name choice to what dired originally got
from the insert-directory-program.

Listing the missing control characters is another option, but placing this
conversion in dired is making it more complex when the
insert-directory-program like "ls" is already handling it.

We could call here insert-directory-program instead of "ls", unless the
escape option is not supported in this program. I don't know how we can
find that out.

On Wed, Apr 5, 2023 at 12:45 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Charles El Hourani <charlie.eh@gmail.com>
> > Date: Tue, 4 Apr 2023 21:52:39 +0300
> >
> > Here is a way to solve the issue by calling `ls` directly, without
> re-implementing the "-b" functionality of ls in
> > elisp.
> >
> > From 22962ffd84370ac05017ed05cca88286d010aa0e Mon Sep 17 00:00:00 2001
> > From: Charlie El Hourani <charlie.eh@gmail.com>
> > Date: Tue, 4 Apr 2023 21:26:07 +0300
> > Subject: [PATCH] Fix dired goto file when -b is provided to ls
> (bug#10607)
> >
> > This fixes the goto file in dired mode for:
> > - files containing a control character
> > - and when dired uses ls with the "-b" flag
> >
> > The goto file function calls 'ls' to give it the escaped name.
>
> Thanks, but is it really a good idea to invoke a program each time we
> move in Dired?  dired-goto-file is a function that is used very
> frequently.
>
> In any case, calling literally "ls" is not TRT, IMO, since the user
> could have modified the value of insert-directory-program.
>

[-- Attachment #2: Type: text/html, Size: 2488 bytes --]

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

end of thread, other threads:[~2023-04-06 16:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <6o62fzm010.fsf@fencepost.gnu.org>
2021-01-20 17:41 ` bug#10607: Handle all the escapes used by ls -b Lars Ingebrigtsen
2023-04-04 18:52 ` bug#10607: bug-10607 Charles El Hourani
2023-04-05  4:45   ` Eli Zaretskii
2023-04-06 16:45     ` Charles El Hourani

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).