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
1 changed files with 21 additions and 15 deletions
|
@ -408,15 +408,19 @@ A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
|
||||||
(last-command-event ?\n)
|
(last-command-event ?\n)
|
||||||
;; Don't auto-fill if we have a numeric argument.
|
;; Don't auto-fill if we have a numeric argument.
|
||||||
(auto-fill-function (if arg nil auto-fill-function))
|
(auto-fill-function (if arg nil auto-fill-function))
|
||||||
|
(arg (prefix-numeric-value arg))
|
||||||
(postproc
|
(postproc
|
||||||
;; Do the rest in post-self-insert-hook, because we want to do it
|
;; Do the rest in post-self-insert-hook, because we want to do it
|
||||||
;; *before* other functions on that hook.
|
;; *before* other functions on that hook.
|
||||||
(lambda ()
|
(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'.
|
;; Mark the newline(s) `hard'.
|
||||||
(if use-hard-newlines
|
(if use-hard-newlines
|
||||||
(set-hard-newline-properties
|
(set-hard-newline-properties
|
||||||
(- (point) (prefix-numeric-value arg)) (point)))
|
(- (point) arg) (point)))
|
||||||
;; If the newline leaves the previous line blank, and we
|
;; If the newline leaves the previous line blank, and we
|
||||||
;; have a left margin, delete that from the blank line.
|
;; have a left margin, delete that from the blank line.
|
||||||
(save-excursion
|
(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)))))
|
(move-to-left-margin nil t)))))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(if (not interactive)
|
(if (not interactive)
|
||||||
;; FIXME: For non-interactive uses, many calls actually just want
|
;; FIXME: For non-interactive uses, many calls actually
|
||||||
;; (insert "\n"), so maybe we should do just that, so as to avoid
|
;; just want (insert "\n"), so maybe we should do just
|
||||||
;; the risk of filling or running abbrevs unexpectedly.
|
;; that, so as to avoid the risk of filling or running
|
||||||
(let ((post-self-insert-hook (list postproc)))
|
;; abbrevs unexpectedly.
|
||||||
(self-insert-command (prefix-numeric-value arg)))
|
(let ((post-self-insert-hook (list postproc)))
|
||||||
(unwind-protect
|
(self-insert-command arg))
|
||||||
(progn
|
(unwind-protect
|
||||||
(add-hook 'post-self-insert-hook postproc nil t)
|
(progn
|
||||||
(self-insert-command (prefix-numeric-value arg)))
|
(add-hook 'post-self-insert-hook postproc nil t)
|
||||||
;; We first used let-binding to protect the hook, but that was naive
|
(self-insert-command arg))
|
||||||
;; since add-hook affects the symbol-default value of the variable,
|
;; We first used let-binding to protect the hook, but that
|
||||||
;; whereas the let-binding might only protect the buffer-local value.
|
;; was naive since add-hook affects the symbol-default
|
||||||
(remove-hook 'post-self-insert-hook postproc t)))
|
;; 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 post-self-insert-hook)))
|
||||||
(cl-assert (not (member postproc (default-value 'post-self-insert-hook))))))
|
(cl-assert (not (member postproc (default-value 'post-self-insert-hook))))))
|
||||||
nil)
|
nil)
|
||||||
|
|
Loading…
Add table
Reference in a new issue