Creating a new buffer with text using EmacsClient

前端 未结 2 1604
别跟我提以往
别跟我提以往 2021-02-09 12:59

I have a program that can send text to any other program for further analysis (eg sed, grep, etc). I would like it to send the data to Emacs and do analysis there. How would I

2条回答
  •  别跟我提以往
    2021-02-09 13:50

    How about this approach?

    emacsclient -e '
      (progn
        (pop-to-buffer (generate-new-buffer "Piped")) 
        (insert (decode-hex-string "
        '$(perl -e 'print unpack "H*", qq("Hello, World!")'
        )'")))
    '
    

    I've inserted newlines to break up this very long line for display purposes.

    When I run this from a terminal window, a new buffer named Piped opens in my Emacs window, containing the text "Hello, World!" (complete with quotes). When I run it again, another buffer named Piped<2> opens, with the same text.

    The hex-escaping (which can probably be just as easily accomplished with any other high-level language, not just Perl) is for escaping quotes that would otherwise terminate the string constant being fed to (insert).

    This approach feeds text to Emacs via Emacsclient on the command line, so very long input text might give it a problem. A more general solution might be able to break up long input data and feed it to Emacs across several Emacsclient invocations.

提交回复
热议问题