emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r102362: * lisp/skeleton.el (skeleton


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r102362: * lisp/skeleton.el (skeleton-newline): New function.
Date: Fri, 12 Nov 2010 08:33:44 -0500
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 102362
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2010-11-12 08:33:44 -0500
message:
  * lisp/skeleton.el (skeleton-newline): New function.
  (skeleton-internal-1): Use it.
  (skeleton-read): Don't use `newline' since it may strip trailing space.
modified:
  lisp/ChangeLog
  lisp/skeleton.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-11-12 13:32:02 +0000
+++ b/lisp/ChangeLog    2010-11-12 13:33:44 +0000
@@ -1,5 +1,10 @@
 2010-11-12  Stefan Monnier  <address@hidden>
 
+       * skeleton.el (skeleton-read): Don't use `newline' since it may strip
+       trailing space.
+       (skeleton-newline): New function.
+       (skeleton-internal-1): Use it.
+
        * simple.el (open-line): `newline' may strip trailing space.
 
 2010-11-12  Kevin Ryde  <address@hidden>

=== modified file 'lisp/skeleton.el'
--- a/lisp/skeleton.el  2010-11-10 04:30:21 +0000
+++ b/lisp/skeleton.el  2010-11-12 13:33:44 +0000
@@ -299,7 +299,10 @@
        (eolp (eolp)))
     ;; since Emacs doesn't show main window's cursor, do something noticeable
     (or eolp
-       (open-line 1))
+        ;; We used open-line before, but that can do a lot more than we want,
+       ;; since it runs self-insert-command.  E.g. it may remove spaces
+       ;; before point.
+        (save-excursion (insert "\n")))
     (unwind-protect
        (setq prompt (if (stringp prompt)
                         (read-string (format prompt skeleton-subprompt)
@@ -352,6 +355,16 @@
       (signal 'quit 'recursive)
     recursive))
 
+(defun skeleton-newline ()
+  (if (or (eq (point) skeleton-point)
+          (eq (point) (car skeleton-positions)))
+      ;; If point is recorded, avoid `newline' since it may do things like
+      ;; strip trailing spaces, and since recorded points are commonly placed
+      ;; right after a trailing space, calling `newline' can destroy the
+      ;; position and renders the recorded position incorrect.
+      (insert "\n")
+    (newline)))
+
 (defun skeleton-internal-1 (element &optional literal recursive)
   (cond
    ((or (integerp element) (stringp element))
@@ -379,13 +392,13 @@
        (if pos (indent-according-to-mode)))
        (skeleton-newline-indent-rigidly
        (let ((pt (point)))
-         (newline)
+         (skeleton-newline)
          (indent-to (save-excursion
                       (goto-char pt)
                       (if pos (indent-according-to-mode))
                       (current-indentation)))))
        (t (if pos (reindent-then-newline-and-indent)
-           (newline)
+           (skeleton-newline)
            (indent-according-to-mode))))))
    ((eq element '>)
     (if (and skeleton-regions (eq (nth 1 skeleton-il) '_))


reply via email to

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