简体   繁体   中英

How do I keep braces from moving in Emacs cperl mode?

I'm using GNU Emacs 22.2.1 and cperl 5.23.

I have perl code like this:

sub foo
{
    if($x)
    {
      print "x";
    }
    else
    {
      print "y";
    }
}

I'd like to reindent the code to a 2-space indent. But when I run cperl-indent-region on this code, I get:

sub foo
  {
    if ($x) {
      print "x";
    } else {
      print "y";
    }
  }
  1. How can I keep the outer brace at the left margin / column 0?
  2. How can I prevent the opening brace for the if and else from moving up to the previous line?

I believe the customization you're looking for is:

(setq cperl-extra-newline-before-brace t
      cperl-brace-offset              -2
      cperl-merge-trailing-else        nil)

You can customize cperl mode with Mx customize-group <ENTER> cperl <ENTER> . The indentation variables are in the Cperl Indentation Details subgroup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM