Mercurial > emacs
comparison lisp/simple.el @ 11324:3190c85854b6
(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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 09 Apr 1995 06:47:22 +0000 |
parents | 45947c4ff70b |
children | 0d5ebc078c51 |
comparison
equal
deleted
inserted
replaced
11323:5f75d3e225c1 | 11324:3190c85854b6 |
---|---|
24 ;; major mode or to file-handling. | 24 ;; major mode or to file-handling. |
25 | 25 |
26 ;;; Code: | 26 ;;; Code: |
27 | 27 |
28 (defun newline (&optional arg) | 28 (defun newline (&optional arg) |
29 "Insert a newline and move to left margin of the new line. | 29 "Insert a newline, and move to left margin of the new line if it's blank. |
30 The newline is marked with the text-property `hard'. | 30 The newline is marked with the text-property `hard'. |
31 With arg, insert that many newlines. | 31 With arg, insert that many newlines. |
32 In Auto Fill mode, if no numeric arg, break the preceding line if it's long." | 32 In Auto Fill mode, if no numeric arg, break the preceding line if it's long." |
33 (interactive "*P") | 33 (interactive "*P") |
34 ;; Inserting a newline at the end of a line produces better redisplay in | 34 ;; Inserting a newline at the end of a line produces better redisplay in |
36 ;; result is the same. So, if we're at beginning of line, pretend to be at | 36 ;; result is the same. So, if we're at beginning of line, pretend to be at |
37 ;; the end of the previous line. | 37 ;; the end of the previous line. |
38 (let ((flag (and (not (bobp)) | 38 (let ((flag (and (not (bobp)) |
39 (bolp) | 39 (bolp) |
40 (< (or (previous-property-change (point)) -2) | 40 (< (or (previous-property-change (point)) -2) |
41 (- (point) 2))))) | 41 (- (point) 2)))) |
42 (was-page-start (and (bolp) | |
43 (looking-at page-delimiter))) | |
44 (beforepos (point))) | |
42 (if flag (backward-char 1)) | 45 (if flag (backward-char 1)) |
43 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens. | 46 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens. |
44 ;; Set last-command-char to tell self-insert what to insert. | 47 ;; Set last-command-char to tell self-insert what to insert. |
45 (let ((last-command-char ?\n) | 48 (let ((last-command-char ?\n) |
46 ;; Don't auto-fill if we have a numeric argument. | 49 ;; Don't auto-fill if we have a numeric argument. |
53 (put-text-property from (point) 'hard 't) | 56 (put-text-property from (point) 'hard 't) |
54 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list | 57 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list |
55 (if (and (listp sticky) (not (memq 'hard sticky))) | 58 (if (and (listp sticky) (not (memq 'hard sticky))) |
56 (put-text-property from (point) 'rear-nonsticky | 59 (put-text-property from (point) 'rear-nonsticky |
57 (cons 'hard sticky))))) | 60 (cons 'hard sticky))))) |
58 (if flag (forward-char 1))) | 61 ;; If the newline leaves the previous line blank, |
59 (move-to-left-margin nil t) | 62 ;; and we have a left margin, delete that from the blank line. |
63 (or flag | |
64 (save-excursion | |
65 (goto-char beforepos) | |
66 (beginning-of-line) | |
67 (and (looking-at "[ \t]$") | |
68 (> (current-left-margin) 0) | |
69 (delete-region (point) (progn (end-of-line) (point)))))) | |
70 (if flag (forward-char 1)) | |
71 ;; Indent the line after the newline, except in one case: | |
72 ;; when we added the newline at the beginning of a line | |
73 ;; which starts a page. | |
74 (or was-page-start | |
75 (move-to-left-margin nil t))) | |
60 nil) | 76 nil) |
61 | 77 |
62 (defun open-line (arg) | 78 (defun open-line (arg) |
63 "Insert a newline and leave point before it. | 79 "Insert a newline and leave point before it. |
64 If there is a fill prefix and/or a left-margin, insert them on the new line | 80 If there is a fill prefix and/or a left-margin, insert them on the new line |
65 if the line would have been empty. | 81 if the line would have been blank. |
66 With arg N, insert N newlines." | 82 With arg N, insert N newlines." |
67 (interactive "*p") | 83 (interactive "*p") |
68 (let* ((do-fill-prefix (and fill-prefix (bolp))) | 84 (let* ((do-fill-prefix (and fill-prefix (bolp))) |
69 (do-left-margin (and (bolp) (> (current-left-margin) 0))) | 85 (do-left-margin (and (bolp) (> (current-left-margin) 0))) |
70 (loc (point))) | 86 (loc (point))) |
87 (newline arg) | |
88 (goto-char loc) | |
71 (while (> arg 0) | 89 (while (> arg 0) |
72 (if do-left-margin (indent-to (current-left-margin))) | 90 (cond ((bolp) |
73 (if do-fill-prefix (insert-and-inherit fill-prefix)) | 91 (if do-left-margin (indent-to (current-left-margin))) |
74 (newline 1) | 92 (if do-fill-prefix (insert-and-inherit fill-prefix)))) |
93 (forward-line 1) | |
75 (setq arg (1- arg))) | 94 (setq arg (1- arg))) |
76 (goto-char loc)) | 95 (goto-char loc) |
77 (end-of-line)) | 96 (end-of-line))) |
78 | 97 |
79 (defun split-line () | 98 (defun split-line () |
80 "Split current line, moving portion beyond point vertically down." | 99 "Split current line, moving portion beyond point vertically down." |
81 (interactive "*") | 100 (interactive "*") |
82 (skip-chars-forward " \t") | 101 (skip-chars-forward " \t") |