Commit d133d835 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(newline): Don't indent afterward if at page sep line.

Delete whitespace on blank line before the inserted newlines.
(open-line): Add all the left margins and fill prefixes
after inserting all the newlines.
parent 144b2637
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
;;; Code: ;;; Code:
(defun newline (&optional arg) (defun newline (&optional arg)
"Insert a newline and move to left margin of the new line. "Insert a newline, and move to left margin of the new line if it's blank.
The newline is marked with the text-property `hard'. The newline is marked with the text-property `hard'.
With arg, insert that many newlines. With arg, insert that many newlines.
In Auto Fill mode, if no numeric arg, break the preceding line if it's long." In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
...@@ -38,7 +38,10 @@ In Auto Fill mode, if no numeric arg, break the preceding line if it's long." ...@@ -38,7 +38,10 @@ In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
(let ((flag (and (not (bobp)) (let ((flag (and (not (bobp))
(bolp) (bolp)
(< (or (previous-property-change (point)) -2) (< (or (previous-property-change (point)) -2)
(- (point) 2))))) (- (point) 2))))
(was-page-start (and (bolp)
(looking-at page-delimiter)))
(beforepos (point)))
(if flag (backward-char 1)) (if flag (backward-char 1))
;; Call self-insert so that auto-fill, abbrev expansion etc. happens. ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
;; Set last-command-char to tell self-insert what to insert. ;; Set last-command-char to tell self-insert what to insert.
...@@ -55,26 +58,42 @@ In Auto Fill mode, if no numeric arg, break the preceding line if it's long." ...@@ -55,26 +58,42 @@ In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
(if (and (listp sticky) (not (memq 'hard sticky))) (if (and (listp sticky) (not (memq 'hard sticky)))
(put-text-property from (point) 'rear-nonsticky (put-text-property from (point) 'rear-nonsticky
(cons 'hard sticky))))) (cons 'hard sticky)))))
(if flag (forward-char 1))) ;; If the newline leaves the previous line blank,
(move-to-left-margin nil t) ;; and we have a left margin, delete that from the blank line.
(or flag
(save-excursion
(goto-char beforepos)
(beginning-of-line)
(and (looking-at "[ \t]$")
(> (current-left-margin) 0)
(delete-region (point) (progn (end-of-line) (point))))))
(if flag (forward-char 1))
;; Indent the line after the newline, except in one case:
;; when we added the newline at the beginning of a line
;; which starts a page.
(or was-page-start
(move-to-left-margin nil t)))
nil) nil)
(defun open-line (arg) (defun open-line (arg)
"Insert a newline and leave point before it. "Insert a newline and leave point before it.
If there is a fill prefix and/or a left-margin, insert them on the new line If there is a fill prefix and/or a left-margin, insert them on the new line
if the line would have been empty. if the line would have been blank.
With arg N, insert N newlines." With arg N, insert N newlines."
(interactive "*p") (interactive "*p")
(let* ((do-fill-prefix (and fill-prefix (bolp))) (let* ((do-fill-prefix (and fill-prefix (bolp)))
(do-left-margin (and (bolp) (> (current-left-margin) 0))) (do-left-margin (and (bolp) (> (current-left-margin) 0)))
(loc (point))) (loc (point)))
(newline arg)
(goto-char loc)
(while (> arg 0) (while (> arg 0)
(if do-left-margin (indent-to (current-left-margin))) (cond ((bolp)
(if do-fill-prefix (insert-and-inherit fill-prefix)) (if do-left-margin (indent-to (current-left-margin)))
(newline 1) (if do-fill-prefix (insert-and-inherit fill-prefix))))
(forward-line 1)
(setq arg (1- arg))) (setq arg (1- arg)))
(goto-char loc)) (goto-char loc)
(end-of-line)) (end-of-line)))
(defun split-line () (defun split-line ()
"Split current line, moving portion beyond point vertically down." "Split current line, moving portion beyond point vertically down."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment