From 07965a3978b656cabc38cbac52fde1ed17dd8332 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 7 Dec 2009 09:43:47 +0000 Subject: [PATCH] dot/emacs, el/dot-emacs.el: Add support for the Go programming language. Interesting and worth playing with. --- dot/emacs | 4 +++- el/dot-emacs.el | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/dot/emacs b/dot/emacs index 480abd1..aa206cf 100644 --- a/dot/emacs +++ b/dot/emacs @@ -447,6 +447,7 @@ ("\\.m$" . objc-mode) ("\\.mxd$" . c-mode) ("\\.cs$" . csharp-mode) + ("\\.go$" . go-mode) ("\\.org$" . org-mode) ;; ("/[ch]/" . c-mode) (,(concat "/\\(" @@ -492,7 +493,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 + 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 @@ -563,6 +564,7 @@ (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) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index e4e7f8d..7bb8214 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -742,8 +742,7 @@ doesn't match any of the regular expressions in `(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 @@ doesn't match any of the regular expressions in (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 @@ -1289,6 +1290,39 @@ doesn't match any of the regular expressions in "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. ;; Make Awk indentation nice. -- 2.11.0