]> code.delx.au - gnu-emacs/blobdiff - lisp/skeleton.el
Calc: Update mode line after change mode
[gnu-emacs] / lisp / skeleton.el
index f85dc8ef06885cac699361cd5cf76a96b5dbecd4..0e81e2d74c6fd76002882efb50b0f05d2fbe1a1d 100644 (file)
@@ -1,6 +1,6 @@
-;;; skeleton.el --- Lisp language extension for writing statement skeletons -*- coding: utf-8 -*-
+;;; skeleton.el --- Lisp language extension for writing statement skeletons
 
-;; Copyright (C) 1993-1996, 2001-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1993-1996, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
 ;; Maintainer: emacs-devel@gnu.org
@@ -62,12 +62,8 @@ region.")
   "If non-nil, make sure that the skeleton inserted ends with a newline.
 This just influences the way the default `skeleton-end-hook' behaves.")
 
-(defvar skeleton-end-hook
-  (lambda ()
-    (or (eolp) (not skeleton-end-newline) (newline-and-indent)))
+(defvar skeleton-end-hook nil
   "Hook called at end of skeleton but before going to point of interest.
-By default this moves out anything following to next line,
-  unless `skeleton-end-newline' is set to nil.
 The variables `v1' and `v2' are still set when calling this.")
 
 
@@ -197,7 +193,9 @@ not needed, a prompt-string or an expression for complex read functions.
 If ELEMENT is a string or a character it gets inserted (see also
 `skeleton-transformation-function').  Other possibilities are:
 
-       \\n     go to next line and indent according to mode
+       \\n     go to next line and indent according to mode, unless
+                this is the first/last element of a skeleton and point
+                is at bol/eol
        _       interesting point, interregion here
        -       interesting point, no interregion interaction, overrides
                interesting point set by _
@@ -212,6 +210,11 @@ If ELEMENT is a string or a character it gets inserted (see also
 After termination, point will be positioned at the last occurrence of -
 or at the first occurrence of _ or at the end of the inserted text.
 
+Note that \\n as the last element of the skeleton only inserts a
+newline if not at eol.  If you want to unconditionally insert a newline
+at the end of the skeleton, use \"\\n\" instead.  Likewise with \\n
+as the first element when at bol.
+
 Further elements can be defined via `skeleton-further-elements'.
 ELEMENT may itself be a SKELETON with an INTERACTOR.  The user is prompted
 repeatedly for different inputs.  The SKELETON is processed as often as
@@ -241,7 +244,8 @@ When done with skeleton, but before going back to `_'-point call
         (setq skeleton-regions
               (if (> skeleton-regions 0)
                   (list (copy-marker (point) t)
-                        (save-excursion (forward-word skeleton-regions)
+                        (save-excursion (forward-word-strictly
+                                          skeleton-regions)
                                         (point-marker)))
                 (setq skeleton-regions (- skeleton-regions))
                 ;; copy skeleton-regions - 1 elements from `mark-ring'
@@ -261,6 +265,7 @@ When done with skeleton, but before going back to `_'-point call
               (mapcar #'car skeleton-further-elements)
               (mapcar (lambda (x) (eval (cadr x))) skeleton-further-elements)
             (skeleton-internal-list skeleton str))
+       (or (eolp) (not skeleton-end-newline) (newline-and-indent))
        (run-hooks 'skeleton-end-hook)
        (sit-for 0)
        (or (pos-visible-in-window-p beg)
@@ -273,7 +278,8 @@ When done with skeleton, but before going back to `_'-point call
 (defun skeleton-read (prompt &optional initial-input recursive)
   "Function for reading a string from the minibuffer within skeletons.
 
-PROMPT must be a string or a form that evaluates to a string.
+PROMPT must be a string or a function that evaluates to a string.
+It may also be a form that evaluates to a string (deprecated).
 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
@@ -302,12 +308,14 @@ automatically, and you are prompted to fill in the variable parts.")))
        ;; before point.
         (save-excursion (insert "\n")))
     (unwind-protect
-       (setq prompt (if (stringp prompt)
-                        (read-string (format prompt skeleton-subprompt)
-                                     (setq initial-input
-                                           (or initial-input
-                                               (symbol-value 'input))))
-                      (eval prompt)))
+       (setq prompt (cond ((stringp prompt)
+                            (read-string (format prompt skeleton-subprompt)
+                                         (setq initial-input
+                                               (or initial-input
+                                                   (symbol-value 'input)))))
+                           ((functionp prompt)
+                            (funcall prompt))
+                           (t (eval prompt))))
       (or eolp
          (delete-char 1))))
   (if (and recursive
@@ -477,7 +485,7 @@ This allows for context-sensitive checking whether pairing is appropriate.")
 Each alist element, which looks like (ELEMENT ...), is passed to
 `skeleton-insert' with no interactor.  Variable `str' does nothing.
 
-Elements might be (?` ?` _ \"''\"), (?\\( ?  _ \" )\") or (?{ \\n > _ \\n ?} >).")
+Elements might be (?\\=` ?\\=` _ \"\\='\\='\"), (?\\( ?  _ \" )\") or (?{ \\n > _ \\n ?} >).")
 
 (defvar skeleton-pair-default-alist '((?( _ ?)) (?\))
                                      (?[ _ ?]) (?\])
@@ -498,8 +506,9 @@ Pairing is also prohibited if we are right after a quoting character
 such as backslash.
 
 If a match is found in `skeleton-pair-alist', that is inserted, else
-the defaults are used.  These are (), [], {}, <> and `' for the
-symmetrical ones, and the same character twice for the others."
+the defaults are used.  These are (), [], {}, <> and (grave
+accent, apostrophe) for the paired ones, and the same character
+twice for the others."
   (interactive "*P")
   (if (or arg (not skeleton-pair))
       (self-insert-command (prefix-numeric-value arg))