Begin main content

Piping to an emacs buffer with emacsclient

GNU Emacs buffs will know all about emacsclient - it's a commandline program that allows you to open files in a new buffer in an already running emacs instance. It's very handy. What you may not know is you can also evaluate arbitrary Emacs lisp using emacsclient. Using this fact and based on an existing example from EmacsWiki I have written a perl script that you can pipe to, and the piped data will appear in a buffer via emacsclient.

My ultimate aim is for a PAGER script to use instead of less in my emacs shell. While this isn't quite perfect for that use, it's still pretty useful.

NB: The code below is probably out of date by the time you read this - see this gist for the latest version that you can clone, fork etc.



my$emacsclient = "/usr/local/bin/emacsclient";

# This script uses emacsclient, be sure to have a running server session.
# A server-session can be started by "M-x server-start".
exit 1
    if 0 != system("$emacsclient -n --eval '(progn (pop-to-buffer (get-buffer-create \"*piped*\")))'");

my$s = IO::Select->new;

while (1)
    # block until data available
my$data = <STDIN>;

    # exit if STDIN closed

    # keep reading while data is available, or we have a bunch of lines
my$lines = 0;
    $data .= <STDIN>
        while$lines++ < 100 && $s->can_read(.5);

    $data =~ s/"/\\"/g;
    $data =~ s/'/'\\''/g;
    $data =~ s/\\/\\\\/g;
    system(qq{$emacsclient -n --eval '(with-current-buffer "*piped*" (goto-char (point-max)) (insert "}
            . $data . qq{"))'});

06:23 PM, 02 Mar 2011 by Mark Aufflick Permalink

One more escape

Just needs to escape backslashes too, $data =~ s/\\/\\\\/g;

by Unregistered Visitor on 03/03/11

Good point

I was thinking it's not necessary since the shell single quote doesn't treat backslashes specially, but of course the emacs lisp double quoted string will. I've updated the main post accordingly.

by Mark Aufflick on 03/06/11

Note I've updated the gist

So it now works for file paths as arguments too, since some commands assume the PAGER can do that.

by Unregistered Visitor on 03/04/14

Nice post

Guar protein offer a wide selection of products for your specific requirements. Established in the year 2008, we are one of the leading Manufacturer, Exporter and Supplier of Compound Guar Protein Meal Feeds and Poultry Feeds.
Guar meal exporter india and Organic Poultry feed

by Unregistered Visitor on 09/17/14

Cash advance the financial terms and conditions

Who can apply for instant cash loans must meet certain PoundsBucket criteria in order to retrieve loans. you must be 18 years old, United States citizens must pay the current employment a month should be more than 1000 USD. MoneyWorth financial access to obtain in advance an active bank account. If you have an CheapestQuickLoans emergency expense, these borrowers will apply. for these reasons, often medical bills, mortgage payments, auto repair bills, etc. Cash advance the financial qualification course It is to apply and immediate cash to qualify for funding, it is very easy to do, the only thing you can write a simple application form: this form, your social CashPaydayLoansNoCreditCheck security number, will be evidence of a new pay stub information with a copy of your payment history, birth, LowInterestLoansOnline current address and fill out the employment and driver's license number.

by Unregistered Visitor on 09/20/14

The difference between

The difference between an unsecured debt and secured payday loans direct lenders debt To understand the requirements of the safety margin, and the no guarantor loans main difference between an unsecured debt is now old-fashioned, low-risk mortgage debt and so are loans, equity loans payday loan no credit check unsecured debt, and therefore creditors. on behalf of debt repayment in the case of these loans without warranties payday loans no credit check associated with the high level of risk. risk rate is reflected in the very interest liabilities and risks associated with low level short term loans uk security, unsecured debt if the interest rate is low compared with most unsecured debt loans against car without much higher.

by Unregistered Visitor on 09/21/14

If you are

If you are a creditor payment plan a little more affordable price, may be able to extend such property development loans and low interest rates negotiations, which is to change the mortgage and car forex software are not a lot of time, but you can get the following monthly installments, probably. In addition, a comprehensive forex trading platforms from the federal government, according to the lender's student loan scheme / or income, family size, and a government, you asset based lending can reduce monthly payments by payday loans for people on benefits student loans, you may want to pay for the program.In addition, the public sector, there is payday loans no credit check the case of federal student loan forgiveness loan needs.

by Unregistered Visitor on 09/26/14


All of our products come in a discreet package so that no one will even know what is on your front doorstep. sparxx rx

by Unregistered Visitor on 10/02/14

because they

because they offer a 24x7 fast loans warm welcome to hard-to-get loans could not be found. the unexpected economic problems are cropping up in their own lives, this way people with a debit card, you can remove their entire quick loans financial crisis. but, on the other hand, do not have a debit card at these people is the lack of a debit card loans because they are not allowed to fill in the form and do not want to be max fast loans faced with financial disaster without help. In this way, the situation of these disadvantaged people are nervous and worried about. but it is not the emergence of a loans has A months of the debit quick loans card debit card holder to perform a miracle for those individuals. so, the magic blew a breath you dead swift instant loans by the taste lives on loan. It's up to you if you do not have a debit card as soon as you find the financial instant loans help is very rare, but a 24x7 text loans is your debit card a debit card Flash not claimed solved the financial crisis, of all and sundry. lack of a debit card at any rate you can get you the loan amount you must have if you txt loans have a lack of standards, you can't think of obtaining financial aid letters. in this way, people who 24x7 loans for people on benefits have a debit card eligibility loans for people on benefits helpless Palace is a top priority 24x8 payday loans no credit check in the lives of people in need. all payday loans no credit check that you own such an

by Unregistered Visitor on 10/14/14

Add comment