emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r114722: * lisp/simple.el (newline): Only run post-s


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r114722: * lisp/simple.el (newline): Only run post-self-insert-hook when
Date: Sat, 19 Oct 2013 22:18:03 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114722
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Sat 2013-10-19 18:17:56 -0400
message:
  * lisp/simple.el (newline): Only run post-self-insert-hook when
  called interactively.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/simple.el                 simple.el-20091113204419-o5vbwnq5f7feedwu-403
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-10-19 15:22:57 +0000
+++ b/lisp/ChangeLog    2013-10-19 22:17:56 +0000
@@ -1,3 +1,8 @@
+2013-10-19  Stefan Monnier  <address@hidden>
+
+       * simple.el (newline): Only run post-self-insert-hook when
+       called interactively.
+
 2013-10-19  Johan Bockgård  <address@hidden>
 
        * icomplete.el (icomplete-with-completion-tables): Add :version.

=== modified file 'lisp/simple.el'
--- a/lisp/simple.el    2013-09-19 20:31:26 +0000
+++ b/lisp/simple.el    2013-10-19 22:17:56 +0000
@@ -377,14 +377,15 @@
 (defvar hard-newline (propertize "\n" 'hard t 'rear-nonsticky '(hard))
   "Propertized string representing a hard newline character.")
 
-(defun newline (&optional arg)
+(defun newline (&optional arg interactive)
   "Insert a newline, and move to left margin of the new line if it's blank.
 If option `use-hard-newlines' is non-nil, the newline is marked with the
 text-property `hard'.
 With ARG, insert that many newlines.
 Call `auto-fill-function' if the current column number is greater
-than the value of `fill-column' and ARG is nil."
-  (interactive "*P")
+than the value of `fill-column' and ARG is nil.
+A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
+  (interactive "*P\np")
   (barf-if-buffer-read-only)
   ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
   ;; Set last-command-event to tell self-insert what to insert.
@@ -415,14 +416,20 @@
             ;; starts a page.
             (or was-page-start
                 (move-to-left-margin nil t)))))
-    (unwind-protect
-        (progn
-          (add-hook 'post-self-insert-hook postproc)
+    (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)))
-      ;; 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)))
+      (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]