diff options
| author | Stefan Monnier | 2010-09-03 13:12:46 +0200 |
|---|---|---|
| committer | Stefan Monnier | 2010-09-03 13:12:46 +0200 |
| commit | e5eddfd190f4b6f5f66d571da0b380b3973d94b0 (patch) | |
| tree | 266201f351906469202814f7b99401066ca8be9e | |
| parent | 59f65f5c422ffda9b4cf9d9b97ed80785064abfc (diff) | |
| download | emacs-e5eddfd190f4b6f5f66d571da0b380b3973d94b0.tar.gz emacs-e5eddfd190f4b6f5f66d571da0b380b3973d94b0.zip | |
* lisp/simple.el (newline): Fix last change to properly remove itself from
the hook.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/simple.el | 69 |
2 files changed, 42 insertions, 32 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ead2c35b192..dd698a0ef40 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2010-09-03 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * simple.el (newline): Fix last change to properly remove itself from | ||
| 4 | the hook. | ||
| 5 | |||
| 1 | 2010-09-02 Stefan Monnier <monnier@iro.umontreal.ca> | 6 | 2010-09-02 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 7 | ||
| 3 | * simple.el (newline): Eliminate optimization. | 8 | * simple.el (newline): Eliminate optimization. |
diff --git a/lisp/simple.el b/lisp/simple.el index 4511208e434..18b2c3a300a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -457,38 +457,43 @@ Call `auto-fill-function' if the current column number is greater | |||
| 457 | than the value of `fill-column' and ARG is nil." | 457 | than the value of `fill-column' and ARG is nil." |
| 458 | (interactive "*P") | 458 | (interactive "*P") |
| 459 | (barf-if-buffer-read-only) | 459 | (barf-if-buffer-read-only) |
| 460 | (let ((was-page-start (and (bolp) | 460 | ;; Call self-insert so that auto-fill, abbrev expansion etc. happens. |
| 461 | (looking-at page-delimiter))) | 461 | ;; Set last-command-event to tell self-insert what to insert. |
| 462 | (beforepos (point))) | 462 | (let* ((was-page-start (and (bolp) (looking-at page-delimiter))) |
| 463 | ;; Call self-insert so that auto-fill, abbrev expansion etc. happens. | 463 | (beforepos (point)) |
| 464 | ;; Set last-command-event to tell self-insert what to insert. | 464 | (last-command-event ?\n) |
| 465 | (let ((last-command-event ?\n) | 465 | ;; Don't auto-fill if we have a numeric argument. |
| 466 | ;; Don't auto-fill if we have a numeric argument. | 466 | (auto-fill-function (if arg nil auto-fill-function)) |
| 467 | (auto-fill-function (if arg nil auto-fill-function)) | 467 | (postproc |
| 468 | (post-self-insert-hook post-self-insert-hook)) | 468 | ;; Do the rest in post-self-insert-hook, because we want to do it |
| 469 | ;; Do the rest in post-self-insert-hook, because we want to do it | 469 | ;; *before* other functions on that hook. |
| 470 | ;; *before* other functions on that hook. | 470 | (lambda () |
| 471 | (add-hook 'post-self-insert-hook | 471 | ;; Mark the newline(s) `hard'. |
| 472 | (lambda () | 472 | (if use-hard-newlines |
| 473 | ;; Mark the newline(s) `hard'. | 473 | (set-hard-newline-properties |
| 474 | (if use-hard-newlines | 474 | (- (point) (prefix-numeric-value arg)) (point))) |
| 475 | (set-hard-newline-properties | 475 | ;; If the newline leaves the previous line blank, and we |
| 476 | (- (point) (prefix-numeric-value arg)) (point))) | 476 | ;; have a left margin, delete that from the blank line. |
| 477 | ;; If the newline leaves the previous line blank, and we | 477 | (save-excursion |
| 478 | ;; have a left margin, delete that from the blank line. | 478 | (goto-char beforepos) |
| 479 | (save-excursion | 479 | (beginning-of-line) |
| 480 | (goto-char beforepos) | 480 | (and (looking-at "[ \t]$") |
| 481 | (beginning-of-line) | 481 | (> (current-left-margin) 0) |
| 482 | (and (looking-at "[ \t]$") | 482 | (delete-region (point) |
| 483 | (> (current-left-margin) 0) | 483 | (line-end-position)))) |
| 484 | (delete-region (point) | 484 | ;; Indent the line after the newline, except in one case: |
| 485 | (line-end-position)))) | 485 | ;; when we added the newline at the beginning of a line which |
| 486 | ;; Indent the line after the newline, except in one case: | 486 | ;; starts a page. |
| 487 | ;; when we added the newline at the beginning of a line which | 487 | (or was-page-start |
| 488 | ;; starts a page. | 488 | (move-to-left-margin nil t))))) |
| 489 | (or was-page-start | 489 | (unwind-protect |
| 490 | (move-to-left-margin nil t)))) | 490 | (progn |
| 491 | (self-insert-command (prefix-numeric-value arg)))) | 491 | (add-hook 'post-self-insert-hook postproc) |
| 492 | (self-insert-command (prefix-numeric-value arg))) | ||
| 493 | ;; We first used let-binding to protect the hook, but that was naive | ||
| 494 | ;; since add-hook affects the symbol-default value of the variable, | ||
| 495 | ;; whereas the let-binding might only protect the buffer-local value. | ||
| 496 | (remove-hook 'post-self-insert-hook postproc))) | ||
| 492 | nil) | 497 | nil) |
| 493 | 498 | ||
| 494 | (defun set-hard-newline-properties (from to) | 499 | (defun set-hard-newline-properties (from to) |