chiark / gitweb /
dot/emacs, el/dot-emacs.el: Introduce support for Scala.
authorMark Wooding <mwooding@good.com>
Thu, 20 Feb 2014 15:26:24 +0000 (15:26 +0000)
committerMark Wooding <mwooding@good.com>
Thu, 20 Feb 2014 15:48:53 +0000 (15:48 +0000)
dot/emacs
el/dot-emacs.el

index f039bab552cdb3fced9e3f248ad31d8d64aca50c..4e28726524813baea66af9594640c86243aaeb49 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
        tcl-mode-hook go-mode-hook js-mode-hook javascript-mode-hook
        conf-mode-hook m4-mode-hook autoconf-mode-hook autotest-mode-hook
        a68-mode-hook a68-mode-hooks asm-mode-hook fsharp-mode-hook
-       TeX-mode-hook LaTeX-mode-hook
+       scala-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
        lisp-mode-hook lisp-interaction-mode-hook makefile-mode-hook
index a463c10a88af35bcfffec71b7edffcda8d4d7789..f8141dce8ae6770e265aeb4068d2f89c1203182d 100644 (file)
@@ -1490,6 +1490,78 @@ (defun mdw-fontify-javascript ()
 
   (mdw-post-config-mode-hack))
 
+;;;--------------------------------------------------------------------------
+;;; Scala programming configuration.
+
+(defun mdw-fontify-scala ()
+
+  ;; Define things to be fontified.
+  (make-local-variable 'font-lock-keywords)
+  (let ((scala-keywords
+        (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
+                     "extends" "final" "finally" "for" "forSome" "if"
+                     "implicit" "import" "lazy" "match" "new" "object"
+                     "override" "package" "protected" "return" "sealed"
+                     "super" "this" "throw" "trait" "try" "type" "val"
+                     "var" "while" "with" "yield"))
+       (scala-constants
+        (mdw-regexps "false" "null" "true"))
+       (punctuation "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"))
+
+    (setq font-lock-keywords
+         (list
+
+          ;; Magical identifiers between backticks.
+          (list (concat "`\\([^`]+\\)`")
+                '(1 font-lock-variable-name-face))
+
+          ;; Handle the keywords defined above.
+          (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
+                '(0 font-lock-keyword-face))
+
+          ;; Handle the constants defined above.
+          (list (concat "\\_<\\(" scala-constants "\\)\\_>")
+                '(0 font-lock-variable-name-face))
+
+          ;; Magical identifiers between backticks.
+          (list (concat "`\\([^`]+\\)`")
+                '(1 font-lock-variable-name-face))
+
+          ;; Handle numbers too.
+          ;;
+          ;; As usual, not quite right.
+          (list (concat "\\_<\\("
+                        "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
+                        "[0-9]+\\(\\.[0-9]*\\|\\)"
+                        "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
+                        "[lLfFdD]?")
+                '(0 mdw-number-face))
+
+          ;; Identifiers with trailing operators.
+          (list (concat "_\\(" punctuation "\\)+")
+                '(0 mdw-trivial-face))
+
+          ;; And everything else is punctuation.
+          (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
+                '(0 mdw-punct-face)))
+
+         font-lock-syntactic-keywords
+         (list
+
+          ;; Single quotes around characters.  But not when used to quote
+          ;; symbol names.  Ugh.
+          (list (concat "\\('\\)"
+                        "\\(" "."
+                        "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
+                              "u+" "[0-9a-fA-F]\\{4\\}"
+                        "\\|" "\\\\" "[0-7]\\{1,3\\}"
+                        "\\|" "\\\\" "." "\\)"
+                        "\\('\\)")
+                '(1 "\"")
+                '(4 "\"")))))
+
+  (mdw-post-config-mode-hack))
+
 ;;;--------------------------------------------------------------------------
 ;;; C# programming configuration.