From 61d632068158706b1c3740f0c0a5a8e27244602d Mon Sep 17 00:00:00 2001 Message-Id: <61d632068158706b1c3740f0c0a5a8e27244602d.1717832213.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 3 Dec 2011 14:12:18 +0000 Subject: [PATCH] dot/emacs, el/dot-emacs.el: Javascript support Organization: Straylight/Edgeware From: Mark Wooding --- dot/emacs | 3 ++- el/dot-emacs.el | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/dot/emacs b/dot/emacs index 5c5c697..80f0cb5 100644 --- a/dot/emacs +++ b/dot/emacs @@ -556,7 +556,7 @@ '(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 @@ -643,6 +643,7 @@ (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) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 4712dc9..82ff4b3 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -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. -- [mdw]