Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Favorite Hacks in Emacs

by jaschwartz (Novice)
on May 12, 2009 at 20:01 UTC ( #763582=perlquestion: print w/replies, xml ) Need Help??
jaschwartz has asked for the wisdom of the Perl Monks concerning the following question:

While I have come across a few very cool hacks in emacs, I'm always in the mood to learn a few more. What tricks do you commonly use or hacks that have helped you?

Replies are listed 'Best First'.
Re: Favorite Hacks in Emacs
by Joost (Canon) on May 12, 2009 at 20:22 UTC
Re: Favorite Hacks in Emacs
by artist (Parson) on May 13, 2009 at 02:23 UTC
    M-x org-mode
    I export the lists to HTML or Freemind.

    Here is a good survey of such features. Also see the most useful ones.

Re: Favorite Hacks in Emacs
by Porculus (Hermit) on May 13, 2009 at 07:09 UTC

    shell-command-on-region. With a prefix argument it replaces the region with the shell command's output. Great way to run Perl one-liners on whatever you're editing!

    Also, align-regexp. Ideal for picky types who want a bunch of assignments to line up on the =. ;)

      that reminds me! I forgot cperl-mode's C-M-| for lining up stuff. I use that alot.

      Just don't miss and hit backspace in X windows...

Re: Favorite Hacks in Emacs
by Your Mother (Chancellor) on May 13, 2009 at 05:39 UTC

    I hope these are pasted right.

    (global-set-key "\M-3" 'script-blank) (global-set-key "\M-4" 'subroutine-blank) (define-skeleton script-blank "Insert a blank script." nil "#!/usr/bin/perl \n use strict; use warnings; # et cetera... Looooooong list of modules which # are easier to cut when unused than type otherwise. \n _ \n \n "exit 0; __DATA__ " ) ;;-------------------------------------------------------------------- (define-skeleton subroutine-blank "Insert a blank sub." nil "sub " _ " {" \n \n \n \n "}" )

Re: Favorite Hacks in Emacs
by shem (Initiate) on May 13, 2009 at 11:37 UTC
    (defun cw_save_check () "Run the Perl syntax checker on this buffer after saving." (cond ((equal mode-name "CPerl") (progn (save-current-buffer (set-buffer (get-buffer-create "*Perl cw output*")) (erase-buffer)) (call-process-region (point-min) (point-max) "/usr/bin/perl" nil + "*Perl cw output*" n il "-c -I.") (save-current-buffer (set-buffer "*Perl cw output*") (cond ((equal (buffer-string) "- syntax OK\n") (message "%s" "Synta +x OK")) (t (message "%s" "The program has errors.")))))) (t nil))) (add-hook 'after-save-hook 'cw_save_check)
Re: Favorite Hacks in Emacs
by juster (Friar) on May 13, 2009 at 04:58 UTC
    I use C-c C-h p aka M-x cperl-perldoc to lookup module and builtin docs but maybe I should try Sepia! I just recently started using 'Emacs Got Git' (egg) and it's pretty cool.
Re: Favorite Hacks in Emacs
by monarch (Priest) on May 13, 2009 at 14:32 UTC

    <Ctrl>-x, <enter>, f

    Changes encoding of a file (useful when converting to/from DOS/Unix line formats).

    e.g. I might be on a Unix system and I need to create a MS-DOS compatible text file, I type <ctrl>-x, <enter>, f and type "undecided-DOS".

    Or I might be on a Win32 machine and want to save a file in unix format for transfer to a remote system as a shell script. <ctrl>-x, <enter>, f and type "undecided-unix".

Re: Favorite Hacks in Emacs
by jplindstrom (Monsignor) on May 13, 2009 at 14:25 UTC


    • org-mode
    • ediff-buffers / ediff-regions-linewise (bet you didn't know about the last one)
    • SVN integration, with ediff (awesome)
    • Keyboard macros
    • PerlySense <-- on top of cperl-mode
    • project-root
    • sql-mysql - buffer
    • yasnippet


    ;; Display trailing whitespace (use a very very light color) (defun my-turn-on-show-trailing-whitespace () "Set `show-trailing-whitespace' to t." (setq show-trailing-whitespace t)) (mapc (lambda (hook) (add-hook hook 'my-turn-on-show-trailing-whitespace)) '(cperl-mode-hook))
Re: Favorite Hacks in Emacs
by morgon (Curate) on May 13, 2009 at 14:55 UTC
    Don't listen to these people.

    They follow a dangerous cult.

    I'll post "favourite hacks in vim" soon :-)


      Perl and Emacs are very similar - kitchen sink philosophy.

      VI falls in line with Unix toolbox philosophy.

      RDBMSes are a similar software prison to Perl and Emacs.

      Never forget: the car is in the cdr, not the cdr in the car

      You beat me to it morgon :-D

      When a sysadmin on Solaris, my favourite emacs hack was to remove the damn thing - one of 2 scenarios kept recurring (both directly traceable to emacs):

      • filling /tmp ... causing kernel panic.
      • process table filling up - preventing any other operation - self-evidently a hard reset was always required as the fix

      A user level that continues to overstate my experience :-))
Re: Favorite Hacks in Emacs
by Nkuvu (Priest) on May 13, 2009 at 18:47 UTC

    I've seen this in a few places, so you are probably already aware of it:

    ;;run the current perl program (defun run-perl () (interactive "*") (setq perl-buffer-name buffer-file-name) (shell) (setq perl-run-command "perl ") (insert perl-run-command) (insert perl-buffer-name) ) (global-set-key [f7] 'run-perl)

    But I have to say that I don't do many perl-specific things from within emacs. I'd rather jump over to a command window instead (somehow the green letters on black background mean "shell" to me a lot more than an emacs window, and black text on a white background means "write code here").

Re: Favorite Hacks in Emacs
by LanX (Chancellor) on May 13, 2009 at 19:00 UTC
    > What tricks do you commonly use or hacks that have helped you?

    Humor helps a lot!
    ...and of course C-x M-c M-butterfly 8 )

    Cheers Rolf

Re: Favorite Hacks in Emacs
by skangas (Novice) on May 15, 2009 at 06:31 UTC

    I'm sure you've heard about it already, but I like outline-minor-mode. Not at all essential, but still very nice to have sometimes.

    CPerlModeOutlineMode at EmacsWiki.

Re: Favorite Hacks in Emacs
by joojar (Initiate) on May 16, 2009 at 10:43 UTC
      I found a better perl tool for emacs call Sepia and it have everything

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://763582]
Approved by Joost
Front-paged by Arunbear
Lady_Aleena goes to read, may take a bit.
[Lady_Aleena]: Um, okay...
[karlgoethebier]: Lady_Aleena see also the source code of Shell
[Lady_Aleena]: ACK! Way over my head.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-06-26 09:00 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (574 votes). Check out past polls.