racer-rust / emacs-racer

Racer support for Emacs
399 stars 48 forks source link

Open definition in new window #92

Open dineshadepu opened 6 years ago

dineshadepu commented 6 years ago

Thanks for the awesome package.

Is there any function which will open the definition in new window.

Thank you.

4lex1v commented 6 years ago

I'm fairly sure that my approach is pretty dumb and buggy, but seems to be working:

  (defun racer-find-definition-other-window ()
    "Run the racer find-definition command and process the results in other window."
    (interactive)
    (-if-let (match (--first (s-starts-with? "MATCH" it)
                             (racer--call-at-point "find-definition")))
        (-let [(_name line col file _matchtype _ctx)
               (s-split-up-to "," (s-chop-prefix "MATCH " match) 5)]
          (if (fboundp 'xref-push-marker-stack)
              (xref-push-marker-stack)
            (with-no-warnings
              (ring-insert find-tag-marker-ring (point-marker))))
          (switch-to-buffer-other-window file)
          (save-selected-window
            (racer--find-file file (string-to-number line) (string-to-number col))))
      (error "No definition found")))

I guess there's a better way to do it, extracting the common part or using the optional argument

dineshadepu commented 6 years ago

Thanks @4lex1v ! It worked just perfect.

dineshadepu commented 6 years ago

Hi @4lex1v , When I invoke open in new window, it will open the definition in new window. But after I close that file, I have another file opened with same name but empty.