1

In most JavaScript IDEs, there is a feature that pressing RET when point is between {}, results in an indented blank line with point on the end of this blank line, as shown in the following two pictures:

enter image description here

when pressing RET:

enter image description here

But I found the electric-indent-mode only do this:

enter image description here

How to make things happen just like the second picture?

1

I have something I use with electric-pair-mode:

(electric-pair-mode 1)
(defun my-electric-pair-post-self-insert-function (orig-fun)
  (let ((indent-after (and (eq last-command-event ?\n)
                           (< (1+ (point-min)) (point) (point-max))
                           (eq (save-excursion
                                 (skip-chars-backward "\t\s")
                                 (char-before (1- (point))))
                               (matching-paren (char-after))))))
    (apply orig-fun nil)
    (when indent-after
      (indent-according-to-mode)
      (save-excursion
        (forward-line 1)
        (indent-according-to-mode)))))
(advice-add 'electric-pair-post-self-insert-function :around #'my-electric-pair-post-self-insert-function)

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.