views:

441

answers:

5

When I do indent-region in cperl-mode

if ($x) { next; }

Emacs reformats it to:

if ($x) {
  next;
}

How can I make it stop doing that?

Note: the question originally said that this reformatting happens when yanking. I have yank setup to indent-region as well.

A: 

It doesn't work that way for me, I just tried it with various settings in the Toggle... submenu under the Perl menu. Could there be something other than Cperl mode that's making that happen?

Nathan
+2  A: 

Assuming you don't want it to autoformat when you type that kind of code either, simply change the bindings of {} to self-insert-command instead of perl-electric-terminator.

Charlie Martin
I fixed a typo. Hope you don't mind...
dmckee
A typo? *Me*? Impossible. ;-)Thanks!
Charlie Martin
+2  A: 

I can't find anything in cperl-mode that would do this. Try starting emacs with no customizations:

$ emacs -q

and then turn on cperl-mode in the scratch buffer:

M-x cperl-mode

Paste your text; it should look like the original (i.e. all on one line). Then start customizing cperl-mode:

M-x customize-group<RET>cperl<RET>

setting each variable individually for the current session only, and trying the paste in between each setting. If you suddenly find the behavior you're seeing, you have a starting place to look further (it could be a combination of options).

If you get cperl fully customized and it still doesn't behave "incorrectly" then you need to start looking at what other packages could be causing it. It could take a while....

Joe Casadonte
+4  A: 
(setq cperl-break-one-line-blocks-when-indent nil)
mmccoo
A: 

Without sounding like I'm giving a copout answer, why not just do this?

next if $x;

Same code, same effect, and just as readable (to me, at least), but I bet emacs won't try to reformat it.

Chris Lutz