[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] emacs-25 b8ea08b: Avoid errors in 'newline'
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] emacs-25 b8ea08b: Avoid errors in 'newline' |
Date: |
Sat, 19 Mar 2016 19:33:34 +0000 |
branch: emacs-25
commit b8ea08b037fb16395b90481162587706e71b487c
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>
Avoid errors in 'newline'
* lisp/simple.el (newline): Don't barf if invoked with
non-positive argument in the middle of a line. (Bug#22490)
---
lisp/simple.el | 36 +++++++++++++++++++++---------------
1 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 84a1919..2a81ee7 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -408,15 +408,19 @@ A non-nil INTERACTIVE argument means to run the
`post-self-insert-hook'."
(last-command-event ?\n)
;; Don't auto-fill if we have a numeric argument.
(auto-fill-function (if arg nil auto-fill-function))
+ (arg (prefix-numeric-value arg))
(postproc
;; Do the rest in post-self-insert-hook, because we want to do it
;; *before* other functions on that hook.
(lambda ()
- (cl-assert (eq ?\n (char-before)))
+ ;; We are not going to insert any newlines if arg is
+ ;; non-positive.
+ (or (and (numberp arg) (<= arg 0))
+ (cl-assert (eq ?\n (char-before))))
;; Mark the newline(s) `hard'.
(if use-hard-newlines
(set-hard-newline-properties
- (- (point) (prefix-numeric-value arg)) (point)))
+ (- (point) arg) (point)))
;; If the newline leaves the previous line blank, and we
;; have a left margin, delete that from the blank line.
(save-excursion
@@ -433,19 +437,21 @@ A non-nil INTERACTIVE argument means to run the
`post-self-insert-hook'."
(move-to-left-margin nil t)))))
(unwind-protect
(if (not interactive)
- ;; FIXME: For non-interactive uses, many calls actually just want
- ;; (insert "\n"), so maybe we should do just that, so as to avoid
- ;; the risk of filling or running abbrevs unexpectedly.
- (let ((post-self-insert-hook (list postproc)))
- (self-insert-command (prefix-numeric-value arg)))
- (unwind-protect
- (progn
- (add-hook 'post-self-insert-hook postproc nil t)
- (self-insert-command (prefix-numeric-value arg)))
- ;; We first used let-binding to protect the hook, but that was naive
- ;; since add-hook affects the symbol-default value of the variable,
- ;; whereas the let-binding might only protect the buffer-local value.
- (remove-hook 'post-self-insert-hook postproc t)))
+ ;; FIXME: For non-interactive uses, many calls actually
+ ;; just want (insert "\n"), so maybe we should do just
+ ;; that, so as to avoid the risk of filling or running
+ ;; abbrevs unexpectedly.
+ (let ((post-self-insert-hook (list postproc)))
+ (self-insert-command arg))
+ (unwind-protect
+ (progn
+ (add-hook 'post-self-insert-hook postproc nil t)
+ (self-insert-command arg))
+ ;; We first used let-binding to protect the hook, but that
+ ;; was naive since add-hook affects the symbol-default
+ ;; value of the variable, whereas the let-binding might
+ ;; only protect the buffer-local value.
+ (remove-hook 'post-self-insert-hook postproc t)))
(cl-assert (not (member postproc post-self-insert-hook)))
(cl-assert (not (member postproc (default-value
'post-self-insert-hook))))))
nil)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] emacs-25 b8ea08b: Avoid errors in 'newline',
Eli Zaretskii <=