cmd/guru: emacs: interpret byte offsets correctly
Change-Id: Id506c6c0b3f3c585781bfc38df1b665d507a7c33 Reviewed-on: https://go-review.googlesource.com/22019 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
837ce23ea3
commit
3114265539
|
@ -262,10 +262,14 @@ If BUFFER, return the number of characters in that buffer instead."
|
||||||
(string-bytes (buffer-substring (point-min)
|
(string-bytes (buffer-substring (point-min)
|
||||||
(point-max)))))
|
(point-max)))))
|
||||||
|
|
||||||
;; FIXME(dominikh): go-guru--goto-pos-no-file and go-guru--goto-pos
|
(defun go-guru--goto-byte (offset)
|
||||||
;; assume that Guru is giving rune offsets in the columns field.
|
"Go to the OFFSETth byte in the buffer."
|
||||||
;; However, it is giving us byte offsets, causing us to highlight
|
(goto-char (byte-to-position offset)))
|
||||||
;; wrong ranges as soon as there's any multi-byte runes in the line.
|
|
||||||
|
(defun go-guru--goto-byte-column (offset)
|
||||||
|
"Go to the OFFSETth byte in the current line."
|
||||||
|
(goto-char (byte-to-position (+ (position-bytes (point-at-bol)) (1- offset)))))
|
||||||
|
|
||||||
(defun go-guru--goto-pos (posn)
|
(defun go-guru--goto-pos (posn)
|
||||||
"Find the file containing the position POSN (of the form `file:line:col')
|
"Find the file containing the position POSN (of the form `file:line:col')
|
||||||
set the point to it, switching the current buffer."
|
set the point to it, switching the current buffer."
|
||||||
|
@ -273,7 +277,7 @@ set the point to it, switching the current buffer."
|
||||||
(find-file (car file-line-pos))
|
(find-file (car file-line-pos))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(forward-line (1- (string-to-number (cadr file-line-pos))))
|
(forward-line (1- (string-to-number (cadr file-line-pos))))
|
||||||
(forward-char (1- (string-to-number (caddr file-line-pos))))))
|
(go-guru--goto-byte-column (string-to-number (caddr file-line-pos)))))
|
||||||
|
|
||||||
(defun go-guru--goto-pos-no-file (posn)
|
(defun go-guru--goto-pos-no-file (posn)
|
||||||
"Given `file:line:col', go to the line and column. The file
|
"Given `file:line:col', go to the line and column. The file
|
||||||
|
@ -281,7 +285,7 @@ component will be ignored."
|
||||||
(let ((file-line-pos (split-string posn ":")))
|
(let ((file-line-pos (split-string posn ":")))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(forward-line (1- (string-to-number (cadr file-line-pos))))
|
(forward-line (1- (string-to-number (cadr file-line-pos))))
|
||||||
(forward-char (1- (string-to-number (caddr file-line-pos))))))
|
(go-guru--goto-byte-column (string-to-number (caddr file-line-pos)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun go-guru-callees ()
|
(defun go-guru-callees ()
|
||||||
|
@ -477,8 +481,8 @@ end point."
|
||||||
(go-guru--enclosing-unique)))
|
(go-guru--enclosing-unique)))
|
||||||
(block (if (> (length enclosing) 0) (elt enclosing 0))))
|
(block (if (> (length enclosing) 0) (elt enclosing 0))))
|
||||||
(when block
|
(when block
|
||||||
(goto-char (1+ (cdr (assoc 'start block))))
|
(go-guru--goto-byte (1+ (cdr (assoc 'start block))))
|
||||||
(set-mark (1+ (cdr (assoc 'end block))))
|
(set-mark (byte-to-position (1+ (cdr (assoc 'end block)))))
|
||||||
(setq go-guru--last-enclosing (subseq enclosing 1))
|
(setq go-guru--last-enclosing (subseq enclosing 1))
|
||||||
(message "Region: %s" (cdr (assoc 'desc block)))
|
(message "Region: %s" (cdr (assoc 'desc block)))
|
||||||
(setq deactivate-mark nil))))
|
(setq deactivate-mark nil))))
|
||||||
|
|
Loading…
Reference in New Issue