0

C-u M-| is wonderful for things like running sort a region. But I've wandered into an interesting place. I wan to run join or comm on two regions in a buffer.

# region 1
a 1
b 2
z 26

# region 2
a foobar
b 2
c 3

and I want join -j1 <(region 1) <(region 2).

I think registers or secondary selection could make this easier than the albeit already quick

  # select region 1
  M-| cat > /tmp/r1
  # select region 2
  M-| cat > /tmp/r2
  # position cursor below
  M-| join -j1 /tmp/r[12]

I don't see anything about referencing registers or selections in shell-command-on-region but maybe there is a similar command, universal argument, or package? Would it be outrageous to point to files through /proc or a la elfuse

(Edit: example output -- current buffer)

# region 1
a 1
b 2
z 26

# region 2
a foobar
b 2
c 3

# join -j1 /tmp/r[12]
a 1 foobar
b 2 2

# comm -12 /tmp/r[12]
b 2

  • 1
    This cries for a simple elisp function that merely automates the steps in your example. Are you interested in elisp based solutions? In fact, even a macro may be possible, I admit there would be a tricky part with handling the temporary files, but if you dedicate a directory to it you could just use fixed names, like you already do in the example. – q.undertow Jun 12 at 18:08
  • What @q.undertow said: define a keyboard macro or an Elisp command. – Drew Jun 12 at 18:29
  • Library zones.el might be able to help with the joining, depending on what you mean; dunno. – Drew Jun 12 at 18:30
  • Could you show explicitly what you want the result of your operation to be, given the original buffer text you show? – Drew Jun 12 at 18:31
  • @Drew, sorry for the confusion. I am using this buffer line an org-babel notebook. I'd run the commands on buffer selections and get the output below it. I start with the original posted buffer, and end with the final output buffer. I added the # comment lines to indicate what happened (as I do in my notes) – Will Jun 29 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.