aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorRichard M. Stallman1996-12-28 20:06:56 +0000
committerRichard M. Stallman1996-12-28 20:06:56 +0000
commit55b723320ad83b26c06f589fb639bfcbbb0e34f2 (patch)
treeff809bddc6c981aafc134c271a3c0366a8c58eee /lisp
parente26f93cc0db7edeb0eaaf93d9a9f34398b1153c2 (diff)
downloademacs-55b723320ad83b26c06f589fb639bfcbbb0e34f2.tar.gz
emacs-55b723320ad83b26c06f589fb639bfcbbb0e34f2.zip
(expand-map): Don't define SPC.
(expand-template-abbreviation): Function deleted. (expand-try-to-expand): Function deleted. (expand-abbrev-hook): Add a no-self-insert property. (expand-skeleton-end-hook): Use skeleton-position. (expand-add-abbrevs): Doc fix.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/expand.el104
1 files changed, 43 insertions, 61 deletions
diff --git a/lisp/expand.el b/lisp/expand.el
index 3046361ad44..121a97514bc 100644
--- a/lisp/expand.el
+++ b/lisp/expand.el
@@ -25,20 +25,12 @@
25 25
26;;; Commentary: 26;;; Commentary:
27;; 27;;
28;; Purpose of this package: 28;; This package defines abbrevs which expand into structured constructs
29;; 1. Expand abbreviations only when they are at the end of a line and not 29;; for certain languages. The construct is indented for you,
30;; in a comment or in a string. 30;; and contains points for you to ;; fill in other text.
31;; 2. Position the cursor after expansion to a place specified by advance. 31
32;; 3. Indent the expanded region. 32;; These abbrevs expand only at the end of a line and when not in a comment
33;; 4. If a list of points as been provided with the abbreviation definition, 33;; or a string.
34;; the functions expand-jump-to-previous-mark and expand-jump-to-next-mark
35;; moved from mark to mark.
36;;
37;; Installation:
38;; * store this file somewhere in your load-path and byte compile it.
39;; * put (require 'expand) in your .emacs or in site-start.el or generate
40;; autoloads.
41;; * and according to the mode install your expansion table.
42;; 34;;
43;; Look at the Sample: section for emacs-lisp, perl and c expand lists. 35;; Look at the Sample: section for emacs-lisp, perl and c expand lists.
44;; For example for c-mode, you could declare your abbrev table with : 36;; For example for c-mode, you could declare your abbrev table with :
@@ -58,7 +50,7 @@
58;; 50;;
59;; and enter Expand mode with the following hook : 51;; and enter Expand mode with the following hook :
60;; 52;;
61;; (add-hook 'c-mode-hook (function (lambda() 53;; (add-hook 'c-mode-hook (function (lambda ()
62;; (expand-add-abbrevs c-mode-abbrev-table c-expand-list) 54;; (expand-add-abbrevs c-mode-abbrev-table c-expand-list)
63;; (expand-mode)))) 55;; (expand-mode))))
64;; 56;;
@@ -67,7 +59,7 @@
67;; 59;;
68;; (add-hook 'expand-mode-load-hook 60;; (add-hook 'expand-mode-load-hook
69;; (function 61;; (function
70;; (lambda() 62;; (lambda ()
71;; (add-hook 'expand-expand-hook 'indent-according-to-mode) 63;; (add-hook 'expand-expand-hook 'indent-according-to-mode)
72;; (add-hook 'expand-jump-hook 'indent-according-to-mode) 64;; (add-hook 'expand-jump-hook 'indent-according-to-mode)
73;; (define-key expand-map '[(control tab)] 'expand-jump-to-next-mark) 65;; (define-key expand-map '[(control tab)] 'expand-jump-to-next-mark)
@@ -88,7 +80,7 @@
88 80
89;;; Constants: 81;;; Constants:
90 82
91(defconst expand-mode-version "$Id: expand.el,v 1.13 1996/11/23 18:59:53 fred Exp $" 83(defconst expand-mode-version "$Id: expand.el,v 1.1 1996/12/28 19:41:45 rms Exp rms $"
92 "Version tag for expand.el.") 84 "Version tag for expand.el.")
93 85
94(defconst expand-mode-help-address "expand-help@sugix.frmug.org" 86(defconst expand-mode-help-address "expand-help@sugix.frmug.org"
@@ -284,7 +276,7 @@
284;;; Code: 276;;; Code:
285 277
286;;;###autoload 278;;;###autoload
287(defun expand-mode(&optional arg) 279(defun expand-mode (&optional arg)
288 "Toggle Expand mode. 280 "Toggle Expand mode.
289With argument ARG, turn Expand mode on if ARG is positive. 281With argument ARG, turn Expand mode on if ARG is positive.
290In Expand mode, inserting an abbreviation at the end of a line 282In Expand mode, inserting an abbreviation at the end of a line
@@ -300,7 +292,6 @@ causes it to expand and be replaced by its expansion."
300;;;###autoload 292;;;###autoload
301(defvar expand-map (make-sparse-keymap) 293(defvar expand-map (make-sparse-keymap)
302 "Key map used in Expand mode.") 294 "Key map used in Expand mode.")
303(define-key expand-map " " 'expand-template-abbreviation)
304 295
305(or (assq 'expand-mode minor-mode-alist) 296(or (assq 'expand-mode minor-mode-alist)
306 (setq minor-mode-alist (cons (list 'expand-mode expand-mode-name) 297 (setq minor-mode-alist (cons (list 'expand-mode expand-mode-name)
@@ -312,22 +303,27 @@ causes it to expand and be replaced by its expansion."
312 303
313;;;###autoload 304;;;###autoload
314(defun expand-add-abbrevs (table abbrevs) 305(defun expand-add-abbrevs (table abbrevs)
315 "Add a list of abbrev to the table. 306 "Add a list of abbrev to abbrev table TABLE.
316Each abbrev description entry has the following format : 307ABBREVS is a list of abbrev definitions; each abbrev description entry
317 (abbrev expansion arg) 308has the form (ABBREV EXPANSION ARG).
318where 309
319 abbrev is the abbreviation to replace. 310ABBREV is the abbreviation to replace.
320 expansion is the replacement string or a function which will make 311
321the expansion. For example you could use the DMacros or skeleton packages 312EXPANSION is the replacement string or a function which will make the
313expansion. For example you, could use the DMacros or skeleton packages
322to generate such functions. 314to generate such functions.
323 arg is an optional element which can be a number or a list of 315
324numbers. If arg is a number, the cursor will be placed at arg chars 316ARG is an optional argument which can be a number or a list of
325from the beginning of the expanded text. If expansion is a list of 317numbers. If ARG is a number, point is placed ARG chars from the
326numbers the cursor will be placed according to the first number of the 318beginning of the expanded text.
327list from the beginning of the expanded text and marks will be placed 319
328and you will be able to visit them cyclicaly with the functions 320If ARG is a list of numbers, point is placed according to the first
329expand-jump-to-previous-mark and expand-jump-to-next-mark. If arg is 321member of the list, but you can visit the other specified positions
330omitted, the cursor will be placed at the end of the expanded text." 322cyclicaly with the functions `expand-jump-to-previous-mark' and
323`expand-jump-to-next-mark'.
324
325If ARG is omitted, point is placed at the end of the expanded text."
326
331 (if (null abbrevs) 327 (if (null abbrevs)
332 table 328 table
333 (expand-add-abbrev table (nth 0 (car abbrevs)) (nth 1 (car abbrevs)) 329 (expand-add-abbrev table (nth 0 (car abbrevs)) (nth 1 (car abbrevs))
@@ -342,7 +338,7 @@ This variable is local to a buffer.")
342(make-variable-buffer-local 'expand-pos) 338(make-variable-buffer-local 'expand-pos)
343 339
344(defvar expand-index 0 340(defvar expand-index 0
345 "Index of the last marker used in expand-pos. 341 "Index of the last marker used in `expand-pos'.
346This variable is local to a buffer.") 342This variable is local to a buffer.")
347(make-variable-buffer-local 'expand-index) 343(make-variable-buffer-local 'expand-index)
348 344
@@ -376,25 +372,10 @@ This variable is local to a buffer.")
376 ) 372 )
377 'expand-abbrev-hook))) 373 'expand-abbrev-hook)))
378 374
379;;;###autoload 375(put 'expand-abbrev-hook 'no-self-insert t)
380(defun expand-template-abbreviation(arg) 376(defun expand-abbrev-hook ()
381 "Do the expansion job if we are at the end of a line or insert space." 377 "Abbrev hook used to do the expansion job of expand abbrevs.
382 (interactive "p") 378See `expand-add-abbrevs'."
383 (or (expand-try-to-expand)
384 (self-insert-command arg)))
385
386;; Try to expand an abbrev. On success check if it is an Expand mode abbrev
387;; else undo the expansion.
388(defun expand-try-to-expand()
389 (if (not (expand-abbrev))
390 nil
391 (if (not (stringp (symbol-value last-abbrev)))
392 t
393 (unexpand-abbrev)
394 nil)))
395
396(defun expand-abbrev-hook()
397 "Abbrev hook used to do the expansion job of expand abbrevs. See `expand-add-abbrevs'."
398 ;; Expand only at the end of a line if we are near a word that has 379 ;; Expand only at the end of a line if we are near a word that has
399 ;; an abbrev built from expand-add-abbrev. 380 ;; an abbrev built from expand-add-abbrev.
400 (if (and (eolp) 381 (if (and (eolp)
@@ -423,7 +404,7 @@ This variable is local to a buffer.")
423 t)))) 404 t))))
424 ) 405 )
425 406
426(defun expand-do-expansion() 407(defun expand-do-expansion ()
427 (delete-backward-char (length last-abbrev-text)) 408 (delete-backward-char (length last-abbrev-text))
428 (let* ((vect (symbol-value last-abbrev)) 409 (let* ((vect (symbol-value last-abbrev))
429 (text (aref vect 0)) 410 (text (aref vect 0))
@@ -442,7 +423,7 @@ This variable is local to a buffer.")
442 t) 423 t)
443 ) 424 )
444 425
445(defun expand-abbrev-from-expand(word) 426(defun expand-abbrev-from-expand (word)
446 "Test if an abbrev has a hook." 427 "Test if an abbrev has a hook."
447 (or 428 (or
448 (and (intern-soft word local-abbrev-table) 429 (and (intern-soft word local-abbrev-table)
@@ -457,7 +438,7 @@ This variable is local to a buffer.")
457 (backward-word 1) 438 (backward-word 1)
458 (buffer-substring p (point))))) 439 (buffer-substring p (point)))))
459 440
460(defun expand-jump-to-previous-mark() 441(defun expand-jump-to-previous-mark ()
461 "Move the cursor to previous mark created by the expansion." 442 "Move the cursor to previous mark created by the expansion."
462 (interactive) 443 (interactive)
463 (if expand-pos 444 (if expand-pos
@@ -468,7 +449,7 @@ This variable is local to a buffer.")
468 (goto-char (aref expand-pos expand-index)) 449 (goto-char (aref expand-pos expand-index))
469 (run-hooks 'expand-jump-hook)))) 450 (run-hooks 'expand-jump-hook))))
470 451
471(defun expand-jump-to-next-mark() 452(defun expand-jump-to-next-mark ()
472 "Move the cursor to next mark created by the expansion." 453 "Move the cursor to next mark created by the expansion."
473 (interactive) 454 (interactive)
474 (if expand-pos 455 (if expand-pos
@@ -556,10 +537,11 @@ This variable is local to a buffer.")
556 v)) 537 v))
557 538
558;; integration with skeleton.el 539;; integration with skeleton.el
540;; Used in `skeleton-end-hook' to fetch the positions for @ skeleton tags.
541;; See `skeleton-insert'.
559(defun expand-skeleton-end-hook () 542(defun expand-skeleton-end-hook ()
560 "`skeleton-end-hook' to enable expand marks jumps for @ skeleton tags see `skeleton-insert'." 543 (if skeleton-positions
561 (if skeleton-marks 544 (setq expand-list skeleton-positions)))
562 (setq expand-list skeleton-marks)))
563 545
564(add-hook 'skeleton-end-hook (function expand-skeleton-end-hook)) 546(add-hook 'skeleton-end-hook (function expand-skeleton-end-hook))
565 547