[Courses] [Perl] Part 1: Getting Started
Avery Ke
avery at u.washington.edu
Wed Apr 6 02:59:22 EST 2005
Is anyone else wanting to try out the perl code in the lessons from
emacs? I wanted to try out script in perl as I was reviwing it in the
lesson, without having to save to separate file. After googling around
for a bit (keywords: compile perl emacs), I found what I wanted at:
http://www.phyast.pitt.edu/~tanc/scripts/.emacs.html
If you put the following in your .emacs file, you can highlight a
portion of perl script and send it to perl. I added the last lines
(add-hook 'cperl-mode hook) so it would work in both perl-mode and
cperl-mode.
;; ------------------------------------------------------------------
;; Perl mode
;; from http://www.phyast.pitt.edu/~tanc/scripts/.emacs.html
;; ------------------------------------------------------------------
;; sburke at netadventure.net
(defun perl-eval ()
"Run selected region as Perl code"
(interactive)
(shell-command-on-region (mark) (point) "perl ")
)
(add-hook 'perl-mode-hook
'(lambda ()
(local-set-key "\M-p" 'perl-eval)
))
(add-hook 'cperl-mode-hook
'(lambda ()
(local-set-key "\M-p" 'perl-eval)
))
;; ------------------------------------------------------------------
To send the whole buffer to perl, I found the following at:
http://lists.gnu.org/archive/html/help-gnu-emacs/2003-08/msg00114.html
;; -------------------------------------------------------------------
;;Compilation mode for perl files
;;http://lists.gnu.org/archive/html/help-gnu-emacs/2003-08/msg00114.html
;; -------------------------------------------------------------------
(require 'compile)
(add-to-list 'compilation-error-regexp-alist '(".* \\([-a-zA-Z._/]+\\) line
\\([0-9]+\\)." 1 2))
(defun perl-compile (&optional prefix)
"Compile perl file"
(interactive "P")
(let* ((include-path (if (eq window-system 'w32) "-I%SP%" "-I$SP"))
(compile-command (concat "perl "include-path " -cw "
(buffer-file-name)))
(compilation-read-command prefix))
(call-interactively 'compile)))
(require 'perl-mode)
(require 'cperl-mode)
(define-key perl-mode-map "\C-c\C-c" 'perl-compile)
(define-key cperl-mode-map "\C-c\C-c" 'perl-compile)
;; ------------------------------------------------------------------
There is also mode-compile-el at:
http://www.tls.cena.fr/~boubaker/Emacs/
I downloaded mode-compile.el, but got some error messages when I tried to
byte-compile-file in Emacs. So I'm using the work-arounds above, which
work fine for my needs right now.
Avery
More information about the Courses
mailing list