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: Thu, 13 Jul 2017 14:52:51 +0900 Message-ID: <8737a0yjbg.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 1499925259 8096 195.159.176.226 (13 Jul 2017 05:54:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Jul 2017 05:54:19 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 27631@debbugs.gnu.org To: =?UTF-8?Q?=E7=A9=8D=E4=B8=B9=E5=B0=BC?= Dan Jacobson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 13 07:54: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 1dVX4l-0001n3-Ny for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Jul 2017 07:54:11 +0200 Original-Received: from localhost ([::1]:57298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVX4r-0008U5-29 for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Jul 2017 01:54:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVX4f-0008NZ-LY for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 01:54:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVX4c-0006oi-Il for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 01:54:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33449) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVX4c-0006oV-EG for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 01:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dVX4c-0004ZY-6s for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2017 01:54: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 05:54: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.149992518617511 (code B ref 27631); Thu, 13 Jul 2017 05:54:02 +0000 Original-Received: (at 27631) by debbugs.gnu.org; 13 Jul 2017 05:53:06 +0000 Original-Received: from localhost ([127.0.0.1]:36125 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVX3h-0004YM-Jx for submit@debbugs.gnu.org; Thu, 13 Jul 2017 01:53:05 -0400 Original-Received: from mail-pg0-f67.google.com ([74.125.83.67]:36611) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVX3f-0004Xs-FC for 27631@debbugs.gnu.org; Thu, 13 Jul 2017 01:53:04 -0400 Original-Received: by mail-pg0-f67.google.com with SMTP id y129so5688777pgy.3 for <27631@debbugs.gnu.org>; Wed, 12 Jul 2017 22:53:03 -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=J/9bUgmeaXS0p/ffzqxy8ghekS+uQ4u9kQNys/76bOo=; b=pW8ZR+61T7nyLP9/r1aIYQHqV52GsVTj4EUrIU7F5fP6vmnyYJaPM5MGyX3kH/e8GE HOT+7mB8MEtfW+ZiY9fxyh8/0c8n5VYrPpFRm6BNpUgWCZzWbQ/938sVK0uVJGzM27GV Yo/ia6FGQQ3OZIKBTpynwazskrn7McQgVGWcPtonzAXcWJgI4ULWKak0w8KQEhpEmKx8 typIsZr3F+aAc/s0m7VXZj4NE5YPZOPFuyruY/v9F+qfwMBIxXMrpqrUiZLjAxfa6zUx wdo8QKKgleSReLjGoCCw47+rSW4nt22bB7M5R3ebyIoHbfTucOP1Yatr3kZ3rrMhMa/F awuw== 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=J/9bUgmeaXS0p/ffzqxy8ghekS+uQ4u9kQNys/76bOo=; b=cpCEORd4GEIGk6kz/bLbnJm3etEr+t6H/ceUnqsS8KmAS5XC1b74aGQU1oIcKChuRH ExZkc7zgG8U+8w6rIopYR14rJY8o/UCwJMXN6VU4ASKWpmlFDElwvnt7rIQaJFBgrzjq MlFbyYK1oWP6mFUmZvtNSgnDB6nkej/+Dpn9ItOO3lDP8kbryaAVnsjgJHsH0eDC+y38 EPVUblM0FvgqpZsvZZFA4igQ1FV4Ijqm5yy8JJyXbgTZ6QwEpAQcCUVATUSV+MYgMVci L5CSkKg84icw1cHA00wnkw1Bowz5anwkoYC9eCfgzt6UqB7JskBUMDPhUu9JK9rjcM4Z YWrQ== X-Gm-Message-State: AIVw110tOzFIZps9CWJta3RwgO/P+JlHfTbDMIj17qfDRsrHkfyQmq4O 0OHY8mrutezWuFj5 X-Received: by 10.84.174.129 with SMTP id r1mr8314686plb.55.1499925177265; Wed, 12 Jul 2017 22:52:57 -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 l4sm8147019pgr.21.2017.07.12.22.52.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Jul 2017 22:52:56 -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:134497 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/ 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 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 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)) + (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)))) =20 (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-wildcar= d 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..96d1b49d50 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6552,6 +6552,23 @@ directory-listing-before-filename-regexp =20 (defvar insert-directory-ls-version 'unknown) =20 +(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 wildca= rs; 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-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. --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