summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-04-09 12:28:27 -0400
committerRui Ueyama <ruiu@google.com>2014-04-09 12:28:27 -0400
commit702c2c55c71768fc6287e3459cc7fc2cb6efe68b (patch)
tree6d7c4d9f0f6bd59ee7f50ccea2c3e9b3251a33b7 /misc
parent6e9fab94c41d4cbc45daca6951b0ef917235afd0 (diff)
downloadgo-702c2c55c71768fc6287e3459cc7fc2cb6efe68b.tar.gz
misc/emacs: ignore backquote in comment or string
go-mode on Emacs 23 wrongly recognizes a backquote in a comment or a string as a start of a raw string literal. Below is an example that go-mode does not work well. This patch is to fix that issue. // ` var x = 1 // ` LGTM=dominik.honnef R=golang-codereviews, dominik.honnef, adonovan CC=golang-codereviews https://codereview.appspot.com/84900043 Committer: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'misc')
-rw-r--r--misc/emacs/go-mode.el14
1 files changed, 13 insertions, 1 deletions
diff --git a/misc/emacs/go-mode.el b/misc/emacs/go-mode.el
index 29b1fa442..6333ff966 100644
--- a/misc/emacs/go-mode.el
+++ b/misc/emacs/go-mode.el
@@ -294,7 +294,7 @@ For mode=set, all covered lines will have this weight."
(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.
- '(("\\(`\\)\\([^`]*\\)\\(`\\)"
+ '((go--match-raw-string-literal
(1 (7 . ?`))
(2 (15 . nil)) ;; 15 = "generic string"
(3 (7 . ?`)))))
@@ -367,6 +367,18 @@ STOP-AT-STRING is not true, over strings."
(- (point-max)
(point-min))))
+(defun go--match-raw-string-literal (end)
+ "Search for a raw string literal. Set point to the end of the
+occurence found on success. Returns nil on failure."
+ (when (search-forward "`" end t)
+ (goto-char (match-beginning 0))
+ (if (go-in-string-or-comment-p)
+ (progn (goto-char (match-end 0))
+ (go--match-raw-string-literal end))
+ (when (looking-at "\\(`\\)\\([^`]*\\)\\(`\\)")
+ (goto-char (match-end 0))
+ t))))
+
(defun go-previous-line-has-dangling-op-p ()
"Returns non-nil if the current line is a continuation line."
(let* ((cur-line (line-number-at-pos))