Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add go-guru-definition-other-window #176

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions go-guru.el
Expand Up @@ -319,11 +319,11 @@ If BUFFER, return the number of characters in that buffer instead."
"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 other-window)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is passing function better than passing flag value ? If its argument is function, we can pass other find-file function like find-function-other-frame etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dominikh what's your opinion?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now: KISS.

"Find the file containing the position POSN (of the form `file:line:col')
set the point to it, switching the current buffer."
(let ((file-line-pos (split-string posn ":")))
(find-file (car file-line-pos))
(funcall (if other-window #'find-file-other-window #'find-file) (car file-line-pos))
(goto-char (point-min))
(forward-line (1- (string-to-number (cadr file-line-pos))))
(go-guru--goto-byte-column (string-to-number (cl-caddr file-line-pos)))))
Expand Down Expand Up @@ -359,7 +359,7 @@ function containing the current point."
(go-guru--start "callstack"))

;;;###autoload
(defun go-guru-definition ()
(defun go-guru-definition (&optional other-window)
"Jump to the definition of the selected identifier."
(interactive)
(or buffer-file-name
Expand All @@ -368,9 +368,15 @@ function containing the current point."
(desc (cdr (assoc 'desc res))))
(push-mark)
(ring-insert find-tag-marker-ring (point-marker))
(go-guru--goto-pos (cdr (assoc 'objpos res)))
(go-guru--goto-pos (cdr (assoc 'objpos res)) other-window)
(message "%s" desc)))

;;;###autoload
(defun go-guru-definition-other-window ()
"Jump to the defintion of the selected identifier in another window"
(interactive)
(go-guru-definition t))

;;;###autoload
(defun go-guru-describe ()
"Describe the selected syntax, its kind, type and methods."
Expand Down