aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)