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

pop-tag-mark doesn't return if haskell-mode-find-def succeeds #1311

Closed
henrylaxen opened this issue May 2, 2016 · 4 comments
Closed

pop-tag-mark doesn't return if haskell-mode-find-def succeeds #1311

henrylaxen opened this issue May 2, 2016 · 4 comments

Comments

@henrylaxen
Copy link

When I am in haskell-mode, and type M-. to find the source of the definition under point, and the definition under point is in a different file, I get the following error message in the Messages buffer:

error: "Marker points into wrong buffer", #<marker at 15335 in Snaplet.hs>

(defun haskell-mode-jump-to-def-or-tag (&optional _next-p)
  ;; FIXME NEXT-P arg is not used
  "Jump to the definition.
Jump to definition of identifier at point by consulting GHCi, or
tag table as fallback.

Remember: If GHCi is busy doing something, this will delay, but
it will always be accurate, in contrast to tags, which always
work but are not always accurate.
If the definition or tag is found, the location from which you jumped
will be pushed onto `xref--marker-ring', so you can return to that
position with `xref-pop-marker-stack'."
  (interactive "P")
  (let ((initial-loc (point-marker))
        (loc (haskell-mode-find-def (haskell-ident-at-point))))
    (if loc
        (haskell-mode-handle-generic-loc loc)
      (call-interactively 'haskell-mode-tag-find))
    (unless (equal initial-loc (point-marker))
      (save-excursion
        (goto-char initial-loc)
        (xref-push-marker-stack)))))

This behaviour does NOT occur if haskell-mode-find-def fails and haskell-mode-tag-find is called and succeeds. I instrumented haskell-mode-jump-to-def-or-tag and found that the error happens at the (goto-char initial-loc) line in the code, hence the (xref-push-marker-stack) line isn't executed. However if haskell-mode-tag-find succeeds, the the previous location is indeed pushed (inside of haskell-mode-tag-find somewhere) so M-* (pop-tag-mark) works correctly. I hope this is helpful.
Best wishes,
Henry Laxen

@fice-t
Copy link
Contributor

fice-t commented May 2, 2016

There should be a (set-buffer (marker-buffer initial-loc)) above the goto-char.

@gracjan 25.1's xref-push-marker-stack allows for an optional marker argument which would mean there's no need for the save-excursion + goto-char:

(defun xref-push-marker-stack (&optional m)
  "Add point M (defaults to `point-marker') to the marker stack."
  (ring-insert xref--marker-ring (or m (point-marker))))

Also, if haskell-mode-tag-find already pushes a marker, then should the unless block run after it?

@gracjan
Copy link
Contributor

gracjan commented May 3, 2016

There was something fishy with xref-push-marker-stack in Emacs 25-snapshot, that is was it looks so strange.

Yes, it should be fixed.

@fice-t
Copy link
Contributor

fice-t commented May 7, 2016

@henrylaxen Should be fixed now. Please report back if something's still wrong.

@gracjan Ah, xref.el does mention that the API is unstable. Hopefully that won't cause issues in the future.

@gracjan
Copy link
Contributor

gracjan commented May 7, 2016

@fice-t, we will fix it again if this happens. Would be great to have a test case for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants