all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Deniz Dogan <deniz.a.m.dogan@gmail.com>
To: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Patch for etags.c adding JavaScript support
Date: Thu, 21 May 2009 23:24:00 +0200	[thread overview]
Message-ID: <7b501d5c0905211424g5b78d8cevd507adb0fa552d25@mail.gmail.com> (raw)

[-- 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)
  *

                 reply	other threads:[~2009-05-21 21:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7b501d5c0905211424g5b78d8cevd507adb0fa552d25@mail.gmail.com \
    --to=deniz.a.m.dogan@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.