]> code.delx.au - gnu-emacs/blobdiff - lisp/expand.el
* net/tramp-cache.el (tramp-get-hash-table): New defun.
[gnu-emacs] / lisp / expand.el
index 121a97514bc85dd0c55853a0382f096006c8805d..81ad1495527d7d374d27964455dbe04d3a2a3f06 100644 (file)
@@ -1,6 +1,6 @@
-;; expand.el --- minor mode to make abbreviations more usable.
+;;; expand.el --- make abbreviations more usable
 
-;; Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+;; Copyright (C) 1995-1996, 2001-2013 Free Software Foundation, Inc.
 
 ;; Author: Frederic Lepied <Frederic.Lepied@sugix.frmug.org>
 ;; Maintainer: Frederic Lepied <Frederic.Lepied@sugix.frmug.org>
@@ -8,10 +8,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 ;;
 ;; This package defines abbrevs which expand into structured constructs
 ;; for certain languages.  The construct is indented for you,
-;; and contains points for you to ;; fill in other text.
+;; and contains slots for you to fill in other text.
 
 ;; These abbrevs expand only at the end of a line and when not in a comment
 ;; or a string.
 ;;     ("default" "default:\n\nbreak;" 10)
 ;;     ("main" "int\nmain(int argc, char * argv[])\n{\n\n}\n" 37))
 ;;   "Expansions for C mode")
-;; 
-;;   and enter Expand mode with the following hook :
 ;;
-;; (add-hook 'c-mode-hook (function (lambda ()
-;;                                (expand-add-abbrevs c-mode-abbrev-table c-expand-list)
-;;                                (expand-mode))))
+;;   and enter Abbrev mode with the following hook :
 ;;
-;;   you can also bind jump functions to some keys and init some post-process
-;; hooks :
+;; (add-hook 'c-mode-hook
+;;       (lambda ()
+;;         (expand-add-abbrevs c-mode-abbrev-table c-expand-list)
+;;         (abbrev-mode 1)))
 ;;
-;; (add-hook 'expand-mode-load-hook
-;;       (function
-;;        (lambda ()
-;;          (add-hook 'expand-expand-hook 'indent-according-to-mode)
-;;          (add-hook 'expand-jump-hook 'indent-according-to-mode)
-;;          (define-key expand-map '[(control tab)] 'expand-jump-to-next-mark)
-;;          (define-key expand-map '[(control shift tab)] 'expand-jump-to-previous-mark))))
+;;   you can also init some post-process hooks :
+;;
+;; (add-hook 'expand-load-hook
+;;       (lambda ()
+;;         (add-hook 'expand-expand-hook 'indent-according-to-mode)
+;;         (add-hook 'expand-jump-hook 'indent-according-to-mode)))
 ;;
 ;; Remarks:
 ;;
-;;   Has been tested under emacs 19.28-19.34 and XEmacs 19.11.
 ;;   Many thanks to Heddy Boubaker <boubaker@cenatls.cena.dgac.fr>,
 ;;                  Jerome Santini <santini@chambord.univ-orleans.fr>,
 ;;                  Jari Aalto <jaalto@tre.tele.nokia.fi>.
 ;;
-;;   Please send me a word to give me your feeling about this mode or
+;;   Please send me a word to give me your feeling about this feature or
 ;; to explain me how you use it (your expansions table for example) using
-;; the function expand-mode-submit-report.
+;; the function expand-submit-report.
+;;; Code:
 \f
-;; Expand mode is not a replacement for abbrev it is just a layer above it.
-
 ;;; Constants:
 
-(defconst expand-mode-version "$Id: expand.el,v 1.1 1996/12/28 19:41:45 rms Exp rms $"
-  "Version tag for expand.el.")
-
-(defconst expand-mode-help-address "expand-help@sugix.frmug.org"
-  "Email address to send requests, comments or bug reports.")
-
-(defvar expand-mode nil
-  "Status variable for Expand mode.")
-(make-variable-buffer-local 'expand-mode)
-
-(defvar expand-mode-name " Expand"
-  "Name of mode displayed in the modeline for Expand mode.")
+(defgroup expand nil
+  "Make abbreviations more usable."
+  :group 'abbrev)
 
-(defvar expand-mode-hook nil
-  "Hooks run when Expand mode is enabled.")
+(defcustom expand-load-hook nil
+  "Hooks run when `expand.el' is loaded."
+  :type 'hook
+  :group 'expand)
 
-(defvar expand-mode-load-hook nil
-  "Hooks run when expand is loaded.")
+(defcustom expand-expand-hook nil
+  "Hooks run when an abbrev made by `expand-add-abbrevs' is expanded."
+  :type 'hook
+  :group 'expand)
 
-(defvar expand-expand-hook nil
-  "Hooks run when expansion is done.")
-
-(defvar expand-jump-hook nil
-  "Hooks run when jump to mark occurs.")
+(defcustom expand-jump-hook nil
+  "Hooks run by `expand-jump-to-previous-slot' and `expand-jump-to-next-slot'."
+  :type 'hook
+  :group 'expand)
 
 ;;; Samples:
 
   "Loop var: "
   "for(" str _ @ "=0; " str @ "; " str @ ") {" \n
   @ _ \n
-  "}" >
-  )
+  "}" > \n)
 
 (defconst expand-c-sample-expand-list
   '(("if" "if () {\n \n} else {\n \n}" (5 10 21))
     ("while" "while () {\n\n}" (8 12))
     ("default" "default:\n\nbreak;" 10)
     ("main" "int\nmain(int argc, char * argv[])\n{\n\n}\n" 37))
-  "Expansions for C mode. See `expand-add-abbrevs'.")
+  "Expansions for C mode.  See `expand-add-abbrevs'.")
 
 ;; lisp example from Jari Aalto <jaalto@tre.tele.nokia.fi>
 (defconst expand-sample-lisp-mode-expand-list
     (concat
      "(defmacro  ()\n"
      "  \"\"\n"
-     "  (` \n"
+     "  `( \n"
      "    ))")
     (list 11 13 18 25))
 
      (list 12 14))
 
     )
-   "Expansions for Lisp mode. See `expand-add-abbrevs'.")
+   "Expansions for Lisp mode.  See `expand-add-abbrevs'.")
+
 ;; perl example from Jari Aalto <jaalto@tre.tele.nokia.fi>
 (defconst expand-sample-perl-mode-expand-list
   (list
    (list "rtu"  "return ;"      (list 8))
 
    )
-  "Expansions for Perl mode. See `expand-add-abbrevs'.")
+  "Expansions for Perl mode.  See `expand-add-abbrevs'.")
 
 ;;; Code:
 
-;;;###autoload
-(defun expand-mode (&optional arg)
-  "Toggle Expand mode.
-With argument ARG, turn Expand mode on if ARG is positive.
-In Expand mode, inserting an abbreviation at the end of a line
-causes it to expand and be replaced by its expansion."
-  (interactive "P")
-  (setq expand-mode (if (null arg) (not expand-mode)
-                      (> (prefix-numeric-value arg) 0)))
-  (if expand-mode
-      (progn
-       (setq abbrev-mode nil)
-       (run-hooks 'expand-mode-hook))))
-
-;;;###autoload
-(defvar expand-map (make-sparse-keymap)
-  "Key map used in Expand mode.")
-
-(or (assq 'expand-mode minor-mode-alist)
-    (setq minor-mode-alist (cons (list 'expand-mode expand-mode-name)
-                                minor-mode-alist)))
-
-(or (assq 'expand-mode minor-mode-map-alist)
-    (setq minor-mode-map-alist (cons (cons 'expand-mode expand-map)
-                                    minor-mode-map-alist)))
 ;;;###autoload
 (defun expand-add-abbrevs (table abbrevs)
-  "Add a list of abbrev to abbrev table TABLE.
+  "Add a list of abbreviations to abbrev table TABLE.
 ABBREVS is a list of abbrev definitions; each abbrev description entry
 has the form (ABBREV EXPANSION ARG).
 
 ABBREV is the abbreviation to replace.
 
 EXPANSION is the replacement string or a function which will make the
-expansion.  For example you, could use the DMacros or skeleton packages
+expansion.  For example, you could use the DMacros or skeleton packages
 to generate such functions.
 
 ARG is an optional argument which can be a number or a list of
@@ -319,8 +279,8 @@ beginning of the expanded text.
 
 If ARG is a list of numbers, point is placed according to the first
 member of the list, but you can visit the other specified positions
-cyclicaly with the functions `expand-jump-to-previous-mark' and
-`expand-jump-to-next-mark'.
+cyclically with the functions `expand-jump-to-previous-slot' and
+`expand-jump-to-next-slot'.
 
 If ARG is omitted, point is placed at the end of the expanded text."
 
@@ -330,21 +290,18 @@ If ARG is omitted, point is placed at the end of the expanded text."
                       (nth 2 (car abbrevs)))
     (expand-add-abbrevs table (cdr abbrevs))))
 
-(defvar expand-list nil "Temporary variable used by Expand mode.")
+(defvar expand-list nil "Temporary variable used by the Expand package.")
 
 (defvar expand-pos nil
-  "If non nil, stores a vector containing markers to positions defined by the last expansion.
-This variable is local to a buffer.")
+  "If non-nil, stores a vector containing markers to positions defined by the last expansion.")
 (make-variable-buffer-local 'expand-pos)
 
 (defvar expand-index 0
-  "Index of the last marker used in `expand-pos'.
-This variable is local to a buffer.")
+  "Index of the last marker used in `expand-pos'.")
 (make-variable-buffer-local 'expand-index)
 
 (defvar expand-point nil
-  "End of the expanded region.
-This variable is local to a buffer.")
+  "End of the expanded region.")
 (make-variable-buffer-local 'expand-point)
 
 (defun expand-add-abbrev (table abbrev expansion arg)
@@ -373,9 +330,10 @@ This variable is local to a buffer.")
       'expand-abbrev-hook)))
 
 (put 'expand-abbrev-hook 'no-self-insert t)
+;;;###autoload
 (defun expand-abbrev-hook ()
   "Abbrev hook used to do the expansion job of expand abbrevs.
-See `expand-add-abbrevs'."
+See `expand-add-abbrevs'.  Value is non-nil if expansion was done."
   ;; Expand only at the end of a line if we are near a word that has
   ;; an abbrev built from expand-add-abbrev.
   (if (and (eolp)
@@ -401,11 +359,12 @@ See `expand-add-abbrevs'."
                          expand-pos (expand-list-to-markers expand-list)
                          expand-list nil)))
              (run-hooks 'expand-expand-hook)
-             t))))
-  )
+             t)
+         nil))
+    nil))
 
 (defun expand-do-expansion ()
-  (delete-backward-char (length last-abbrev-text))
+  (delete-char (- (length last-abbrev-text)))
   (let* ((vect (symbol-value last-abbrev))
         (text (aref vect 0))
         (position (aref vect 1))
@@ -438,8 +397,10 @@ See `expand-add-abbrevs'."
       (backward-word 1)
       (buffer-substring p (point)))))
 
-(defun expand-jump-to-previous-mark ()
-  "Move the cursor to previous mark created by the expansion."
+;;;###autoload
+(defun expand-jump-to-previous-slot ()
+  "Move the cursor to the previous slot in the last abbrev expansion.
+This is used only in conjunction with `expand-add-abbrevs'."
   (interactive)
   (if expand-pos
       (progn
@@ -449,8 +410,10 @@ See `expand-add-abbrevs'."
        (goto-char (aref expand-pos expand-index))
        (run-hooks 'expand-jump-hook))))
 
-(defun expand-jump-to-next-mark ()
-  "Move the cursor to next mark created by the expansion."
+;;;###autoload
+(defun expand-jump-to-next-slot ()
+  "Move the cursor to the next slot in the last abbrev expansion.
+This is used only in conjunction with `expand-add-abbrevs'."
   (interactive)
   (if expand-pos
       (progn
@@ -460,6 +423,9 @@ See `expand-add-abbrevs'."
        (goto-char (aref expand-pos expand-index))
        (run-hooks 'expand-jump-hook))))
 
+;;;###autoload (define-key abbrev-map "p" 'expand-jump-to-previous-slot)
+;;;###autoload (define-key abbrev-map "n" 'expand-jump-to-next-slot)
+
 (defun expand-build-list (len l)
   "Build a vector of offset positions from the list of positions."
   (expand-clear-markers)
@@ -500,29 +466,12 @@ See `expand-add-abbrevs'."
                      (beginning-of-defun)
                      (point))
                    (point-min)))
-          (here (point))
           (state (parse-partial-sexp lim (point))))
       (cond
        ((nth 3 state) 'string)
        ((nth 4 state) 'comment)
        (t nil)))))
 
-(defun expand-mode-submit-report ()
-  "Report a problem, a suggestion or a comment about Expand mode."
-  (interactive)
-  (require 'reporter)
-  (reporter-submit-bug-report
-   expand-mode-help-address
-    (concat "expand.el " expand-mode-version)
-    '(expand-mode-name
-      expand-mode-hook
-      expand-mode-load-hook
-      expand-map
-      )
-    nil
-    nil
-    "Dear expand.el maintainer,"))
-
 ;; support functions to add marks to jump from outside function
 
 (defun expand-list-to-markers (l)
@@ -542,12 +491,12 @@ See `expand-add-abbrevs'."
 (defun expand-skeleton-end-hook ()
   (if skeleton-positions
       (setq expand-list skeleton-positions)))
-  
+
 (add-hook 'skeleton-end-hook (function expand-skeleton-end-hook))
 
 (provide 'expand)
 
 ;; run load hooks
-(run-hooks 'expand-mode-load-hook)
+(run-hooks 'expand-load-hook)
 
 ;;; expand.el ends here