emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master bd4f04f 2/3: * lisp/simple.el (open-line): Integrat


From: Artur Malabarba
Subject: [Emacs-diffs] master bd4f04f 2/3: * lisp/simple.el (open-line): Integrate with electric-indent-mode
Date: Mon, 26 Oct 2015 00:28:48 +0000

branch: master
commit bd4f04f86cea893e3369decdda074a4898491518
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>

    * lisp/simple.el (open-line): Integrate with electric-indent-mode
    
    Also run `post-self-insert-hook' when called interactively.
---
 lisp/simple.el |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 5b05037..338a060 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'."
        (put-text-property from (point) 'rear-nonsticky
                           (cons 'hard sticky)))))
 
-(defun open-line (n)
+(declare-function electric-indent-just-newline "electric")
+(defun open-line (n &optional interactive)
   "Insert a newline and leave point before it.
+If `electric-indent-mode' is enabled, indent the new line if it's
+not empty.
 If there is a fill prefix and/or a `left-margin', insert them on
 the new line.  If the old line would have been blank, insert them
 on the old line as well.
+
+With arg N, insert N newlines.
+A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
+  (interactive "*p\np")
   (let* ((do-fill-prefix (and fill-prefix (bolp)))
         (do-left-margin (and (bolp) (> (current-left-margin) 0)))
         (loc (point-marker))
-        ;; Don't expand an abbrev before point.
+         ;; Don't expand an abbrev before point.
         (abbrev-mode nil))
-    (newline n)
+    (if (and interactive
+             (looking-at-p "[[:space:]]*$"))
+        (electric-indent-just-newline n)
+      (newline n interactive))
     (goto-char loc)
     (while (> n 0)
       (cond ((bolp)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]