Mercurial > emacs
comparison lisp/skeleton.el @ 12619:9d4a4e914215
(local-variables-section): Delete autoload cookie.
(skeleton-pair-insert-maybe): Renamed from pair-insert-maybe.
(skeleton-pair, skeleton-pair-filter, skeleton-pair-alist)
(skeleton-pair-on-word): Renamed from pair-...
(mirror-mode): Commented out.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 20 Jul 1995 20:28:45 +0000 |
parents | 6c57be2d372f |
children | 9d994b0faaa3 |
comparison
equal
deleted
inserted
replaced
12618:60c4c0fee545 | 12619:9d4a4e914215 |
---|---|
108 (setq function (nth 1 (backtrace-frame 5))) | 108 (setq function (nth 1 (backtrace-frame 5))) |
109 (if (eq function 'byte-code) ; tracing byte-compiled function | 109 (if (eq function 'byte-code) ; tracing byte-compiled function |
110 (setq function (nth 1 (backtrace-frame 2))))) | 110 (setq function (nth 1 (backtrace-frame 2))))) |
111 (if (not (setq function (funcall skeleton-filter (symbol-value function)))) | 111 (if (not (setq function (funcall skeleton-filter (symbol-value function)))) |
112 (if (or (eq this-command 'self-insert-command) | 112 (if (or (eq this-command 'self-insert-command) |
113 (eq this-command 'pair-insert-maybe) | 113 (eq this-command 'skeleton-pair-insert-maybe) |
114 (eq this-command 'expand-abbrev)) | 114 (eq this-command 'expand-abbrev)) |
115 (setq buffer-undo-list | 115 (setq buffer-undo-list |
116 (primitive-undo 1 buffer-undo-list))) | 116 (primitive-undo 1 buffer-undo-list))) |
117 (skeleton-insert function | 117 (skeleton-insert function |
118 nil | 118 nil |
119 (if (setq skeleton-abbrev-cleanup | 119 (if (setq skeleton-abbrev-cleanup |
120 (or (eq this-command 'self-insert-command) | 120 (or (eq this-command 'self-insert-command) |
121 (eq this-command 'pair-insert-maybe))) | 121 (eq this-command 'skeleton-pair-insert-maybe))) |
122 () | 122 () |
123 ;; Pretend C-x a e passed the prefix arg to us | 123 ;; Pretend C-x a e passed the prefix arg to us |
124 (if (or arg current-prefix-arg) | 124 (if (or arg current-prefix-arg) |
125 (prefix-numeric-value (or arg | 125 (prefix-numeric-value (or arg |
126 current-prefix-arg))))) | 126 current-prefix-arg))))) |
343 ((null element)) | 343 ((null element)) |
344 ((skeleton-internal-1 (eval element) t)))) | 344 ((skeleton-internal-1 (eval element) t)))) |
345 | 345 |
346 ;; Maybe belongs into simple.el or elsewhere | 346 ;; Maybe belongs into simple.el or elsewhere |
347 | 347 |
348 ;;;###autoload | |
349 (define-skeleton local-variables-section | 348 (define-skeleton local-variables-section |
350 "Insert a local variables section. Use current comment syntax if any." | 349 "Insert a local variables section. Use current comment syntax if any." |
351 () | 350 () |
352 '(save-excursion | 351 '(save-excursion |
353 (if (re-search-forward page-delimiter nil t) | 352 (if (re-search-forward page-delimiter nil t) |
371 'read-expression-history) | _ | 370 'read-expression-history) | _ |
372 comment-end \n) | 371 comment-end \n) |
373 resume: | 372 resume: |
374 comment-start "End:" comment-end) | 373 comment-start "End:" comment-end) |
375 | 374 |
376 ;; variables and command for automatically inserting pairs like () or "" | 375 ;; Variables and command for automatically inserting pairs like () or "". |
377 | 376 |
378 (defvar pair nil | 377 (defvar skeleton-pair nil |
379 "*If this is nil pairing is turned off, no matter what else is set. | 378 "*If this is nil pairing is turned off, no matter what else is set. |
380 Otherwise modes with `pair-insert-maybe' on some keys will attempt this.") | 379 Otherwise modes with `skeleton-pair-insert-maybe' on some keys |
381 | 380 will attempt to insert pairs of matching characters.") |
382 | 381 |
383 (defvar pair-on-word nil | 382 |
384 "*If this is nil pairing is not attempted before or inside a word.") | 383 (defvar skeleton-pair-on-word nil |
385 | 384 "*If this is nil, paired insertion is inhibited before or inside a word.") |
386 | 385 |
387 (defvar pair-filter (lambda ()) | 386 |
388 "Attempt pairing if this function returns nil, before inserting. | 387 (defvar skeleton-pair-filter (lambda ()) |
388 "Attempt paired insertion if this function returns nil, before inserting. | |
389 This allows for context-sensitive checking whether pairing is appropriate.") | 389 This allows for context-sensitive checking whether pairing is appropriate.") |
390 | 390 |
391 | 391 |
392 (defvar pair-alist () | 392 (defvar skeleton-pair-alist () |
393 "An override alist of pairing partners matched against | 393 "An override alist of pairing partners matched against `last-command-char'. |
394 `last-command-char'. Each alist element, which looks like (ELEMENT | 394 Each alist element, which looks like (ELEMENT ...), is passed to |
395 ...), is passed to `skeleton-insert' with no interactor. Variable `str' | 395 `skeleton-insert' with no interactor. Variable `str' does nothing. |
396 does nothing. | |
397 | 396 |
398 Elements might be (?` ?` _ \"''\"), (?\\( ? _ \" )\") or (?{ \\n > _ \\n ?} >).") | 397 Elements might be (?` ?` _ \"''\"), (?\\( ? _ \" )\") or (?{ \\n > _ \\n ?} >).") |
399 | 398 |
400 | 399 |
401 | |
402 ;;;###autoload | 400 ;;;###autoload |
403 (defun pair-insert-maybe (arg) | 401 (defun skeleton-pair-insert-maybe (arg) |
404 "Insert the character you type ARG times. | 402 "Insert the character you type ARG times. |
405 | 403 |
406 With no ARG, if `pair' is non-nil, and if | 404 With no ARG, if `skeleton-pair' is non-nil, and if |
407 `pair-on-word' is non-nil or we are not before or inside a | 405 `skeleton-pair-on-word' is non-nil or we are not before or inside a |
408 word, and if `pair-filter' returns nil, pairing is performed. | 406 word, and if `skeleton-pair-filter' returns nil, pairing is performed. |
409 | 407 |
410 If a match is found in `pair-alist', that is inserted, else | 408 If a match is found in `skeleton-pair-alist', that is inserted, else |
411 the defaults are used. These are (), [], {}, <> and `' for the | 409 the defaults are used. These are (), [], {}, <> and `' for the |
412 symmetrical ones, and the same character twice for the others." | 410 symmetrical ones, and the same character twice for the others." |
413 (interactive "*P") | 411 (interactive "*P") |
414 (if (or arg | 412 (if (or arg |
415 (not pair) | 413 (not skeleton-pair) |
416 (if (not pair-on-word) (looking-at "\\w")) | 414 (if (not skeleton-pair-on-word) (looking-at "\\w")) |
417 (funcall pair-filter)) | 415 (funcall skeleton-pair-filter)) |
418 (self-insert-command (prefix-numeric-value arg)) | 416 (self-insert-command (prefix-numeric-value arg)) |
419 (self-insert-command 1) | 417 (self-insert-command 1) |
420 (if skeleton-abbrev-cleanup | 418 (if skeleton-abbrev-cleanup |
421 () | 419 () |
422 ;; (preceding-char) is stripped of any Meta-stuff in last-command-char | 420 ;; (preceding-char) is stripped of any Meta-stuff in last-command-char |
423 (if (setq arg (assq (preceding-char) pair-alist)) | 421 (if (setq arg (assq (preceding-char) skeleton-pair-alist)) |
424 ;; typed char is inserted, and car means no interactor | 422 ;; typed char is inserted, and car means no interactor |
425 (skeleton-insert arg t) | 423 (skeleton-insert arg t) |
426 (save-excursion | 424 (save-excursion |
427 (insert (or (cdr (assq (preceding-char) | 425 (insert (or (cdr (assq (preceding-char) |
428 '((?( . ?)) | 426 '((?( . ?)) |
431 (?< . ?>) | 429 (?< . ?>) |
432 (?` . ?')))) | 430 (?` . ?')))) |
433 last-command-char))))))) | 431 last-command-char))))))) |
434 | 432 |
435 | 433 |
436 ;; A more serious example can be found in sh-script.el | 434 ;;; ;; A more serious example can be found in sh-script.el |
437 ;; The quote before (defun prevents this from being byte-compiled. | 435 ;;; ;; The quote before (defun prevents this from being byte-compiled. |
438 '(defun mirror-mode () | 436 ;;;(defun mirror-mode () |
439 "This major mode is an amusing little example of paired insertion. | 437 ;;; "This major mode is an amusing little example of paired insertion. |
440 All printable characters do a paired self insert, while the other commands | 438 ;;;All printable characters do a paired self insert, while the other commands |
441 work normally." | 439 ;;;work normally." |
442 (interactive) | 440 ;;; (interactive) |
443 (kill-all-local-variables) | 441 ;;; (kill-all-local-variables) |
444 (make-local-variable 'pair) | 442 ;;; (make-local-variable 'pair) |
445 (make-local-variable 'pair-on-word) | 443 ;;; (make-local-variable 'pair-on-word) |
446 (make-local-variable 'pair-filter) | 444 ;;; (make-local-variable 'pair-filter) |
447 (make-local-variable 'pair-alist) | 445 ;;; (make-local-variable 'pair-alist) |
448 (setq major-mode 'mirror-mode | 446 ;;; (setq major-mode 'mirror-mode |
449 mode-name "Mirror" | 447 ;;; mode-name "Mirror" |
450 pair-on-word t | 448 ;;; pair-on-word t |
451 ;; in the middle column insert one or none if odd window-width | 449 ;;; ;; in the middle column insert one or none if odd window-width |
452 pair-filter (lambda () | 450 ;;; pair-filter (lambda () |
453 (if (>= (current-column) | 451 ;;; (if (>= (current-column) |
454 (/ (window-width) 2)) | 452 ;;; (/ (window-width) 2)) |
455 ;; insert both on next line | 453 ;;; ;; insert both on next line |
456 (next-line 1) | 454 ;;; (next-line 1) |
457 ;; insert one or both? | 455 ;;; ;; insert one or both? |
458 (= (* 2 (1+ (current-column))) | 456 ;;; (= (* 2 (1+ (current-column))) |
459 (window-width)))) | 457 ;;; (window-width)))) |
460 ;; mirror these the other way round as well | 458 ;;; ;; mirror these the other way round as well |
461 pair-alist '((?) _ ?() | 459 ;;; pair-alist '((?) _ ?() |
462 (?] _ ?[) | 460 ;;; (?] _ ?[) |
463 (?} _ ?{) | 461 ;;; (?} _ ?{) |
464 (?> _ ?<) | 462 ;;; (?> _ ?<) |
465 (?/ _ ?\\) | 463 ;;; (?/ _ ?\\) |
466 (?\\ _ ?/) | 464 ;;; (?\\ _ ?/) |
467 (?` ?` _ "''") | 465 ;;; (?` ?` _ "''") |
468 (?' ?' _ "``")) | 466 ;;; (?' ?' _ "``")) |
469 ;; in this mode we exceptionally ignore the user, else it's no fun | 467 ;;; ;; in this mode we exceptionally ignore the user, else it's no fun |
470 pair t) | 468 ;;; pair t) |
471 (let ((map (make-keymap)) | 469 ;;; (let ((map (make-keymap)) |
472 (i ? )) | 470 ;;; (i ? )) |
473 (use-local-map map) | 471 ;;; (use-local-map map) |
474 (setq map (car (cdr map))) | 472 ;;; (setq map (car (cdr map))) |
475 (while (< i ?\^?) | 473 ;;; (while (< i ?\^?) |
476 (aset map i 'pair-insert-maybe) | 474 ;;; (aset map i 'skeleton-pair-insert-maybe) |
477 (setq i (1+ i)))) | 475 ;;; (setq i (1+ i)))) |
478 (run-hooks 'mirror-mode-hook)) | 476 ;;; (run-hooks 'mirror-mode-hook)) |
479 | 477 |
480 ;; skeleton.el ends here | 478 ;; skeleton.el ends here |