3

If I'm in a term-mode buffer and there is a file path displayed, how would I go about making the path "clickable", opening the file in a new buffer? It doesn't have to be mouse-clickable, in fact I'd prefer a key binding that works when the point is on the file path. Other than the common case of using ls, this function could be used when viewing a log file. Some debug info contains the file path and line number. Something like lib/library.rb:34 for example. Ideally, Emacs could open a new buffer and move the cursor to line 34.

17
  • Although not term-mode, dired-mode offers that feature: gnu.org/software/emacs/manual/html_node/dired-x/… And here is something else that looks even more promising (i.e., find-file-at-point in shell-mode?): snarfed.org/why_i_dont_run_shells_inside_emacs Commented Sep 19, 2014 at 5:23
  • 2
    Xah Lee has written something similar that skips the confirmation: ergoemacs.org/emacs/emacs_open_file_path_fast.html Well, that's the general idea -- variations of find-file-at-point. Commented Sep 19, 2014 at 5:30
  • 1
    @ReedG.Law i think the problem with using my function is that it grabs the :n as part of the file path. That's why it complains file doesn't exist. It's trivial to modify it so the path is grabbed and jump to line number though. Commented Oct 8, 2014 at 8:50
  • 1
    @ReedG.Law i edited the code so now it should do what you want. Commented Oct 8, 2014 at 9:47
  • 1
    @XahLee thank you! It works nicely with relative paths as well. Commented Oct 8, 2014 at 9:54

1 Answer 1

3

The short answer is: don't work against Emacs. Let Emacs work for you.

While you can use find-file-at-point or put together something yourself, you will be much better off running make, grep and other stuff which prints "dir/file:pos" using M-x compile or M-x grep.

  • If you need to interact with your program which prints "dir/file:pos", you can pass a prefix argument to compile and the compilation buffer will be interactive.

  • If you have an arbitrary program whose output starts with "dir/file:pos", e.g., rails server, all you need to do is run it as (grep "rails server").

Sign up to request clarification or add additional context in comments.

7 Comments

Good suggestion, and that's my normal workflow for using ag. But recently I've switched to running Rails and Java applications in multi-terms and I would love it if the debugging info could take me directly to the file and position.
Why are you using term? What is ag?
I just decided to make the switch to using a terminal emulator within Emacs rather than gnome-terminal so I could better integrate my editing workflow. ag is the silver searcher, similar to grep.
So all you need to do is M-x grep and then replace the grep in the command line with ag.
I'm not sure I follow you. My main use case is to be able to quickly open paths in the form of dir/file:pos that are output by web applications run in a multi-term. I'm not sure how using grep relates to that. However, I did just think of a more Emacs-friendly way. Maybe I can pipe the output of rails server to another buffer that runs in a mode that highlights file paths such as dired-mode or ag-mode.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.