unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Drew Adams <drew.adams@oracle.com>
Cc: Tu Do <tuhdo1710@gmail.com>, 17218@debbugs.gnu.org
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	[thread overview]
Message-ID: <871twjjhrx.fsf@mail.jurta.org> (raw)
In-Reply-To: <bf4844bc-fcac-418a-bf76-fe23cdc58154@default> (Drew Adams's message of "Mon, 7 Apr 2014 09:00:56 -0700 (PDT)")

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

>> 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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2777 bytes --]

=== 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


  parent reply	other threads:[~2014-04-27  8:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-07 14:12 bug#17218: 24.3; Dired does not insert subdirs when used with switch "--group-directories-first" Tu Do
2014-04-07 16:00 ` Drew Adams
2014-04-08  8:45   ` Juri Linkov
2014-04-27  8:30   ` Juri Linkov [this message]
2014-05-03  9:23     ` Juri Linkov
2014-05-07 19:50       ` Glenn Morris
2014-05-07 20:14         ` Juri Linkov
2014-05-08 18:15           ` Glenn Morris

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871twjjhrx.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=17218@debbugs.gnu.org \
    --cc=drew.adams@oracle.com \
    --cc=tuhdo1710@gmail.com \
    /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 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).