brian42miller has asked for the wisdom of the Perl Monks concerning the following question:

I realize that this is not really a Perl question, but does anyone know a way (from Perl) to get an existing session of Emacs to load a file (or do anything for that matter)? Thanks in advance Brian

Replies are listed 'Best First'.
Re: perl interface to emacs
by duelafn (Parson) on Apr 07, 2011 at 21:05 UTC

    Add

    (server-start)

    To your .emacs file. Then,

    system "emacsclient", "--no-wait", $file;

    See also Emacs::Run?

    Good Day,
        Dean

      Thanks for the help, that works great, exactly what I was hoping for. I hate to ask, but is there a way to do the same thing with xemacs? Thanks Again Brian

        I should have looked myself, seeing that you got me on the right track.

        (load "gnuserv") (gnuserv-start)

        then use the gnuclient comment.

        Thanks anyways, Brian
Re: perl interface to emacs
by chrestomanci (Priest) on Apr 07, 2011 at 21:03 UTC

    Not a perl question, but seeing as the monastery has many helpful monks, I can see why you asked.

    I don't know the answer, but in short you need to find a way of signalling to an existing emacs process that it needs to load a new file. There is probably a command line option to emacs that tells it to look for an existing emacs process, and then use some sort of private IPC to get the existing process to load the file. The new emacs process will then quit. There might be an alternative binary for the purpose, as there is with GIMP under windows.

    In short you need to read the docs, and use google.

    Once you figure out the command line, it is a simple matter to invoke it from perl with system

    As a side note, does anyone know how to achieve the same with Padre?

Re: perl interface to emacs
by Anonymous Monk on Apr 08, 2011 at 16:09 UTC
    If the emacs session is running with a the server started you can run something like 'emacsclient --eval '(message "Hello World!")'´.
Re: perl interface to emacs
by Anonymous Monk on Apr 07, 2011 at 20:29 UTC
    I realize that this is not really a Perl question

    Who is more likely to know the answer, perlmonks, emacs support forum, or google?