aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-06-24 22:33:56 +0000
committerRichard M. Stallman1996-06-24 22:33:56 +0000
commitff85d4f3be32e2367e129064c52dac2b59f32f1c (patch)
tree7dd57167ef41c8b7b9927bdca2aab8cf9295f34b
parent4d123b4d43867264055b8f544e4db4c135786798 (diff)
downloademacs-ff85d4f3be32e2367e129064c52dac2b59f32f1c.tar.gz
emacs-ff85d4f3be32e2367e129064c52dac2b59f32f1c.zip
(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.
-rw-r--r--lisp/skeleton.el165
1 files changed, 83 insertions, 82 deletions
diff --git a/lisp/skeleton.el b/lisp/skeleton.el
index 2bb33ee4db6..edea9c4c3e9 100644
--- a/lisp/skeleton.el
+++ b/lisp/skeleton.el
@@ -126,7 +126,7 @@ INTERACTOR and ELEMENT ... are as defined under `skeleton-insert'."
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').
128Prefix ARG allows wrapping around words or regions (see `skeleton-insert'). 128Prefix ARG allows wrapping around words or regions (see `skeleton-insert').
129If no ARG was given, and the region is visible, it defaults to -1 depending 129If no ARG was given, but the region is visible, ARG defaults to -1 depending
130on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once. 130on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once.
131This command can also be an abbrev expansion (3rd and 4th columns in 131This command can also be an abbrev expansion (3rd and 4th columns in
132\\[edit-abbrevs] buffer: \"\" command-name). 132\\[edit-abbrevs] buffer: \"\" command-name).
@@ -158,7 +158,7 @@ ignored."
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
@@ -396,32 +396,32 @@ automatically, and you are prompted to fill in the variable parts.")))
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
@@ -452,78 +452,79 @@ Elements might be (?` ?` _ \"''\"), (?\\( ? _ \" )\") or (?{ \\n > _ \\n ?} >).
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
455With no ARG, if `skeleton-pair' is non-nil, and if 455With 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 456is visible the pair is wrapped around it depending on `skeleton-autowrap'.
457Else, if `skeleton-pair-on-word' is non-nil or we are not before or inside a
457word, and if `skeleton-pair-filter' returns nil, pairing is performed. 458word, and if `skeleton-pair-filter' returns nil, pairing is performed.
458 459
459If a match is found in `skeleton-pair-alist', that is inserted, else 460If a match is found in `skeleton-pair-alist', that is inserted, else
460the defaults are used. These are (), [], {}, <> and `' for the 461the defaults are used. These are (), [], {}, <> and `' for the
461symmetrical ones, and the same character twice for the others." 462symmetrical 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