 	(remove-text-properties
 	 b (min go-mode-mark-cs-end (point-max)) '(go-mode-cs nil))
 	(setq go-mode-mark-cs-end b)))
+
+    (when (<= b go-mode-mark-string-end)
+      ;; Remove the property adjacent to the change position.
+      ;; It may contain positions pointing beyond the new end mark.
+      (let ((b (let ((cs (get-text-property (max 1 (1- b)) 'go-mode-string)))
+		 (if cs (car cs) b))))
+	(remove-text-properties
+	 b (min go-mode-mark-string-end (point-max)) '(go-mode-string nil))
+	(setq go-mode-mark-string-end b)))
+    (when (<= b go-mode-mark-comment-end)
+      ;; Remove the property adjacent to the change position.
+      ;; It may contain positions pointing beyond the new end mark.
+      (let ((b (let ((cs (get-text-property (max 1 (1- b)) 'go-mode-comment)))
+		 (if cs (car cs) b))))
+	(remove-text-properties
+	 b (min go-mode-mark-string-end (point-max)) '(go-mode-comment nil))
+	(setq go-mode-mark-comment-end b)))
+    
     (when (< b go-mode-mark-nesting-end)
       (remove-text-properties b (min go-mode-mark-nesting-end (point-max)) '(go-mode-nesting nil))
       (setq go-mode-mark-nesting-end b))))

                   (incf indent tab-width))
                  ((?\()
                   (goto-char (car nest))
                   (beginning-of-line)
                   (go-mode-backward-skip-comments)
                   ;; Really just want the token before
                   (when (looking-back "\\<import\\|const\\|var\\|type"
                                       (max (- (point) 7) (point-min)))
                     (incf indent tab-width)
                     (when first

	     (setq pos end)))))
       (setq go-mode-mark-cs-end pos)))))

(defun go-mode-in-comment (&optional pos)
  "Return the comment/string state at point POS.  If point is
inside a comment (including the delimiters), this
returns a pair (START . END) indicating the extents of the
comment or string."

  (unless pos
    (setq pos (point)))
  (when (> pos go-mode-mark-comment-end)
    (go-mode-mark-comment pos))
  (get-text-property pos 'go-mode-comment))

(defun go-mode-mark-comment (end)
  "Mark comments up to point END.  Don't call this directly; use `go-mode-in-comment'."
  (setq end (min end (point-max)))
  (go-mode-parser
   (save-match-data
     (let ((pos
	    ;; Back up to the last known state.
	    (let ((last-comment
		   (and (> go-mode-mark-comment-end 1)
			(get-text-property (1- go-mode-mark-comment-end) 
					   'go-mode-comment))))
	      (if last-comment
		  (car last-comment)
		(max 1 (1- go-mode-mark-comment-end))))))
       (while (< pos end)
	 (goto-char pos)
	 (let ((comment-end			; end of the text property
		(cond
		 ((looking-at "//")
		  (end-of-line)
		  (1+ (point)))
		 ((looking-at "/\\*")
		  (goto-char (+ pos 2))
		  (if (search-forward "*/" (1+ end) t)
		      (point)
		    end)))))
	   (cond
	    (comment-end
	     (put-text-property pos comment-end 'go-mode-comment (cons pos comment-end))
	     (setq pos comment-end))
	    ((re-search-forward "/[/*]" end t)
	     (setq pos (match-beginning 0)))
	    (t
	     (setq pos end)))))
       (setq go-mode-mark-comment-end pos)))))

(defun go-mode-in-string (&optional pos)
  "Return the string state at point POS.  If point is
inside a string (including the delimiters), this
returns a pair (START . END) indicating the extents of the
comment or string."

  (unless pos
    (setq pos (point)))
  (when (> pos go-mode-mark-string-end)
    (go-mode-mark-string pos))
  (get-text-property pos 'go-mode-string))

(defun go-mode-mark-string (end)
  "Mark strings up to point END.  Don't call this
directly; use `go-mode-in-string'."
  (setq end (min end (point-max)))
  (go-mode-parser
   (save-match-data
     (let ((pos
	    ;; Back up to the last known state.
	    (let ((last-cs
		   (and (> go-mode-mark-string-end 1)
			(get-text-property (1- go-mode-mark-string-end) 
					   'go-mode-string))))
	      (if last-cs
		  (car last-cs)
		(max 1 (1- go-mode-mark-string-end))))))
       (while (< pos end)
	 (goto-char pos)
	 (let ((cs-end			; end of the text property
		(cond 
		 ((looking-at "\"")
		  (goto-char (1+ pos))
		  (if (looking-at "[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*\"")
		      (match-end 0)
		    (end-of-line)
		    (point)))
		 ((looking-at "'")
		  (goto-char (1+ pos))
		  (if (looking-at "[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*'")
		      (match-end 0)
		    (end-of-line)
		    (point)))
		 ((looking-at "`")
		  (goto-char (1+ pos))
		  (while (if (search-forward "`" end t)
			     (if (eq (char-after) ?`)
				 (goto-char (1+ (point))))
			   (goto-char end)
			   nil))
		  (point)))))
	   (cond
	    (cs-end
	     (put-text-property pos cs-end 'go-mode-string (cons pos cs-end))
	     (setq pos cs-end))
	    ((re-search-forward "[\"'`]" end t)
	     (setq pos (match-beginning 0)))
	    (t
	     (setq pos end)))))
       (setq go-mode-mark-string-end pos)))))

(defun go-mode-font-lock-cs (limit comment)
  "Helper function for highlighting comment/strings.  If COMMENT is t,
