From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#27631: dired a/*/b Date: Fri, 14 Jul 2017 00:13:28 +0900 Message-ID: <877ezcxtd3.fsf@calancha-pc> References: <87o9sth2oi.fsf@jidanni.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1499958859 22005 195.159.176.226 (13 Jul 2017 15:14:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Jul 2017 15:14:19 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 27631@debbugs.gnu.org To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 13 17:14:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVfof-0005Ga-V2 for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Jul 2017 17:14:10 +0200 Original-Received: from localhost ([::1]:60606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfol-0004qL-Be for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Jul 2017 11:14:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfoc-0004oc-VX for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 11:14:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVfoY-00058s-OR for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 11:14:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34571) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVfoY-00058k-K3 for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 11:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dVfoY-0004Wo-Bn for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 11:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Jul 2017 15:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27631 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27631-submit@debbugs.gnu.org id=B27631.149995882217364 (code B ref 27631); Thu, 13 Jul 2017 15:14:02 +0000 Original-Received: (at 27631) by debbugs.gnu.org; 13 Jul 2017 15:13:42 +0000 Original-Received: from localhost ([127.0.0.1]:37248 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVfoD-0004Vz-HW for submit@debbugs.gnu.org; Thu, 13 Jul 2017 11:13:41 -0400 Original-Received: from mail-pf0-f173.google.com ([209.85.192.173]:34171) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVfoB-0004Vg-By for 27631@debbugs.gnu.org; Thu, 13 Jul 2017 11:13:40 -0400 Original-Received: by mail-pf0-f173.google.com with SMTP id q85so30950440pfq.1 for <27631@debbugs.gnu.org>; Thu, 13 Jul 2017 08:13:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=JPlJFATNBNGlW6K8TF80q7zhXp1kseYh1BvocoZkq+I=; b=XcrP77FJIeVHsxXfRbqOHzk0sJusLDuf9Qn4bDRa5VTvod/kNHbtc3eDwkGGdoYvXS DCmpa9bYa+kvi8HFEdtpH+yer+ROzfadUEguWUOEUie6dnYkiveXlBspSulFiZC2Y7SV lKc7qDEPe0ubRS2js9gnNfB7rRbhik+EIA0/q8Z8KT2ShCI5Ak+IF7tb46tF9Oqr3qhJ u0Zp0swuXeraN3+J/02HEmk/o1S62j8L7riJCb7kaKKOud+McgGqYS8WynVM0aTUwcA4 jhRklr/xrSxl5XkgP8v16C48z/3fVaaoFW+58+FxNKEL1X2PFRZSKUz1NqQd3l5I6xW8 E+pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=JPlJFATNBNGlW6K8TF80q7zhXp1kseYh1BvocoZkq+I=; b=KdPpmeu17wL40yBNz2YwzeKIi46Say3b/njC72y/s8/ttiSoQhl0TjfZYIH51h6ta4 UpvNUhX2C6R5I3grdFi4hxKorCOXnpnZK8LniHAY/jlQzsg2/yj2NTVHhcSM/xXDkX+C jv6dqG4HsT0mODOABswJ60EG1bW5L3T7GuU8Sx3SnYSX/5zf5o0k8KaKIUyrhTBwzuEU 2r8U4SktSqndamcg8faCVbR5CKrFmcK0f1jAT1W+Kn9qowiJt7N5ltcls/tOPgzGF65C yuUdxymYK7zDK3Be/qiD31KHNrnFWtlNjQUDeYqc1zj98tZJ9JvkmImtD1ooI/hy1jR1 kkOg== X-Gm-Message-State: AIVw111T3FbYVeseMZggpWslBM7Xb7aInZ1swzydMpkXw5GXpbkcMysM MVy0sg6yGU2vpN4f X-Received: by 10.84.130.76 with SMTP id 70mr10629192plc.138.1499958813028; Thu, 13 Jul 2017 08:13:33 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id w85sm17536703pfj.115.2017.07.13.08.13.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 08:13:32 -0700 (PDT) In-Reply-To: <87o9sth2oi.fsf@jidanni.org> ("=?UTF-8?Q?=E7=A9=8D=E4=B8=B9=E5=B0=BC?= Dan Jacobson"'s message of "Mon, 10 Jul 2017 02:42:53 +0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134506 Archived-At: =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson 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 Date: Thu Jul 13 23:56:43 2017 +0900 Dired: Handle wildards in directory part =20=20=20=20 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}). =20 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 =20 ** Dired -You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets repla= ced ++++ +*** You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets r= eplaced by the current file name. =20 ++++ +*** Now Dired support wildcards in the directory part of file names. + *** html2text is now marked obsolete. =20 *** 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 Dir= ed"))))) ;; 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)))) =20 (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))))) =20 (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 =20 (defvar insert-directory-ls-version 'unknown) =20 +(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 wildca= rs; 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-nondirecto= ry 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 Date: Thu Jul 13 23:56:43 2017 +0900 Dired: Tramp support for wildcards in directory part =20=20=20=20 * lisp/net/tramp-sh.el (tramp-sh-handle-insert-directory-wildcard-in-di= r-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 =20 (goto-char (point-max))))))) =20 +(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. =20 (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