From: Charles El Hourani <charlie.eh@gmail.com>
To: 10607@debbugs.gnu.org
Subject: bug#10607: bug-10607
Date: Tue, 4 Apr 2023 21:52:39 +0300 [thread overview]
Message-ID: <CAAB1LQWCUj_eR+5QjyOOH1ohtzKmmqP861Z-5uRG7DJmrY=tdA@mail.gmail.com> (raw)
In-Reply-To: <6o62fzm010.fsf@fencepost.gnu.org>
[-- 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
next prev parent reply other threads:[~2023-04-04 18:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 [this message]
2023-04-05 4:45 ` bug#10607: bug-10607 Eli Zaretskii
2023-04-06 16:45 ` Charles El Hourani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAB1LQWCUj_eR+5QjyOOH1ohtzKmmqP861Z-5uRG7DJmrY=tdA@mail.gmail.com' \
--to=charlie.eh@gmail.com \
--cc=10607@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.