Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

(OT) emacs perl tweaks -- help sought w/ emacs lisp

by water (Deacon)
on Oct 14, 2004 at 10:32 UTC ( #399154=perlquestion: print w/ replies, xml ) Need Help??
water has asked for the wisdom of the Perl Monks concerning the following question:

After finding no help via google, I figured I'd ask two perl Emacs questions here, even tho they're more about E than P, as I figure some monk may have solved them already. I don't yet know lisp, that's the root issue here. Sorry for the OT post, and thanks for any ideas --

water

  1. InfiniteLoop posted a snippet (check syntax of perl code and pod in emacs) which binds a perl syntax check into Emacs save.
    Asking again: could an elisp-proficient person suggest how I might change InfiniteLoop's fine tweak so that the perlsyn buffer only comes up where there is an error (rather than if everything is OK) on a save?
  2. Could an elisp-proficient person suggest how I might bind 'perltidy' to some key, such that control-whatever would tidy the current buffer?
many many many thanks

Comment on (OT) emacs perl tweaks -- help sought w/ emacs lisp
Re: (OT) emacs perl tweaks -- help sought w/ emacs lisp
by EverLast (Scribe) on Oct 14, 2004 at 11:07 UTC
    Ad (1):

    This is done already in the original post.

    Ad (2):

    (define-key global-map "\C-q" 'myperl-check-syntax)
    Update: Strike part #2, mizzunderstood scope and context... See below for exhaustive answer.
Re: (OT) emacs perl tweaks -- help sought w/ emacs lisp
by stefan k (Curate) on Oct 14, 2004 at 12:13 UTC
    Hi,
    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 cperl-check-syntax which invokes mode-compile 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 mode-compile. There is one variable called mode-compile-other-frame-p 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.

    Another possibility might be to use one of the hooks run before and after running mode-compile but after looking at the code I can't find an obvious way.

    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.

    This call would look like this:

    C-x h C-u M-| perltidy
    Here C-x h should mark the whole buffer, the prefix argument C-u enables the replacement of the region and finally M-| calls the function shell-command-on-region which asks for the command to use. Unfortunately I don't have perltidy at hand to test it.

    Putting all this into a single function which can be bound to a key would be like:

    (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)))
    And then:
    (add-hook 'cperl-mode-hook '(lambda () (local-set-key '[(control c) (control t)] 'my-perltidy)))
    or something like that.

    Please note, that I use XEmacs, but this code should be usable on both emacsen, I guess

    Update Thu Oct 14 14:15:41 CEST 2004: Added note on emacs-version

    Regards... Stefan
    you begin bashing the string with a +42 regexp of confusion

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://399154]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-12-21 15:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls