emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r101311: * lisp/simple.el (newline):


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r101311: * lisp/simple.el (newline): Fix last change to properly remove itself from
Date: Fri, 03 Sep 2010 13:12:46 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 101311
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2010-09-03 13:12:46 +0200
message:
  * lisp/simple.el (newline): Fix last change to properly remove itself from
  the hook.
modified:
  lisp/ChangeLog
  lisp/simple.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-09-02 21:57:08 +0000
+++ b/lisp/ChangeLog    2010-09-03 11:12:46 +0000
@@ -1,3 +1,8 @@
+2010-09-03  Stefan Monnier  <address@hidden>
+
+       * simple.el (newline): Fix last change to properly remove itself from
+       the hook.
+
 2010-09-02  Stefan Monnier  <address@hidden>
 
        * simple.el (newline): Eliminate optimization.

=== modified file 'lisp/simple.el'
--- a/lisp/simple.el    2010-09-02 21:57:08 +0000
+++ b/lisp/simple.el    2010-09-03 11:12:46 +0000
@@ -457,38 +457,43 @@
 than the value of `fill-column' and ARG is nil."
   (interactive "*P")
   (barf-if-buffer-read-only)
-  (let ((was-page-start (and (bolp)
-                            (looking-at page-delimiter)))
-       (beforepos (point)))
-    ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
-    ;; Set last-command-event to tell self-insert what to insert.
-    (let ((last-command-event ?\n)
-         ;; Don't auto-fill if we have a numeric argument.
-         (auto-fill-function (if arg nil auto-fill-function))
-          (post-self-insert-hook post-self-insert-hook))
-      ;; Do the rest in post-self-insert-hook, because we want to do it
-      ;; *before* other functions on that hook.
-      (add-hook 'post-self-insert-hook
-                (lambda ()
-                  ;; Mark the newline(s) `hard'.
-                  (if use-hard-newlines
-                      (set-hard-newline-properties
-                       (- (point) (prefix-numeric-value arg)) (point)))
-                  ;; If the newline leaves the previous line blank, and we
-                  ;; have a left margin, delete that from the blank line.
-                  (save-excursion
-                    (goto-char beforepos)
-                    (beginning-of-line)
-                    (and (looking-at "[ \t]$")
-                         (> (current-left-margin) 0)
-                         (delete-region (point)
-                                        (line-end-position))))
-                  ;; Indent the line after the newline, except in one case:
-                  ;; when we added the newline at the beginning of a line which
-                  ;; starts a page.
-                  (or was-page-start
-                      (move-to-left-margin nil t))))
-      (self-insert-command (prefix-numeric-value arg))))
+  ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
+  ;; Set last-command-event to tell self-insert what to insert.
+  (let* ((was-page-start (and (bolp) (looking-at page-delimiter)))
+         (beforepos (point))
+         (last-command-event ?\n)
+         ;; Don't auto-fill if we have a numeric argument.
+         (auto-fill-function (if arg nil auto-fill-function))
+         (postproc
+          ;; Do the rest in post-self-insert-hook, because we want to do it
+          ;; *before* other functions on that hook.
+          (lambda ()
+            ;; Mark the newline(s) `hard'.
+            (if use-hard-newlines
+                (set-hard-newline-properties
+                 (- (point) (prefix-numeric-value arg)) (point)))
+            ;; If the newline leaves the previous line blank, and we
+            ;; have a left margin, delete that from the blank line.
+            (save-excursion
+              (goto-char beforepos)
+              (beginning-of-line)
+              (and (looking-at "[ \t]$")
+                   (> (current-left-margin) 0)
+                   (delete-region (point)
+                                  (line-end-position))))
+            ;; Indent the line after the newline, except in one case:
+            ;; when we added the newline at the beginning of a line which
+            ;; starts a page.
+            (or was-page-start
+                (move-to-left-margin nil t)))))
+    (unwind-protect
+        (progn
+          (add-hook 'post-self-insert-hook postproc)
+          (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)))
   nil)
 
 (defun set-hard-newline-properties (from to)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]