When I type a loop keyword (for, while, do) in perl program, emacs automatically inserts brackets and parenthesizes to complete the loop structure. I would like to disable this but I'm not sure what is actually doing it. I have CPerl, Flymake, AC, Outl, and Abbrev modes loaded.


Since it looks like cperl-mode always rewrites its abbreviations, my previous answer is not a long term solution.

A better solution is to run a hook after cperl has been loaded and redefine the cperl-mode-abbrev-table. Add it to your emacs configuration file after other commands modifying cperl. I've removed the loop abbreviations from the redefined table, but if and do expansions are still there.

(add-hook 'cperl-mode-hook
        (lambda ()
          (clear-abbrev-table cperl-mode-abbrev-table)
          (define-abbrev-table 'cperl-mode-abbrev-table
              ("=head1" "=head1" cperl-electric-pod 0)
              ("=head2" "=head2" cperl-electric-pod 0)
              ("=over" "=over" cperl-electric-pod 0)
              ("=pod" "=pod" cperl-electric-pod 0)
              ("continue" "continue" cperl-electric-else 0)
              ("do" "do" cperl-electric-keyword 0)
              ("else" "else" cperl-electric-else 0)
              ("elsif" "elsif" cperl-electric-keyword 0)
              ("head1" "head1" cperl-electric-pod 0)
              ("head2" "head2" cperl-electric-pod 0)
              ("if" "if" cperl-electric-keyword 4)
              ("over" "over" cperl-electric-pod 0)
              ("pod" "pod" cperl-electric-pod 0)))))
  • Great, but now when I close emacs, it asks "Save abbrevs in ~/.emacs.d/abbrev_defs? (y or n)". – gogators Apr 6 '17 at 13:52
  • Add (setq save-abbrevs 'silently). – Heikki Apr 6 '17 at 14:07

cperl creates abbreviations for perl keywords into ~/.emacs.d/abbrev_defs that trigger function cperl-electric-keyword that does the expansion.

To remove the offending entries, call M-x edit-abbrevs, remove the lines you want, save, and press C-c C-c to activate the changes.

  • 1
    That works for the current session, but when I run emacs again, the entries are back in the cperl-mode-abbrev-table. Even when I save the .emacs.d/abbrev_defs file. – gogators Apr 5 '17 at 14:34

It's hard to tell for the little bit you've provided but you may want to start with (setq cperl-electric-parens nil) and lookup perl-hairy in the documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.