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.
1 Answer
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 tocompileand 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").
7 Comments
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.term? What is ag?gnome-terminal so I could better integrate my editing workflow. ag is the silver searcher, similar to grep.M-x grep and then replace the grep in the command line with ag.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.
term-mode,dired-modeoffers 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-pointinshell-mode?): snarfed.org/why_i_dont_run_shells_inside_emacs