]> code.delx.au - gnu-emacs/blobdiff - lisp/skeleton.el
* lisp/net/rcirc.el: Clean log filenames (Bug#7933).
[gnu-emacs] / lisp / skeleton.el
index c98e06fe76ff6a49f2ce3d866ca7c2d3b93dd4b5..946e0a4480dd9fbc459ef70e82203cf96b2d21f7 100644 (file)
@@ -1,7 +1,6 @@
 ;;; skeleton.el --- Lisp language extension for writing statement skeletons -*- coding: utf-8 -*-
 
-;; Copyright (C) 1993, 1994, 1995, 1996, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+;; Copyright (C) 1993-1996, 2001-2011  Free Software Foundation, Inc.
 
 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
 ;; Maintainer: FSF
@@ -299,7 +298,10 @@ automatically, and you are prompted to fill in the variable parts.")))
        (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 +354,16 @@ automatically, and you are prompted to fill in the variable parts.")))
       (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 +391,13 @@ automatically, and you are prompted to fill in the variable parts.")))
        (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) '_))