* bug#27631: dired a/*/b
@ 2017-07-09 18:42 積丹尼 Dan Jacobson
2017-07-13 5:52 ` Tino Calancha
` (2 more replies)
0 siblings, 3 replies; 25+ messages in thread
From: 積丹尼 Dan Jacobson @ 2017-07-09 18:42 UTC (permalink / raw)
To: 27631
Maybe make dired and list-directory deal with wildcards in positions like
~/.config/chromium/Default/*/menkifleemblimdogmoihpfopnplikde/
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-09 18:42 bug#27631: dired a/*/b 積丹尼 Dan Jacobson
@ 2017-07-13 5:52 ` Tino Calancha
2017-08-02 17:30 ` Stefan Monnier
2017-07-13 13:15 ` 積丹尼 Dan Jacobson
2017-07-13 15:13 ` Tino Calancha
2 siblings, 1 reply; 25+ messages in thread
From: Tino Calancha @ 2017-07-13 5:52 UTC (permalink / raw)
To: 積丹尼 Dan Jacobson; +Cc: 27631
積丹尼 Dan Jacobson <jidanni@jidanni.org> writes:
> Maybe make dired and list-directory deal with wildcards in positions like
> ~/.config/chromium/Default/*/menkifleemblimdogmoihpfopnplikde/
Thank you for the report.
IMO, this is a nice thing to have.
It must be possible to extend the current code so that
dired might handle wildcards in the directory part.
Following is a crude patch as a proof of principle. Not heavily
tested yet, but for simple cases seems to work.
--8<-----------------------------cut here---------------start------------->8---
commit c172cd911229a02877dea2681f533c10e8e34b4f
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Thu Jul 13 14:43:34 2017 +0900
dired: Handle wildcards in the directory part (Bug#27631)
diff --git a/lisp/dired.el b/lisp/dired.el
index 0c1f3e4af6..7fa3a47db5 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -913,11 +913,13 @@ dired-internal-noselect
"Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
;; Else a new buffer
(setq default-directory
- ;; We can do this unconditionally
- ;; because dired-noselect ensures that the name
- ;; is passed in directory name syntax
- ;; if it was the name of a directory at all.
- (file-name-directory dirname))
+ (if (insert-directory-wildcard-in-dir-p dirname)
+ (car (insert-directory-process-wildcard dirname))
+ ;; We can do this unconditionally
+ ;; because dired-noselect ensures that the name
+ ;; is passed in directory name syntax
+ ;; if it was the name of a directory at all.
+ (file-name-directory dirname)))
(or switches (setq switches dired-listing-switches))
(if mode (funcall mode)
(dired-mode dir-or-list switches))
@@ -1049,13 +1051,14 @@ dired-readin-insert
(not file-list))
;; If we are reading a whole single directory...
(dired-insert-directory dir dired-actual-switches nil nil t)
- (if (not (file-readable-p
- (directory-file-name (file-name-directory dir))))
- (error "Directory %s inaccessible or nonexistent" dir)
- ;; Else treat it as a wildcard spec
- ;; unless we have an explicit list of files.
- (dired-insert-directory dir dired-actual-switches
- file-list (not file-list) t)))))
+ (if (and (not (insert-directory-wildcard-in-dir-p dir))
+ (not (file-readable-p
+ (directory-file-name (file-name-directory dir)))))
+ (error "Directory %s inaccessible or nonexistent" dir))
+ ;; Else treat it as a wildcard spec
+ ;; unless we have an explicit list of files.
+ (dired-insert-directory dir dired-actual-switches
+ file-list (not file-list) t))))
(defun dired-align-file (beg end)
"Align the fields of a file to the ones of surrounding lines.
@@ -1272,11 +1275,16 @@ dired-insert-directory
;; Note that dired-build-subdir-alist will replace the name
;; by its expansion, so it does not matter whether what we insert
;; here is fully expanded, but it should be absolute.
- (insert " " (directory-file-name (file-name-directory dir)) ":\n")
+ (insert " " (if (insert-directory-wildcard-in-dir-p dir)
+ (car (insert-directory-process-wildcard dir))
+ (directory-file-name (file-name-directory dir))) ":\n")
(setq content-point (point)))
(when wildcard
;; Insert "wildcard" line where "total" line would be for a full dir.
- (insert " wildcard " (file-name-nondirectory dir) "\n")))
+ (insert " wildcard " (if (insert-directory-wildcard-in-dir-p dir)
+ (cdr (insert-directory-process-wildcard dir))
+ (file-name-nondirectory dir))
+ "\n")))
(dired-insert-set-properties content-point (point)))))
(defun dired-insert-set-properties (beg end)
diff --git a/lisp/files.el b/lisp/files.el
index 2f3efa33c2..96d1b49d50 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6552,6 +6552,23 @@ directory-listing-before-filename-regexp
(defvar insert-directory-ls-version 'unknown)
+(defun insert-directory-wildcard-in-dir-p (dir)
+ (string-match "\\`\\([^*]+\\)\\([*].*\\)"
+ (file-name-directory dir)))
+
+(defun insert-directory-process-wildcard (dir)
+ (let ((switches "")
+ (newdir "")
+ (regexp "\\`\\([^*]+/\\)\\([^*]*[*].*\\)"))
+ (cond ((string-match regexp (file-name-directory dir))
+ (string-match regexp dir)
+ (setq newdir (match-string 1 dir)
+ switches (match-string 2 dir)))
+ (t
+ (setq newdir (file-name-directory dir)
+ switches (file-name-nondirectory dir))))
+ (cons newdir switches)))
+
;; insert-directory
;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
;; FULL-DIRECTORY-P is nil.
@@ -6611,13 +6628,20 @@ insert-directory
default-file-name-coding-system))))
(setq result
(if wildcard
- ;; Run ls in the directory part of the file pattern
- ;; using the last component as argument.
- (let ((default-directory
- (if (file-name-absolute-p file)
- (file-name-directory file)
- (file-name-directory (expand-file-name file))))
- (pattern (file-name-nondirectory file)))
+ ;; If the wildcard is just in the file part, then run ls in
+ ;; the directory part of the file pattern using the last
+ ;; component as argument. Otherwise, run ls in the longest
+ ;; subdirectory of the directory part free of wildcars; use
+ ;; the remaining of the file pattern as argument.
+ (let* ((dir-wildcard (and (insert-directory-wildcard-in-dir-p file)
+ (insert-directory-process-wildcard file)))
+ (default-directory
+ (cond (dir-wildcard (car dir-wildcard))
+ (t
+ (if (file-name-absolute-p file)
+ (file-name-directory file)
+ (file-name-directory (expand-file-name file))))))
+ (pattern (if dir-wildcard (cdr dir-wildcard) (file-name-nondirectory file))))
;; NB since switches is passed to the shell, be
;; careful of malicious values, eg "-l;reboot".
;; See eg dired-safe-switches-p.
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 7, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-07-12
Repository revision: dde7f2d48b53996bdf767a8cf91aafc2e10add23
^ permalink raw reply related [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-09 18:42 bug#27631: dired a/*/b 積丹尼 Dan Jacobson
2017-07-13 5:52 ` Tino Calancha
@ 2017-07-13 13:15 ` 積丹尼 Dan Jacobson
2017-07-13 15:13 ` Tino Calancha
2 siblings, 0 replies; 25+ messages in thread
From: 積丹尼 Dan Jacobson @ 2017-07-13 13:15 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Thank you for making dired as powerful as ls(1).
Though I did not test your patch, I hope it gets into emacs.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-09 18:42 bug#27631: dired a/*/b 積丹尼 Dan Jacobson
2017-07-13 5:52 ` Tino Calancha
2017-07-13 13:15 ` 積丹尼 Dan Jacobson
@ 2017-07-13 15:13 ` Tino Calancha
2017-07-14 8:40 ` Eli Zaretskii
2017-07-14 9:30 ` Michael Albinus
2 siblings, 2 replies; 25+ messages in thread
From: Tino Calancha @ 2017-07-13 15:13 UTC (permalink / raw)
To: Michael Albinus; +Cc: 27631
積丹尼 Dan Jacobson <jidanni@jidanni.org> writes:
> Maybe make dired and list-directory deal with wildcards in positions like
> ~/.config/chromium/Default/*/menkifleemblimdogmoihpfopnplikde/
Hi Michael,
i'd like to provide Tramp support for this new Dired feature.
The implementation is fairly straight: just adds a function
'insert-directory-wildcard-in-dir-p' in files.el, and use it in
'insert-directory' and Dired.
To get Tramp support i've added a handler
'tramp-sh-handle-insert-directory-wildcard-in-dir-p'.
Is this procedure OK or i am doing something weird?
Best regards,
Tino
--8<-----------------------------cut here---------------start------------->8---
commit e5d5bd9822c1c562a7feb16f035062fda603d4d9
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Thu Jul 13 23:56:43 2017 +0900
Dired: Handle wildards in directory part
Allow to Dired to handle calls like
\(dired \"~/foo/*/*.el\"), that is, with wildcards withing
the directory part of the file argument.
* lisp/files.el (insert-directory-wildcard-in-dir-p): New predicate.
(insert-directory)
* lisp/dired.el(dired-internal-noselect)
(dired-insert-directory): Use it.
* /etc/NEWS: Announce it.
* doc/emacs/dired.texi (Dired Enter): Update manual.
diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 28cb51d88b..2113381e3a 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -64,10 +64,23 @@ Dired Enter
directory name using the minibuffer, and opens a @dfn{Dired buffer}
listing the files in that directory. You can also supply a wildcard
file name pattern as the minibuffer argument, in which case the Dired
-buffer lists all files matching that pattern. The usual history and
-completion commands can be used in the minibuffer; in particular,
-@kbd{M-n} puts the name of the visited file (if any) in the minibuffer
-(@pxref{Minibuffer History}).
+buffer lists all files matching that pattern. A wildcard may appear
+in the directory part as well.
+For instance,
+
+@example
+C-x d ~/foo/*.el @key{RET}
+C-x d ~/foo/*/*.el @key{RET}
+@end example
+
+The former lists all the files with extension @samp{.el} in directory
+@samp{foo}. The latter lists the files with extension @samp{.el}
+in @samp{foo} subdirectories; the sudirectories are 1 level of depth
+below @samp{foo}.
+
+The usual history and completion commands can be used in the minibuffer;
+in particular, @kbd{M-n} puts the name of the visited file (if any) in
+the minibuffer (@pxref{Minibuffer History}).
You can also invoke Dired by giving @kbd{C-x C-f} (@code{find-file})
a directory name.
diff --git a/etc/NEWS b/etc/NEWS
index 71a2da1b63..e16c4a7b76 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -559,9 +559,13 @@ properties as intact as possible.
* Changes in Specialized Modes and Packages in Emacs 26.1
** Dired
-You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets replaced
++++
+*** You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets replaced
by the current file name.
++++
+*** Now Dired support wildcards in the directory part of file names.
+
*** html2text is now marked obsolete.
*** smerge-refine-regions can refine regions in separate buffers
diff --git a/lisp/dired.el b/lisp/dired.el
index 0c1f3e4af6..50dd81dfdd 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -913,11 +913,12 @@ dired-internal-noselect
"Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
;; Else a new buffer
(setq default-directory
- ;; We can do this unconditionally
- ;; because dired-noselect ensures that the name
- ;; is passed in directory name syntax
- ;; if it was the name of a directory at all.
- (file-name-directory dirname))
+ (or (car (insert-directory-wildcard-in-dir-p dirname))
+ ;; We can do this unconditionally
+ ;; because dired-noselect ensures that the name
+ ;; is passed in directory name syntax
+ ;; if it was the name of a directory at all.
+ (file-name-directory dirname)))
(or switches (setq switches dired-listing-switches))
(if mode (funcall mode)
(dired-mode dir-or-list switches))
@@ -1049,13 +1050,14 @@ dired-readin-insert
(not file-list))
;; If we are reading a whole single directory...
(dired-insert-directory dir dired-actual-switches nil nil t)
- (if (not (file-readable-p
- (directory-file-name (file-name-directory dir))))
- (error "Directory %s inaccessible or nonexistent" dir)
- ;; Else treat it as a wildcard spec
- ;; unless we have an explicit list of files.
- (dired-insert-directory dir dired-actual-switches
- file-list (not file-list) t)))))
+ (if (and (not (insert-directory-wildcard-in-dir-p dir))
+ (not (file-readable-p
+ (directory-file-name (file-name-directory dir)))))
+ (error "Directory %s inaccessible or nonexistent" dir))
+ ;; Else treat it as a wildcard spec
+ ;; unless we have an explicit list of files.
+ (dired-insert-directory dir dired-actual-switches
+ file-list (not file-list) t))))
(defun dired-align-file (beg end)
"Align the fields of a file to the ones of surrounding lines.
@@ -1272,11 +1274,14 @@ dired-insert-directory
;; Note that dired-build-subdir-alist will replace the name
;; by its expansion, so it does not matter whether what we insert
;; here is fully expanded, but it should be absolute.
- (insert " " (directory-file-name (file-name-directory dir)) ":\n")
+ (insert " " (or (car (insert-directory-wildcard-in-dir-p dir))
+ (directory-file-name (file-name-directory dir))) ":\n")
(setq content-point (point)))
(when wildcard
;; Insert "wildcard" line where "total" line would be for a full dir.
- (insert " wildcard " (file-name-nondirectory dir) "\n")))
+ (insert " wildcard " (or (cdr (insert-directory-wildcard-in-dir-p dir))
+ (file-name-nondirectory dir))
+ "\n")))
(dired-insert-set-properties content-point (point)))))
(defun dired-insert-set-properties (beg end)
diff --git a/lisp/files.el b/lisp/files.el
index 2f3efa33c2..96c6357d92 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6552,6 +6552,12 @@ directory-listing-before-filename-regexp
(defvar insert-directory-ls-version 'unknown)
+(defun insert-directory-wildcard-in-dir-p (dir)
+ (when (string-match "[*]" (file-name-directory dir))
+ (let ((regexp "\\`\\([^*]+/\\)\\([^*]*[*].*\\)"))
+ (string-match regexp dir)
+ (cons (match-string 1 dir) (match-string 2 dir)))))
+
;; insert-directory
;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
;; FULL-DIRECTORY-P is nil.
@@ -6611,13 +6617,19 @@ insert-directory
default-file-name-coding-system))))
(setq result
(if wildcard
- ;; Run ls in the directory part of the file pattern
- ;; using the last component as argument.
- (let ((default-directory
- (if (file-name-absolute-p file)
- (file-name-directory file)
- (file-name-directory (expand-file-name file))))
- (pattern (file-name-nondirectory file)))
+ ;; If the wildcard is just in the file part, then run ls in
+ ;; the directory part of the file pattern using the last
+ ;; component as argument. Otherwise, run ls in the longest
+ ;; subdirectory of the directory part free of wildcars; use
+ ;; the remaining of the file pattern as argument.
+ (let* ((dir-wildcard (insert-directory-wildcard-in-dir-p file))
+ (default-directory
+ (cond (dir-wildcard (car dir-wildcard))
+ (t
+ (if (file-name-absolute-p file)
+ (file-name-directory file)
+ (file-name-directory (expand-file-name file))))))
+ (pattern (if dir-wildcard (cdr dir-wildcard) (file-name-nondirectory file))))
;; NB since switches is passed to the shell, be
;; careful of malicious values, eg "-l;reboot".
;; See eg dired-safe-switches-p.
commit 15eef43279e2d92ef1e20e66bb2a4ff23c22ead3
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Thu Jul 13 23:56:43 2017 +0900
Dired: Tramp support for wildcards in directory part
* lisp/net/tramp-sh.el (tramp-sh-handle-insert-directory-wildcard-in-dir-p):
New handler for 'insert-directory-wildcard-in-dir-p'.
(tramp-sh-file-name-handler-alist):
Add it t the list.
(tramp-sh-handle-insert-directory): Use it.
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 4beb6fe521..3a0094d8f7 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1030,6 +1030,7 @@ tramp-sh-file-name-handler-alist
;; `find-file-noselect' performed by default handler.
;; `get-file-buffer' performed by default handler.
(insert-directory . tramp-sh-handle-insert-directory)
+ (insert-directory-wildcard-in-dir-p . tramp-sh-handle-insert-directory-wildcard-in-dir-p)
(insert-file-contents . tramp-handle-insert-file-contents)
(load . tramp-handle-load)
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
@@ -2632,8 +2633,12 @@ tramp-sh-handle-insert-directory
(not (tramp-get-ls-command-with-dired v)))
(setq switches (delete "--dired" switches)))
(when wildcard
- (setq wildcard (tramp-run-real-handler
- 'file-name-nondirectory (list localname)))
+ (setq wildcard (or (cdr (tramp-run-real-handler
+ 'insert-directory-wildcard-in-dir-p
+ (list localname)))
+ (tramp-run-real-handler
+ 'file-name-nondirectory
+ (list localname))))
(setq localname (tramp-run-real-handler
'file-name-directory (list localname))))
(unless (or full-directory-p (member "-d" switches))
@@ -2654,13 +2659,19 @@ tramp-sh-handle-insert-directory
(tramp-get-ls-command v)
switches
(if wildcard
- localname
+ (or (car (tramp-run-real-handler
+ 'insert-directory-wildcard-in-dir-p
+ (list localname))) localname)
(tramp-shell-quote-argument (concat localname ".")))))
(tramp-barf-unless-okay
v
(format "cd %s" (tramp-shell-quote-argument
- (tramp-run-real-handler
- 'file-name-directory (list localname))))
+ (or (car (tramp-run-real-handler
+ 'insert-directory-wildcard-in-dir-p
+ (list localname)))
+ (tramp-run-real-handler
+ 'file-name-directory
+ (list localname)))))
"Couldn't `cd %s'"
(tramp-shell-quote-argument
(tramp-run-real-handler 'file-name-directory (list localname))))
@@ -2736,6 +2747,11 @@ tramp-sh-handle-insert-directory
(goto-char (point-max)))))))
+(defun tramp-sh-handle-insert-directory-wildcard-in-dir-p (dir)
+ "Like `insert-directory-wildcard-in-dir-p' for Tramp files."
+ (with-parsed-tramp-file-name dir nil
+ (insert-directory-wildcard-in-dir-p localname)))
+
;; Canonicalization of file names.
(defun tramp-sh-handle-expand-file-name (name &optional dir)
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-07-13
Repository revision: 1f08279e1b20bd1e07132b6ee0a25a154811615a
^ permalink raw reply related [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-13 15:13 ` Tino Calancha
@ 2017-07-14 8:40 ` Eli Zaretskii
2017-07-25 15:19 ` Tino Calancha
2017-07-14 9:30 ` Michael Albinus
1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2017-07-14 8:40 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631, michael.albinus
> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Fri, 14 Jul 2017 00:13:28 +0900
> Cc: 27631@debbugs.gnu.org
>
> commit e5d5bd9822c1c562a7feb16f035062fda603d4d9
> Author: Tino Calancha <tino.calancha@gmail.com>
> Date: Thu Jul 13 23:56:43 2017 +0900
>
> Dired: Handle wildards in directory part
>
> Allow to Dired to handle calls like
> \(dired \"~/foo/*/*.el\"), that is, with wildcards withing
> the directory part of the file argument.
> * lisp/files.el (insert-directory-wildcard-in-dir-p): New predicate.
> (insert-directory)
> * lisp/dired.el(dired-internal-noselect)
> (dired-insert-directory): Use it.
> * /etc/NEWS: Announce it.
> * doc/emacs/dired.texi (Dired Enter): Update manual.
Thanks, but this doesn't seem to work with ls-lisp.el, so I guess it
relies on some features of the 'ls' command. (ls-lisp.el does support
wildcards in the likes of "C-x d foo* RET".) So if we are going to
accept this, either it should be made to work with ls-lisp.el
(preferred), or some kind of error message should be emitted in that
case, because presenting an empty Dired buffer is not very
user-friendly.
A few random comments on the code:
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -559,9 +559,13 @@ properties as intact as possible.
> * Changes in Specialized Modes and Packages in Emacs 26.1
>
> ** Dired
> -You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets replaced
> ++++
> +*** You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets replaced
> by the current file name.
This is unrelated, right?
> +(defun insert-directory-wildcard-in-dir-p (dir)
> + (when (string-match "[*]" (file-name-directory dir))
> + (let ((regexp "\\`\\([^*]+/\\)\\([^*]*[*].*\\)"))
> + (string-match regexp dir)
> + (cons (match-string 1 dir) (match-string 2 dir)))))
Any reason you only want to support '*'? What about '?' or '[a-b]',
for example?
Also, what happens if the directory includes a literal '*' character?
That's possible on Posix systems.
> + ;; subdirectory of the directory part free of wildcars; use
^^^^^^^^^
A typo.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-13 15:13 ` Tino Calancha
2017-07-14 8:40 ` Eli Zaretskii
@ 2017-07-14 9:30 ` Michael Albinus
1 sibling, 0 replies; 25+ messages in thread
From: Michael Albinus @ 2017-07-14 9:30 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Tino Calancha <tino.calancha@gmail.com> writes:
> Hi Michael,
> i'd like to provide Tramp support for this new Dired feature.
> The implementation is fairly straight: just adds a function
> 'insert-directory-wildcard-in-dir-p' in files.el, and use it in
> 'insert-directory' and Dired.
>
> To get Tramp support i've added a handler
> 'tramp-sh-handle-insert-directory-wildcard-in-dir-p'.
> Is this procedure OK or i am doing something weird?
That's not sufficient, it takes much more for adding a new handler in
Tramp. At least, it must be declared in tramp.el, and it must also be
added to the other backends but tramp-sh.el.
And you can also not call it directly; Tramp is backwards compatible
with Emacs 24 and 25.
> +(defun insert-directory-wildcard-in-dir-p (dir)
> + (when (string-match "[*]" (file-name-directory dir))
> + (let ((regexp "\\`\\([^*]+/\\)\\([^*]*[*].*\\)"))
> + (string-match regexp dir)
> + (cons (match-string 1 dir) (match-string 2 dir)))))
Unfortunately, there's no docstring, so it isn't clear to me what you
expect as result. Reading `tramp-sh-handle-insert-directory-wildcard-in-dir-p',
I believe you just want to work over the local part of a remote file
name. So you could do at the beginning:
;; DIR could be remote.
(setq dir (file-local-name dir))
And I don't believe that it is mandatory to call
`insert-directory-wildcard-in-dir-p' in Tramp. All what's needed could be
done outside Tramp file name handlers.
.
> Best regards,
> Tino
Best regards, Michael.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-14 8:40 ` Eli Zaretskii
@ 2017-07-25 15:19 ` Tino Calancha
2017-07-26 7:36 ` Michael Albinus
2017-07-29 8:30 ` Eli Zaretskii
0 siblings, 2 replies; 25+ messages in thread
From: Tino Calancha @ 2017-07-25 15:19 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 27631, michael.albinus
Eli Zaretskii <eliz@gnu.org> writes:
>> commit e5d5bd9822c1c562a7feb16f035062fda603d4d9
>> Author: Tino Calancha <tino.calancha@gmail.com>
>> Date: Thu Jul 13 23:56:43 2017 +0900
>>
>> Dired: Handle wildards in directory part
>>
>> Allow to Dired to handle calls like
>> \(dired \"~/foo/*/*.el\"), that is, with wildcards withing
>> the directory part of the file argument.
> Thanks, but this doesn't seem to work with ls-lisp.el, so I guess it
> relies on some features of the 'ls' command. (ls-lisp.el does support
> wildcards in the likes of "C-x d foo* RET".) So if we are going to
> accept this, either it should be made to work with ls-lisp.el
> (preferred), or some kind of error message should be emitted in that
> case,
Added support for ls-lisp and em-ls.
>> +(defun insert-directory-wildcard-in-dir-p (dir)
>> + (when (string-match "[*]" (file-name-directory dir))
>> + (let ((regexp "\\`\\([^*]+/\\)\\([^*]*[*].*\\)"))
>> + (string-match regexp dir)
>> + (cons (match-string 1 dir) (match-string 2 dir)))))
>
> Any reason you only want to support '*'? What about '?' or '[a-b]',
> for example?
Added support for (all?) posix globing.
> Also, what happens if the directory includes a literal '*' character?
> That's possible on Posix systems.
Fixed. Then, we will visit that file if does exist.
I have something working pretty well. I gave up with `find-lisp' lib
because it was really slow. I changed to use 'em-glob' which is really
fast!
But current implementation doesn't work with (Donald) tramp :-(. If we
want this in tramp, i am afraid i will need a tramp super-expert,
i.e. Michael.
Best smiles,
Tino
--8<-----------------------------cut here---------------start------------->8---
commit 92330e7e08a62f8731633d78a05b523b98025de2
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Wed Jul 26 00:10:15 2017 +0900
Dired: Handle posix wildcards in directory part
Allow to Dired to handle calls like
\(dired \"~/foo/*/*.el\"), that is, with wildcards within
the directory part of the file argument.
* lisp/files.el (insert-directory-wildcard-in-dir-p): New predicate.
(insert-directory)
* lisp/dired.el (dired-internal-noselect)
(dired-insert-directory): Use it.
* lisp/eshell/em-ls.el (eshell-ls-use-in-dired): Add/remove both advices.
(eshell-ls-unload-hook): New defun. Use it in
eshell-ls-unload-hook instead of an anonymous function.
(eshell-ls--dired)
* lisp/ls-lisp.el (ls-lisp--dired):
Advice dired to handle wildcards in the directory part with both
em-ls and ls-lisp.
* /etc/NEWS: Announce it.
* doc/emacs/dired.texi (Dired Enter): Update manual.
* test/lisp/dired-tests.el (dired-test-bug27631): Add test.
diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index ddd7229b0c..150ac8427a 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -64,10 +64,22 @@ Dired Enter
directory name using the minibuffer, and opens a @dfn{Dired buffer}
listing the files in that directory. You can also supply a wildcard
file name pattern as the minibuffer argument, in which case the Dired
-buffer lists all files matching that pattern. The usual history and
-completion commands can be used in the minibuffer; in particular,
-@kbd{M-n} puts the name of the visited file (if any) in the minibuffer
-(@pxref{Minibuffer History}).
+buffer lists all files matching that pattern. A wildcard may appear
+in the directory part as well.
+For instance,
+
+@example
+C-x d ~/foo/*.el @key{RET}
+C-x d ~/foo/*/*.el @key{RET}
+@end example
+
+The former lists all the files with extension @samp{.el} in directory
+@samp{foo}. The latter lists the files with extension @samp{.el}
+in subdirectories 2 levels of depth below @samp{foo}.
+
+The usual history and completion commands can be used in the minibuffer;
+in particular, @kbd{M-n} puts the name of the visited file (if any) in
+the minibuffer (@pxref{Minibuffer History}).
You can also invoke Dired by giving @kbd{C-x C-f} (@code{find-file})
a directory name.
diff --git a/etc/NEWS b/etc/NEWS
index f43491b630..af0f461d1f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -604,6 +604,9 @@ paragraphs, for the purposes of bidirectional display.
*** You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets replaced
by the current file name.
++++
+*** Dired supports wildcards in the directory part of the file names.
+
*** html2text is now marked obsolete.
*** smerge-refine-regions can refine regions in separate buffers
diff --git a/lisp/dired.el b/lisp/dired.el
index 9d500a9f52..358e50d73c 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -920,11 +920,12 @@ dired-internal-noselect
"Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
;; Else a new buffer
(setq default-directory
- ;; We can do this unconditionally
- ;; because dired-noselect ensures that the name
- ;; is passed in directory name syntax
- ;; if it was the name of a directory at all.
- (file-name-directory dirname))
+ (or (car-safe (insert-directory-wildcard-in-dir-p dirname))
+ ;; We can do this unconditionally
+ ;; because dired-noselect ensures that the name
+ ;; is passed in directory name syntax
+ ;; if it was the name of a directory at all.
+ (file-name-directory dirname)))
(or switches (setq switches dired-listing-switches))
(if mode (funcall mode)
(dired-mode dir-or-list switches))
@@ -1056,13 +1057,14 @@ dired-readin-insert
(not file-list))
;; If we are reading a whole single directory...
(dired-insert-directory dir dired-actual-switches nil nil t)
- (if (not (file-readable-p
- (directory-file-name (file-name-directory dir))))
- (error "Directory %s inaccessible or nonexistent" dir)
- ;; Else treat it as a wildcard spec
- ;; unless we have an explicit list of files.
- (dired-insert-directory dir dired-actual-switches
- file-list (not file-list) t)))))
+ (if (and (not (insert-directory-wildcard-in-dir-p dir))
+ (not (file-readable-p
+ (directory-file-name (file-name-directory dir)))))
+ (error "Directory %s inaccessible or nonexistent" dir))
+ ;; Else treat it as a wildcard spec
+ ;; unless we have an explicit list of files.
+ (dired-insert-directory dir dired-actual-switches
+ file-list (not file-list) t))))
(defun dired-align-file (beg end)
"Align the fields of a file to the ones of surrounding lines.
@@ -1279,11 +1281,14 @@ dired-insert-directory
;; Note that dired-build-subdir-alist will replace the name
;; by its expansion, so it does not matter whether what we insert
;; here is fully expanded, but it should be absolute.
- (insert " " (directory-file-name (file-name-directory dir)) ":\n")
+ (insert " " (or (car-safe (insert-directory-wildcard-in-dir-p dir))
+ (directory-file-name (file-name-directory dir))) ":\n")
(setq content-point (point)))
(when wildcard
;; Insert "wildcard" line where "total" line would be for a full dir.
- (insert " wildcard " (file-name-nondirectory dir) "\n")))
+ (insert " wildcard " (or (cdr-safe (insert-directory-wildcard-in-dir-p dir))
+ (file-name-nondirectory dir))
+ "\n")))
(dired-insert-set-properties content-point (point)))))
(defun dired-insert-set-properties (beg end)
diff --git a/lisp/eshell/em-ls.el b/lisp/eshell/em-ls.el
index 79799db30b..14c83d072a 100644
--- a/lisp/eshell/em-ls.el
+++ b/lisp/eshell/em-ls.el
@@ -65,17 +65,19 @@ eshell-ls-use-in-dired
"If non-nil, use `eshell-ls' to read directories in Dired.
Changing this without using customize has no effect."
:set (lambda (symbol value)
- (if value
- (advice-add 'insert-directory :around
- #'eshell-ls--insert-directory)
- (advice-remove 'insert-directory
- #'eshell-ls--insert-directory))
+ (cond (value
+ (require 'dired)
+ (advice-add 'insert-directory :around
+ #'eshell-ls--insert-directory)
+ (advice-add 'dired :around #'eshell-ls--dired))
+ (t
+ (advice-remove 'insert-directory
+ #'eshell-ls--insert-directory)
+ (advice-remove 'dired #'eshell-ls--dired)))
(set symbol value))
:type 'boolean
:require 'em-ls)
-(add-hook 'eshell-ls-unload-hook
- (lambda () (advice-remove 'insert-directory
- #'eshell-ls--insert-directory)))
+(add-hook 'eshell-ls-unload-hook #'eshell-ls-unload-function)
(defcustom eshell-ls-default-blocksize 1024
@@ -279,6 +281,36 @@ eshell-ls--insert-directory
eshell-ls-dired-initial-args)
(eshell-do-ls (append switches (list file)))))))))
+(declare-function eshell-extended-glob "em-glob" (glob))
+(declare-function dired-read-dir-and-switches "dired" (str))
+(declare-function dired-goto-next-file "em-glob" ())
+
+(defun eshell-ls--dired (orig-fun dir-or-list &optional switches)
+ (interactive (dired-read-dir-and-switches ""))
+ (require 'em-glob)
+ (if (consp dir-or-list)
+ (funcall orig-fun dir-or-list switches)
+ (let* ((dir-wildcard (insert-directory-wildcard-in-dir-p
+ (file-local-name (expand-file-name dir-or-list))))
+ (default-directory (car dir-wildcard)))
+ (if (not dir-wildcard)
+ (funcall orig-fun dir-or-list switches)
+ (let ((files (eshell-extended-glob (cdr dir-wildcard)))
+ (dir (car dir-wildcard)))
+ (if files
+ (let ((inhibit-read-only t)
+ (buf
+ (apply orig-fun
+ (nconc (list dir) files)
+ (and switches (list switches)))))
+ (with-current-buffer buf
+ (save-excursion
+ (goto-char (point-min))
+ (dired-goto-next-file)
+ (forward-line 0)
+ (insert " wildcard " (cdr dir-wildcard) "\n"))))
+ (user-error "No files matching regexp")))))))
+
(defsubst eshell/ls (&rest args)
"An alias version of `eshell-do-ls'."
(let ((insert-func 'eshell-buffered-print)
@@ -909,6 +941,11 @@ eshell-ls-decorated-name
(car file)))))
(car file))
+(defun eshell-ls-unload-function ()
+ (advice-remove 'insert-directory #'eshell-ls--insert-directory)
+ (advice-remove 'dired #'eshell-ls--dired)
+ nil)
+
(provide 'em-ls)
;; Local Variables:
diff --git a/lisp/files.el b/lisp/files.el
index 321a35b530..fa72dff58e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6552,6 +6552,22 @@ directory-listing-before-filename-regexp
(defvar insert-directory-ls-version 'unknown)
+(defun insert-directory-wildcard-in-dir-p (dir)
+ "Return non-nil if DIR contents a shell wildcard in the directory part.
+The return value is a cons (DIR . WILDCARDS); DIR is the
+`default-directory' in the Dired buffer, and WILDCARDS are the wildcards.
+
+Valid wildcards are '*', '?', '[abc]' and '[a-z]'."
+ (let ((wildcards "[?*"))
+ (when (and (or (not (featurep 'ls-lisp))
+ ls-lisp-support-shell-wildcards)
+ (string-match (concat "[" wildcards "]") (file-name-directory dir))
+ (not (file-exists-p dir))) ; Prefer an existing file to wildcards.
+ (let ((regexp (format "\\`\\([^%s]+/\\)\\([^%s]*[%s].*\\)"
+ wildcards wildcards wildcards)))
+ (string-match regexp dir)
+ (cons (match-string 1 dir) (match-string 2 dir))))))
+
;; insert-directory
;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
;; FULL-DIRECTORY-P is nil.
@@ -6611,13 +6627,19 @@ insert-directory
default-file-name-coding-system))))
(setq result
(if wildcard
- ;; Run ls in the directory part of the file pattern
- ;; using the last component as argument.
- (let ((default-directory
- (if (file-name-absolute-p file)
- (file-name-directory file)
- (file-name-directory (expand-file-name file))))
- (pattern (file-name-nondirectory file)))
+ ;; If the wildcard is just in the file part, then run ls in
+ ;; the directory part of the file pattern using the last
+ ;; component as argument. Otherwise, run ls in the longest
+ ;; subdirectory of the directory part free of wildcards; use
+ ;; the remaining of the file pattern as argument.
+ (let* ((dir-wildcard (insert-directory-wildcard-in-dir-p file))
+ (default-directory
+ (cond (dir-wildcard (car dir-wildcard))
+ (t
+ (if (file-name-absolute-p file)
+ (file-name-directory file)
+ (file-name-directory (expand-file-name file))))))
+ (pattern (if dir-wildcard (cdr dir-wildcard) (file-name-nondirectory file))))
;; NB since switches is passed to the shell, be
;; careful of malicious values, eg "-l;reboot".
;; See eg dired-safe-switches-p.
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 730ba26c6c..611350fbc1 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -60,6 +60,9 @@
;;; Code:
+\f
+(require 'em-glob)
+
(defgroup ls-lisp nil
"Emulate the ls program completely in Emacs Lisp."
:version "21.1"
@@ -477,6 +480,32 @@ ls-lisp-insert-directory
(message "%s: doesn't exist or is inaccessible" file)
(ding) (sit-for 2))))) ; to show user the message!
+
+(defun ls-lisp--dired (orig-fun dir-or-list &optional switches)
+ (interactive (dired-read-dir-and-switches ""))
+ (if (consp dir-or-list)
+ (funcall orig-fun dir-or-list switches)
+ (let* ((dir-wildcard (insert-directory-wildcard-in-dir-p
+ (file-local-name (expand-file-name dir-or-list))))
+ (default-directory (car dir-wildcard)))
+ (if (not dir-wildcard)
+ (funcall orig-fun dir-or-list switches)
+ (let ((files (eshell-extended-glob (cdr dir-wildcard)))
+ (dir (car dir-wildcard)))
+ (if files
+ (let ((inhibit-read-only t)
+ (buf
+ (apply orig-fun (nconc (list dir) files) (and switches (list switches)))))
+ (with-current-buffer buf
+ (save-excursion
+ (goto-char (point-min))
+ (dired-goto-next-file)
+ (forward-line 0)
+ (insert " wildcard " (cdr dir-wildcard) "\n"))))
+ (user-error "No files matching regexp")))))))
+
+(advice-add 'dired :around #'ls-lisp--dired)
+
(defun ls-lisp-sanitize (file-alist)
"Sanitize the elements in FILE-ALIST.
Fixes any elements in the alist for directory entries whose file
@@ -869,6 +898,7 @@ ls-lisp-format-file-size
(defun ls-lisp-unload-function ()
"Unload ls-lisp library."
(advice-remove 'insert-directory #'ls-lisp--insert-directory)
+ (advice-remove 'dired #'ls-lisp--dired)
;; Continue standard unloading.
nil)
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 69331457c0..005a82031f 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -175,5 +175,43 @@
(should (looking-at "src")))
(when (buffer-live-p buf) (kill-buffer buf)))))
+(ert-deftest dired-test-bug27631 ()
+ "Test for http://debbugs.gnu.org/27631 ."
+ (let* ((dir (make-temp-file "bug27631" 'dir))
+ (dir1 (expand-file-name "dir1" dir))
+ (dir2 (expand-file-name "dir2" dir))
+ (default-directory dir)
+ buf)
+ (unwind-protect
+ (progn
+ (make-directory dir1)
+ (make-directory dir2)
+ (with-temp-file (expand-file-name "a.txt" dir1))
+ (with-temp-file (expand-file-name "b.txt" dir2))
+ (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
+ (dired-toggle-marks)
+ (should (cdr (dired-get-marked-files)))
+ ;; Must work with ls-lisp ...
+ (require 'ls-lisp)
+ (kill-buffer buf)
+ (setq default-directory dir)
+ (let (ls-lisp-use-insert-directory-program)
+ (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
+ (dired-toggle-marks)
+ (should (cdr (dired-get-marked-files))))
+ ;; ... And with em-ls as well.
+ (kill-buffer buf)
+ (setq default-directory dir)
+ (unload-feature 'ls-lisp 'force)
+ (require 'em-ls)
+ (let ((orig eshell-ls-use-in-dired))
+ (customize-set-value 'eshell-ls-use-in-dired t)
+ (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
+ (dired-toggle-marks)
+ (should (cdr (dired-get-marked-files)))))
+ (delete-directory dir 'recursive)
+ (when (buffer-live-p buf) (kill-buffer buf)))))
+
+
(provide 'dired-tests)
;; dired-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-07-25
Repository revision: 24b91584c214caadff0f2394cf1f021bf480b624
^ permalink raw reply related [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-25 15:19 ` Tino Calancha
@ 2017-07-26 7:36 ` Michael Albinus
2017-07-28 7:50 ` Tino Calancha
2017-07-29 8:30 ` Eli Zaretskii
1 sibling, 1 reply; 25+ messages in thread
From: Michael Albinus @ 2017-07-26 7:36 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Tino Calancha <tino.calancha@gmail.com> writes:
Hi Tino,
> But current implementation doesn't work with (Donald) tramp :-(. If we
> want this in tramp, i am afraid i will need a tramp super-expert,
> i.e. Michael.
I've applied your patch, and I've performed "C-x C-f
/scp:remotehost:~/src/tramp/*/*". It works as expected.
Neither "C-x d ~/src/*/lisp" nor "C-x d /scp:remotehost:~/src/*/lisp"
works. According to the NEWS entry in your patch, I would expect that at
least the former works.
Could you, pls, tell me what I shall do? Sorry, I didn't follow the
whole thread.
> Best smiles,
> Tino
Best regards, Michael.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-26 7:36 ` Michael Albinus
@ 2017-07-28 7:50 ` Tino Calancha
2017-07-28 9:23 ` Michael Albinus
2017-07-28 12:00 ` Michael Albinus
0 siblings, 2 replies; 25+ messages in thread
From: Tino Calancha @ 2017-07-28 7:50 UTC (permalink / raw)
To: Michael Albinus; +Cc: 27631
Michael Albinus <michael.albinus@gmx.de> writes:
> I've applied your patch, and I've performed "C-x C-f
> /scp:remotehost:~/src/tramp/*/*". It works as expected.
>
> Neither "C-x d ~/src/*/lisp" nor "C-x d /scp:remotehost:~/src/*/lisp"
> works. According to the NEWS entry in your patch, I would expect that at
> least the former works.
No, the former must fails because there is n match. Maybe just the error is not clear.
The wildcard, ~/src/*/lisp
matches things like:
~/src/foo/lisp
but not:
~/src/lisp
I)
The following should match something:
C-x d ~/src/*/gray*
I got a dired buffer with 3 files:
bitmaps/gray1.xbm
bitmaps/gray3.xbm
bitmaps/gray.xbm
II)
If i try I) with tramp, for instance calling sudo:
/sudo:calancha@calancha-pc:/home/calancha/soft/emacs-master/src/*/gray* RET
then i get:
tramp-file-name-handler: Couldn’t ‘cd /home/calancha/soft/emacs-master/src/\*/’
;; Which doesn't sorprise me because my patch doesn't touch any
;; tramp file.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-28 7:50 ` Tino Calancha
@ 2017-07-28 9:23 ` Michael Albinus
2017-07-28 9:34 ` Tino Calancha
2017-07-28 12:00 ` Michael Albinus
1 sibling, 1 reply; 25+ messages in thread
From: Michael Albinus @ 2017-07-28 9:23 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Tino Calancha <tino.calancha@gmail.com> writes:
>> Neither "C-x d ~/src/*/lisp" nor "C-x d /scp:remotehost:~/src/*/lisp"
>> works. According to the NEWS entry in your patch, I would expect that at
>> least the former works.
> No, the former must fails because there is n match. Maybe just the
> error is not clear.
> The wildcard, ~/src/*/lisp
> matches things like:
> ~/src/foo/lisp
> but not:
> ~/src/lisp
I should have said that there exist ~/src/emacs/lisp and
~/src/tramp/lisp. I would expect to see them with "C-x d ~/src/*/lisp".
I'll check again why it doesn't work for me.
Best regards, Michael.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-28 9:23 ` Michael Albinus
@ 2017-07-28 9:34 ` Tino Calancha
2017-07-28 11:23 ` Michael Albinus
0 siblings, 1 reply; 25+ messages in thread
From: Tino Calancha @ 2017-07-28 9:34 UTC (permalink / raw)
To: Michael Albinus; +Cc: 27631, Tino Calancha
On Fri, 28 Jul 2017, Michael Albinus wrote:
>>> Neither "C-x d ~/src/*/lisp" nor "C-x d /scp:remotehost:~/src/*/lisp"
>>> works. According to the NEWS entry in your patch, I would expect that at
>>> least the former works.
>> No, the former must fails because there is n match. Maybe just the
>> error is not clear.
>> The wildcard, ~/src/*/lisp
>> matches things like:
>> ~/src/foo/lisp
>> but not:
>> ~/src/lisp
>
> I should have said that there exist ~/src/emacs/lisp and
> ~/src/tramp/lisp. I would expect to see them with "C-x d ~/src/*/lisp".
When you are not using neither 'ls-lisp' nor 'eshell-ls', then it is the
system shell who performs the wildcard expansion.
That means, if the following doesn't work:
M-! ls ~/src/*/lisp RET
then,
C-x d ~/src/*/lisp RET
must fail as well.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-28 9:34 ` Tino Calancha
@ 2017-07-28 11:23 ` Michael Albinus
0 siblings, 0 replies; 25+ messages in thread
From: Michael Albinus @ 2017-07-28 11:23 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Tino Calancha <tino.calancha@gmail.com> writes:
Hi Tino,
> That means, if the following doesn't work:
> M-! ls ~/src/*/lisp RET
> then,
> C-x d ~/src/*/lisp RET
> must fail as well.
That command works.
I'll check, what's up with your patch and why it doesn't work for me.
Best regards, Michael.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-28 7:50 ` Tino Calancha
2017-07-28 9:23 ` Michael Albinus
@ 2017-07-28 12:00 ` Michael Albinus
2017-07-29 12:20 ` Tino Calancha
1 sibling, 1 reply; 25+ messages in thread
From: Michael Albinus @ 2017-07-28 12:00 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Tino Calancha <tino.calancha@gmail.com> writes:
> I)
> The following should match something:
> C-x d ~/src/*/gray*
>
> I got a dired buffer with 3 files:
> bitmaps/gray1.xbm
> bitmaps/gray3.xbm
> bitmaps/gray.xbm
The second time I've applied your patch it works. I get a similar
result. Don't ask me what happened before, pilot error very likely.
> II)
> If i try I) with tramp, for instance calling sudo:
> /sudo:calancha@calancha-pc:/home/calancha/soft/emacs-master/src/*/gray* RET
> then i get:
>
> tramp-file-name-handler: Couldn’t ‘cd /home/calancha/soft/emacs-master/src/\*/’
Same error here. The backtrace shows me:
--8<---------------cut here---------------start------------->8---
tramp-file-name-handler(insert-directory "/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" "--dired -al" t nil)
insert-directory("/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" "--dired -al" t nil)
dired-insert-directory("/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" "-al" nil t t)
dired-readin-insert()
dired-readin()
dired-internal-noselect("/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" nil)
dired-noselect("/ssh:localhost:~/src/emacs/src/*/gray*" nil)
dired("/ssh:localhost:~/src/emacs/src/*/gray*" nil)
funcall-interactively(dired "/ssh:localhost:~/src/emacs/src/*/gray*" nil)
call-interactively(dired nil nil)
command-execute(dired)
--8<---------------cut here---------------end--------------->8---
I believe it is wrong to expand wilcards in `insert-directory'. It is
not designed for that. Expanding must happen in
`dired-insert-directory', which calls then `insert-directory' for the
results.
This relates to your description in etc/NEWS:
*** Dired supports wildcards in the directory part of the file names.
Best regards, Michael.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-25 15:19 ` Tino Calancha
2017-07-26 7:36 ` Michael Albinus
@ 2017-07-29 8:30 ` Eli Zaretskii
2017-07-29 12:03 ` Tino Calancha
1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2017-07-29 8:30 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631, michael.albinus
> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: 27631@debbugs.gnu.org, michael.albinus@gmx.de
> Date: Wed, 26 Jul 2017 00:19:18 +0900
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> commit e5d5bd9822c1c562a7feb16f035062fda603d4d9
> >> Author: Tino Calancha <tino.calancha@gmail.com>
> >> Date: Thu Jul 13 23:56:43 2017 +0900
> >>
> >> Dired: Handle wildards in directory part
> >>
> >> Allow to Dired to handle calls like
> >> \(dired \"~/foo/*/*.el\"), that is, with wildcards withing
> >> the directory part of the file argument.
>
> > Thanks, but this doesn't seem to work with ls-lisp.el, so I guess it
> > relies on some features of the 'ls' command. (ls-lisp.el does support
> > wildcards in the likes of "C-x d foo* RET".) So if we are going to
> > accept this, either it should be made to work with ls-lisp.el
> > (preferred), or some kind of error message should be emitted in that
> > case,
> Added support for ls-lisp and em-ls.
>
> >> +(defun insert-directory-wildcard-in-dir-p (dir)
> >> + (when (string-match "[*]" (file-name-directory dir))
> >> + (let ((regexp "\\`\\([^*]+/\\)\\([^*]*[*].*\\)"))
> >> + (string-match regexp dir)
> >> + (cons (match-string 1 dir) (match-string 2 dir)))))
> >
> > Any reason you only want to support '*'? What about '?' or '[a-b]',
> > for example?
> Added support for (all?) posix globing.
>
> > Also, what happens if the directory includes a literal '*' character?
> > That's possible on Posix systems.
> Fixed. Then, we will visit that file if does exist.
>
>
> I have something working pretty well. I gave up with `find-lisp' lib
> because it was really slow. I changed to use 'em-glob' which is really
> fast!
LGTM, please push.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-29 8:30 ` Eli Zaretskii
@ 2017-07-29 12:03 ` Tino Calancha
0 siblings, 0 replies; 25+ messages in thread
From: Tino Calancha @ 2017-07-29 12:03 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 27631, michael.albinus, Tino Calancha
On Sat, 29 Jul 2017, Eli Zaretskii wrote:
>> because it was really slow. I changed to use 'em-glob' which is really
>> fast!
>
> LGTM, please push.
Thanks. I think is better to wait until i provide tramp support.
Michael is giving me guidance wo i get we can get this working in tramp
soon.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-28 12:00 ` Michael Albinus
@ 2017-07-29 12:20 ` Tino Calancha
2017-07-29 20:39 ` Michael Albinus
0 siblings, 1 reply; 25+ messages in thread
From: Tino Calancha @ 2017-07-29 12:20 UTC (permalink / raw)
To: Michael Albinus; +Cc: 27631, Tino Calancha
[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]
On Fri, 28 Jul 2017, Michael Albinus wrote:
>> If i try I) with tramp, for instance calling sudo:
>> /sudo:calancha@calancha-pc:/home/calancha/soft/emacs-master/src/*/gray* RET
>> then i get:
>>
>> tramp-file-name-handler: Couldn’t ‘cd /home/calancha/soft/emacs-master/src/\*/’
>
> Same error here. The backtrace shows me:
>
> --8<---------------cut here---------------start------------->8---
> tramp-file-name-handler(insert-directory "/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" "--dired -al" t nil)
> insert-directory("/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" "--dired -al" t nil)
> dired-insert-directory("/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" "-al" nil t t)
> dired-readin-insert()
> dired-readin()
> dired-internal-noselect("/ssh:localhost:/home/albinus/src/emacs/src/*/gray*" nil)
> dired-noselect("/ssh:localhost:~/src/emacs/src/*/gray*" nil)
> dired("/ssh:localhost:~/src/emacs/src/*/gray*" nil)
> funcall-interactively(dired "/ssh:localhost:~/src/emacs/src/*/gray*" nil)
> call-interactively(dired nil nil)
> command-execute(dired)
> --8<---------------cut here---------------end--------------->8---
>
> I believe it is wrong to expand wilcards in `insert-directory'. It is
> not designed for that. Expanding must happen in
> `dired-insert-directory', which calls then `insert-directory' for the
> results.
Hi Michael,
thank you for your advice on this. I have a new version which handle the
expansion in `dired-insert-directory'. I pushed a new branch with
the newest patch:
origin/feature/dired-wildcard-in-dir-bug#27631
When the user is neither using 'ls-lisp' nor 'eshell-ls', then we run
in the remote host something like:
(process-file "/bin/sh" nil (current-buffer) nil "-c" (format "ls %s %s" switches wildcard)))
I have tested it running tramp in a remote machine and it seems to work.
What do you think?
Tino
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-29 12:20 ` Tino Calancha
@ 2017-07-29 20:39 ` Michael Albinus
2017-07-30 2:20 ` Tino Calancha
2017-07-30 11:13 ` Michael Albinus
0 siblings, 2 replies; 25+ messages in thread
From: Michael Albinus @ 2017-07-29 20:39 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Tino Calancha <tino.calancha@gmail.com> writes:
> Hi Michael,
Hi Tino,
> thank you for your advice on this. I have a new version which handle the
> expansion in `dired-insert-directory'. I pushed a new branch with
> the newest patch:
> origin/feature/dired-wildcard-in-dir-bug#27631
>
> When the user is neither using 'ls-lisp' nor 'eshell-ls', then we run
> in the remote host something like:
> (process-file "/bin/sh" nil (current-buffer) nil "-c" (format "ls %s
> %s" switches wildcard)))
>
> I have tested it running tramp in a remote machine and it seems to work.
> What do you think?
I made a short test, works for remote directories. Likely, I'll add a
test to tramp-tests.el next days, in order to let it run for a variety
of other Tramp methods, like adb, gdrive and smb.
You might push it to master.
> Tino
Best regards, Michael.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-29 20:39 ` Michael Albinus
@ 2017-07-30 2:20 ` Tino Calancha
2017-07-30 11:13 ` Michael Albinus
1 sibling, 0 replies; 25+ messages in thread
From: Tino Calancha @ 2017-07-30 2:20 UTC (permalink / raw)
To: 27631-done
Michael Albinus <michael.albinus@gmx.de> writes:
>> I have tested it running tramp in a remote machine and it seems to work.
>> What do you think?
>
> I made a short test, works for remote directories. Likely, I'll add a
> test to tramp-tests.el next days, in order to let it run for a variety
> of other Tramp methods, like adb, gdrive and smb.
Sounds great.
> You might push it to master.
I've pushed into master as commit 6f6639d6ed6c6314b2643f6c22498fc2e23d34c7
Thank you very much.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-29 20:39 ` Michael Albinus
2017-07-30 2:20 ` Tino Calancha
@ 2017-07-30 11:13 ` Michael Albinus
1 sibling, 0 replies; 25+ messages in thread
From: Michael Albinus @ 2017-07-30 11:13 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631
Michael Albinus <michael.albinus@gmx.de> writes:
Hi Tino,
> I made a short test, works for remote directories. Likely, I'll add a
> test to tramp-tests.el next days, in order to let it run for a variety
> of other Tramp methods, like adb, gdrive and smb.
See tramp-test17-dired-with-wildcards.
Best regards, Michael.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-07-13 5:52 ` Tino Calancha
@ 2017-08-02 17:30 ` Stefan Monnier
2017-08-02 17:49 ` Eli Zaretskii
2017-08-03 4:38 ` Tino Calancha
0 siblings, 2 replies; 25+ messages in thread
From: Stefan Monnier @ 2017-08-02 17:30 UTC (permalink / raw)
To: Tino Calancha; +Cc: 27631, 積丹尼 Dan Jacobson
>> Maybe make dired and list-directory deal with wildcards in positions like
>> ~/.config/chromium/Default/*/menkifleemblimdogmoihpfopnplikde/
> Thank you for the report.
> IMO, this is a nice thing to have.
> It must be possible to extend the current code so that
> dired might handle wildcards in the directory part.
I'm not sure the recent patch for this fix is the right approach.
The old code already used the shell to do the wildcard expansion, so why
not just adjust the old code.
Here's some starting patch.
Stefan
diff --git a/lisp/dired.el b/lisp/dired.el
index 24759c6c9b..29755712cf 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1089,25 +1038,31 @@ dired-readin
(defun dired-readin-insert ()
;; Insert listing for the specified dir (and maybe file list)
;; already in dired-directory, assuming a clean buffer.
- (let (dir file-list)
- (if (consp dired-directory)
- (setq dir (car dired-directory)
- file-list (cdr dired-directory))
- (setq dir dired-directory
- file-list nil))
- (setq dir (expand-file-name dir))
+ (let* ((dir (expand-file-name
+ (if (consp dired-directory)
+ (car dired-directory)
+ dired-directory)))
+ (file-list (cdr-safe dired-directory))
+ (wildcard (not file-list)))
+ (unless (file-directory-p dir)
+ (unless file-list (setq file-list '("")))
+ (while (not (file-directory-p dir))
+ (setq dir (directory-file-name dir))
+ (let ((n (file-name-nondirectory dir)))
+ (setq file-list (mapcar (lambda (f) (concat n "/" f)) file-list)))
+ (setq dir (file-name-directory dir)))
+ (setq default-directory dir))
(if (and (equal "" (file-name-nondirectory dir))
(not file-list))
;; If we are reading a whole single directory...
(dired-insert-directory dir dired-actual-switches nil nil t)
- (if (and (not (insert-directory-wildcard-in-dir-p dir))
- (not (file-readable-p
- (directory-file-name (file-name-directory dir)))))
- (error "Directory %s inaccessible or nonexistent" dir))
- ;; Else treat it as a wildcard spec
- ;; unless we have an explicit list of files.
- (dired-insert-directory dir dired-actual-switches
- file-list (not file-list) t))))
+ (if (not (file-readable-p
+ (directory-file-name (file-name-directory dir))))
+ (error "Directory %s inaccessible or nonexistent" dir)
+ ;; Else treat it as a wildcard spec
+ ;; unless we have an explicit list of files.
+ (dired-insert-directory dir dired-actual-switches
+ file-list wildcard t)))))
(defun dired-align-file (beg end)
"Align the fields of a file to the ones of surrounding lines.
@@ -1252,56 +1207,29 @@ dired-insert-directory
;; as indicated by `ls-lisp-use-insert-directory-program'.
(not (and (featurep 'ls-lisp)
(null ls-lisp-use-insert-directory-program)))
- (not (and (featurep 'eshell)
- (bound-and-true-p eshell-ls-use-in-dired)))
- (or (file-remote-p dir)
- (if (eq dired-use-ls-dired 'unspecified)
+ (or (if (eq dired-use-ls-dired 'unspecified)
;; Check whether "ls --dired" gives exit code 0, and
;; save the answer in `dired-use-ls-dired'.
(or (setq dired-use-ls-dired
(eq 0 (call-process insert-directory-program
- nil nil nil "--dired")))
+ nil nil nil "--dired")))
(progn
(message "ls does not support --dired; \
see `dired-use-ls-dired' for more details.")
nil))
- dired-use-ls-dired)))
+ dired-use-ls-dired)
+ (file-remote-p dir)))
(setq switches (concat "--dired " switches)))
- ;; Expand directory wildcards and fill file-list.
- (let ((dir-wildcard (insert-directory-wildcard-in-dir-p dir)))
- (cond (dir-wildcard
- (setq switches (concat "-d " switches))
- ;; We don't know whether the remote ls supports
- ;; "--dired", so we cannot add it to the `process-file'
- ;; call for wildcards.
- (when (file-remote-p dir)
- (setq switches (dired-replace-in-string "--dired" "" switches)))
- (let* ((default-directory (car dir-wildcard))
- (script (format "ls %s %s" switches (cdr dir-wildcard)))
- (remotep (file-remote-p dir))
- (sh (or (and remotep "/bin/sh")
- (and (bound-and-true-p explicit-shell-file-name)
- (executable-find explicit-shell-file-name))
- (executable-find "sh")))
- (switch (if remotep "-c" shell-command-switch)))
- (unless
- (zerop
- (process-file sh nil (current-buffer) nil switch script))
- (user-error
- "%s: No files matching wildcard" (cdr dir-wildcard)))
- (insert-directory-clean (point) switches)))
- (t
- ;; We used to specify the C locale here, to force English
- ;; month names; but this should not be necessary any
- ;; more, with the new value of
- ;; `directory-listing-before-filename-regexp'.
- (if file-list
- (dolist (f file-list)
- (let ((beg (point)))
- (insert-directory f switches nil nil)
- ;; Re-align fields, if necessary.
- (dired-align-file beg (point))))
- (insert-directory dir switches wildcard (not wildcard))))))
+ ;; We used to specify the C locale here, to force English month names;
+ ;; but this should not be necessary any more,
+ ;; with the new value of `directory-listing-before-filename-regexp'.
+ (if file-list
+ (dolist (f file-list)
+ (let ((beg (point)))
+ (insert-directory f switches wildcard nil)
+ ;; Re-align fields, if necessary.
+ (dired-align-file beg (point))))
+ (insert-directory dir switches wildcard (not wildcard)))
;; Quote certain characters, unless ls quoted them for us.
(if (not (dired-switches-escape-p dired-actual-switches))
(save-excursion
diff --git a/lisp/files.el b/lisp/files.el
index 96647fb262..1f69391d51 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6683,19 +6608,15 @@ insert-directory
default-file-name-coding-system))))
(setq result
(if wildcard
- ;; If the wildcard is just in the file part, then run ls in
- ;; the directory part of the file pattern using the last
- ;; component as argument. Otherwise, run ls in the longest
- ;; subdirectory of the directory part free of wildcards; use
- ;; the remaining of the file pattern as argument.
- (let* ((dir-wildcard (insert-directory-wildcard-in-dir-p file))
- (default-directory
- (cond (dir-wildcard (car dir-wildcard))
- (t
- (if (file-name-absolute-p file)
- (file-name-directory file)
- (file-name-directory (expand-file-name file))))))
- (pattern (if dir-wildcard (cdr dir-wildcard) (file-name-nondirectory file))))
+ ;; Run ls in the directory part of the file pattern
+ ;; using the last component as argument.
+ (let ((default-directory
+ (if (file-name-absolute-p file)
+ (file-name-directory file)
+ default-directory))
+ (pattern (if (file-name-absolute-p file)
+ (file-name-nondirectory file)
+ file)))
;; NB since switches is passed to the shell, be
;; careful of malicious values, eg "-l;reboot".
;; See eg dired-safe-switches-p.
^ permalink raw reply related [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-08-02 17:30 ` Stefan Monnier
@ 2017-08-02 17:49 ` Eli Zaretskii
2017-08-03 1:25 ` Stefan Monnier
2017-08-03 4:38 ` Tino Calancha
1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2017-08-02 17:49 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 27631, tino.calancha, jidanni
> From: Stefan Monnier <monnier@IRO.UMontreal.CA>
> Date: Wed, 02 Aug 2017 13:30:40 -0400
> Cc: 27631@debbugs.gnu.org,
> 積丹尼 Dan Jacobson <jidanni@jidanni.org>
>
> The old code already used the shell to do the wildcard expansion, so why
> not just adjust the old code.
I'm not sure I understand what you mean by "used the shell to do the
wildcard expansion", but if you actually mean to let the shell do
that, it's unportable to non-Posix shells.
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-08-02 17:49 ` Eli Zaretskii
@ 2017-08-03 1:25 ` Stefan Monnier
0 siblings, 0 replies; 25+ messages in thread
From: Stefan Monnier @ 2017-08-03 1:25 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 27631, tino.calancha, jidanni
>> The old code already used the shell to do the wildcard expansion, so why
>> not just adjust the old code.
> I'm not sure I understand what you mean by "used the shell to do the
> wildcard expansion",
Just what you think it means: if you requested M-x dired RET ~/foo/* RET
it called "ls --dired -al *" from directory ~/foo.
My patch just changes the code so that M-x dired RET ~/foo/*/bar RET
is turned into "ls --dired -al */bar" from directory ~/foo.
> but if you actually mean to let the shell do that, it's unportable to
> non-Posix shells.
I know. That's why ls-lisp advises the corresponding function.
Stefan
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-08-02 17:30 ` Stefan Monnier
2017-08-02 17:49 ` Eli Zaretskii
@ 2017-08-03 4:38 ` Tino Calancha
2017-08-03 15:48 ` Stefan Monnier
1 sibling, 1 reply; 25+ messages in thread
From: Tino Calancha @ 2017-08-03 4:38 UTC (permalink / raw)
To: Stefan Monnier
Cc: 27631, Tino Calancha, Michael Albinus,
積丹尼 Dan Jacobson
On Wed, 2 Aug 2017, Stefan Monnier wrote:
>>> Maybe make dired and list-directory deal with wildcards in positions like
>>> ~/.config/chromium/Default/*/menkifleemblimdogmoihpfopnplikde/
>> Thank you for the report.
>> IMO, this is a nice thing to have.
>> It must be possible to extend the current code so that
>> dired might handle wildcards in the directory part.
>
> I'm not sure the recent patch for this fix is the right approach.
> The old code already used the shell to do the wildcard expansion, so why
> not just adjust the old code.
>
> Here's some starting patch.
Thank you for the patch.
Part of the complexity of the original patch is to provide this new
feature in _tramp_ connections as well; your patch does the thing
well (see patch below) in the local machine but it fails in remote
ones.
--8<-----------------------------cut here---------------start------------->8---
commit 21f02469bf5ef3733e3705e9836a7d91f625ce11
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Thu Aug 3 13:20:40 2017 +0900
Apply some minor tweaks
diff --git a/lisp/dired.el b/lisp/dired.el
index 211b622fd9..7862d0405c 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1100,7 +1100,7 @@ dired-readin-insert
(while (not (file-directory-p dir))
(setq dir (directory-file-name dir))
(let ((n (file-name-nondirectory dir)))
- (setq file-list (mapcar (lambda (f) (concat n "/" f)) file-list)))
+ (setq file-list (mapcar (lambda (f) (concat n (and (not (string= "" f)) "/") f)) file-list)))
(setq dir (file-name-directory dir)))
(setq default-directory dir))
(if (and (equal "" (file-name-nondirectory dir))
@@ -1258,6 +1258,8 @@ dired-insert-directory
;; as indicated by `ls-lisp-use-insert-directory-program'.
(not (and (featurep 'ls-lisp)
(null ls-lisp-use-insert-directory-program)))
+ (not (and (featurep 'eshell)
+ (bound-and-true-p eshell-ls-use-in-dired)))
(or (if (eq dired-use-ls-dired 'unspecified)
;; Check whether "ls --dired" gives exit code 0, and
;; save the answer in `dired-use-ls-dired'.
@@ -1335,9 +1337,7 @@ dired-insert-directory
(setq content-point (point)))
(when wildcard
;; Insert "wildcard" line where "total" line would be for a full dir.
- (insert " wildcard " (or (cdr-safe (insert-directory-wildcard-in-dir-p dir))
- (file-name-nondirectory dir))
- "\n")))
+ (insert " wildcard " (car-safe file-list) "\n")))
(dired-insert-set-properties content-point (point)))))
(defun dired-insert-set-properties (beg end)
--8<-----------------------------cut here---------------end--------------->8---
^ permalink raw reply related [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-08-03 4:38 ` Tino Calancha
@ 2017-08-03 15:48 ` Stefan Monnier
2017-08-04 5:12 ` Tino Calancha
0 siblings, 1 reply; 25+ messages in thread
From: Stefan Monnier @ 2017-08-03 15:48 UTC (permalink / raw)
To: Tino Calancha
Cc: 27631, Michael Albinus, 積丹尼 Dan Jacobson
> Part of the complexity of the original patch is to provide this new
> feature in _tramp_ connections as well; your patch does the thing
> well (see patch below) in the local machine but it fails in remote ones.
I didn't adjust the Tramp code accordingly, indeed. My patch probably
also fails for ls-lisp (aka Windows). Both of those will need
corresponding adjustments.
My point is that it seems like we can get the same end-result without
changing the structure.
> @@ -1100,7 +1100,7 @@ dired-readin-insert
> (while (not (file-directory-p dir))
> (setq dir (directory-file-name dir))
> (let ((n (file-name-nondirectory dir)))
> - (setq file-list (mapcar (lambda (f) (concat n "/" f)) file-list)))
> + (setq file-list (mapcar (lambda (f) (concat n (and (not (string= "" f)) "/") f)) file-list)))
> (setq dir (file-name-directory dir)))
> (setq default-directory dir))
> (if (and (equal "" (file-name-nondirectory dir))
`n` represents a directory name, so isn't it OK to have "<n>/" rather
than "<n>"? Or is the above tweak purely cosmetic?
> @@ -1335,9 +1337,7 @@ dired-insert-directory
> (setq content-point (point)))
> (when wildcard
> ;; Insert "wildcard" line where "total" line would be for a full dir.
> - (insert " wildcard " (or (cdr-safe (insert-directory-wildcard-in-dir-p dir))
> - (file-name-nondirectory dir))
> - "\n")))
> + (insert " wildcard " (car-safe file-list) "\n")))
> (dired-insert-set-properties content-point (point)))))
Yes, my patch needs a bunch more cleanups: it was a quick hack job, just
to confirm my intuition.
Stefan
^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#27631: dired a/*/b
2017-08-03 15:48 ` Stefan Monnier
@ 2017-08-04 5:12 ` Tino Calancha
0 siblings, 0 replies; 25+ messages in thread
From: Tino Calancha @ 2017-08-04 5:12 UTC (permalink / raw)
To: Stefan Monnier
Cc: 27631, Tino Calancha, Michael Albinus,
積丹尼 Dan Jacobson
On Thu, 3 Aug 2017, Stefan Monnier wrote:
>> Part of the complexity of the original patch is to provide this new
>> feature in _tramp_ connections as well; your patch does the thing
>> well (see patch below) in the local machine but it fails in remote ones.
>
> I didn't adjust the Tramp code accordingly, indeed. My patch probably
> also fails for ls-lisp (aka Windows). Both of those will need
> corresponding adjustments.
> My point is that it seems like we can get the same end-result without
> changing the structure.
Maybe that's the reason why this feature didn't exit before: people found
it wasn't straight to implemented it for everything: local and remote
connections, external or emulated 'ls'.
Now we have it, but you are very welcome to rewrite it so that it fits in
the original structure. I am volunteer to be the patch tester!
>> @@ -1100,7 +1100,7 @@ dired-readin-insert
>> (while (not (file-directory-p dir))
>> (setq dir (directory-file-name dir))
>> (let ((n (file-name-nondirectory dir)))
>> - (setq file-list (mapcar (lambda (f) (concat n "/" f)) file-list)))
>> + (setq file-list (mapcar (lambda (f) (concat n (and (not (string= "" f)) "/") f)) file-list)))
>> (setq dir (file-name-directory dir)))
>> (setq default-directory dir))
>> (if (and (equal "" (file-name-nondirectory dir))
>
> `n` represents a directory name, so isn't it OK to have "<n>/" rather
> than "<n>"? Or is the above tweak purely cosmetic?
No cosmetic, i need it, otherwise i get an error if i eval the form:
(dired (expand-file-name "lisp/*.el" source-directory))
Debugger entered--Lisp error: (file-missing "Reading directory" "No such file or directory" "*.el/")
access-file("*.el/" "Reading directory")
insert-directory("*.el/" "--dired -al" t nil)
dired-insert-directory("/home/calancha/soft/emacs-master/lisp/" "-al" ("*.el/") t t)
dired-readin-insert()
dired-readin()
dired-internal-noselect("~/soft/emacs-master/lisp/*.el" nil)
dired-noselect("/home/calancha/soft/emacs-master/lisp/*.el" nil)
dired("/home/calancha/soft/emacs-master/lisp/*.el")
eval((dired (expand-file-name "lisp/*.el" source-directory)) nil)
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2017-08-04 5:12 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-09 18:42 bug#27631: dired a/*/b 積丹尼 Dan Jacobson
2017-07-13 5:52 ` Tino Calancha
2017-08-02 17:30 ` Stefan Monnier
2017-08-02 17:49 ` Eli Zaretskii
2017-08-03 1:25 ` Stefan Monnier
2017-08-03 4:38 ` Tino Calancha
2017-08-03 15:48 ` Stefan Monnier
2017-08-04 5:12 ` Tino Calancha
2017-07-13 13:15 ` 積丹尼 Dan Jacobson
2017-07-13 15:13 ` Tino Calancha
2017-07-14 8:40 ` Eli Zaretskii
2017-07-25 15:19 ` Tino Calancha
2017-07-26 7:36 ` Michael Albinus
2017-07-28 7:50 ` Tino Calancha
2017-07-28 9:23 ` Michael Albinus
2017-07-28 9:34 ` Tino Calancha
2017-07-28 11:23 ` Michael Albinus
2017-07-28 12:00 ` Michael Albinus
2017-07-29 12:20 ` Tino Calancha
2017-07-29 20:39 ` Michael Albinus
2017-07-30 2:20 ` Tino Calancha
2017-07-30 11:13 ` Michael Albinus
2017-07-29 8:30 ` Eli Zaretskii
2017-07-29 12:03 ` Tino Calancha
2017-07-14 9:30 ` Michael Albinus
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.