From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Hong Xu Newsgroups: gmane.emacs.bugs Subject: bug#37518: [PATCH] Search upward from current dir for the default TAGS file Date: Sun, 6 Oct 2019 21:48:52 -0700 Message-ID: References: <87imp19ohm.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------FA4176741345FFABC1EF1D6C" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="239366"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 Cc: 37518@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 07 06:50:11 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.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iHKyI-00109o-TB for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Oct 2019 06:50:11 +0200 Original-Received: from localhost ([::1]:40584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHKyH-0004Df-Nw for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Oct 2019 00:50:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55019) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHKyB-0004DY-Tr for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 00:50:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHKyA-0003rU-PD for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 00:50:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38378) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHKyA-0003r8-HB for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 00:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iHKyA-0002nZ-DA for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 00:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Hong Xu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Oct 2019 04:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37518 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 37518-submit@debbugs.gnu.org id=B37518.157042375110629 (code B ref 37518); Mon, 07 Oct 2019 04:50:02 +0000 Original-Received: (at 37518) by debbugs.gnu.org; 7 Oct 2019 04:49:11 +0000 Original-Received: from localhost ([127.0.0.1]:47199 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iHKxK-0002lN-Mj for submit@debbugs.gnu.org; Mon, 07 Oct 2019 00:49:11 -0400 Original-Received: from sender4-of-o55.zoho.com ([136.143.188.55]:21510) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iHKxI-0002lA-Bu for 37518@debbugs.gnu.org; Mon, 07 Oct 2019 00:49:09 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1570423734; cv=none; d=zoho.com; s=zohoarc; b=nujrwHk0TpvosRy7m2OAdjAvMWvZOCs4zNjbsUZKY3q1O5sjF3ZXwjFXnoG4fosEKGnA9XSlEqcXPpJu3FjGwvSTHOygUfmp+Ymfdzc7FLbD01CQJ6RBz+DCihxah6FnbscW3tx5Q1n85jtOm65HXHV49021pAcEyojkrImJajE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570423734; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=2PSrRR3vtdmio95H4VrG5DsXpqZxPztyfbUY2uL4kX0=; b=GxeAsU+Q1qDImTqh2nvp3cbxAPbrtDCvhngmMHPAYsZh89zpxJJZxTaTGWi18M66rXlrZ91YiiKdcx1fDnrCg7c2nNHrRe8Q2rWAiQciP9YHjul8ikqGuAbSlC9kNajTV+Q+VxOFxyf97coQAKCg6yWaQcadqNVSZO5U88zKdI4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=topbug.net; spf=pass smtp.mailfrom=hong@topbug.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1570423734; s=zoho; d=topbug.net; i=hong@topbug.net; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version:In-Reply-To:Content-Type; l=4721; bh=2PSrRR3vtdmio95H4VrG5DsXpqZxPztyfbUY2uL4kX0=; b=BXqV820Zv2o+OQRgGFbqwXHbUIk/g6ILZZSDkOQI1e+Sia0i8bBhcLnTHfUXTu38 4qkHgiyMqtAyEjoblQdA+cDmw76fBhiWeSv86KmJEI3FSKupR8j0Dw9t2Smfb3Hp5H5 i34R/Uq22QI3Ib+hrIElmPHL8T41jXNby2bzMC7Y= Original-Received: from [192.168.88.88] (69-215-149-151.lightspeed.sntcca.sbcglobal.net [69.215.149.151]) by mx.zohomail.com with SMTPS id 1570423733169629.7626513798267; Sun, 6 Oct 2019 21:48:53 -0700 (PDT) Openpgp: preference=signencrypt In-Reply-To: <87imp19ohm.fsf@gnus.org> Content-Language: en-US X-Zoho-Virus-Status: 1 X-ZohoMailClient: External 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:168497 Archived-At: This is a multi-part message in MIME format. --------------FA4176741345FFABC1EF1D6C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks. I've attached an updated patch below. On 10/6/19 9:19 PM, Lars Ingebrigtsen wrote: > >> +(defun tags--find-default-tags-dir-impl (current-dir) > > We don't really call functions for "-impl" or the like -- as this > recurses upwards, what about calling it something more descriptive like > `tags--find-default-tags-dir-recursively'? Makes sense. > > This is basically > > (or (tags--find-default-tags-dir-impl default-directory) > default-directory) > > so I don't think this intermediary function is needed. How could I forget the magical "or" :) --------------FA4176741345FFABC1EF1D6C Content-Type: text/x-patch; name="0001-Search-upward-from-current-dir-for-the-default-TAGS-.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Search-upward-from-current-dir-for-the-default-TAGS-.pa"; filename*1="tch" >From db1a9407f427c9d08957b9552560ff9dbb753c48 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Sun, 6 Oct 2019 21:42:57 -0700 Subject: [PATCH] Search upward from current dir for the default TAGS file * lisp/progmodes/etags.el (tags--find-default-tags-dir-recursively) (visit-tags-table): Search upward from current dir for the default TAGS file * doc/emacs/maintaining.texi (Select Tags Table): Update the doc of `visit-tags-table'. --- doc/emacs/maintaining.texi | 11 ++++++----- lisp/progmodes/etags.el | 31 +++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 519667dfbe92..9d1da2ee497a 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -2666,11 +2666,12 @@ Select Tags Table @subsection Selecting a Tags Table @findex visit-tags-table - Emacs has at any time at most one @dfn{selected} tags table. All the -commands for working with tags tables use the selected one. To select -a tags table, type @kbd{M-x visit-tags-table}, which reads the tags -table file name as an argument, with @file{TAGS} in the default -directory as the default. + Emacs has at any time at most one @dfn{selected} tags table. All +the commands for working with tags tables use the selected one. To +select a tags table, type @kbd{M-x visit-tags-table}, which reads the +tags table file name as an argument, with @file{TAGS} defaulting to +the first directory that contains a file named TAGS encountered when +recursively searching upward from the default directory. @vindex tags-file-name Emacs does not actually read in the tags table contents until you diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index c40422dbc5c3..5cc62543415f 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el @@ -274,6 +274,19 @@ tags-table-mode (setq buffer-undo-list t) (initialize-new-tags-table)) +(defun tags--find-default-tags-dir-recursively (current-dir) + "Find the directory that hosts the default TAGS file. +It is the first directory that contains a file named TAGS +encountered when recursively searching upward from CURRENT-DIR." + (let ((tag-filename (expand-file-name "TAGS" current-dir))) + (if (file-exists-p tag-filename) + current-dir + (let ((parent-dir + (file-name-directory (directory-file-name current-dir)))) + (if (string= parent-dir current-dir) ;; root dir is reached + nil + (tags--find-default-tags-dir-recursively parent-dir)))))) + ;;;###autoload (defun visit-tags-table (file &optional local) "Tell tags commands to use tags table file FILE. @@ -286,12 +299,18 @@ visit-tags-table When you find a tag with \\[find-tag], the buffer it finds the tag in is given a local value of this variable which is the name of the tags file the tag was in." - (interactive (list (read-file-name "Visit tags table (default TAGS): " - default-directory - (expand-file-name "TAGS" - default-directory) - t) - current-prefix-arg)) + (interactive + (let ((default-tag-dir + (or (tags--find-default-tags-dir-recursively default-directory) + default-directory))) + (list (read-file-name + "Visit tags table (default TAGS): " + ;; default to TAGS from default-directory up to root. + default-tag-dir + (expand-file-name "TAGS" default-tag-dir) + t))) + current-prefix-arg) + (or (stringp file) (signal 'wrong-type-argument (list 'stringp file))) ;; Bind tags-file-name so we can control below whether the local or ;; global value gets set. -- 2.20.1 --------------FA4176741345FFABC1EF1D6C--