Replace "Maintainer: FSF" with the emacs-devel mailing address
[bpt/emacs.git] / lisp / skeleton.el
index 0f28d32..767f0b3 100644 (file)
@@ -1,9 +1,9 @@
 ;;; skeleton.el --- Lisp language extension for writing statement skeletons -*- coding: utf-8 -*-
 
-;; Copyright (C) 1993-1996, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1993-1996, 2001-2014 Free Software Foundation, Inc.
 
 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: extensions, abbrev, languages, tools
 
 ;; This file is part of GNU Emacs.
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 ;; page 1:     statement skeleton language definition & interpreter
 ;; page 2:     paired insertion
 ;; page 3:     mirror-mode, an example for setting up paired insertion
 
 
 (defvar skeleton-transformation-function 'identity
-  "*If non-nil, function applied to literal strings before they are inserted.
+  "If non-nil, function applied to literal strings before they are inserted.
 It should take strings and characters and return them transformed, or nil
 which means no transformation.
 Typical examples might be `upcase' or `capitalize'.")
@@ -77,29 +79,27 @@ The variables `v1' and `v2' are still set when calling this.")
   "Function for transforming a skeleton proxy's aliases' variable value.")
 (defvaralias 'skeleton-filter 'skeleton-filter-function)
 
-(defvar skeleton-untabify t
+(defvar skeleton-untabify nil          ; bug#12223
   "When non-nil untabifies when deleting backwards with element -ARG.")
 
 (defvar skeleton-newline-indent-rigidly nil
   "When non-nil, indent rigidly under current line for element `\\n'.
 Else use mode's `indent-line-function'.")
 
-(defvar skeleton-further-elements ()
+(defvar-local skeleton-further-elements ()
   "A buffer-local varlist (see `let') of mode specific skeleton elements.
 These variables are bound while interpreting a skeleton.  Their value may
 in turn be any valid skeleton element if they are themselves to be used as
 skeleton elements.")
-(make-variable-buffer-local 'skeleton-further-elements)
-
 
 (defvar skeleton-subprompt
   (substitute-command-keys
    "RET, \\<minibuffer-local-map>\\[abort-recursive-edit] or \\[help-command]")
-  "*Replacement for %s in prompts of recursive subskeletons.")
+  "Replacement for %s in prompts of recursive subskeletons.")
 
 
 (defvar skeleton-debug nil
-  "*If non-nil `define-skeleton' will override previous definition.")
+  "If non-nil `define-skeleton' will override previous definition.")
 
 (defvar skeleton-positions nil
   "List of positions marked with @, after skeleton insertion.
@@ -121,7 +121,7 @@ are integer buffer positions in the reverse order of the insertion order.")
   "Define a user-configurable COMMAND that enters a statement skeleton.
 DOCUMENTATION is that of the command.
 SKELETON is as defined under `skeleton-insert'."
-  (declare (debug (&define name stringp skeleton-edebug-spec)))
+  (declare (doc-string 2) (debug (&define name stringp skeleton-edebug-spec)))
   (if skeleton-debug
       (set command skeleton))
   `(progn
@@ -260,8 +260,10 @@ When done with skeleton, but before going back to `_'-point call
          skeleton-modified skeleton-point resume: help input v1 v2)
       (setq skeleton-positions nil)
       (unwind-protect
-         (eval `(let ,skeleton-further-elements
-                  (skeleton-internal-list skeleton str)))
+         (cl-progv
+              (mapcar #'car skeleton-further-elements)
+              (mapcar (lambda (x) (eval (cadr x))) skeleton-further-elements)
+            (skeleton-internal-list skeleton str))
        (run-hooks 'skeleton-end-hook)
        (sit-for 0)
        (or (pos-visible-in-window-p beg)
@@ -354,15 +356,6 @@ 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
@@ -382,7 +375,7 @@ automatically, and you are prompted to fill in the variable parts.")))
     (let ((pos (if (eq element '>) (point))))
       (cond
        ((and skeleton-regions (eq (nth 1 skeleton-il) '_))
-       (or (eolp) (newline))
+       (or (eolp) (insert "\n"))
        (if pos (save-excursion (goto-char pos) (indent-according-to-mode)))
        (indent-region (line-beginning-position)
                       (car skeleton-regions) nil))
@@ -391,13 +384,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)))
-         (skeleton-newline)
+          (insert "\n")
          (indent-to (save-excursion
                       (goto-char pt)
                       (if pos (indent-according-to-mode))
                       (current-indentation)))))
        (t (if pos (reindent-then-newline-and-indent)
-           (skeleton-newline)
+           (insert "\n")
            (indent-according-to-mode))))))
    ((eq element '>)
     (if (and skeleton-regions (eq (nth 1 skeleton-il) '_))
@@ -456,7 +449,7 @@ automatically, and you are prompted to fill in the variable parts.")))
 ;;                  obarray
 ;;                  (lambda (symbol)
 ;;                    (or (eq symbol 'eval)
-;;                        (user-variable-p symbol)))
+;;                        (custom-variable-p symbol)))
 ;;                  t)
 ;;    comment-start str ": "
 ;;    (read-from-minibuffer "Expression: " nil read-expression-map nil
@@ -468,13 +461,13 @@ automatically, and you are prompted to fill in the variable parts.")))
 ;; Variables and command for automatically inserting pairs like () or "".
 
 (defvar skeleton-pair nil
-  "*If this is nil pairing is turned off, no matter what else is set.
+  "If this is nil pairing is turned off, no matter what else is set.
 Otherwise modes with `skeleton-pair-insert-maybe' on some keys
 will attempt to insert pairs of matching characters.")
 
 
 (defvar skeleton-pair-on-word nil
-  "*If this is nil, paired insertion is inhibited before or inside a word.")
+  "If this is nil, paired insertion is inhibited before or inside a word.")
 
 
 (defvar skeleton-pair-filter-function (lambda () nil)
@@ -516,7 +509,6 @@ symmetrical ones, and the same character twice for the others."
     (let* ((mark (and skeleton-autowrap
                      (or (eq last-command 'mouse-drag-region)
                          (and transient-mark-mode mark-active))))
-          (skeleton-end-hook)
           (char last-command-event)
           (skeleton (or (assq char skeleton-pair-alist)
                         (assq char skeleton-pair-default-alist)
@@ -527,7 +519,9 @@ symmetrical ones, and the same character twice for the others."
                       (if (not skeleton-pair-on-word) (looking-at "\\w"))
                       (funcall skeleton-pair-filter-function))))
          (self-insert-command (prefix-numeric-value arg))
-       (skeleton-insert (cons nil skeleton) (if mark -1))))))
+       ;; Newlines not desirable for inserting pairs.  See bug#16138.
+       (let ((skeleton-end-newline nil))
+         (skeleton-insert (cons nil skeleton) (if mark -1)))))))
 
 \f
 ;; A more serious example can be found in sh-script.el