Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs cperl-mode make if more ergonomic

Tags:

emacs

I am using emacs cperl-mode. When I type

if(

it gives me the code template:

if(<cursor goes here>){
}

But I want to make it like this:

if(<cursor goes here>){
    <tab, according to the mode>
}

So after I wrote the condition inside 'if', I won't need to click <End> <Enter> <tab> and will only need to click <Down arrow>.

The same method can be used for the similar cases: while, for, etc.

like image 430
user4035 Avatar asked Dec 11 '25 19:12

user4035


1 Answers

I use Yasnippet to cover this case:

YASnippet is a template system for Emacs. It allows you to type an abbreviation and automatically expand it into function templates. Bundled language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more. The snippet syntax is inspired from TextMate's syntax, you can even import most TextMate templates to YASnippet.

Your case would be just i f tab condition tab then block.

In cperl-mode you have following default templates:

eval, for, fore, if, ife, ifee, sub, unless, while, xfore, xif, xunless, xwhile

and - what's even more awesome - you can easily create your own templates or use an existing collection of yasnippet snippets for many languages.

like image 115
Xaerxess Avatar answered Dec 14 '25 09:12

Xaerxess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!