diff options
author | Rui Ueyama <ruiu@google.com> | 2014-03-27 15:22:52 -0400 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2014-03-27 15:22:52 -0400 |
commit | 688c7d359f266abb881a9432b9bec9954f7960af (patch) | |
tree | 3c9e1809fc3df22272a5258e296c9d679be84c34 | |
parent | ae4f3f0533575577bc2fdb02a15f0ab65bb47c81 (diff) | |
download | go-688c7d359f266abb881a9432b9bec9954f7960af.tar.gz |
misc/emacs: handle backslash in raw string in Emacs 23
Go-mode in Emacs 23 does not recognize a backslash followed
by a backquote as end of raw string literal, as it does not
support syntax-propertize-function which Go-mode uses to
remove special meaning from backslashes in ``.
This patch provides a fallback mechanism to do the same thing
using font-lock-syntactic-keywords, which is supported by
Emacs 23.
LGTM=dominik.honnef
R=golang-codereviews, dominik.honnef
CC=adonovan, golang-codereviews
https://codereview.appspot.com/78730048
Committer: Alan Donovan <adonovan@google.com>
-rw-r--r-- | misc/emacs/go-mode.el | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/misc/emacs/go-mode.el b/misc/emacs/go-mode.el index c55d83ac6..a536a17d2 100644 --- a/misc/emacs/go-mode.el +++ b/misc/emacs/go-mode.el @@ -272,6 +272,7 @@ For mode=set, all covered lines will have this weight." `((,go-func-meth-regexp 2 font-lock-function-name-face))) ;; method name `( + ("\\(`[^`]*`\\)" 1 font-lock-multiline) ;; raw string literal, needed for font-lock-syntactic-keywords (,(concat (go--regexp-enclose-in-symbol "type") "[[:space:]]+\\([^[:space:]]+\\)") 1 font-lock-type-face) ;; types (,(concat (go--regexp-enclose-in-symbol "type") "[[:space:]]+" go-identifier-regexp "[[:space:]]*" go-type-name-regexp) 1 font-lock-type-face) ;; types (,(concat "[^[:word:][:multibyte:]]\\[\\([[:digit:]]+\\|\\.\\.\\.\\)?\\]" go-type-name-regexp) 2 font-lock-type-face) ;; Arrays/slices @@ -290,6 +291,14 @@ For mode=set, all covered lines will have this weight." (,(concat "^[[:space:]]*\\(" go-label-regexp "\\)[[:space:]]*:\\(\\S.\\|$\\)") 1 font-lock-constant-face) ;; Labels and compound literal fields (,(concat (go--regexp-enclose-in-symbol "\\(goto\\|break\\|continue\\)") "[[:space:]]*\\(" go-label-regexp "\\)") 2 font-lock-constant-face)))) ;; labels in goto/break/continue +(defconst go--font-lock-syntactic-keywords + ;; Override syntax property of raw string literal contents, so that + ;; backslashes have no special meaning in ``. Used in Emacs 23 or older. + '(("\\(`\\)\\([^`]*\\)\\(`\\)" + (1 (7 . ?`)) + (2 (15 . nil)) ;; 15 = "generic string" + (3 (7 . ?`))))) + (defvar go-mode-map (let ((m (make-sparse-keymap))) (define-key m "}" #'go-mode-insert-and-indent) @@ -564,7 +573,10 @@ recommended that you look at goflymake (set (make-local-variable 'parse-sexp-lookup-properties) t) (if (boundp 'syntax-propertize-function) - (set (make-local-variable 'syntax-propertize-function) #'go-propertize-syntax)) + (set (make-local-variable 'syntax-propertize-function) #'go-propertize-syntax) + (set (make-local-variable 'font-lock-syntactic-keywords) + go--font-lock-syntactic-keywords) + (set (make-local-variable 'font-lock-multiline) t)) (set (make-local-variable 'go-dangling-cache) (make-hash-table :test 'eql)) (add-hook 'before-change-functions (lambda (x y) (setq go-dangling-cache (make-hash-table :test 'eql))) t t) |