Skip to content

Instantly share code, notes, and snippets.

@cpaulbond
Last active January 27, 2016 16:30
Show Gist options
  • Save cpaulbond/74862f4d9ce38506d1c5 to your computer and use it in GitHub Desktop.
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.
(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