1

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.

mmccoo
  • 8,386
  • 5
  • 41
  • 60
  • I don't think cperl-mode is doing this, unless you are "yanking" by middle-mouse-pasting into an xterm. In that case, turn off cperl-hairy via customize, then try again. – jrockway Feb 27 '09 at 02:44

5 Answers5

5
(setq cperl-break-one-line-blocks-when-indent nil)
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
mmccoo
  • 8,386
  • 5
  • 41
  • 60
2

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.

dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
2

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
  • 15,888
  • 11
  • 45
  • 57
0

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
  • 3,842
  • 1
  • 26
  • 31
0

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
  • 73,191
  • 16
  • 130
  • 183