Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Perl code directly in Emacs

Tags:

emacs

perl

On the Emacs on the pc's in school we can use 'F5' to run a selected piece of perl code. However, when im trying to do this at home it fails. I have installed Emacs and Activeperl on my windows7 machine.

Whenever i try to run a piece of code i get the error 'F5 is undefined'. However, when i look into the .Emacs file i see that the F5 function key is correctly binded to the function perl-eval. This afternoon it worked by putting (defalias 'perl-mode 'cperl-mode) in my .Emacs file, but when i tried to write code this evening i received again the error 'f5 is undefined'.

Anyone who can help me with this subject? I know i can run my perl code with the cmd tool, but it's much easier when i can run directly from my Emacs :).

like image 402
Najdo Avatar asked Oct 02 '10 21:10

Najdo


People also ask

How do I run a Perl script in a shell script?

Run the "perl" command with the Perl script included in the command line. For example, enter the following command line in a shell window: /home/herong$ perl -e "print 'Hello world! ';" Hello world!

How do I debug Perl in Emacs?

If you have perl installed on your computer, you may debug a perl script by simply typing "alt-x perldb" "perl -d myscript.pl". Once the command is entered, you will see 2 buffers in Emacs, the top buffer is the debugger, the bottom buffer is your perl script.


2 Answers

It looks like your .emacs is valid, but it could be in the wrong place.

To check where .emacs should be do:

M-x getenv RET HOME RET

Which should show something like: (windows xp)

C:\Documents and Settings\YourName\Application Data\

(or windows7)

C:\Users\YourName\Application Data\

If it is the same location as .emacs then add a debug message to the end of your .emacs file. e.g.

(message " >------------< This is the one >------------< ") 

And restart Emacs and look in the *messages* buffer.

If it's showing the debug message, the key binding should be available, check it with C-h k F5

Let us know the outcome of these tests.

like image 144
ocodo Avatar answered Sep 25 '22 05:09

ocodo


You can do C-h k F5 in both Emacs instances. It will tell you to which command the key F5 is bound, so you can see the difference. To bind the key on your local computer after you know what to call, use something like:

(add-hook 'perl-mode-hook '(lambda () (local-set-key  [f7] 'compile)))
like image 29
fschmitt Avatar answered Sep 23 '22 05:09

fschmitt