Mercurial > emacs
comparison lisp/skeleton.el @ 15506:1a66dbb1a470
(local-variables-section): Adapted comment to outline minor mode.
(skeleton-pair-insert-maybe): Rewritten to support autowrapping.
(mirror-mode): Fixed change of pair-* to skeleton-pair-*. Also pairs
8 bit characters.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 24 Jun 1996 22:33:56 +0000 |
parents | 5393431269db |
children | ef2b47c6c225 |
comparison
equal
deleted
inserted
replaced
15505:4d3ce6ab31d8 | 15506:1a66dbb1a470 |
---|---|
124 ;; names are. | 124 ;; names are. |
125 ;;;###autoload | 125 ;;;###autoload |
126 (defun skeleton-proxy (&optional str arg) | 126 (defun skeleton-proxy (&optional str arg) |
127 "Insert skeleton defined by variable of same name (see `skeleton-insert'). | 127 "Insert skeleton defined by variable of same name (see `skeleton-insert'). |
128 Prefix ARG allows wrapping around words or regions (see `skeleton-insert'). | 128 Prefix ARG allows wrapping around words or regions (see `skeleton-insert'). |
129 If no ARG was given, and the region is visible, it defaults to -1 depending | 129 If no ARG was given, but the region is visible, ARG defaults to -1 depending |
130 on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once. | 130 on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once. |
131 This command can also be an abbrev expansion (3rd and 4th columns in | 131 This command can also be an abbrev expansion (3rd and 4th columns in |
132 \\[edit-abbrevs] buffer: \"\" command-name). | 132 \\[edit-abbrevs] buffer: \"\" command-name). |
133 | 133 |
134 When called as a function, optional first argument STR may also be a string | 134 When called as a function, optional first argument STR may also be a string |
156 (prefix-numeric-value (or arg | 156 (prefix-numeric-value (or arg |
157 current-prefix-arg)) | 157 current-prefix-arg)) |
158 (and skeleton-autowrap | 158 (and skeleton-autowrap |
159 (or (eq last-command 'mouse-drag-region) | 159 (or (eq last-command 'mouse-drag-region) |
160 (and transient-mark-mode mark-active)) | 160 (and transient-mark-mode mark-active)) |
161 -1))) | 161 -1))) |
162 (if (stringp str) | 162 (if (stringp str) |
163 str)) | 163 str)) |
164 (and skeleton-abbrev-cleanup | 164 (and skeleton-abbrev-cleanup |
165 (setq skeleton-abbrev-cleanup (point)) | 165 (setq skeleton-abbrev-cleanup (point)) |
166 (add-hook 'post-command-hook 'skeleton-abbrev-cleanup nil t))))) | 166 (add-hook 'post-command-hook 'skeleton-abbrev-cleanup nil t))))) |
394 ((null element)) | 394 ((null element)) |
395 ((skeleton-internal-1 (eval element) t)))) | 395 ((skeleton-internal-1 (eval element) t)))) |
396 | 396 |
397 | 397 |
398 ;; Maybe belongs into simple.el or elsewhere | 398 ;; Maybe belongs into simple.el or elsewhere |
399 | 399 ;; ;###autoload |
400 ;;;(define-skeleton local-variables-section | 400 ;;; (define-skeleton local-variables-section |
401 ;;; "Insert a local variables section. Use current comment syntax if any." | 401 ;; "Insert a local variables section. Use current comment syntax if any." |
402 ;;; (completing-read "Mode: " obarray | 402 ;; (completing-read "Mode: " obarray |
403 ;;; (lambda (symbol) | 403 ;; (lambda (symbol) |
404 ;;; (if (commandp symbol) | 404 ;; (if (commandp symbol) |
405 ;;; (string-match "-mode$" (symbol-name symbol)))) | 405 ;; (string-match "-mode$" (symbol-name symbol)))) |
406 ;;; t) | 406 ;; t) |
407 ;;; '(save-excursion | 407 ;; '(save-excursion |
408 ;;; (if (re-search-forward page-delimiter nil t) | 408 ;; (if (re-search-forward page-delimiter nil t) |
409 ;;; (error "Not on last page."))) | 409 ;; (error "Not on last page."))) |
410 ;;; comment-start "Local Variables:" comment-end \n | 410 ;; comment-start "Local Variables:" comment-end \n |
411 ;;; comment-start "mode: " str | 411 ;; comment-start "mode: " str |
412 ;;; & -5 | '(kill-line 0) & -1 | comment-end \n | 412 ;; & -5 | '(kill-line 0) & -1 | comment-end \n |
413 ;;; ( (completing-read (format "Variable, %s: " skeleton-subprompt) | 413 ;; ( (completing-read (format "Variable, %s: " skeleton-subprompt) |
414 ;;; obarray | 414 ;; obarray |
415 ;;; (lambda (symbol) | 415 ;; (lambda (symbol) |
416 ;;; (or (eq symbol 'eval) | 416 ;; (or (eq symbol 'eval) |
417 ;;; (user-variable-p symbol))) | 417 ;; (user-variable-p symbol))) |
418 ;;; t) | 418 ;; t) |
419 ;;; comment-start str ": " | 419 ;; comment-start str ": " |
420 ;;; (read-from-minibuffer "Expression: " nil read-expression-map nil | 420 ;; (read-from-minibuffer "Expression: " nil read-expression-map nil |
421 ;;; 'read-expression-history) | _ | 421 ;; 'read-expression-history) | _ |
422 ;;; comment-end \n) | 422 ;; comment-end \n) |
423 ;;; resume: | 423 ;; resume: |
424 ;;; comment-start "End:" comment-end) | 424 ;; comment-start "End:" comment-end) |
425 | 425 |
426 ;; Variables and command for automatically inserting pairs like () or "". | 426 ;; Variables and command for automatically inserting pairs like () or "". |
427 | 427 |
428 (defvar skeleton-pair nil | 428 (defvar skeleton-pair nil |
429 "*If this is nil pairing is turned off, no matter what else is set. | 429 "*If this is nil pairing is turned off, no matter what else is set. |
450 | 450 |
451 ;;;###autoload | 451 ;;;###autoload |
452 (defun skeleton-pair-insert-maybe (arg) | 452 (defun skeleton-pair-insert-maybe (arg) |
453 "Insert the character you type ARG times. | 453 "Insert the character you type ARG times. |
454 | 454 |
455 With no ARG, if `skeleton-pair' is non-nil, and if | 455 With no ARG, if `skeleton-pair' is non-nil, pairing can occur. If the region |
456 `skeleton-pair-on-word' is non-nil or we are not before or inside a | 456 is visible the pair is wrapped around it depending on `skeleton-autowrap'. |
457 Else, if `skeleton-pair-on-word' is non-nil or we are not before or inside a | |
457 word, and if `skeleton-pair-filter' returns nil, pairing is performed. | 458 word, and if `skeleton-pair-filter' returns nil, pairing is performed. |
458 | 459 |
459 If a match is found in `skeleton-pair-alist', that is inserted, else | 460 If a match is found in `skeleton-pair-alist', that is inserted, else |
460 the defaults are used. These are (), [], {}, <> and `' for the | 461 the defaults are used. These are (), [], {}, <> and `' for the |
461 symmetrical ones, and the same character twice for the others." | 462 symmetrical ones, and the same character twice for the others." |
462 (interactive "*P") | 463 (interactive "*P") |
463 (if (or arg | 464 (let ((mark (and skeleton-autowrap |
464 overwrite-mode | 465 (or (eq last-command 'mouse-drag-region) |
465 (not skeleton-pair) | 466 (and transient-mark-mode mark-active)))) |
466 (if (not skeleton-pair-on-word) (looking-at "\\w")) | 467 (skeleton-end-hook)) |
467 (funcall skeleton-pair-filter)) | 468 (if (or arg |
468 (self-insert-command (prefix-numeric-value arg)) | 469 (not skeleton-pair) |
469 (self-insert-command 1) | 470 (and (not mark) |
470 (if skeleton-abbrev-cleanup | 471 (or overwrite-mode |
471 () | 472 (if (not skeleton-pair-on-word) (looking-at "\\w")) |
472 ;; (preceding-char) is stripped of any Meta-stuff in last-command-char | 473 (funcall skeleton-pair-filter)))) |
473 (if (setq arg (assq (preceding-char) skeleton-pair-alist)) | 474 (self-insert-command (prefix-numeric-value arg)) |
474 ;; typed char is inserted (car is no real interactor) | 475 (setq last-command-char (logand last-command-char 255)) |
475 (let (skeleton-end-hook) | 476 (or skeleton-abbrev-cleanup |
476 (skeleton-insert arg)) | 477 (skeleton-insert |
477 (save-excursion | 478 (cons nil (or (assq last-command-char skeleton-pair-alist) |
478 (insert (or (cdr (assq (preceding-char) | 479 (assq last-command-char '((?( _ ?)) |
479 '((?( . ?)) | 480 (?[ _ ?]) |
480 (?[ . ?]) | 481 (?{ _ ?}) |
481 (?{ . ?}) | 482 (?< _ ?>) |
482 (?< . ?>) | 483 (?` _ ?'))) |
483 (?` . ?')))) | 484 `(,last-command-char _ ,last-command-char))) |
484 last-command-char))))))) | 485 (if mark -1)))))) |
485 | 486 |
486 | 487 |
487 ;;; A more serious example can be found in sh-script.el | 488 ;; A more serious example can be found in sh-script.el |
488 ;;;(defun mirror-mode () | 489 ;;; (defun mirror-mode () |
489 ;; "This major mode is an amusing little example of paired insertion. | 490 ;; "This major mode is an amusing little example of paired insertion. |
490 ;;All printable characters do a paired self insert, while the other commands | 491 ;;All printable characters do a paired self insert, while the other commands |
491 ;;work normally." | 492 ;;work normally." |
492 ;; (interactive) | 493 ;; (interactive) |
493 ;; (kill-all-local-variables) | 494 ;; (kill-all-local-variables) |
494 ;; (make-local-variable 'pair) | 495 ;; (make-local-variable 'skeleton-pair) |
495 ;; (make-local-variable 'pair-on-word) | 496 ;; (make-local-variable 'skeleton-pair-on-word) |
496 ;; (make-local-variable 'pair-filter) | 497 ;; (make-local-variable 'skeleton-pair-filter) |
497 ;; (make-local-variable 'pair-alist) | 498 ;; (make-local-variable 'skeleton-pair-alist) |
498 ;; (setq major-mode 'mirror-mode | 499 ;; (setq major-mode 'mirror-mode |
499 ;; mode-name "Mirror" | 500 ;; mode-name "Mirror" |
500 ;; pair-on-word t | 501 ;; skeleton-pair-on-word t |
501 ;; ;; in the middle column insert one or none if odd window-width | 502 ;; ;; in the middle column insert one or none if odd window-width |
502 ;; pair-filter (lambda () | 503 ;; skeleton-pair-filter (lambda () |
503 ;; (if (>= (current-column) | 504 ;; (if (>= (current-column) |
504 ;; (/ (window-width) 2)) | 505 ;; (/ (window-width) 2)) |
505 ;; ;; insert both on next line | 506 ;; ;; insert both on next line |
506 ;; (next-line 1) | 507 ;; (next-line 1) |
507 ;; ;; insert one or both? | 508 ;; ;; insert one or both? |
508 ;; (= (* 2 (1+ (current-column))) | 509 ;; (= (* 2 (1+ (current-column))) |
509 ;; (window-width)))) | 510 ;; (window-width)))) |
510 ;; ;; mirror these the other way round as well | 511 ;; ;; mirror these the other way round as well |
511 ;; pair-alist '((?) _ ?() | 512 ;; skeleton-pair-alist '((?) _ ?() |
512 ;; (?] _ ?[) | 513 ;; (?] _ ?[) |
513 ;; (?} _ ?{) | 514 ;; (?} _ ?{) |
514 ;; (?> _ ?<) | 515 ;; (?> _ ?<) |
515 ;; (?/ _ ?\\) | 516 ;; (?/ _ ?\\) |
516 ;; (?\\ _ ?/) | 517 ;; (?\\ _ ?/) |
517 ;; (?` ?` _ "''") | 518 ;; (?` ?` _ "''") |
518 ;; (?' ?' _ "``")) | 519 ;; (?' ?' _ "``")) |
519 ;; ;; in this mode we exceptionally ignore the user, else it's no fun | 520 ;; ;; in this mode we exceptionally ignore the user, else it's no fun |
520 ;; pair t) | 521 ;; skeleton-pair t) |
521 ;; (let ((map (make-keymap)) | 522 ;; (let ((map (make-vector 256 'skeleton-pair-insert-maybe)) |
522 ;; (i ? )) | 523 ;; (i 0)) |
523 ;; (use-local-map map) | 524 ;; (use-local-map `(keymap ,map)) |
524 ;; (setq map (car (cdr map))) | 525 ;; (while (< i ? ) |
525 ;; (while (< i ?\^?) | 526 ;; (aset map i nil) |
526 ;; (aset map i 'skeleton-pair-insert-maybe) | 527 ;; (aset map (+ i 128) nil) |
527 ;; (setq i (1+ i)))) | 528 ;; (setq i (1+ i)))) |
528 ;; (run-hooks 'mirror-mode-hook)) | 529 ;; (run-hooks 'mirror-mode-hook)) |
529 | 530 |
530 (provide 'skeleton) | 531 (provide 'skeleton) |
531 | 532 |