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: Thu, 26 Sep 2019 02:52:30 -0700 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="181474"; 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 To: 37518@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 26 11:53:10 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 1iDQSU-000l5N-BF for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Sep 2019 11:53:10 +0200 Original-Received: from localhost ([::1]:33110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDQST-000885-4z for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Sep 2019 05:53:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60473) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDQSN-00087x-8h for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 05:53:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iDQSM-0008QY-6Z for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 05:53:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33897) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iDQSM-0008QQ-3U for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 05:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iDQSM-0006zg-1D for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 05:53: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: Thu, 26 Sep 2019 09:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 37518 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.156949156726862 (code B ref -1); Thu, 26 Sep 2019 09:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Sep 2019 09:52:47 +0000 Original-Received: from localhost ([127.0.0.1]:42718 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iDQS5-0006z9-3S for submit@debbugs.gnu.org; Thu, 26 Sep 2019 05:52:46 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:59312) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iDQS2-0006z1-KX for submit@debbugs.gnu.org; Thu, 26 Sep 2019 05:52:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60428) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDQS0-00087d-MI for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 05:52:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iDQRz-0008HJ-8P for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 05:52:40 -0400 Original-Received: from sender4-of-o55.zoho.com ([136.143.188.55]:21527) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iDQRy-0008Fh-6z for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 05:52:39 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1569491551; cv=none; d=zoho.com; s=zohoarc; b=PqhFYBftEKgfjJC0rMPvd+wKt8z7dDwsItdYe3YsHZ9sAd8xR/2bbGyAbE7UKJ4YNgrbSeZbtRvuOC2yqmh3kaeDnNTFM/sWmYttJR4MzYaaZMk/RmFvjSAZLpnr8c28vX0BaZQ8tvv+QPyfnuO+U3OnpUlbTnMT74qL/oj4LoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569491551; h=Content-Type:Content-Transfer-Encoding:Date:From:MIME-Version:Message-ID:Subject:To:ARC-Authentication-Results; bh=o7qiHsIQpj7A8a/DOMiMEhnDSEP6q8bybKobCZrpI3k=; b=IsMEwI+nhO84gnqXhGrrVhLw3YVszUtv2KTmwCDTkPlXoIYBSin8muWIfw589OaeaztyIgJkIjXJlpHKisXD66tDAraGUm7RENxot66fQIekIUq3p4ONLLPwklUYiGyV0t2k4QtEm6CTNdHXq7hpQh1hwmcm8rOZsgrSGUJUD+Y= 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=1569491551; s=zoho; d=topbug.net; i=hong@topbug.net; h=To:From:Subject:Message-ID:Date:MIME-Version:Content-Type:Content-Transfer-Encoding; l=2468; bh=o7qiHsIQpj7A8a/DOMiMEhnDSEP6q8bybKobCZrpI3k=; b=OADpBYJcJ4DVQKK+ypHBo2dxD8+fE8J5cdQtlNEVg9TmKk00wnSTHJ5AgfbYr6ss QG3KW/quJxn0ZihheuQ/2VwXszO0QD5SL/Oeh9oLVp+RwJA8O9EYAemOKzpUGqXWFuT j3vHSWe7cGq8b+OkoL+JPcAgsOkStH6O72dgCIQE= 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 1569491550770573.3252564381269; Thu, 26 Sep 2019 02:52:30 -0700 (PDT) Openpgp: preference=signencrypt Content-Language: en-US X-ZohoMailClient: External X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] 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:167218 Archived-At: * lisp/progmodes/etags.el (tags--find-default-tags-dir) (tags--find-default-tags-dir-impl, visit-tags-table): Search upward from current dir for the default TAGS file --- lisp/progmodes/etags.el | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index a03516100087..81f0f135c577 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el @@ -274,6 +274,29 @@ tags-table-mode (setq buffer-undo-list t) (initialize-new-tags-table)) +(defun tags--find-default-tags-dir-impl (current-dir) + "Implements finding the directory that hosts the default TAGS file. +It finds the first directory that contains a file named TAGS encountered +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-impl parent-dir)))))) + +(defun tags--find-default-tags-dir () + "Find the directory that hosts the default TAGS file. +It is the first directory that contains a file named TAGS encountered +searching upward from `default-directory'." + (let ((default-tag-dir + (tags--find-default-tags-dir-impl default-directory))) + (if default-tag-dir + default-tag-dir + default-directory))) + ;;;###autoload (defun visit-tags-table (file &optional local) "Tell tags commands to use tags table file FILE. @@ -286,12 +309,15 @@ 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 (tags--find-default-tags-dir))) + (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