tags:

views:

94

answers:

3

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 :).

+2  A: 

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)))
fschmitt
I allready tried C-h k F5, but then it also say 'F5 is undefined'. But if i look in my .Emacs file i see the following command: '(global-set-key (kbd "<f5>") 'perl-eval)'
Najdo
This is rather strange, because this looks perfectly legal. Are you sure your .emacs is loaded? By the way: You write .Emacs, however it has to be named .emacs (no capital e), this might be a cause of error. Do in Emacs C-x f ~/.emacs and make sure it loads the correct file.
fschmitt
As you can see, the correct answer has been given. But thank you for your help.
Najdo
A: 

In your .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)
+3  A: 

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.

slomojo
Thank you :). Indeed, the .emacs file must be in the C:\Users\Name\Application Data\Roaming, now the file is loaded and i can run perl-code with the F5 key. They really should put this in the README file because the original .emacs was in c:\emacs\. You sir are a life saver ;).
Najdo
There's just not that many Emacs users running Windows, and even less running Windows7, and those that are, aren't updatng the Emacs README, or EmacsWiki.org. - Thankfully you can get a lot of Emacs help here on SO.
slomojo