Last active
January 27, 2016 16:30
-
-
Save cpaulbond/74862f4d9ce38506d1c5 to your computer and use it in GitHub Desktop.
elisp: Find a filename in a go stack and convert it over to my local environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(global-set-key [f9 ?s] 'gostack-goto) | |
(defun gostack-file () | |
(save-excursion | |
(save-restriction | |
(end-of-line) | |
(let ((eol (point))) | |
(beginning-of-line) | |
(narrow-to-region (point) eol) | |
(if (re-search-forward "in \\(/[^:]+\\):\\([0-9]+\\)" nil t) | |
(list (match-string-no-properties 1) (string-to-number (match-string 2))) | |
nil))))) | |
(defun gostack-fix-file-name (name) | |
(let ((top (getenv "GOPATH")) | |
(prefix "/go/src/")) | |
(if top | |
(if (string= (substring name 0 (length prefix)) prefix) | |
(concat top "/src/" (substring name (length prefix))) | |
name) | |
(message "No value for GOPATH") | |
name))) | |
(defun gostack-goto () | |
(interactive) | |
(let ((location (gostack-file))) | |
(if location | |
(let ((name (gostack-fix-file-name (car location))) | |
(line (cadr location))) | |
;;(message (format "DBG: name=%s line=%d" name line)) | |
(find-file name) | |
(goto-line line)) | |
(message "File name was not found.")))) | |
(provide 'gostack) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment