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: Mon, 7 Oct 2019 10:36:36 -0700 Message-ID: References: <87imp19ohm.fsf@gnus.org> <83tv8kzfpi.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5DA35F3CF5FFD995E95A29DD" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="47948"; 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: larsi@gnus.org, 37518@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 07 19:37:14 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 1iHWwb-000CFV-Qf for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Oct 2019 19:37:13 +0200 Original-Received: from localhost ([::1]:48223 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHWwa-0004gX-G2 for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Oct 2019 13:37:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41951) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHWwR-0004dD-FK for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 13:37:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHWwQ-0001cW-5b for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 13:37:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40223) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHWwQ-0001cO-2I for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 13:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iHWwP-0002UR-Th for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2019 13:37:01 -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 17:37:01 +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.15704698049545 (code B ref 37518); Mon, 07 Oct 2019 17:37:01 +0000 Original-Received: (at 37518) by debbugs.gnu.org; 7 Oct 2019 17:36:44 +0000 Original-Received: from localhost ([127.0.0.1]:49044 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iHWw7-0002Ts-Un for submit@debbugs.gnu.org; Mon, 07 Oct 2019 13:36:44 -0400 Original-Received: from sender4-of-o55.zoho.com ([136.143.188.55]:21514) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iHWw6-0002Tl-Qo for 37518@debbugs.gnu.org; Mon, 07 Oct 2019 13:36:43 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1570469798; cv=none; d=zoho.com; s=zohoarc; b=FAJsbWoI4soWu+k13IHRtVB24hfoFdNZgalQcztvcJCcqR0uJ/QlTAjfJBf0FYpnG2mGP9hVNBf+GPjybjXBVcG2YjWdJes3WfNJm+xufRSo6P3IhzQchGzrUjSzN0kjBWEgCL5ligIuSHvVkAm5Vl8o0t59WGXXCIY9AvmLtb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570469798; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=FViyPJsGxNXzcrjlBoxJs78CVWNCqc36+JioKxtnz1I=; b=km7bjtQIvFH9VALXllrhR7/NPrHJTVXZAiV1w6hwX0XbiQiuxlbYx/4EUqy3UQjBs2yedkK4wtV8OmNiXkKKKRmtyacv5j5wGxt8KlEaZOIGdO0CHd8zloKEPxBxtGSsR6EkwFKCpSV4CwTn6SbSdrFd6OFfMDXcBvhDUc1Be6k= 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=1570469798; 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=4774; bh=FViyPJsGxNXzcrjlBoxJs78CVWNCqc36+JioKxtnz1I=; b=ZCb8+zB2Da88u0AwoMfCid+5LLm8+ESgnjEo6yVHmlYls0Eo57rWJ9Zyq7rzX9Lz Gxu5QrxV260TLdX3Dr+fOdLqlZHKaf4j3D3kl74HbLVLCRkENXr5X2bJ3WUUIY60JEr t5X5qVvQbEvTuIpVqtfcOJaFYEFlbVNAVzwGw8xs= 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 1570469797414698.0150006259571; Mon, 7 Oct 2019 10:36:37 -0700 (PDT) Openpgp: preference=signencrypt In-Reply-To: <83tv8kzfpi.fsf@gnu.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:168562 Archived-At: This is a multi-part message in MIME format. --------------5DA35F3CF5FFD995E95A29DD Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit See the attached update. On 10/7/19 9:24 AM, Eli Zaretskii wrote: >> From: Hong Xu >> Date: Sun, 6 Oct 2019 21:48:52 -0700 >> Cc: 37518@debbugs.gnu.org > > The second instance of "TAGS" should also have the @file markup. Yes. > >> +(defun tags--find-default-tags-dir-recursively (current-dir) >> + "Find the directory that hosts the default TAGS file. > > "hosts" might be somewhat confusing. How about > > Find the directory with the default TAGS file. > I changed it to Find the directory in which the default TAGS file sits. Hopefully this is more articulate than "with". --------------5DA35F3CF5FFD995E95A29DD 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 c970ae7913bdf4803be07d6fcf895359825747bc 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..ef448dd595be 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 @file{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..e5cf5f156559 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 in which the default TAGS file sits. +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 --------------5DA35F3CF5FFD995E95A29DD--