aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-10-24 22:26:27 +0100
committerArtur Malabarba2015-10-26 00:27:10 +0000
commitbd4f04f86cea893e3369decdda074a4898491518 (patch)
treefeb833f3b1cde1c2d030f9e36687cb54816fbcc1
parent6939896e2ffe2e742954c14bba6129af456f0857 (diff)
downloademacs-bd4f04f86cea893e3369decdda074a4898491518.tar.gz
emacs-bd4f04f86cea893e3369decdda074a4898491518.zip
* lisp/simple.el (open-line): Integrate with electric-indent-mode
Also run `post-self-insert-hook' when called interactively.
-rw-r--r--lisp/simple.el16
1 files changed, 13 insertions, 3 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 5b0503778bd..338a0600829 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -458,17 +458,27 @@ A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
458 (put-text-property from (point) 'rear-nonsticky 458 (put-text-property from (point) 'rear-nonsticky
459 (cons 'hard sticky))))) 459 (cons 'hard sticky)))))
460 460
461(defun open-line (n) 461(declare-function electric-indent-just-newline "electric")
462(defun open-line (n &optional interactive)
462 "Insert a newline and leave point before it. 463 "Insert a newline and leave point before it.
464If `electric-indent-mode' is enabled, indent the new line if it's
465not empty.
463If there is a fill prefix and/or a `left-margin', insert them on 466If there is a fill prefix and/or a `left-margin', insert them on
464the new line. If the old line would have been blank, insert them 467the new line. If the old line would have been blank, insert them
465on the old line as well. 468on the old line as well.
469
470With arg N, insert N newlines.
471A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
472 (interactive "*p\np")
466 (let* ((do-fill-prefix (and fill-prefix (bolp))) 473 (let* ((do-fill-prefix (and fill-prefix (bolp)))
467 (do-left-margin (and (bolp) (> (current-left-margin) 0))) 474 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
468 (loc (point-marker)) 475 (loc (point-marker))
469 ;; Don't expand an abbrev before point. 476 ;; Don't expand an abbrev before point.
470 (abbrev-mode nil)) 477 (abbrev-mode nil))
471 (newline n) 478 (if (and interactive
479 (looking-at-p "[[:space:]]*$"))
480 (electric-indent-just-newline n)
481 (newline n interactive))
472 (goto-char loc) 482 (goto-char loc)
473 (while (> n 0) 483 (while (> n 0)
474 (cond ((bolp) 484 (cond ((bolp)