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#31495: 26.1; filename completion -vs- "*" Date: Sat, 19 May 2018 22:32:03 +0900 Message-ID: <87wovzzs8c.fsf@gmail.com> References: <877eo1gern.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1526736670 4413 195.159.176.226 (19 May 2018 13:31:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 19 May 2018 13:31:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Michael Albinus , 31495@debbugs.gnu.org To: Tom Tromey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 19 15:31:06 2018 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 1fK1wu-00011w-Gv for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 May 2018 15:31:04 +0200 Original-Received: from localhost ([::1]:43170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fK1z1-0000JH-IM for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 May 2018 09:33:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fK1ys-0000H5-1z for bug-gnu-emacs@gnu.org; Sat, 19 May 2018 09:33:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fK1yo-0005bj-Rw for bug-gnu-emacs@gnu.org; Sat, 19 May 2018 09:33:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60905) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fK1yo-0005bf-Mh for bug-gnu-emacs@gnu.org; Sat, 19 May 2018 09:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fK1yo-0007pw-8D for bug-gnu-emacs@gnu.org; Sat, 19 May 2018 09:33: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: Sat, 19 May 2018 13:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31495 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31495-submit@debbugs.gnu.org id=B31495.152673674030075 (code B ref 31495); Sat, 19 May 2018 13:33:02 +0000 Original-Received: (at 31495) by debbugs.gnu.org; 19 May 2018 13:32:20 +0000 Original-Received: from localhost ([127.0.0.1]:40569 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fK1y8-0007p1-H0 for submit@debbugs.gnu.org; Sat, 19 May 2018 09:32:20 -0400 Original-Received: from mail-pf0-f196.google.com ([209.85.192.196]:36338) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fK1y6-0007om-5w for 31495@debbugs.gnu.org; Sat, 19 May 2018 09:32:18 -0400 Original-Received: by mail-pf0-f196.google.com with SMTP id w129-v6so5032783pfd.3 for <31495@debbugs.gnu.org>; Sat, 19 May 2018 06:32:18 -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; bh=DTpIxsmb4dI/oRHNTH8KWSjOYWnjRWhzJSjVbuy7raU=; b=sKyXvfPuT5+fTV76xk189XHg3HNSpFKNF5SpRxp/8yfiUHfwgk2IkxQ80e1SdHHSC8 Npkd/AEMASHnJocqHAZCCGE/JqZ1FwnWqaSDI8aVAdUMiE7D47M6DmkG4M9t8l/F9h5D G4gxSFRZ4mrjgwppydR6j8xHuAVuzw5YZ3ftwkzeJmWsuIcayB/gji1AlyV+HhfWlDJK 4kquxHU/K9nptwXW/JUW76lPDhxCfw25XDM64vdHWTN8wOknyaGaWtbhvDKSiCOjmRSi tlZ22EwapPp4uY62jPFks9IJvLgvXHTKyBLiv8GKwV8TNM1n5Ep3Xj1RyXA8H7AGwJrh gZFg== 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; bh=DTpIxsmb4dI/oRHNTH8KWSjOYWnjRWhzJSjVbuy7raU=; b=mCwCKSfujflQRR6oVHZsS3rH7KuJQzVEujeFKBIgl0aeuuiisKWTumPxID+wvBSt9X Fqa9zZPco2oBiTSYozVSzXQ8+W747w+Lj75Lz6xe1vw/ifOGXGrJ4JtqJ0+sLZ+hklM0 uwGfsnIViWvNjO9/coB7+RepUFAgNHKxlIZhPlp64Sau0BA3tiLkDutDcT9Ev6MiPGNc D7lBjRwjhpk/HIbIrFxQwTLZ/0qlnxrta02LVMMHtVk39MKVGoC0TE66Ks8/oOkGr/fs LVIYA5N4f2S0czs3yNBX6saS59gbPzc7p3zmbmhbbWvJpxOOwvWzgWyVZVMV1dmT230e UDkQ== X-Gm-Message-State: ALKqPwcIYWh2FPa4igmqEfheTsAFaTOZuol1dT0NOYlE6ZDFCiz0KuH4 3eMIuaNaQcngpSPCVSy9HCs= X-Google-Smtp-Source: AB8JxZqjf4uKuAFpYA/CBgj67uQad4P9JqWVJPwnP3eJBXQbW7UJ+/kH0OPIJoOkDd/Mvd43Dl37WA== X-Received: by 2002:a63:6185:: with SMTP id v127-v6mr10507442pgb.441.1526736732195; Sat, 19 May 2018 06:32:12 -0700 (PDT) Original-Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id e18-v6sm14898979pfi.100.2018.05.19.06.32.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 19 May 2018 06:32:11 -0700 (PDT) In-Reply-To: <877eo1gern.fsf@tromey.com> (Tom Tromey's message of "Fri, 18 May 2018 09:33:16 -0600") 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:146292 Archived-At: Tom Tromey writes: > I found a situation where using "*" globbing in filename completion acts > strangely. > > Here is how to set up to see the bug: > > $ cd /tmp > $ mkdir -p a/b/c a/d/c > $ touch a/b/c/q > > Now in Emacs, C-x C-f /tmp/a/*/c TAB > > On the first TAB, a "/" is appended, and then point moves to the "/" > before "c". Yeah, it's broken. In this example adding a '/' makes the completion works C-x C-f /tmp/a/*/c/ TAB > Now type TAB again. > At this point, the "/tmp/a" is greyed out and the minibuffer shows: > > Find file: /tmp/a//c/ > > ... so now only completions for "/c" are available. > > I think instead the "*" should be preserved. Often I'm using this > feature to try to find a specific file where I don't know the exact > subdirectory it is in. Since Emacs 26.1 dired supports wildcards in the directory part. You can use C-x d /tmp/a/*/c/q RET If you shell in '/bin/sh' supports globstar (and have it enabled by default) then you can do just: C-x d /tmp/**/q RET We could even let the user enable globstar in those shells supporting it but having it disable by default (e.g. bash). For instance, following patch: --8<-----------------------------cut here---------------start------------->8--- commit 1c1116e6a6ed369db63ddf00865f04f687579e71 Author: Tino Calancha Date: Sat May 19 21:57:42 2018 +0900 Handle globstar in dired Allow user to enable globstar when the shell support it and disable it by default (e.g. bash). * lisp/dired.el (dired-maybe-use-globstar): New user option. (dired-enable-globstar-in-shell): New variable. (dired-insert-directory): if `dired-maybe-use-globstar' is non-nil and the shell supports globstar, then enable it. * doc/emacs/dired.texi: Document feature. ; * etc/NEWS: Add entry. diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index fbb3030c2a..ad63c2f6a5 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -79,6 +79,24 @@ Dired Enter @samp{foo}. The latter lists the files with extension @samp{.el} in all the subdirectories of @samp{foo}. +When the system shell supports globstar and it's enabled, then you +can use recursive globbing: + +@example +C-x d ~/foo/**/*.el @key{RET} +@end example + +This command lists all the files with extension @samp{.el} descending +recursively in all the subdirectories of @samp{foo}. Note that there +are small differences in the implementation of globstar between shells. +Check your shell manual to know the expected behavior. + +@vindex dired-maybe-use-globstar +@vindex dired-enable-globstar-in-shell +If the shell supports globstar and disables it by default, you +can still enable this feature with @code{dired-maybe-use-globstar} if +the shell is included in @code{dired-enable-globstar-in-shell}. + 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}). diff --git a/etc/NEWS b/etc/NEWS index c7ffb17ad3..931289f0af 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -266,6 +266,12 @@ unescaping text. ** Dired +++ +*** The new user option 'dired-maybe-use-globstar' enables globstar +in shells that support this feature. The new variable +'dired-enable-globstar-in-shell' lists which shells can have enabled +globstar. + ++++ *** The new user option 'dired-create-destination-dirs' controls whether 'dired-do-copy' and 'dired-rename-file' should create non-existent directories in the destination. diff --git a/lisp/dired.el b/lisp/dired.el index 1348df6934..0adffdbd3f 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -77,6 +77,26 @@ dired-subdir-switches :type '(choice (const :tag "Use dired-listing-switches" nil) (string :tag "Switches"))) +(defcustom dired-maybe-use-globstar nil + "If non-nil, enable globstar if the shell support it. +Some shells enable this feature by default (e.g. zsh or fish). + +See `dired-enable-globstar-in-shell' for a list of shells +that support globstar and disable it by default. + +Note that the implementation of globstar have small differences +between shells. You must check your shell documentation to see +what to expect." + :type 'boolean + :group 'dired) + +(defconst dired-enable-globstar-in-shell + '(("ksh" . "set -G") + ("bash" . "shopt -s globstar")) + "Alist of (SHELL . COMMAND), where COMMAND enables globstar in SHELL. +If `dired-maybe-use-globstar' is non-nil, then `dired-insert-directory' +checks this alist to enable globstar in the shell subprocess.") + (defcustom dired-chown-program (purecopy (cond ((executable-find "chown") "chown") ((file-executable-p "/usr/sbin/chown") "/usr/sbin/chown") @@ -1297,6 +1317,13 @@ dired-insert-directory (executable-find explicit-shell-file-name)) (executable-find "sh"))) (switch (if remotep "-c" shell-command-switch))) + ;; Enable globstar + (when-let ((globstar dired-maybe-use-globstar) + (enable-it + (assoc-default + (file-truename sh) dired-enable-globstar-in-shell + (lambda (reg shell) (string-match reg shell))))) + (setq script (format "%s; %s" enable-it script))) (unless (zerop (process-file sh nil (current-buffer) nil switch script)) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 27.0.50 (build 12, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2018-05-17 built on calancha-pc Repository revision: 593c367b0727affc739832ab4f4bdb9d7dd1ddd7