(send-mail-function): Customize.
[bpt/emacs.git] / lisp / skeleton.el
index 9a1ec8d..b758339 100644 (file)
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 1993, 1994, 1995, 1996 by Free Software Foundation, Inc.
 
-;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
+;; Author: Daniel Pfeiffer <occitan@esperanto.org>
 ;; Maintainer: FSF
 ;; Keywords: extensions, abbrev, languages, tools
 
@@ -100,6 +100,11 @@ skeleton elements.")
 (defvar skeleton-debug nil
   "*If non-nil `define-skeleton' will override previous definition.")
 
+(defvar skeleton-positions nil
+  "List of positions marked with @, after skeleton insertion.
+The list describes the most recent skeleton insertion, and its elements
+are integer buffer positions in the reverse order of the insertion order.")
+
 ;; reduce the number of compiler warnings
 (defvar skeleton)
 (defvar skeleton-modified)
@@ -126,8 +131,9 @@ If there is a highlighted region, the skeleton text is wrapped
 around the region text.
 
 A prefix argument ARG says to wrap the skeleton around the next ARG words.
+A prefix argument of -1 says to wrap around region, even if not highlighted.
 A prefix argument of zero says to wrap around zero words---that is, nothing.
-This is a way of overiding the use of a highlighted region.")
+This is a way of overriding the use of a highlighted region.")
        (interactive "*P\nP")
        (skeleton-proxy-new ',skeleton str arg))))
 
@@ -226,20 +232,22 @@ ignored."
 
 
 ;;;###autoload
-(defun skeleton-insert (skeleton &optional skeleton-regions str)
+(defun skeleton-insert (skeleton &optional regions str)
   "Insert the complex statement skeleton SKELETON describes very concisely.
 
-With optional third REGIONS wrap first interesting point (`_') in skeleton
-around next REGIONS words, if REGIONS is positive.  If REGIONS is negative,
-wrap REGIONS preceding interregions into first REGIONS interesting positions
-\(successive `_'s) in skeleton.  An interregion is the stretch of text between
-two contiguous marked points.  If you marked A B C [] (where [] is the cursor)
-in alphabetical order, the 3 interregions are simply the last 3 regions.  But
-if you marked B A [] C, the interregions are B-A, A-[], []-C.
+With optional second argument REGIONS, wrap first interesting point
+\(`_') in skeleton around next REGIONS words, if REGIONS is positive.
+If REGIONS is negative, wrap REGIONS preceding interregions into first
+REGIONS interesting positions \(successive `_'s) in skeleton.
+
+An interregion is the stretch of text between two contiguous marked
+points.  If you marked A B C [] (where [] is the cursor) in
+alphabetical order, the 3 interregions are simply the last 3 regions.
+But if you marked B A [] C, the interregions are B-A, A-[], []-C.
 
-Optional fourth STR is the value for the variable `str' within the skeleton.
-When this is non-`nil' the interactor gets ignored, and this should be a valid
-skeleton element.
+The optional third argument STR, if specified, is the value for the
+variable `str' within the skeleton.  When this is non-nil, the
+interactor gets ignored, and this should be a valid skeleton element.
 
 SKELETON is made up as (INTERACTOR ELEMENT ...).  INTERACTOR may be nil if
 not needed, a prompt-string or an expression for complex read functions.
@@ -250,6 +258,7 @@ If ELEMENT is a string or a character it gets inserted (see also
        \\n     go to next line and indent according to mode
        _       interesting point, interregion here, point after termination
        >       indent line (or interregion if > _) according to major mode
+       @       add position to `skeleton-positions'
        &       do next ELEMENT if previous moved point
        |       do next ELEMENT if previous didn't move point
        -num    delete num preceding characters (see `skeleton-untabify')
@@ -262,10 +271,10 @@ different inputs.  The SKELETON is processed as often as the user enters a
 non-empty string.  \\[keyboard-quit] terminates skeleton insertion, but
 continues after `resume:' and positions at `_' if any.  If INTERACTOR in such
 a subskeleton is a prompt-string which contains a \".. %s ..\" it is
-formatted with `skeleton-subprompt'.  Such an INTERACTOR may also a list of
+formatted with `skeleton-subprompt'.  Such an INTERACTOR may also be a list of
 strings with the subskeleton being repeated once for each string.
 
-Quoted Lisp expressions are evaluated evaluated for their side-effect.
+Quoted Lisp expressions are evaluated for their side-effects.
 Other Lisp expressions are evaluated and the value treated as above.
 Note that expressions may not return `t' since this implies an
 endless loop.  Modes can define other symbols by locally setting them
@@ -280,46 +289,50 @@ available:
 
 When done with skeleton, but before going back to `_'-point call
 `skeleton-end-hook' if that is non-`nil'."
-  (and skeleton-regions
-       (setq skeleton-regions
-            (if (> skeleton-regions 0)
-                (list (point-marker)
-                      (save-excursion (forward-word skeleton-regions)
-                                      (point-marker)))
-              (setq skeleton-regions (- skeleton-regions))
-              ;; copy skeleton-regions - 1 elements from `mark-ring'
-              (let ((l1 (cons (mark-marker) mark-ring))
-                    (l2 (list (point-marker))))
-                (while (and l1 (> skeleton-regions 0))
-                  (setq l2 (cons (car l1) l2)
-                        skeleton-regions (1- skeleton-regions)
-                        l1 (cdr l1)))
-                (sort l2 '<))))
-       (goto-char (car skeleton-regions))
-       (setq skeleton-regions (cdr skeleton-regions)))
-  (let ((beg (point))
-       skeleton-modified skeleton-point resume: help input v1 v2)
-    (unwind-protect
-       (eval `(let ,skeleton-further-elements
-                (skeleton-internal-list skeleton str)))
-      (run-hooks 'skeleton-end-hook)
-      (sit-for 0)
-      (or (pos-visible-in-window-p beg)
-         (progn
-           (goto-char beg)
-           (recenter 0)))
-      (if skeleton-point
-         (goto-char skeleton-point)))))
-
-(defun skeleton-read (str &optional initial-input recursive)
+  (let ((skeleton-regions regions))
+    (and skeleton-regions
+        (setq skeleton-regions
+              (if (> skeleton-regions 0)
+                  (list (point-marker)
+                        (save-excursion (forward-word skeleton-regions)
+                                        (point-marker)))
+                (setq skeleton-regions (- skeleton-regions))
+                ;; copy skeleton-regions - 1 elements from `mark-ring'
+                (let ((l1 (cons (mark-marker) mark-ring))
+                      (l2 (list (point-marker))))
+                  (while (and l1 (> skeleton-regions 0))
+                    (setq l2 (cons (car l1) l2)
+                          skeleton-regions (1- skeleton-regions)
+                          l1 (cdr l1)))
+                  (sort l2 '<))))
+        (goto-char (car skeleton-regions))
+        (setq skeleton-regions (cdr skeleton-regions)))
+    (let ((beg (point))
+         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)))
+       (run-hooks 'skeleton-end-hook)
+       (sit-for 0)
+       (or (pos-visible-in-window-p beg)
+           (progn
+             (goto-char beg)
+             (recenter 0)))
+       (if skeleton-point
+           (goto-char skeleton-point))))))
+
+(defun skeleton-read (prompt &optional initial-input recursive)
   "Function for reading a string from the minibuffer within skeletons.
-PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'.
+
+PROMPT must be a string or a form that evaluates to a string.
+It may contain a `%s' which will be replaced by `skeleton-subprompt'.
 If non-`nil' second arg INITIAL-INPUT or variable `input' is a string or
 cons with index to insert before reading.  If third arg RECURSIVE is non-`nil'
 i.e. we are handling the iterator of a subskeleton, returns empty string if
 user didn't modify input.
 While reading, the value of `minibuffer-help-form' is variable `help' if that
-is non-`nil' or a default string."
+is non-nil or a default string."
   (let ((minibuffer-help-form (or (if (boundp 'help) (symbol-value 'help))
                                  (if recursive "\
 As long as you provide input you will insert another subskeleton.
@@ -330,7 +343,7 @@ left, and the current one is removed as far as it has been entered.
 If you quit, the current subskeleton is removed as far as it has been
 entered.  No more of the skeleton will be inserted, except maybe for a
 syntactically necessary termination."
-                                        "\
+                                   "\
 You are inserting a skeleton.  Standard text gets inserted into the buffer
 automatically, and you are prompted to fill in the variable parts.")))
        (eolp (eolp)))
@@ -338,21 +351,21 @@ automatically, and you are prompted to fill in the variable parts.")))
     (or eolp
        (open-line 1))
     (unwind-protect
-       (setq str (if (stringp str)
-                     (read-string (format str skeleton-subprompt)
-                                  (setq initial-input
-                                        (or initial-input
-                                            (symbol-value 'input))))
-                   (eval str)))
+       (setq prompt (if (stringp prompt)
+                        (read-string (format prompt skeleton-subprompt)
+                                     (setq initial-input
+                                           (or initial-input
+                                               (symbol-value 'input))))
+                      (eval prompt)))
       (or eolp
          (delete-char 1))))
   (if (and recursive
-          (or (null str)
-              (string= str "")
-              (equal str initial-input)
-              (equal str (car-safe initial-input))))
+          (or (null prompt)
+              (string= prompt "")
+              (equal prompt initial-input)
+              (equal prompt (car-safe initial-input))))
       (signal 'quit t)
-    str))
+    prompt))
 
 (defun skeleton-internal-list (skeleton &optional str recursive)
   (let* ((start (save-excursion (beginning-of-line) (point)))
@@ -431,6 +444,8 @@ automatically, and you are prompted to fill in the variable parts.")))
        ((eq element '|)
         (or skeleton-modified
             (setq skeleton (cdr skeleton))))
+       ((eq element '@)
+        (setq skeleton-positions (cons (point) skeleton-positions)))
        ((eq 'quote (car-safe element))
         (eval (nth 1 element)))
        ((or (stringp (car-safe element))