<?xml version="1.0" encoding="windows-1252"?>
<node id="399171" title="Re: (OT) emacs perl tweaks -- help sought w/ emacs lisp" created="2004-10-14 08:13:28" updated="2005-06-03 11:51:18">
<type id="11">
note</type>
<author id="5094">
stefan k</author>
<data>
<field name="doctext">
Hi,&lt;br&gt;
first, as I posted before, although I really appreciate when someone writes code in elisp (even if it were just for the fun in it ;-) I suggest using the function &lt;code&gt;cperl-check-syntax&lt;/code&gt; which invokes &lt;code&gt;mode-compile&lt;/code&gt; which is quite clever.  One gain would be that you can jump to errors found my that process directly.  Another gain would be the customizability of &lt;code&gt;mode-compile&lt;/code&gt;.  There is one variable called &lt;code&gt;mode-compile-other-frame-p&lt;/code&gt; which could be used to achieve your first goal in a way: simply let it use a different frame (known as "window" to all other users ;-) and hide that frame somewhere on your desktop where it won't get in your way.
&lt;p&gt;
Another possibility might be to use one of the hooks run before and after running &lt;code&gt;mode-compile&lt;/code&gt; but after looking at the code I can't find an obvious way.
&lt;p&gt;
As to your second question you're probably interested in using the emacs-feature where you can pass a region or a buffer to a shell command and replace the region/buffer with the result of that command.  This can also be used for sorting lines for example.
&lt;p&gt;
This call would look like this:
&lt;code&gt;
C-x h C-u M-| perltidy
&lt;/code&gt;
Here &lt;code&gt;C-x h&lt;/code&gt; should mark the whole buffer, the prefix argument &lt;code&gt;C-u&lt;/code&gt; enables the replacement of the region and finally &lt;code&gt;M-|&lt;/code&gt; calls the function &lt;code&gt;shell-command-on-region&lt;/code&gt; which asks for the command to use.  Unfortunately I don't have perltidy at hand to test it.
&lt;p&gt;
Putting all this into a single function which can be bound to a key would be like:
&lt;code&gt;
(defun my-perltidy ()
  "Call perltidy on the current buffer.
This replaces the current content of the buffer with the output of the
perltidy programm.  You must have perltidy installed.

See http://perlmonks.org/?node_id=399154 for the start of this."
  (interactive)
  (when (yes-or-no-p "Really run perltidy? ")
	(goto-char (point-min))
	(shell-command-on-region (point-min)
							 (point-max)
							 "perltidy"
							 nil
							 t)))
&lt;/code&gt;

And then:
&lt;code&gt;
(add-hook 'cperl-mode-hook
          '(lambda ()
             (local-set-key '[(control c) (control t)] 'my-perltidy)))
&lt;/code&gt;
or something like that.
&lt;p&gt;
Please note, that I use XEmacs, but this code should be usable on both emacsen, I guess
&lt;p&gt;
&lt;b&gt;Update Thu Oct 14 14:15:41 CEST 2004:&lt;/b&gt; Added note on emacs-version
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-5094"&gt;
&lt;p&gt;
&lt;table width="80%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td&gt;&lt;small&gt;Regards...&lt;/small&gt;&lt;/td&gt;
&lt;td align="right"&gt;&lt;small&gt;
&lt;a href="http://www.skamphausen.de"&gt;Stefan&lt;/a&gt;
&lt;/small&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="2" align="center"&gt;
&lt;small&gt;you begin bashing the string with a +42 regexp of confusion&lt;/small&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
399154</field>
<field name="parent_node">
399154</field>
</data>
</node>
