Commit 58ce655f authored by Dominik Honnef's avatar Dominik Honnef Committed by Alan Donovan

misc/emacs: Add godef-jump-other-window

This will behave like similar "*-other-window" functions in Emacs.

Default key bind is C-x 4 C-c C-j – while awkward, it follows both
the convention for other-window functions and the convention for
not using user- or emacs-reserved keys.

R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/10707045
parent b913cf84
...@@ -193,6 +193,7 @@ ...@@ -193,6 +193,7 @@
(define-key m "=" 'go-mode-insert-and-indent) (define-key m "=" 'go-mode-insert-and-indent)
(define-key m (kbd "C-c C-a") 'go-import-add) (define-key m (kbd "C-c C-a") 'go-import-add)
(define-key m (kbd "C-c C-j") 'godef-jump) (define-key m (kbd "C-c C-j") 'godef-jump)
(define-key m (kbd "C-x 4 C-c C-j") 'godef-jump-other-window)
(define-key m (kbd "C-c C-d") 'godef-describe) (define-key m (kbd "C-c C-d") 'godef-describe)
m) m)
"Keymap used by Go mode to implement electric keys.") "Keymap used by Go mode to implement electric keys.")
...@@ -870,7 +871,7 @@ will be commented, otherwise they will be removed completely." ...@@ -870,7 +871,7 @@ will be commented, otherwise they will be removed completely."
(message "Removed %d imports" (length lines))) (message "Removed %d imports" (length lines)))
(if flymake-state (flymake-mode-on))))) (if flymake-state (flymake-mode-on)))))
(defun godef--find-file-line-column (specifier) (defun godef--find-file-line-column (specifier other-window)
"Given a file name in the format of `filename:line:column', "Given a file name in the format of `filename:line:column',
visit FILENAME and go to line LINE and column COLUMN." visit FILENAME and go to line LINE and column COLUMN."
(if (not (string-match "\\(.+\\):\\([0-9]+\\):\\([0-9]+\\)" specifier)) (if (not (string-match "\\(.+\\):\\([0-9]+\\):\\([0-9]+\\)" specifier))
...@@ -878,7 +879,7 @@ visit FILENAME and go to line LINE and column COLUMN." ...@@ -878,7 +879,7 @@ visit FILENAME and go to line LINE and column COLUMN."
(let ((filename (match-string 1 specifier)) (let ((filename (match-string 1 specifier))
(line (string-to-number (match-string 2 specifier))) (line (string-to-number (match-string 2 specifier)))
(column (string-to-number (match-string 3 specifier)))) (column (string-to-number (match-string 3 specifier))))
(with-current-buffer (find-file filename) (with-current-buffer (funcall (if other-window 'find-file-other-window 'find-file) filename)
(goto-char (point-min)) (goto-char (point-min))
(forward-line (1- line)) (forward-line (1- line))
(beginning-of-line) (beginning-of-line)
...@@ -910,7 +911,7 @@ description at POINT." ...@@ -910,7 +911,7 @@ description at POINT."
(message "%s" description))) (message "%s" description)))
(file-error (message "Could not run godef binary")))) (file-error (message "Could not run godef binary"))))
(defun godef-jump (point) (defun godef-jump (point &optional other-window)
"Jump to the definition of the expression at POINT." "Jump to the definition of the expression at POINT."
(interactive "d") (interactive "d")
(condition-case nil (condition-case nil
...@@ -924,7 +925,11 @@ description at POINT." ...@@ -924,7 +925,11 @@ description at POINT."
(message "%s" file)) (message "%s" file))
(t (t
(push-mark) (push-mark)
(godef--find-file-line-column file)))) (godef--find-file-line-column file other-window))))
(file-error (message "Could not run godef binary")))) (file-error (message "Could not run godef binary"))))
(defun godef-jump-other-window (point)
(interactive "d")
(godef-jump point t))
(provide 'go-mode) (provide 'go-mode)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment