Run Perl Code Directly in Emacs

In Emacs, on a computer at school, we can use “F5” to run the selected piece of perl code. However, when I try to do this at home, it fails. I installed Emacs and Activeperl on my Windows7 computer.

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

Who can help me in this matter? I know that I can run my perl code with the cmd tool, but it is much easier when I can run directly from my Emacs :).

+5
source share
3 answers

It looks like yours is .emacsvalid, but may be in the wrong place.

To check where it should be executed .emacs:

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 this is the same place as .emacs, add a debug message to the end of your file .emacs. eg.

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

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

If it shows a debug message, key binding should be available, check it with C-h k F5

Let us know the results of these tests.

+3

C-h k F5 Emacs. , F5, . , , , - :

(add-hook 'perl-mode-hook '(lambda () (local-set-key  [f7] 'compile)))
+2

In the .emacs file

(defun perl-eval () "Run selected region as Perl code" (interactive)
   (shell-command-on-region (mark) (point) "perl"))
(global-set-key (kbd "<f5>") 'perl-eval)
+2
source

All Articles