Reputation: 261
Below is my novice .abbrev_defs file for emacs. I don't know if this is the convention way or not. If there is a better way, I would like to know.
(define-abbrev-table 'global-abbrev-table '(
("if" "if()\n {\n\n }" nil 1)
("else" "else\n {\n\n }" nil 1)
("while" "while()\n {\n\n }" nil 1)
("for" "for(;;)\n {\n\n }" nil 1)
))
Upvotes: 2
Views: 322
Reputation: 13937
You could make use of mode-specific abbrev tables. For the c-mode and c++-modes, you'd add:
(define-abbrev-table 'c-mode-abbrev-table '(
("if" "if()\n {\n\n }" nil 1)
("else" "else\n {\n\n }" nil 1)
("while" "while()\n {\n\n }" nil 1)
("for" "for(;;)\n {\n\n }" nil 1)
))
(define-abbrev-table 'c++-mode-abbrev-table '(
("if" "if()\n {\n\n }" nil 1)
("else" "else\n {\n\n }" nil 1)
("while" "while()\n {\n\n }" nil 1)
("for" "for(;;)\n {\n\n }" nil 1)
))
At first, I was concerned about the repetition, but in theory, you'd probably want to have abbreviations for c++ specific constructs in c++-mode-abbrev-table
.
Alternatively, you could go with yasnippet [http://code.google.com/p/yasnippet/] for more features.
Upvotes: 3