* Patch for etags.c adding JavaScript support
@ 2009-05-21 21:24 Deniz Dogan
0 siblings, 0 replies; only message in thread
From: Deniz Dogan @ 2009-05-21 21:24 UTC (permalink / raw)
To: Emacs-Devel devel
[-- Attachment #1: Type: text/plain, Size: 564 bytes --]
Hi
I found that etags doesn't support JavaScript syntax yet, so I used
the little knowledge of C that I have and hacked this patch together.
If I'm not mistaken Emacs is now in feature-freeze, but I thought I'd
just send this here anyways, since someone would probably still have
to fix up my code.
This is also a bit special since it not only recognizes ordinary
function declarations[1] but also assignments of otherwise anonymous
functions[2].
I hope someone finds use for this.
[1] function hello() { ... }
[2] var hello = function () { ... }
Deniz Dogan
[-- Attachment #2: etags-javascript.diff --]
[-- Type: application/octet-stream, Size: 2270 bytes --]
--- etags-old.c 2009-05-21 22:20:11.000000000 +0200
+++ etags.c 2009-05-21 23:11:57.000000000 +0200
@@ -381,6 +381,7 @@
static void Forth_words __P((FILE *));
static void Fortran_functions __P((FILE *));
static void HTML_labels __P((FILE *));
+static void JavaScript_functions __P((FILE *));
static void Lisp_functions __P((FILE *));
static void Lua_functions __P((FILE *));
static void Makefile_targets __P((FILE *));
@@ -701,6 +702,11 @@
argument of any expression that starts with `(def' in column zero\n\
is a tag.";
+static char *JavaScript_suffixes [] =
+ { "js", NULL };
+static char JavaScript_help [] =
+"In JavaScript, all functions are tags.";
+
static char *Lua_suffixes [] =
{ "lua", "LUA", NULL };
static char Lua_help [] =
@@ -833,6 +839,7 @@
{ "forth", Forth_help, Forth_words, Forth_suffixes },
{ "fortran", Fortran_help, Fortran_functions, Fortran_suffixes },
{ "html", HTML_help, HTML_labels, HTML_suffixes },
+ { "javascript", JavaScript_help, JavaScript_functions, JavaScript_suffixes },
{ "java", Cjava_help, Cjava_entries, Cjava_suffixes },
{ "lisp", Lisp_help, Lisp_functions, Lisp_suffixes },
{ "lua", Lua_help, Lua_functions, Lua_suffixes },
@@ -4644,6 +4651,46 @@
\f
/*
+ * JavaScript language parsing
+ * Original code by Deniz Dogan (2009)
+ *
+ * Finds ordinary function declarations and functions assigned to
+ * variables.
+ */
+static void
+JavaScript_functions (inf)
+ FILE *inf;
+{
+ register char *bp, *found;
+
+ LOOP_ON_INPUT_LINES (inf, lb, bp)
+ {
+ bp = skip_spaces (bp);
+
+ // Find ordinary functions.
+ if (LOOKING_AT (bp, "function")) {
+ bp = skip_spaces (bp);
+ if (begtoken (bp)) {
+ get_tag (bp, NULL);
+ }
+ }
+
+ // Find functions assigned to variables.
+ if (LOOKING_AT (bp, "var")) {
+ found = bp;
+ while (*bp != ';' && *bp != '=')
+ bp++;
+ if (*bp++ == '=') {
+ bp = skip_spaces (bp);
+ if (LOOKING_AT (bp, "function"))
+ get_tag(bp, NULL);
+ }
+ }
+ }
+}
+
+\f
+/*
* Pascal parsing
* Original code by Mosur K. Mohan (1989)
*
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-05-21 21:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-21 21:24 Patch for etags.c adding JavaScript support Deniz Dogan
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.