Mercurial > emacs
comparison lisp/expand.el @ 16838:9bcab3c812bb
No longer a minor mode.
(expand-submit-bug-report): Function deleted.
(expand-mode-version, expand-mode-help-address): Variables deleted.
(expand-mode): Variable and function deleted.
(expand-mode-hook, expand-mode-name): Variables deleted.
(expand-load-hook): Variable renamed from expand-mode-load-hook.
(expand-map): Variable deleted.
(expand-jump-to-next-slot): Renamed from expand-jump-to-next-mark.
Add autoload.
(expand-jump-to-previous-slot): Add autoload.
Renamed from expand-jump-to-previous-mark.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 07 Jan 1997 08:14:12 +0000 |
parents | 26698958bd84 |
children | 8f952e921136 |
comparison
equal
deleted
inserted
replaced
16837:7370bcad5cb1 | 16838:9bcab3c812bb |
---|---|
1 ;; expand.el --- minor mode to make abbreviations more usable. | 1 ;; expand.el --- make abbreviations more usable. |
2 | 2 |
3 ;; Copyright (C) 1995, 1996 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1995, 1996 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Frederic Lepied <Frederic.Lepied@sugix.frmug.org> | 5 ;; Author: Frederic Lepied <Frederic.Lepied@sugix.frmug.org> |
6 ;; Maintainer: Frederic Lepied <Frederic.Lepied@sugix.frmug.org> | 6 ;; Maintainer: Frederic Lepied <Frederic.Lepied@sugix.frmug.org> |
25 | 25 |
26 ;;; Commentary: | 26 ;;; Commentary: |
27 ;; | 27 ;; |
28 ;; This package defines abbrevs which expand into structured constructs | 28 ;; This package defines abbrevs which expand into structured constructs |
29 ;; for certain languages. The construct is indented for you, | 29 ;; for certain languages. The construct is indented for you, |
30 ;; and contains points for you to ;; fill in other text. | 30 ;; and contains slots for you to fill in other text. |
31 | 31 |
32 ;; These abbrevs expand only at the end of a line and when not in a comment | 32 ;; These abbrevs expand only at the end of a line and when not in a comment |
33 ;; or a string. | 33 ;; or a string. |
34 ;; | 34 ;; |
35 ;; 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. |
46 ;; ("while" "while () {\n\n}" (8 12)) | 46 ;; ("while" "while () {\n\n}" (8 12)) |
47 ;; ("default" "default:\n\nbreak;" 10) | 47 ;; ("default" "default:\n\nbreak;" 10) |
48 ;; ("main" "int\nmain(int argc, char * argv[])\n{\n\n}\n" 37)) | 48 ;; ("main" "int\nmain(int argc, char * argv[])\n{\n\n}\n" 37)) |
49 ;; "Expansions for C mode") | 49 ;; "Expansions for C mode") |
50 ;; | 50 ;; |
51 ;; and enter Expand mode with the following hook : | 51 ;; and enter Abbrev mode with the following hook : |
52 ;; | 52 ;; |
53 ;; (add-hook 'c-mode-hook (function (lambda () | 53 ;; (add-hook 'c-mode-hook (function (lambda () |
54 ;; (expand-add-abbrevs c-mode-abbrev-table c-expand-list) | 54 ;; (expand-add-abbrevs c-mode-abbrev-table c-expand-list) |
55 ;; (expand-mode)))) | 55 ;; (abbrev-mode)))) |
56 ;; | 56 ;; |
57 ;; you can also bind jump functions to some keys and init some post-process | 57 ;; you can also init some post-process hooks : |
58 ;; hooks : | 58 ;; |
59 ;; | 59 ;; (add-hook 'expand-load-hook |
60 ;; (add-hook 'expand-mode-load-hook | |
61 ;; (function | 60 ;; (function |
62 ;; (lambda () | 61 ;; (lambda () |
63 ;; (add-hook 'expand-expand-hook 'indent-according-to-mode) | 62 ;; (add-hook 'expand-expand-hook 'indent-according-to-mode) |
64 ;; (add-hook 'expand-jump-hook 'indent-according-to-mode) | 63 ;; (add-hook 'expand-jump-hook 'indent-according-to-mode)))) |
65 ;; (define-key expand-map '[(control tab)] 'expand-jump-to-next-mark) | |
66 ;; (define-key expand-map '[(control shift tab)] 'expand-jump-to-previous-mark)))) | |
67 ;; | 64 ;; |
68 ;; Remarks: | 65 ;; Remarks: |
69 ;; | 66 ;; |
70 ;; Has been tested under emacs 19.28-19.34 and XEmacs 19.11. | |
71 ;; Many thanks to Heddy Boubaker <boubaker@cenatls.cena.dgac.fr>, | 67 ;; Many thanks to Heddy Boubaker <boubaker@cenatls.cena.dgac.fr>, |
72 ;; Jerome Santini <santini@chambord.univ-orleans.fr>, | 68 ;; Jerome Santini <santini@chambord.univ-orleans.fr>, |
73 ;; Jari Aalto <jaalto@tre.tele.nokia.fi>. | 69 ;; Jari Aalto <jaalto@tre.tele.nokia.fi>. |
74 ;; | 70 ;; |
75 ;; Please send me a word to give me your feeling about this mode or | 71 ;; Please send me a word to give me your feeling about this feature or |
76 ;; to explain me how you use it (your expansions table for example) using | 72 ;; to explain me how you use it (your expansions table for example) using |
77 ;; the function expand-mode-submit-report. | 73 ;; the function expand-submit-report. |
78 | 74 |
79 ;; Expand mode is not a replacement for abbrev it is just a layer above it. | |
80 | |
81 ;;; Constants: | 75 ;;; Constants: |
82 | 76 |
83 (defconst expand-mode-version "$Id: expand.el,v 1.1 1996/12/28 19:41:45 rms Exp rms $" | 77 (defvar expand-load-hook nil |
84 "Version tag for expand.el.") | 78 "Hooks run when `expand.el' is loaded.") |
85 | |
86 (defconst expand-mode-help-address "expand-help@sugix.frmug.org" | |
87 "Email address to send requests, comments or bug reports.") | |
88 | |
89 (defvar expand-mode nil | |
90 "Status variable for Expand mode.") | |
91 (make-variable-buffer-local 'expand-mode) | |
92 | |
93 (defvar expand-mode-name " Expand" | |
94 "Name of mode displayed in the modeline for Expand mode.") | |
95 | |
96 (defvar expand-mode-hook nil | |
97 "Hooks run when Expand mode is enabled.") | |
98 | |
99 (defvar expand-mode-load-hook nil | |
100 "Hooks run when expand is loaded.") | |
101 | 79 |
102 (defvar expand-expand-hook nil | 80 (defvar expand-expand-hook nil |
103 "Hooks run when expansion is done.") | 81 "Hooks run when an abbrev made by `expand-add-abbrevs' is expanded.") |
104 | 82 |
105 (defvar expand-jump-hook nil | 83 (defvar expand-jump-hook nil |
106 "Hooks run when jump to mark occurs.") | 84 "Hooks run by `expand-jump-to-previous-slot' and `expand-jump-to-next-slot'.") |
107 | 85 |
108 ;;; Samples: | 86 ;;; Samples: |
109 | 87 |
110 (define-skeleton expand-c-for-skeleton "For loop skeleton" | 88 (define-skeleton expand-c-for-skeleton "For loop skeleton" |
111 "Loop var: " | 89 "Loop var: " |
274 "Expansions for Perl mode. See `expand-add-abbrevs'.") | 252 "Expansions for Perl mode. See `expand-add-abbrevs'.") |
275 | 253 |
276 ;;; Code: | 254 ;;; Code: |
277 | 255 |
278 ;;;###autoload | 256 ;;;###autoload |
279 (defun expand-mode (&optional arg) | |
280 "Toggle Expand mode. | |
281 With argument ARG, turn Expand mode on if ARG is positive. | |
282 In Expand mode, inserting an abbreviation at the end of a line | |
283 causes it to expand and be replaced by its expansion." | |
284 (interactive "P") | |
285 (setq expand-mode (if (null arg) (not expand-mode) | |
286 (> (prefix-numeric-value arg) 0))) | |
287 (if expand-mode | |
288 (progn | |
289 (setq abbrev-mode nil) | |
290 (run-hooks 'expand-mode-hook)))) | |
291 | |
292 ;;;###autoload | |
293 (defvar expand-map (make-sparse-keymap) | |
294 "Key map used in Expand mode.") | |
295 | |
296 (or (assq 'expand-mode minor-mode-alist) | |
297 (setq minor-mode-alist (cons (list 'expand-mode expand-mode-name) | |
298 minor-mode-alist))) | |
299 | |
300 (or (assq 'expand-mode minor-mode-map-alist) | |
301 (setq minor-mode-map-alist (cons (cons 'expand-mode expand-map) | |
302 minor-mode-map-alist))) | |
303 | |
304 ;;;###autoload | |
305 (defun expand-add-abbrevs (table abbrevs) | 257 (defun expand-add-abbrevs (table abbrevs) |
306 "Add a list of abbrev to abbrev table TABLE. | 258 "Add a list of abbrev to abbrev table TABLE. |
307 ABBREVS is a list of abbrev definitions; each abbrev description entry | 259 ABBREVS is a list of abbrev definitions; each abbrev description entry |
308 has the form (ABBREV EXPANSION ARG). | 260 has the form (ABBREV EXPANSION ARG). |
309 | 261 |
317 numbers. If ARG is a number, point is placed ARG chars from the | 269 numbers. If ARG is a number, point is placed ARG chars from the |
318 beginning of the expanded text. | 270 beginning of the expanded text. |
319 | 271 |
320 If ARG is a list of numbers, point is placed according to the first | 272 If ARG is a list of numbers, point is placed according to the first |
321 member of the list, but you can visit the other specified positions | 273 member of the list, but you can visit the other specified positions |
322 cyclicaly with the functions `expand-jump-to-previous-mark' and | 274 cyclicaly with the functions `expand-jump-to-previous-slot' and |
323 `expand-jump-to-next-mark'. | 275 `expand-jump-to-next-slot'. |
324 | 276 |
325 If ARG is omitted, point is placed at the end of the expanded text." | 277 If ARG is omitted, point is placed at the end of the expanded text." |
326 | 278 |
327 (if (null abbrevs) | 279 (if (null abbrevs) |
328 table | 280 table |
329 (expand-add-abbrev table (nth 0 (car abbrevs)) (nth 1 (car abbrevs)) | 281 (expand-add-abbrev table (nth 0 (car abbrevs)) (nth 1 (car abbrevs)) |
330 (nth 2 (car abbrevs))) | 282 (nth 2 (car abbrevs))) |
331 (expand-add-abbrevs table (cdr abbrevs)))) | 283 (expand-add-abbrevs table (cdr abbrevs)))) |
332 | 284 |
333 (defvar expand-list nil "Temporary variable used by Expand mode.") | 285 (defvar expand-list nil "Temporary variable used by the Expand package.") |
334 | 286 |
335 (defvar expand-pos nil | 287 (defvar expand-pos nil |
336 "If non nil, stores a vector containing markers to positions defined by the last expansion. | 288 "If non nil, stores a vector containing markers to positions defined by the last expansion. |
337 This variable is local to a buffer.") | 289 This variable is local to a buffer.") |
338 (make-variable-buffer-local 'expand-pos) | 290 (make-variable-buffer-local 'expand-pos) |
436 (save-excursion | 388 (save-excursion |
437 (let ((p (point))) | 389 (let ((p (point))) |
438 (backward-word 1) | 390 (backward-word 1) |
439 (buffer-substring p (point))))) | 391 (buffer-substring p (point))))) |
440 | 392 |
441 (defun expand-jump-to-previous-mark () | 393 ;;;###autoload |
442 "Move the cursor to previous mark created by the expansion." | 394 (defun expand-jump-to-previous-slot () |
395 "Move the cursor to the previous slot in the last abbrev expansion. | |
396 This is used only in conjunction with `expand-add-abbrevs'." | |
443 (interactive) | 397 (interactive) |
444 (if expand-pos | 398 (if expand-pos |
445 (progn | 399 (progn |
446 (setq expand-index (1- expand-index)) | 400 (setq expand-index (1- expand-index)) |
447 (if (< expand-index 0) | 401 (if (< expand-index 0) |
448 (setq expand-index (1- (length expand-pos)))) | 402 (setq expand-index (1- (length expand-pos)))) |
449 (goto-char (aref expand-pos expand-index)) | 403 (goto-char (aref expand-pos expand-index)) |
450 (run-hooks 'expand-jump-hook)))) | 404 (run-hooks 'expand-jump-hook)))) |
451 | 405 |
452 (defun expand-jump-to-next-mark () | 406 ;;;###autoload |
453 "Move the cursor to next mark created by the expansion." | 407 (defun expand-jump-to-next-slot () |
408 "Move the cursor to the next slot in the last abbrev expansion. | |
409 This is used only in conjunction with `expand-add-abbrevs'." | |
454 (interactive) | 410 (interactive) |
455 (if expand-pos | 411 (if expand-pos |
456 (progn | 412 (progn |
457 (setq expand-index (1+ expand-index)) | 413 (setq expand-index (1+ expand-index)) |
458 (if (>= expand-index (length expand-pos)) | 414 (if (>= expand-index (length expand-pos)) |
459 (setq expand-index 0)) | 415 (setq expand-index 0)) |
460 (goto-char (aref expand-pos expand-index)) | 416 (goto-char (aref expand-pos expand-index)) |
461 (run-hooks 'expand-jump-hook)))) | 417 (run-hooks 'expand-jump-hook)))) |
418 | |
419 ;;;###autoload (define-key ctl-x-map "ap" 'expand-jump-to-previous-slot) | |
420 ;;;###autoload (define-key ctl-x-map "an" 'expand-jump-to-next-slot) | |
462 | 421 |
463 (defun expand-build-list (len l) | 422 (defun expand-build-list (len l) |
464 "Build a vector of offset positions from the list of positions." | 423 "Build a vector of offset positions from the list of positions." |
465 (expand-clear-markers) | 424 (expand-clear-markers) |
466 (setq expand-list (vconcat l)) | 425 (setq expand-list (vconcat l)) |
505 (cond | 464 (cond |
506 ((nth 3 state) 'string) | 465 ((nth 3 state) 'string) |
507 ((nth 4 state) 'comment) | 466 ((nth 4 state) 'comment) |
508 (t nil))))) | 467 (t nil))))) |
509 | 468 |
510 (defun expand-mode-submit-report () | |
511 "Report a problem, a suggestion or a comment about Expand mode." | |
512 (interactive) | |
513 (require 'reporter) | |
514 (reporter-submit-bug-report | |
515 expand-mode-help-address | |
516 (concat "expand.el " expand-mode-version) | |
517 '(expand-mode-name | |
518 expand-mode-hook | |
519 expand-mode-load-hook | |
520 expand-map | |
521 ) | |
522 nil | |
523 nil | |
524 "Dear expand.el maintainer,")) | |
525 | |
526 ;; support functions to add marks to jump from outside function | 469 ;; support functions to add marks to jump from outside function |
527 | 470 |
528 (defun expand-list-to-markers (l) | 471 (defun expand-list-to-markers (l) |
529 "Transform a list of markers in reverse order into a vector in the correct order." | 472 "Transform a list of markers in reverse order into a vector in the correct order." |
530 (let* ((len (1- (length l))) | 473 (let* ((len (1- (length l))) |
546 (add-hook 'skeleton-end-hook (function expand-skeleton-end-hook)) | 489 (add-hook 'skeleton-end-hook (function expand-skeleton-end-hook)) |
547 | 490 |
548 (provide 'expand) | 491 (provide 'expand) |
549 | 492 |
550 ;; run load hooks | 493 ;; run load hooks |
551 (run-hooks 'expand-mode-load-hook) | 494 (run-hooks 'expand-load-hook) |
552 | 495 |
553 ;;; expand.el ends here | 496 ;;; expand.el ends here |