mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-28 07:45:00 +00:00
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)
This commit is contained in:
parent
fc3cd53900
commit
b8ea08b037
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user