From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#34621: [PATCH] Fix rgrep in dired taking default search file pattern from directory name (e.g. *.11 for django-1.11) Date: Tue, 09 Apr 2019 23:32:01 +0300 Organization: LINKOV.NET Message-ID: <8736mq6gwe.fsf@mail.linkov.net> References: <08e7108149ce2374fd0c9b7fc3e6ae38@reckondigital.com> <40839b67-bce7-4a01-89f1-c14643b18b32@default> <80f4335be923e21fe782780c6812a03f@reckondigital.com> <878sxd248k.fsf@mail.linkov.net> <82347809b60dfc4e18a822d2d604475c@reckondigital.com> <87mul0wacr.fsf@mail.linkov.net> <336a681ce53ad7623fc5f98936577d82@reckondigital.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="17230"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 34621@debbugs.gnu.org To: Christopher Thorne Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 09 23:00:15 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDxqo-0004H9-I6 for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Apr 2019 23:00:15 +0200 Original-Received: from localhost ([127.0.0.1]:49038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDxqn-0007M9-Hv for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Apr 2019 17:00:13 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDxqd-0007Lu-SI for bug-gnu-emacs@gnu.org; Tue, 09 Apr 2019 17:00:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDxqc-0001YR-OV for bug-gnu-emacs@gnu.org; Tue, 09 Apr 2019 17:00:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38515) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hDxqc-0001YH-EL for bug-gnu-emacs@gnu.org; Tue, 09 Apr 2019 17:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hDxqc-0006vk-Ag for bug-gnu-emacs@gnu.org; Tue, 09 Apr 2019 17:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 Apr 2019 21:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34621 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 34621-submit@debbugs.gnu.org id=B34621.155484356126559 (code B ref 34621); Tue, 09 Apr 2019 21:00:02 +0000 Original-Received: (at 34621) by debbugs.gnu.org; 9 Apr 2019 20:59:21 +0000 Original-Received: from localhost ([127.0.0.1]:52059 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hDxpx-0006uI-Bn for submit@debbugs.gnu.org; Tue, 09 Apr 2019 16:59:21 -0400 Original-Received: from palegreen.birch.relay.mailchannels.net ([23.83.209.140]:44885) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hDxpu-0006u8-5j for 34621@debbugs.gnu.org; Tue, 09 Apr 2019 16:59:19 -0400 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id A06BE12598E; Tue, 9 Apr 2019 20:59:16 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a36.g.dreamhost.com (unknown [100.96.20.50]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 47C371258B0; Tue, 9 Apr 2019 20:59:16 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a36.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.2); Tue, 09 Apr 2019 20:59:16 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Scare-Illustrious: 023670406d854db5_1554843556435_2318013207 X-MC-Loop-Signature: 1554843556435:1261677313 X-MC-Ingress-Time: 1554843556435 Original-Received: from pdx1-sub0-mail-a36.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a36.g.dreamhost.com (Postfix) with ESMTP id C1D1580592; Tue, 9 Apr 2019 13:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=GkOfsIin95s1nOxFlvJ43wNH2DE=; b= 3jiaX9UZOVYQsy1bJAOtZ+1zBgGtC089fom5nzHrSzWMao3R8F6C5cK7zzogrBBl bQmqY5aQItrTLGntt5NcnRSAoBGtxk0A1zT03YiPhcFXGB1GXKKNrnZyOoTf7ilr Jo8Ne9v6jsdikZ4LHYjA++GCc+LStEtDCVD5CrBJvrA= Original-Received: from mail.jurta.org (m91-129-97-48.cust.tele2.ee [91.129.97.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a36.g.dreamhost.com (Postfix) with ESMTPSA id 27D348058B; Tue, 9 Apr 2019 13:59:12 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a36 In-Reply-To: <336a681ce53ad7623fc5f98936577d82@reckondigital.com> (Christopher Thorne's message of "Tue, 09 Apr 2019 12:09:27 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduuddrudehgdduheeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrdeljedrgeeknecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledrleejrdegkedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegtrdhthhhorhhnvgesrhgvtghkohhnughighhithgrlhdrtghomhenucevlhhushhtvghrufhiiigvpedu 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: 209.51.188.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:157432 Archived-At: > However, it doesn't cover the case where emacs is in a dired buffer called > django-1.11 with nothing at point. In this case, *.11 will be suggested > because buffer-name is used. I'm not sure how to fix this in grep.el > without an "if is dired" check. When I tried the change that I suggested to use, I forgot that I have this customization: (add-hook 'dired-after-readin-hook (lambda () ;; Set name of dired buffers to absolute directory names. (when (stringp dired-directory) (rename-buffer (generate-new-buffer-name dired-directory))))) that renames dired buffers to e.g. "django-1.11/", and due to the trailing slash, grep-read-files doesn't use it's buffer name. But since by default there is no trailing slash in dired buffer names, this is unsuitable. So I agree with your approach to allow modes to override using buffer names as candidates. > diff --git a/lisp/dired.el b/lisp/dired.el > index fc0b71238b..33abca550a 100644 > --- a/lisp/dired.el > +++ b/lisp/dired.el > @@ -4162,6 +4162,17 @@ dired-restore-desktop-buffer > (add-to-list 'desktop-buffer-mode-handlers > '(dired-mode . dired-restore-desktop-buffer)) > > +(defun dired-grep-file-name-for-default-pattern () > + "Use file at point as the file for grep's default file-name pattern suggestion. > +If a directory or nothing is found at point, return nil." > + (let ((dired-file-name > + (run-hook-with-args-until-success 'file-name-at-point-functions))) > + (if (and dired-file-name > + (not (file-directory-p dired-file-name))) > + dired-file-name))) > +(put 'dired-mode 'grep-file-name-for-default-pattern-function 'dired-grep-file-name-for-default-pattern) This is an overwhelmingly long name, please use the same name as the function that uses this feature, i.e. just 'grep-read-files'. Then when someone reading dired.el will find a line (put 'dired-mode 'grep-read-files 'dired-grep-read-files) it will be clear for them the purpose of this feature. Please place this change in dired.el after the definition of 'dired-file-name-at-point' that you can use in your dired function instead of (run-hook-with-args-until-success 'file-name-at-point-functions) > diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el > index c0f47159c9..b0bb8e6924 100644 > --- a/lisp/progmodes/grep.el > +++ b/lisp/progmodes/grep.el > @@ -959,8 +959,12 @@ grep-read-files > The pattern can include shell wildcards. As whitespace triggers > completion when entering a pattern, including it requires > quoting, e.g. `\\[quoted-insert]'." > - (let* ((bn (or (buffer-file-name) > - (replace-regexp-in-string "<[0-9]+>\\'" "" (buffer-name)))) > + (let* ((file-name-for-default-pattern-function > + (get major-mode 'grep-file-name-for-default-pattern-function)) > + (bn (if file-name-for-default-pattern-function > + (funcall file-name-for-default-pattern-function) > + (or (buffer-file-name) > + (replace-regexp-in-string "<[0-9]+>\\'" "" (buffer-name))))) If you want you could also add as a 4th option additionally (run-hook-with-args-until-success 'file-name-at-point-functions) to automatically support modes other than dired, i.e. other modes that set file-name-at-point-functions.