• João Távora's avatar
    electric-layout-mode kicks in before electric-pair-mode · fd943124
    João Távora authored
    This aims to solve problems with indentation.  Previously in, say, a
    js-mode buffer with electric-layout-rules set to
       (?\{ before after)
       (?\} before)
    would produce an intended:
       function ()
         <indented point>
    The initial state
      function () {
    Would go immediately to the following by e-p-m
      function () {}
    Only then would e-l-m be applied to } first, and then again to {.
    This makes lines indent in the wrong order, which can be a problem in
    some modes.
    The way we fix this is by reversing the order of e-p-m and e-l-m in
    the post-self-insert-hook (and also fixing a number of details that
    this uncovered).  In the end this changes the sequence from
      function () {
    By way of e-l-m becomes:
      function () <newline>
    The e-p-m inserts the pair
      function () <newline>
    And then e-l-m kicks in for the pair again, yielding the desired result
      function () <newline>
      <indented point>
    * lisp/elec-pair.el (electric-pair--insert): Bind
    (electric-pair-skip-if-helps-balance): Use insert-before-markers,
    playing nice with save-excurion.
    (electric-pair-post-self-insert-function): Go to correct position
    before checking electric-pair-inhibit-predicate and
    electric-pair-skip-self predicate.
    (electric-pair-post-self-insert-function): Increase priority to
    * lisp/electric.el (electric-indent-post-self-insert-function):
    Delete trailing space in reindented line only if line was
    really reindented.  Rewrite comment.
    (electric-layout-allow-duplicate-newlines): New variable.
    (electric-layout-post-self-insert-function-1): Rewrite comments.
    Honours electric-layout-allow-duplicate-newlines.  Don't reindent
    previous line because racecar.
    * test/lisp/electric-tests.el: New test.
    (plainer-c-mode): Move up.
    (electric-layout-int-main-kernel-style): Simplify
    (electric-layout-for-c-style-du-jour): New helper.
    (electric-layout-plainer-c-mode-use-c-style): New test.