Emacs - Support for Perl embedded in GNU Emacs
perlmacs -w -MEmacs -e main -- --display :0.0 file.txt #! /usr/bin/perlmacs use Emacs; use Emacs::Lisp; setq { $mail_self_blind = t; }; exit main ($0, "-q", @ARGV);
This module replaces STDIN, STDOUT, STDERR, %ENV, and %SIG with versions that work safely within an Emacs session. It also defines a function named main, which launches an Emacs editing session from within a script.
STDIN
STDOUT
STDERR
%ENV
%SIG
When you use Emacs in a perlmacs script, a Perl sub named main may be used to invoke the Emacs editor. This makes it possible to put customization code, which would normally appear as Lisp in ~/.emacs, into a Perl script. For example, this startup code
use Emacs
main
(setq user-mail-address "gnaeus@perl.moc" mail-self-blind t mail-yank-prefix "> " ) (put 'eval-expression 'disabled nil) (global-font-lock-mode 1 t) (set-face-background 'highlight "maroon") (set-face-background 'region "Sienna")
could be placed in a file with the following contents:
#! /usr/local/bin/perlmacs use Emacs; use Emacs::Lisp; setq { $user_mail_address = 'gnaeus@perl.moc'; $mail_self_blind = t; $mail_yank_prefix = '> '; $eval_expression{\*disabled} = undef; }; &global_font_lock_mode(1, t); &set_face_background(\*highlight, "maroon"); &set_face_background(\*region, "Sienna"); exit main($0, "-q", @ARGV);
When you wanted to run Emacs, you would invoke this program.
The arguments to main correspond to the argv of the main function in a C program. The first argument should be the program's invocation name, as in this example. -q inhibits running ~/.emacs (which is the point, after all).
argv
Reading a line from Perl's STDIN filehandle causes a string to be read from the minibuffer with the prompt "Enter input: ". To show a different prompt, use:
"Enter input: "
use Emacs::Lisp; $string = &read_string ("Prompt: ");
Printing to Perl's STDOUT filehandle inserts text into the current buffer as though typed, unless you have changed the Lisp variable standard-output to do something different.
standard-output
Perl's warn operator and STDERR filehandle are redirected to the minibuffer.
warn
Access to %ENV is redirected to the Lisp variable process-environment.
process-environment
Setting signal handlers is not currently permitted under Emacs.
Problems with `main'.
The main sub may open an X display and not close it. That is the most obvious of many problems with main.
The thing is, Emacs was not written with the expectation of being embedded in another program, least of all a language interpreter such as Perl. Therefore, when Emacs is told to exit, it believes the process is really about to exit, and it neglects to tidy up after itself.
For best results, the value returned by main should be passed to Perl's exit soon, as in this code:
exit
exit (main($0, @args));
Copyright (C) 1998,1999,2000 by John Tobey, jtobey@john-edwin-tobey.org. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
perl, Emacs::Lisp, emacs.
To install Emacs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Emacs
CPAN shell
perl -MCPAN -e shell install Emacs
For more information on module installation, please visit the detailed CPAN module installation guide.