From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pierre-Antoine Rouby Newsgroups: gmane.emacs.bugs Subject: bug#46055: [PATCH] Add rust lang to etags Date: Mon, 25 Jan 2021 11:15:46 +0100 Message-ID: <20210125101546.6929-1-contact@parouby.fr> References: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18025"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Pierre-Antoine Rouby To: 46055@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 25 11:19:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l3yxh-0004Yd-0K for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 25 Jan 2021 11:19:09 +0100 Original-Received: from localhost ([::1]:44886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l3yxf-0001op-L7 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 25 Jan 2021 05:19:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3yxa-0001og-9t for bug-gnu-emacs@gnu.org; Mon, 25 Jan 2021 05:19:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54651) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l3yxa-0000qQ-2Y for bug-gnu-emacs@gnu.org; Mon, 25 Jan 2021 05:19:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l3yxZ-0002N7-Tq for bug-gnu-emacs@gnu.org; Mon, 25 Jan 2021 05:19:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Pierre-Antoine Rouby Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 25 Jan 2021 10:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46055 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 46055-submit@debbugs.gnu.org id=B46055.16115699289093 (code B ref 46055); Mon, 25 Jan 2021 10:19:01 +0000 Original-Received: (at 46055) by debbugs.gnu.org; 25 Jan 2021 10:18:48 +0000 Original-Received: from localhost ([127.0.0.1]:37964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l3yxL-0002MZ-TO for submit@debbugs.gnu.org; Mon, 25 Jan 2021 05:18:48 -0500 Original-Received: from 10.mo5.mail-out.ovh.net ([46.105.52.148]:50030) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l3yxJ-0002MQ-ET for 46055@debbugs.gnu.org; Mon, 25 Jan 2021 05:18:46 -0500 Original-Received: from player791.ha.ovh.net (unknown [10.110.171.96]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id 0D1BC2AD657 for <46055@debbugs.gnu.org>; Mon, 25 Jan 2021 11:18:43 +0100 (CET) Original-Received: from parouby.fr (91-175-17-70.subs.proxad.net [91.175.17.70]) (Authenticated sender: contact@parouby.fr) by player791.ha.ovh.net (Postfix) with ESMTPSA id 38D891A4BBBFE; Mon, 25 Jan 2021 10:18:42 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-99G003027077ef-d99a-4097-a97b-bb496c3f479a, 8854E7433D5AD1D10FBE0073606383D2091F8FEE) smtp.auth=contact@parouby.fr X-OVh-ClientIp: 91.175.17.70 X-Mailer: git-send-email 2.29.2 In-Reply-To: X-Ovh-Tracer-Id: 11169771503595304174 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrvdefgdduvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefrihgvrhhrvgdqtehnthhoihhnvgcutfhouhgshicuoegtohhnthgrtghtsehprghrohhusgihrdhfrheqnecuggftrfgrthhtvghrnhepheelkedukeffgfehkefgvdeiiedtkeeifedvudeiueekhfehkeeiudetjedtiefhnecukfhppedtrddtrddtrddtpdeluddrudejhedrudejrdejtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejledurdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghonhhtrggtthesphgrrhhouhgshidrfhhrpdhrtghpthhtohepgeeitdehheesuggvsggsuhhgshdrghhnuhdrohhrgh X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:198560 Archived-At: * lib-src/etags.c (Rust_functions): New function to make tags for rust files. (Rust_help, Rust_suffixes): New constant. * doc/emacs/maintaining.texi (Tag Syntax): Add Rust item. * doc/man/etags.1: Add Rust. --- doc/emacs/maintaining.texi | 4 ++++ doc/man/etags.1 | 2 +- lib-src/etags.c | 49 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 415815473e..0f96dc65d1 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -2639,6 +2639,10 @@ Tag Syntax @item In Ruby code, @code{def} or @code{class} or @code{module} at the beginning of a line generate a tag. Constants also generate tags. + +@item +In Rust code, tags anything defined with @code{fn}, @code{enum}, +@code{struct} or @code{macro_rules!}. @end itemize You can also generate tags based on regexp matching (@pxref{Etags diff --git a/doc/man/etags.1 b/doc/man/etags.1 index c5c15fb182..354f6ca88b 100644 --- a/doc/man/etags.1 +++ b/doc/man/etags.1 @@ -51,7 +51,7 @@ format understood by \&. Both forms of the program understand the syntax of C, Objective C, C++, Java, Fortran, Ada, Cobol, Erlang, Forth, Go, HTML, LaTeX, Emacs Lisp/Common Lisp, Lua, Makefile, Pascal, Perl, -Ruby, PHP, PostScript, Python, Prolog, Scheme and +Ruby, Rust, PHP, PostScript, Python, Prolog, Scheme and most assembler\-like syntaxes. Both forms read the files specified on the command line, and write a tag table (defaults: \fBTAGS\fP for \fBetags\fP, \fBtags\fP for diff --git a/lib-src/etags.c b/lib-src/etags.c index b5c18e0e01..8243861c69 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -366,6 +366,7 @@ #define xrnew(op, n, m) ((op) = xnrealloc (op, n, (m) * sizeof *(op))) static void Prolog_functions (FILE *); static void Python_functions (FILE *); static void Ruby_functions (FILE *); +static void Rust_functions (FILE *); static void Scheme_functions (FILE *); static void TeX_commands (FILE *); static void Texinfo_nodes (FILE *); @@ -752,6 +753,12 @@ #define STDIN 0x1001 /* returned by getopt_long on --parse-stdin */ static const char *Ruby_interpreters [] = { "ruby", NULL }; +static const char *Rust_suffixes [] = + { "rs", NULL }; +static const char Rust_help [] = + "In Rust code, tags anything defined with 'fn', 'enum', \n\ +'struct' or 'macro_rules!'."; + /* Can't do the `SCM' or `scm' prefix with a version number. */ static const char *Scheme_suffixes [] = { "oak", "sch", "scheme", "SCM", "scm", "SM", "sm", "ss", "t", NULL }; @@ -836,6 +843,7 @@ #define STDIN 0x1001 /* returned by getopt_long on --parse-stdin */ NULL, Python_interpreters }, { "ruby", Ruby_help, Ruby_functions, Ruby_suffixes, Ruby_filenames, Ruby_interpreters }, + { "rust", Rust_help, Rust_functions, Rust_suffixes }, { "scheme", Scheme_help, Scheme_functions, Scheme_suffixes }, { "tex", TeX_help, TeX_commands, TeX_suffixes }, { "texinfo", Texinfo_help, Texinfo_nodes, Texinfo_suffixes }, @@ -5019,6 +5027,47 @@ Ruby_functions (FILE *inf) } } + +/* + * Rust support + * Look for: + * - fn: Function + * - struct: Structure + * - enum: Enumeration + * - macro_rules!: Macro + */ +static void +Rust_functions (FILE *inf) +{ + char *cp, *name; + + LOOP_ON_INPUT_LINES(inf, lb, cp) + { + cp = skip_spaces(cp); + name = cp; + + // Skip 'pub' keyworld + (void)LOOKING_AT (cp, "pub"); + + // Look for define + if (LOOKING_AT (cp, "fn") + || LOOKING_AT (cp, "enum") + || LOOKING_AT (cp, "struct") + || LOOKING_AT (cp, "macro_rules!")) + { + cp = skip_spaces (cp); + name = cp; + + while (!notinname (*cp)) + cp++; + + make_tag (name, cp - name, true, + lb.buffer, cp - lb.buffer + 1, + lineno, linecharno); + } + } +} + /* * PHP support -- 2.29.2