bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#17218: 24.3; Dired does not insert subdirs when used with switch "--


From: Juri Linkov
Subject: bug#17218: 24.3; Dired does not insert subdirs when used with switch "--group-directories-first"
Date: Sun, 27 Apr 2014 11:30:58 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu)

>> I found out the problem in the function "dired-insert-old-subdirs"
>> at line 1367 in dired.el.
>
> There is a similar problem in `dired-sort-R-check' and
> `dired-build-subdir-alist'.
>
> [There probably should be a function that checks for a given switch,
> and does not just use `string-match-p' in such a simple way.
> (At least it should respect case etc.)]

Below is the implementation of such a function:

=== modified file 'lisp/dired.el'
--- lisp/dired.el       2014-04-22 18:17:17 +0000
+++ lisp/dired.el       2014-04-27 08:28:10 +0000
@@ -1142,10 +1142,20 @@ (defun dired-align-file (beg end)
 
 (defvar ls-lisp-use-insert-directory-program)
 
+(defun dired-switches-check (switches long short)
+  "Return non-nil if the string SWITCHES matches LONG or SHORT format."
+  (let (case-fold-search)
+    (string-match-p (concat "\\(\\`\\| \\)-[[:alnum:]]*" short
+                           "\\|--" long "\\>") switches)))
+
 (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-p "\\(\\`\\| \\)-[[:alnum:]]*b\\|--escape\\>" switches))
+  (dired-switches-check switches "escape" "b"))
+
+(defun dired-switches-recursive-p (switches)
+  "Return non-nil if the string SWITCHES contains -R or --recursive."
+  (dired-switches-check switches "recursive" "R"))
 
 (defun dired-insert-directory (dir switches &optional file-list wildcard hdr)
   "Insert a directory listing of DIR, Dired style.
@@ -1402,7 +1412,7 @@ (defun dired-remember-hidden ()
 (defun dired-insert-old-subdirs (old-subdir-alist)
   "Try to insert all subdirs that were displayed before.
 Do so according to the former subdir alist OLD-SUBDIR-ALIST."
-  (or (string-match-p "R" dired-actual-switches)
+  (or (dired-switches-recursive-p dired-actual-switches)
       (let (elt dir)
        (while old-subdir-alist
          (setq elt (car old-subdir-alist)
@@ -2613,7 +2623,7 @@ (defun dired-build-subdir-alist (&option
           (R-ftp-base-dir-regex
            ;; Used to expand subdirectory names correctly in recursive
            ;; ange-ftp listings.
-           (and (string-match-p "R" switches)
+           (and (dired-switches-recursive-p switches)
                 (string-match "\\`/.*:\\(/.*\\)" default-directory)
                 (concat "\\`" (match-string 1 default-directory)))))
       (goto-char (point-min))
@@ -3688,12 +3698,12 @@ (defun dired-sort-R-check (switches)
 minus any directories explicitly deleted when R is cleared.
 To be called first in body of `dired-sort-other', etc."
   (cond
-   ((and (string-match-p "R" switches)
-        (not (string-match-p "R" dired-actual-switches)))
+   ((and (dired-switches-recursive-p switches)
+        (not (dired-switches-recursive-p dired-actual-switches)))
     ;; Adding -R to ls switches -- save `dired-subdir-alist':
     (setq dired-subdir-alist-pre-R dired-subdir-alist))
-   ((and (string-match-p "R" dired-actual-switches)
-        (not (string-match-p "R" switches)))
+   ((and (dired-switches-recursive-p dired-actual-switches)
+        (not (dired-switches-recursive-p switches)))
     ;; Deleting -R from ls switches -- revert to pre-R subdirs
     ;; that are still present:
     (setq dired-subdir-alist


reply via email to

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