emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r106859: dired fix for `ls -b' quotin


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r106859: dired fix for `ls -b' quoting of spaces (bug#10469)
Date: Fri, 13 Jan 2012 18:09:28 -0500
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 106859
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Fri 2012-01-13 18:09:28 -0500
message:
  dired fix for `ls -b' quoting of spaces (bug#10469)
  
  * lisp/dired.el (dired-switches-escape-p): New function.
  (dired-insert-directory): Use dired-switches-escape-p.
  (dired-get-filename): Undo "\ " quoting if needed.
modified:
  lisp/ChangeLog
  lisp/dired.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-01-13 02:32:07 +0000
+++ b/lisp/ChangeLog    2012-01-13 23:09:28 +0000
@@ -1,5 +1,9 @@
 2012-01-13  Glenn Morris  <address@hidden>
 
+       * dired.el (dired-switches-escape-p): New function.
+       (dired-insert-directory): Use dired-switches-escape-p.
+       (dired-get-filename): Undo "\ " quoting if needed.  (Bug#10469)
+
        * find-dired.el (find-ls-option): Doc fix.  (Bug#10262)
 
 2012-01-12  Glenn Morris  <address@hidden>

=== modified file 'lisp/dired.el'
--- a/lisp/dired.el     2012-01-11 11:18:53 +0000
+++ b/lisp/dired.el     2012-01-13 23:09:28 +0000
@@ -1111,6 +1111,11 @@
 
 (defvar ls-lisp-use-insert-directory-program)
 
+(defun dired-switches-escape-p (switches)
+  "Return non-nil if the string SWITCHES contains -b or --escape."
+  ;; Do not match things like "--block-size" that happen to contain "b".
+  (string-match "\\(\\`\\| \\)-[[:alnum:]]*b\\|--escape\\>" switches))
+
 (defun dired-insert-directory (dir switches &optional file-list wildcard hdr)
   "Insert a directory listing of DIR, Dired style.
 Use SWITCHES to make the listings.
@@ -1152,7 +1157,7 @@
            (dired-align-file beg (point))))
       (insert-directory dir switches wildcard (not wildcard)))
     ;; Quote certain characters, unless ls quoted them for us.
-    (if (not (string-match "b" dired-actual-switches))
+    (if (not (dired-switches-escape-p dired-actual-switches))
        (save-excursion
          (setq end (point-marker))
          (goto-char opoint)
@@ -2099,7 +2104,13 @@
           ;; with quotation marks in their names.
          (while (string-match "\\(?:[^\\]\\|\\`\\)\\(\"\\)" file)
            (setq file (replace-match "\\\"" nil t file 1)))
-
+          ;; Unescape any spaces escaped by ls -b (bug#10469).
+          ;; Other -b quotes, eg \t, \n, work transparently.
+          (if (dired-switches-escape-p dired-actual-switches)
+              (let ((start 0))
+                (while (string-match "\\(\\\\\\) " file start)
+                  (setq file (replace-match "" nil t file 1)
+                        start (1- (match-end 0))))))
          (when (eq system-type 'windows-nt)
            (save-match-data
              (let ((start 0))
@@ -2107,6 +2118,7 @@
                  (aset file (match-beginning 0) ?/)
                  (setq start (match-end 0))))))
 
+          ;; Hence we don't need to worry about converting `\\' back to `\'.
           (setq file (read (concat "\"" file "\"")))
          ;; The above `read' will return a unibyte string if FILE
          ;; contains eight-bit-control/graphic characters.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]