aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2016-03-19 21:32:27 +0200
committerEli Zaretskii2016-03-19 21:32:27 +0200
commitb8ea08b037fb16395b90481162587706e71b487c (patch)
treee3f89c3485a0ca756ac3a4d89a6f3920747ab7f5
parentfc3cd53900eb5e80b91b6d2615b3800fd2f59c16 (diff)
downloademacs-b8ea08b037fb16395b90481162587706e71b487c.tar.gz
emacs-b8ea08b037fb16395b90481162587706e71b487c.zip
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)
-rw-r--r--lisp/simple.el36
1 files changed, 21 insertions, 15 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 84a1919bc01..2a81ee745cb 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'."
408 (last-command-event ?\n) 408 (last-command-event ?\n)
409 ;; Don't auto-fill if we have a numeric argument. 409 ;; Don't auto-fill if we have a numeric argument.
410 (auto-fill-function (if arg nil auto-fill-function)) 410 (auto-fill-function (if arg nil auto-fill-function))
411 (arg (prefix-numeric-value arg))
411 (postproc 412 (postproc
412 ;; Do the rest in post-self-insert-hook, because we want to do it 413 ;; Do the rest in post-self-insert-hook, because we want to do it
413 ;; *before* other functions on that hook. 414 ;; *before* other functions on that hook.
414 (lambda () 415 (lambda ()
415 (cl-assert (eq ?\n (char-before))) 416 ;; We are not going to insert any newlines if arg is
417 ;; non-positive.
418 (or (and (numberp arg) (<= arg 0))
419 (cl-assert (eq ?\n (char-before))))
416 ;; Mark the newline(s) `hard'. 420 ;; Mark the newline(s) `hard'.
417 (if use-hard-newlines 421 (if use-hard-newlines
418 (set-hard-newline-properties 422 (set-hard-newline-properties
419 (- (point) (prefix-numeric-value arg)) (point))) 423 (- (point) arg) (point)))
420 ;; If the newline leaves the previous line blank, and we 424 ;; If the newline leaves the previous line blank, and we
421 ;; have a left margin, delete that from the blank line. 425 ;; have a left margin, delete that from the blank line.
422 (save-excursion 426 (save-excursion
@@ -433,19 +437,21 @@ A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
433 (move-to-left-margin nil t))))) 437 (move-to-left-margin nil t)))))
434 (unwind-protect 438 (unwind-protect
435 (if (not interactive) 439 (if (not interactive)
436 ;; FIXME: For non-interactive uses, many calls actually just want 440 ;; FIXME: For non-interactive uses, many calls actually
437 ;; (insert "\n"), so maybe we should do just that, so as to avoid 441 ;; just want (insert "\n"), so maybe we should do just
438 ;; the risk of filling or running abbrevs unexpectedly. 442 ;; that, so as to avoid the risk of filling or running
439 (let ((post-self-insert-hook (list postproc))) 443 ;; abbrevs unexpectedly.
440 (self-insert-command (prefix-numeric-value arg))) 444 (let ((post-self-insert-hook (list postproc)))
441 (unwind-protect 445 (self-insert-command arg))
442 (progn 446 (unwind-protect
443 (add-hook 'post-self-insert-hook postproc nil t) 447 (progn
444 (self-insert-command (prefix-numeric-value arg))) 448 (add-hook 'post-self-insert-hook postproc nil t)
445 ;; We first used let-binding to protect the hook, but that was naive 449 (self-insert-command arg))
446 ;; since add-hook affects the symbol-default value of the variable, 450 ;; We first used let-binding to protect the hook, but that
447 ;; whereas the let-binding might only protect the buffer-local value. 451 ;; was naive since add-hook affects the symbol-default
448 (remove-hook 'post-self-insert-hook postproc t))) 452 ;; value of the variable, whereas the let-binding might
453 ;; only protect the buffer-local value.
454 (remove-hook 'post-self-insert-hook postproc t)))
449 (cl-assert (not (member postproc post-self-insert-hook))) 455 (cl-assert (not (member postproc post-self-insert-hook)))
450 (cl-assert (not (member postproc (default-value 'post-self-insert-hook)))))) 456 (cl-assert (not (member postproc (default-value 'post-self-insert-hook))))))
451 nil) 457 nil)