chiark / gitweb /
dot/emacs, el/dot-emacs.el: Add support for the Go programming language.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 7 Dec 2009 09:43:47 +0000 (09:43 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 7 Dec 2009 09:43:47 +0000 (09:43 +0000)
Interesting and worth playing with.

dot/emacs
el/dot-emacs.el

index 480abd116fba4cc21a0870c4742995b7ae67d719..aa206cf3d6bc9e0997a4aaee491989b04d428133 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
                ("\\.m$" . objc-mode)
                ("\\.mxd$" . c-mode)
                ("\\.cs$" . csharp-mode)
+               ("\\.go$" . go-mode)
                ("\\.org$" . org-mode)
                ;; ("/[ch]/" . c-mode)
                (,(concat "/\\("
        '(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
+         tcl-mode-hook go-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 'c++-mode-hook 'mdw-fontify-c-and-c++ t)
   (add-hook 'linux-c-mode-hook #'(lambda () (setq c-basic-offset 8)))
   (add-hook 'asm-mode-hook 'mdw-fontify-asm t)
+  (add-hook 'go-mode-hook 'mdw-fontify-go t)
 
   (add-hook 'icon-mode-hook 'mdw-fontify-icon t)
 
index e4e7f8d499ba82ab206b3630b9a51a5271da5615..7bb8214b8455555ff642836fefc0e24ed68e0dca 100644 (file)
@@ -742,8 +742,7 @@ (defmacro mdw-define-face (name &rest body)
   `(progn
      (make-face ',name)
      (defvar ,name ',name)
-     (put ',name 'face-defface-spec ',body)
-     ))
+     (put ',name 'face-defface-spec ',body)))
 
 (mdw-define-face default
   (((type w32)) :family "courier new" :height 85)
@@ -798,6 +797,8 @@ (mdw-define-face font-lock-constant-face
   (t :slant italic))
 (mdw-define-face font-lock-builtin-face
   (t :weight bold))
+(mdw-define-face font-lock-type-face
+  (t :weight bold :slant italic))
 (mdw-define-face font-lock-reference-face
   (t :weight bold))
 (mdw-define-face font-lock-variable-name-face
@@ -1288,6 +1289,39 @@ (defun mdw-fontify-csharp ()
 (define-derived-mode csharp-mode java-mode "C#"
   "Major mode for editing C# code.")
 
+;;;--------------------------------------------------------------------------
+;;; Go programming configuration.
+
+(defun mdw-fontify-go ()
+
+  (make-local-variable 'font-lock-keywords)
+  (let ((go-keywords
+        (mdw-regexps "break" "case" "chan" "const" "continue"
+                     "default" "defer" "else" "fallthrough" "for"
+                     "func" "go" "goto" "if" "import"
+                     "interface" "map" "package" "range" "return"
+                     "select" "struct" "switch" "type" "var")))
+
+    (setq font-lock-keywords
+         (list
+
+          ;; Handle the keywords defined above.
+          (list (concat "\\<\\(" go-keywords "\\)\\>")
+                '(0 font-lock-keyword-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]+\\|\\)\\)")
+                '(0 mdw-number-face))
+
+          ;; And anything else is punctuation.
+          (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
+                '(0 mdw-punct-face))))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Awk programming configuration.