emacs, dot-emacs: Icon fontification support.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 14 Jul 2009 13:16:42 +0000 (14:16 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 18 Jul 2009 15:16:00 +0000 (16:16 +0100)
Icon is a cool language.  It seems a shame not to support it.

dot-emacs.el
emacs

index 0d27f52..f687acb 100644 (file)
@@ -1414,6 +1414,67 @@ strip numbers instead."
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
                 '(0 mdw-punct-face))))))
 
+;;;----- Icon programming style ---------------------------------------------
+
+;; --- Icon indentation style ---
+
+(setq icon-brace-offset 0
+      icon-continued-brace-offset 0
+      icon-continued-statement-offset 2
+      icon-indent-level 2)
+
+;; --- Define Icon fontification style ---
+
+(defun mdw-fontify-icon ()
+
+  ;; --- Miscellaneous fiddling ---
+
+  (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
+
+  ;; --- Now define fontification things ---
+
+  (make-local-variable 'font-lock-keywords)
+  (let ((icon-keywords
+        (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
+                     "end" "every" "fail" "global" "if" "initial"
+                     "invocable" "link" "local" "next" "not" "of"
+                     "procedure" "record" "repeat" "return" "static"
+                     "suspend" "then" "to" "until" "while"))
+       (preprocessor-keywords
+        (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
+                     "include" "line" "undef")))
+    (setq font-lock-keywords
+         (list
+
+          ;; --- Set up the keywords defined above ---
+
+          (list (concat "\\<\\(" icon-keywords "\\)\\>")
+                '(0 font-lock-keyword-face))
+
+          ;; --- The things that Icon calls keywords ---
+
+          (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
+
+          ;; --- At least numbers are simpler than C ---
+
+          (list (concat "\\<[0-9]+"
+                        "\\([rR][0-9a-zA-Z]+\\|"
+                        "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
+                        "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
+                '(0 mdw-number-face))
+
+          ;; --- Preprocessor ---
+
+          (list (concat "^[ \t]*$[ \t]*\\<\\("
+                        preprocessor-keywords
+                        "\\)\\>")
+                '(0 font-lock-keyword-face))
+
+          ;; --- And anything else is punctuation ---
+
+          (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
+                '(0 mdw-punct-face))))))
+
 ;;;----- ARM assembler programming configuration ----------------------------
 
 ;; --- There doesn't appear to be an Emacs mode for this yet ---
diff --git a/emacs b/emacs
index 14d9b1e..07adea8 100644 (file)
--- a/emacs
+++ b/emacs
 (mapcar (lambda (hook) (add-hook hook 'mdw-misc-mode-config))
        '(c-mode-hook c++-mode-hook objc-mode-hook java-mode-hook
          csharp-mode-hook perl-mode-hook cperl-mode-hook
-         python-mode-hook awk-mode-hook tcl-mode-hook
+         python-mode-hook icon-mode-hook awk-mode-hook tcl-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 'linux-c-mode-hook #'(lambda () (setq c-basic-offset 8)))
 (add-hook 'asm-mode-hook 'mdw-fontify-asm t)
 
+(add-hook 'icon-mode-hook 'mdw-fontify-icon t)
+
 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t)