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 15:33:44 +0100 Message-ID: <20210125143344.21837-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="13971"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 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 15:35:11 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 1l42xT-0003WL-G9 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 25 Jan 2021 15:35:11 +0100 Original-Received: from localhost ([::1]:38988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l42xS-0007nS-Dy for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 25 Jan 2021 09:35:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l42xK-0007l2-40 for bug-gnu-emacs@gnu.org; Mon, 25 Jan 2021 09:35:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55038) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l42xJ-000607-SO for bug-gnu-emacs@gnu.org; Mon, 25 Jan 2021 09:35:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l42xJ-0005ZH-No for bug-gnu-emacs@gnu.org; Mon, 25 Jan 2021 09:35: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 14:35: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.161158529721388 (code B ref 46055); Mon, 25 Jan 2021 14:35:01 +0000 Original-Received: (at 46055) by debbugs.gnu.org; 25 Jan 2021 14:34:57 +0000 Original-Received: from localhost ([127.0.0.1]:38351 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l42xF-0005Yu-5w for submit@debbugs.gnu.org; Mon, 25 Jan 2021 09:34:57 -0500 Original-Received: from 1.mo2.mail-out.ovh.net ([46.105.63.121]:37123) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l42xC-0005Yk-2B for 46055@debbugs.gnu.org; Mon, 25 Jan 2021 09:34:55 -0500 Original-Received: from player755.ha.ovh.net (unknown [10.109.138.183]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 63A4B1F93B5 for <46055@debbugs.gnu.org>; Mon, 25 Jan 2021 15:34:52 +0100 (CET) Original-Received: from parouby.fr (91-175-17-70.subs.proxad.net [91.175.17.70]) (Authenticated sender: contact@parouby.fr) by player755.ha.ovh.net (Postfix) with ESMTPSA id B2BF61A73F521; Mon, 25 Jan 2021 14:34:45 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-99G003ae519c25-9193-45c9-a6a6-9a5e7db89e24, 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: 15495478943056803054 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrvdefgdeigecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefrihgvrhhrvgdqtehnthhoihhnvgcutfhouhgshicuoegtohhnthgrtghtsehprghrohhusgihrdhfrheqnecuggftrfgrthhtvghrnhepheelkedukeffgfehkefgvdeiiedtkeeifedvudeiueekhfehkeeiudetjedtiefhnecukfhppedtrddtrddtrddtpdeluddrudejhedrudejrdejtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejheehrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghonhhtrggtthesphgrrhhouhgshidrfhhrpdhrtghpthhtohepgeeitdehheesuggvsggsuhhgshdrghhnuhdrohhrgh 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:198567 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 | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 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..d703183cef 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_entries (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_entries, 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,49 @@ Ruby_functions (FILE *inf) } } + +/* + * Rust support + * Look for: + * - fn: Function + * - struct: Structure + * - enum: Enumeration + * - macro_rules!: Macro + */ +static void +Rust_entries (FILE *inf) +{ + char *cp, *name; + bool is_func = false; + + 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 ((is_func = LOOKING_AT (cp, "fn")) + || LOOKING_AT (cp, "enum") + || LOOKING_AT (cp, "struct") + || (is_func = LOOKING_AT (cp, "macro_rules!"))) + { + cp = skip_spaces (cp); + name = cp; + + while (!notinname (*cp)) + cp++; + + make_tag (name, cp - name, is_func, + lb.buffer, cp - lb.buffer + 1, + lineno, linecharno); + is_func = false; + } + } +} + /* * PHP support -- 2.29.2