chiark / gitweb /
dot/emacs, el/dot-emacs.el: Javascript support
authorMark Wooding <mdw@distorted.org.uk>
Sat, 3 Dec 2011 14:12:18 +0000 (14:12 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 3 Dec 2011 14:12:58 +0000 (14:12 +0000)
dot/emacs
el/dot-emacs.el

index 5c5c69795ae0dffd39b9e3ee21d8aeb2eb56c0a2..80f0cb51b431c39a1e28a26da85fd30b26b30d53 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
        '(c-mode-hook c++-mode-hook objc-mode-hook java-mode-hook
          csharp-mode-hook perl-mode-hook cperl-mode-hook
          python-mode-hook pyrec-mode-hook icon-mode-hook awk-mode-hook
-         tcl-mode-hook go-mode-hook
+         tcl-mode-hook go-mode-hook js-mode-hook
          asm-mode-hook TeX-mode-hook LaTeX-mode-hook
          TeXinfo-mode-hook tex-mode-hook latex-mode-hook
          texinfo-mode-hook emacs-lisp-mode-hook scheme-mode-hook
   (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t)
 
   (add-hook 'java-mode-hook 'mdw-fontify-java t)
+  (add-hook 'js-mode-hook 'mdw-fontify-javascript t)
   (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
 
   (add-hook 'awk-mode-hook 'mdw-fontify-awk t)
index 4712dc94d7d0aba0426b29ce4a7e55cf63a9f186..82ff4b3548cd884ad40c9d0afe2434d96311250a 100644 (file)
@@ -1340,6 +1340,66 @@ (defun mdw-fontify-java ()
 
   (mdw-post-config-mode-hack))
 
+;;;--------------------------------------------------------------------------
+;;; Javascript programming configuration.
+
+(defun mdw-javascript-style ()
+  (setq js-indent-level 2)
+  (setq js-expr-indent-offset 0))
+
+(defun mdw-fontify-javascript ()
+
+  ;; Other stuff.
+  (mdw-javascript-style)
+  (setq js-auto-indent-flag t)
+
+  ;; Now define things to be fontified.
+  (make-local-variable 'font-lock-keywords)
+  (let ((javascript-keywords
+        (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
+                     "char" "class" "const" "continue" "debugger" "default"
+                     "delete" "do" "double" "else" "enum" "export" "extends"
+                     "final" "finally" "float" "for" "function" "goto" "if"
+                     "implements" "import" "in" "instanceof" "int"
+                     "interface" "let" "long" "native" "new" "package"
+                     "private" "protected" "public" "return" "short"
+                     "static" "super" "switch" "synchronized" "throw"
+                     "throws" "transient" "try" "typeof" "var" "void"
+                     "volatile" "while" "with" "yield"
+
+                     "boolean" "byte" "char" "double" "float" "int" "long"
+                     "short" "void"))
+       (javascript-constants
+        (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
+                     "arguments" "this")))
+
+    (setq font-lock-keywords
+         (list
+
+          ;; Handle the keywords defined above.
+          (list (concat "\\<\\(" javascript-keywords "\\)\\>")
+                '(0 font-lock-keyword-face))
+
+          ;; Handle the predefined constants defined above.
+          (list (concat "\\<\\(" javascript-constants "\\)\\>")
+                '(0 font-lock-variable-name-face))
+
+          ;; Handle numbers too.
+          ;;
+          ;; The following isn't quite right, but it's close enough.
+          (list (concat "\\<\\("
+                        "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
+                        "[0-9]+\\(\\.[0-9]*\\|\\)"
+                        "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
+                        "[lLfFdD]?")
+                '(0 mdw-number-face))
+
+          ;; And anything else is punctuation.
+          (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
+                '(0 mdw-punct-face)))))
+
+  (mdw-post-config-mode-hack))
+
 ;;;--------------------------------------------------------------------------
 ;;; C# programming configuration.