I've always thought that I could do more with emacs, and last week I decided to put some time into searching for emacs tricks. I found a pretty cool way to create templates for commonly typed code - the DMACRO package. With it I've set up macros for common blocks of code/comments. So now all I have to do to create an if-else block, for example, is type "C-c d ife", which prompts me in the minibuffer for the if condition. Once I enter that, emacs inserts the following code and puts the prompt in the right place for me to start filling in the if block.
So far I've set up templates for 'if', 'if/else', 'foreach', and 'for' statements, and for subs.if (condition) { (prompt here) } else { }
Anyone else have good tricks or suggestions for speeding up the process of moving code from your head into the computer? Here are some other ideas I've thought of:
Here's my dmacro setup for anyone who's interested:
1. some docs are at: http://www.informatik.uni-hamburg.de/RZ/software/emacs/dmacro/dmacro_toc.html
2.downloaded dmacro at ftp://ftp.sgi.com/other/dmacro and unzipped to C:\emacs\dmacro
3.opened emacs and ran M-x customize-option, typed load-path, and then inserted the C:\emacs\dmacro dir so that emacs can find the dmacro files
4.added this to my .emacs file:
5.And here's my macros file, joe.dm:(require 'dmacro) ;;; load my macros: (dmacro-load "C:/emacs/dmacro/joe.dm") ;;; my macros use this function for tabbing: ;;; (indent-region doesn't bring the {'s with it in perl-mode.) (def-dmacro-function perltab perl-indent-command)
####### # MODE: nil ###### # ####### fori indent for statement (prompts for variable name) for (~(prompt var "Variable: ") = 0; ~prompt < ~@; ~prompt++) ~perltab { ~perltab ~perltab ~mark } ~perltab # ####### fore indent interactive foreach type statment (prompts for varia +ble names) foreach my ~(prompt loopVar "loop var: ") (~(prompt loopList "list/arr +ay to loop over: ")) ~perltab { ~perltab ~perltab ~@ } ~perltab # # ####### if expand if statement if (~(prompt conditionString "Condition: ")) ~perltab { ~perltab ~perltab ~@ } ~perltab # # ####### ifelse expand if-else statement if (~(prompt conditionString "Condition: ")) ~perltab { ~perltab ~perltab ~@ } ~perltab else ~perltab { ~perltab ~perltab ~mark } ~perltab # # ####### sub expand create a new sub \# Name: ~(prompt subName "sub name: ") \# Synopsis: \# Arguments: \# Returns: \# Notes: \# sub ~prompt ~perltab { ~perltab ~perltab ~@ } ~perltab #
In reply to Programmer Efficiency / dmacro by blahblahblah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |