pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/editors/javascript-mode Added editors/javascript-mode ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/e160d52e9dc5
branches:  trunk
changeset: 568953:e160d52e9dc5
user:      abs <abs%pkgsrc.org@localhost>
date:      Wed Dec 30 12:05:37 2009 +0000

description:
Added editors/javascript-mode version 2.2.1 - addresses PR pkg/35669

Emacs major mode for Javascript programming language.

The main features of this JavaScript mode are syntactic highlighting
(enabled with `font-lock-mode' or `global-font-lock-mode'), automatic
indentation and filling of comments.

diffstat:

 editors/javascript-mode/DESCR               |    5 +
 editors/javascript-mode/Makefile            |   38 +
 editors/javascript-mode/PLIST               |    3 +
 editors/javascript-mode/distinfo            |    5 +
 editors/javascript-mode/files/javascript.el |  699 ++++++++++++++++++++++++++++
 5 files changed, 750 insertions(+), 0 deletions(-)

diffs (truncated from 770 to 300 lines):

diff -r e60677b30ce9 -r e160d52e9dc5 editors/javascript-mode/DESCR
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/editors/javascript-mode/DESCR     Wed Dec 30 12:05:37 2009 +0000
@@ -0,0 +1,5 @@
+Emacs major mode for Javascript programming language.
+
+The main features of this JavaScript mode are syntactic highlighting
+(enabled with `font-lock-mode' or `global-font-lock-mode'), automatic
+indentation and filling of comments.
diff -r e60677b30ce9 -r e160d52e9dc5 editors/javascript-mode/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/editors/javascript-mode/Makefile  Wed Dec 30 12:05:37 2009 +0000
@@ -0,0 +1,38 @@
+# $NetBSD: Makefile,v 1.1.1.1 2009/12/30 12:05:37 abs Exp $
+
+DISTNAME=      javascript-2.2.1
+PKGNAME=       ${EMACS_PKGNAME_PREFIX}${DISTNAME:S/-/-mode-/}
+CATEGORIES=    devel editors
+MASTER_SITES=  #
+DISTFILES=     #
+
+MAINTAINER=    vle%gmx.net@localhost
+HOMEPAGE=      http://www.brgeight.se/
+COMMENT=       Javascript major mode for Emacs
+
+PKG_DESTDIR_SUPPORT=   user-destdir
+
+INSTALLATION_DIRS=     ${EMACS_LISPPREFIX}
+
+NO_CONFIGURE=          yes
+
+LICENSE=               gnu-gpl-v2
+
+SRC=                   javascript.el
+
+WRKSRC=                        ${WRKDIR}
+
+do-build:
+       set -e; \
+       cd ${WRKDIR}; cp ${.CURDIR}/files/${SRC} .; \
+       ${EMACS_BIN} --no-init-file --no-site-file -batch \
+               -f batch-byte-compile ${SRC}
+
+do-install:
+       set -e; \
+       cd ${WRKDIR}; \
+       ${INSTALL_DATA} ${SRC} ${SRC:.el=.elc} \
+               ${DESTDIR}${EMACS_LISPPREFIX}
+
+.include "../../editors/emacs/modules.mk"
+.include "../../mk/bsd.pkg.mk"
diff -r e60677b30ce9 -r e160d52e9dc5 editors/javascript-mode/PLIST
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/editors/javascript-mode/PLIST     Wed Dec 30 12:05:37 2009 +0000
@@ -0,0 +1,3 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2009/12/30 12:05:37 abs Exp $
+${EMACS_LISPPREFIX}/javascript.el
+${EMACS_LISPPREFIX}/javascript.elc
diff -r e60677b30ce9 -r e160d52e9dc5 editors/javascript-mode/distinfo
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/editors/javascript-mode/distinfo  Wed Dec 30 12:05:37 2009 +0000
@@ -0,0 +1,5 @@
+$NetBSD: distinfo,v 1.1.1.1 2009/12/30 12:05:37 abs Exp $
+
+SHA1 (javascript-2.1b1.el) = da39a3ee5e6b4b0d3255bfef95601890afd80709
+RMD160 (javascript-2.1b1.el) = 9c1185a5c5e9fc54612808977ee8f548b2258d31
+Size (javascript-2.1b1.el) = 23633 bytes
diff -r e60677b30ce9 -r e160d52e9dc5 editors/javascript-mode/files/javascript.el
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/editors/javascript-mode/files/javascript.el       Wed Dec 30 12:05:37 2009 +0000
@@ -0,0 +1,699 @@
+;;; javascript.el --- Major mode for editing JavaScript source text
+
+;; Copyright (C) 2008 Free Software Foundation, Inc.
+
+;; Author: Karl Landstrom <karl.landstrom%brgeight.se@localhost>
+;; Maintainer: Karl Landstrom <karl.landstrom%brgeight.se@localhost>
+;; Version: 2.2.1
+;; Date: 2008-12-27
+;; Keywords: languages, oop
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+;;
+;; The main features of this JavaScript mode are syntactic
+;; highlighting (enabled with `font-lock-mode' or
+;; `global-font-lock-mode'), automatic indentation and filling of
+;; comments.
+;;
+;; This package has (only) been tested with GNU Emacs 21.4 (the latest
+;; stable release).
+;;
+;; Installation:
+;;
+;; Put this file in a directory where Emacs can find it (`C-h v
+;; load-path' for more info). Then add the following lines to your
+;; Emacs initialization file:
+;; 
+;;    (add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
+;;    (autoload 'javascript-mode "javascript" nil t)
+;;    
+;; General Remarks:
+;; 
+;; This mode assumes that block comments are not nested inside block
+;; comments and that strings do not contain line breaks.
+;; 
+;; Exported names start with "javascript-" whereas private names start
+;; with "js-".
+;; 
+;; Changes:
+;;
+;; See javascript.el.changelog.
+
+;;; Code:
+
+(require 'cc-mode)
+(require 'font-lock)
+(require 'newcomment)
+
+(defgroup javascript nil 
+  "Customization variables for `javascript-mode'."
+  :tag "JavaScript"
+  :group 'languages)
+
+(defcustom javascript-indent-level 4
+  "Number of spaces for each indentation step."
+  :type 'integer
+  :group 'javascript)
+
+(defcustom javascript-expr-indent-offset 0
+  "Number of additional spaces used for indentation of continued
+expressions. The value must be no less than minus
+`javascript-indent-level'."
+  :type 'integer
+  :group 'javascript)
+
+(defcustom javascript-auto-indent-flag t
+  "Automatic indentation with punctuation characters. If non-nil, the
+current line is indented when certain punctuations are inserted."
+  :type 'boolean
+  :group 'javascript)
+
+
+;; --- Keymap ---
+
+(defvar javascript-mode-map nil 
+  "Keymap used in JavaScript mode.")
+
+(unless javascript-mode-map 
+  (setq javascript-mode-map (make-sparse-keymap)))
+
+(when javascript-auto-indent-flag
+  (mapc (lambda (key) 
+         (define-key javascript-mode-map key 'javascript-insert-and-indent))
+       '("{" "}" "(" ")" ":" ";" ",")))
+
+(defun javascript-insert-and-indent (key)
+  "Run command bound to key and indent current line. Runs the command
+bound to KEY in the global keymap and indents the current line."
+  (interactive (list (this-command-keys)))
+  (call-interactively (lookup-key (current-global-map) key))
+  (indent-according-to-mode))
+
+
+;; --- Syntax Table And Parsing ---
+
+(defvar javascript-mode-syntax-table
+  (let ((table (make-syntax-table)))
+    (c-populate-syntax-table table)
+    (modify-syntax-entry ?$ "_" table)
+    table)
+  "Syntax table used in JavaScript mode.")
+
+(defvar js-ident-as-word-syntax-table
+  (let ((table (copy-syntax-table javascript-mode-syntax-table)))
+    (modify-syntax-entry ?$ "w" table)
+    (modify-syntax-entry ?_ "w" table)
+    table)
+  "Alternative syntax table used internally to simplify detection
+  of identifiers and keywords and its boundaries.")
+
+
+(defun js-re-search-forward-inner (regexp &optional bound count)
+  "Auxiliary function for `js-re-search-forward'."
+  (let ((parse)
+        (saved-point (point-min)))
+    (while (> count 0)
+      (re-search-forward regexp bound)
+      (setq parse (parse-partial-sexp saved-point (point)))
+      (cond ((nth 3 parse)
+             (re-search-forward 
+              (concat "\\([^\\]\\|^\\)" (string (nth 3 parse))) 
+              (save-excursion (end-of-line) (point)) t))
+            ((nth 7 parse)
+             (forward-line))
+            ((or (nth 4 parse)
+                 (and (eq (char-before) ?\/) (eq (char-after) ?\*)))
+             (re-search-forward "\\*/"))
+            (t
+             (setq count (1- count))))
+      (setq saved-point (point))))
+  (point))
+
+
+(defun js-re-search-forward (regexp &optional bound noerror count)
+  "Search forward but ignore strings and comments. Invokes
+`re-search-forward' but treats the buffer as if strings and
+comments have been removed."
+  (let ((saved-point (point))
+        (search-expr 
+         (cond ((null count)
+                '(js-re-search-forward-inner regexp bound 1))
+               ((< count 0)
+                '(js-re-search-backward-inner regexp bound (- count)))
+               ((> count 0)
+                '(js-re-search-forward-inner regexp bound count)))))
+    (condition-case err
+        (eval search-expr)
+      (search-failed
+       (goto-char saved-point)
+       (unless noerror
+         (error (error-message-string err)))))))
+
+
+(defun js-re-search-backward-inner (regexp &optional bound count)
+  "Auxiliary function for `js-re-search-backward'."
+  (let ((parse)
+        (saved-point (point-min)))
+    (while (> count 0)
+      (re-search-backward regexp bound)
+      (when (and (> (point) (point-min))
+                 (save-excursion (backward-char) (looking-at "/[/*]")))
+        (backward-char))
+      (setq parse (parse-partial-sexp saved-point (point)))
+      (cond ((nth 3 parse)
+             (re-search-backward
+              (concat "\\([^\\]\\|^\\)" (string (nth 3 parse))) 
+              (save-excursion (beginning-of-line) (point)) t))
+            ((nth 7 parse) 
+             (goto-char (nth 8 parse)))
+            ((or (nth 4 parse)
+                 (and (eq (char-before) ?/) (eq (char-after) ?*)))
+             (re-search-backward "/\\*"))
+            (t
+             (setq count (1- count))))))
+  (point))
+
+
+(defun js-re-search-backward (regexp &optional bound noerror count)
+  "Search backward but ignore strings and comments. Invokes
+`re-search-backward' but treats the buffer as if strings and
+comments have been removed."
+  (let ((saved-point (point))
+        (search-expr 
+         (cond ((null count)
+                '(js-re-search-backward-inner regexp bound 1))
+               ((< count 0)
+                '(js-re-search-forward-inner regexp bound (- count)))
+               ((> count 0)
+                '(js-re-search-backward-inner regexp bound count)))))
+    (condition-case err
+        (eval search-expr)
+      (search-failed
+       (goto-char saved-point)
+       (unless noerror
+         (error (error-message-string err)))))))
+
+
+;; --- Font Lock ---
+
+(defun js-inside-param-list-p ()
+  "Return non-nil if point is inside a function parameter list."
+  (condition-case err
+      (save-excursion
+       (up-list -1)
+       (and (looking-at "(")
+            (progn (backward-word 1)
+                   (or (looking-at "function")
+                       (progn (backward-word 1) (looking-at "function"))))))
+    (error nil)))
+
+
+(defconst js-function-heading-1-re 
+  "^[ \t]*function[ \t]+\\(\\w+\\)"
+  "Regular expression matching the start of a function header.")
+



Home | Main Index | Thread Index | Old Index