Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to make an indirect control for Emacs (in Ubuntu Linux) so that I can swipe some text in an xterm with the cursor, cutting it into the X cut buffer, then run a macro in Emacs to parse the cut buffer text to look for text saying "line XXXX" where X is all digits, then go to that line in the current Emacs buffer.

I think this is possible by using emacsclient to get emacs to run a macro, then the macro parsing the cut buffer, then issuing a goto-line command to the number that's been parsed.

My problem is I don't know how to write the emacs script to read the X cut buffer and parse it.. I've been going through cookbook examples but none seem to fit.

My goal is to ease development. When I have an error/information/status message printed in an xterm, I want to swipe the error message which says something like "syntax error on line 2776" then press a keyboard shortcut which Ubuntu will interpret to launch emacsclient, which causes my already-open Emacs to grab that text, parse it, and go to the line number I just swiped. Only this last step of parsing is the hard part.

(Yes, I know you can run a shell INSIDE of emacs, but this is doesn't fit my workflow)

How would I make emacs look at that X cut buffer and parse out the line number and issue the "goto-line" command to the current buffer?


share|improve this question
up vote 1 down vote accepted

(x-get-selection) is an elisp function that returns the current X11 selected text.

Also, the standard way to get an error message and use it in emacs to be able to jump directly to the specified file/line is to run M-x compile, or use a command that customizes compilation mode. emacs already recognizes gcc, g++, and many other programs' output. With M-x compile emacs automatically generates clickable links for the error messages that it recognizes, and with newer emacs versions they respond to left click, rather then defaulting to middle-click.

share|improve this answer

If you can parse the output with some other utility to get the filename and line number, you can easily open that file with the cursor on the specified line by doing:


This should cause emacsclient to take the nearest buffer and replace it with FILE_NAME at LINE_NUMBER.

share|improve this answer
I like this idea.. do the parsing in a little Perl one-liner or something. Emacs is clearly powerful enough to do this, but it may be easier to use the launcher to parse. Now to figure out how to get the X cut buffer in Perl... – BobBanana Jan 18 '10 at 17:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.