From: Chris Hanson Date: Tue, 23 Apr 1996 22:33:54 +0000 (+0000) Subject: Add more features to Texinfo mode, to make it more like the current X-Git-Tag: 20090517-FFI~5596 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=96954386c691cd5469b4235e24eb57c382000ddc;p=mit-scheme.git Add more features to Texinfo mode, to make it more like the current Emacs version. --- diff --git a/v7/src/edwin/tximod.scm b/v7/src/edwin/tximod.scm index f6285cbb9..90c054b49 100644 --- a/v7/src/edwin/tximod.scm +++ b/v7/src/edwin/tximod.scm @@ -1,8 +1,8 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: tximod.scm,v 1.19 1994/10/09 21:59:24 cph Exp $ +;;; $Id: tximod.scm,v 1.20 1996/04/23 22:33:54 cph Exp $ ;;; -;;; Copyright (c) 1987-94 Massachusetts Institute of Technology +;;; Copyright (c) 1987-96 Massachusetts Institute of Technology ;;; ;;; This material was developed by the Scheme project at the ;;; Massachusetts Institute of Technology, Department of @@ -67,24 +67,23 @@ set up so expression commands skip Texinfo bracket groups. frequently used @-sign commands into the buffer. You can use these commands to save keystrokes." (lambda (buffer) - (define-variable-local-value! buffer (ref-variable-object syntax-table) - texinfo-mode:syntax-table) - (define-variable-local-value! buffer (ref-variable-object fill-column) 72) - (define-variable-local-value! buffer - (ref-variable-object require-final-newline) - true) - (define-variable-local-value! buffer - (ref-variable-object indent-tabs-mode) - false) - (define-variable-local-value! buffer (ref-variable-object page-delimiter) - "^@\\(chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading\\)") - (define-variable-local-value! buffer (ref-variable-object paragraph-start) - (string-append "^\010\\|^@[a-zA-Z]*[ \n]\\|" - (ref-variable paragraph-start buffer))) - (define-variable-local-value! buffer - (ref-variable-object paragraph-separate) - (string-append "^\010\\|^@[a-zA-Z]*[ \n]\\|" - (ref-variable paragraph-separate buffer))) + (local-set-variable! syntax-table texinfo-mode:syntax-table buffer) + (local-set-variable! fill-column 72 buffer) + (local-set-variable! require-final-newline #t buffer) + (local-set-variable! indent-tabs-mode #f buffer) + (local-set-variable! + page-delimiter + "^@\\(chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading\\)" + buffer) + (local-set-variable! paragraph-start + (string-append "^\010\\|^@[a-zA-Z]*[ \n]\\|" + (ref-variable paragraph-start buffer)) + buffer) + (local-set-variable! paragraph-separate + (string-append "^\010\\|^@[a-zA-Z]*[ \n]\\|" + (ref-variable paragraph-separate + buffer)) + buffer) (event-distributor/invoke! (ref-variable texinfo-mode-hook buffer) buffer))) @@ -95,81 +94,150 @@ commands to save keystrokes." (modify-syntax-entry! texinfo-mode:syntax-table #\DC1 "\\") (modify-syntax-entry! texinfo-mode:syntax-table #\' "w") +(define-key 'texinfo '(#\C-c #\{) 'texinfo-insert-braces) +(define-key 'texinfo '(#\C-c #\}) 'up-list) + (define-key 'texinfo '(#\C-c #\C-c #\c) 'texinfo-insert-@code) (define-key 'texinfo '(#\C-c #\C-c #\d) 'texinfo-insert-@dfn) (define-key 'texinfo '(#\C-c #\C-c #\e) 'texinfo-insert-@end) +(define-key 'texinfo '(#\C-c #\C-c #\f) 'texinfo-insert-@file) (define-key 'texinfo '(#\C-c #\C-c #\i) 'texinfo-insert-@item) (define-key 'texinfo '(#\C-c #\C-c #\k) 'texinfo-insert-@kbd) +(define-key 'texinfo '(#\C-c #\C-c #\n) 'texinfo-insert-@node) (define-key 'texinfo '(#\C-c #\C-c #\o) 'texinfo-insert-@noindent) -(define-key 'texinfo '(#\C-c #\C-c #\r) 'texinfo-insert-@refill) (define-key 'texinfo '(#\C-c #\C-c #\s) 'texinfo-insert-@samp) +(define-key 'texinfo '(#\C-c #\C-c #\t) 'texinfo-insert-@table) (define-key 'texinfo '(#\C-c #\C-c #\v) 'texinfo-insert-@var) (define-key 'texinfo '(#\C-c #\C-c #\x) 'texinfo-insert-@example) -(define-command texinfo-insert-@code - "Insert the string @code in a texinfo buffer." +(define ((texinfo-insert-@-with-arg keyword) argument) + (call-with-values + (lambda () + (if argument + (let ((n (command-argument-value argument))) + (if (< n 0) + (let ((end + (skip-chars-backward " \t\n\r\f" (current-point)))) + (values (forward-sexp end n 'ERROR) end)) + (let ((start + (skip-chars-forward " \t\n\r\f" (current-point)))) + (values start (forward-sexp start n 'ERROR))))) + (let ((start (current-point))) + (values start start)))) + (lambda (start end) + (let ((end (mark-left-inserting-copy end))) + (insert-string (string-append "@" keyword "{") start) + (insert-string "}" end) + (set-current-point! (if argument end (mark-1+ end))) + (mark-temporary! end))))) + +(define-command texinfo-insert-braces + "Make a pair of braces and be poised to type inside of them. +Use \\[up-list] to move forward out of the braces." () (lambda () - (insert-string "@code{}") + (insert-string "{}") (set-current-point! (mark-1+ (current-point))))) +(define-command texinfo-insert-@code + "Insert a `@code{...}' command in a texinfo buffer. +A numeric argument says how many words the braces should surround. +The default is not to surround any existing words with the braces." + "P" + (texinfo-insert-@-with-arg "code")) + (define-command texinfo-insert-@dfn - "Insert the string @dfn in a texinfo buffer." - () - (lambda () - (insert-string "@dfn{}") - (set-current-point! (mark-1+ (current-point))))) + "Insert a `@dfn{...}' command in a texinfo buffer. +A numeric argument says how many words the braces should surround. +The default is not to surround any existing words with the braces." + "P" + (texinfo-insert-@-with-arg "dfn")) -(define-command texinfo-insert-@kbd - "Insert the string @kbd in a texinfo buffer." +(define-command texinfo-insert-@example + "Insert the string `@example' in a texinfo buffer." () - (lambda () - (insert-string "@kbd{}") - (set-current-point! (mark-1+ (current-point))))) + (lambda () (insert-string "@example\n"))) -(define-command texinfo-insert-@samp - "Insert the string @samp in a texinfo buffer." - () - (lambda () - (insert-string "@samp{}") - (set-current-point! (mark-1+ (current-point))))) +(define-command texinfo-insert-@file + "Insert a `@file{...}' command in a texinfo buffer. +A numeric argument says how many words the braces should surround. +The default is not to surround any existing words with the braces." + "P" + (texinfo-insert-@-with-arg "file")) -(define-command texinfo-insert-@var - "Insert the string @var in a texinfo buffer." +(define-command texinfo-insert-@item + "Insert the string `@item' in a texinfo buffer." () - (lambda () - (insert-string "@var{}") - (set-current-point! (mark-1+ (current-point))))) + (lambda () (insert-string "@item\n"))) -(define-command texinfo-insert-@end - "Insert the string `@end ' (end followed by a space) in a texinfo buffer." +(define-command texinfo-insert-@kbd + "Insert a `@kbd{...}' command in a texinfo buffer. +A numeric argument says how many words the braces should surround. +The default is not to surround any existing words with the braces." + "P" + (texinfo-insert-@-with-arg "kbd")) + +(define-command texinfo-insert-@node + "Insert the string `@node' in a texinfo buffer. +This also inserts on the following line a comment indicating +the order of arguments to @node." () (lambda () - (insert-string "@end "))) + (insert-string "@node ") + (let ((m (mark-right-inserting-copy (current-point)))) + (insert-string "\n@comment node-name, next, previous, up") + (set-current-point! m) + (mark-temporary! m)))) -(define-command texinfo-insert-@refill - "Insert the string @refill in a texinfo buffer." +(define-command texinfo-insert-@noindent + "Insert the string `@noindent' in a texinfo buffer." () - (lambda () - (insert-string "@refill"))) + (lambda () (insert-string "@noindent\n"))) -(define-command texinfo-insert-@example - "Insert the string @example in a texinfo buffer." +(define-command texinfo-insert-@samp + "Insert a `@samp{...}' command in a texinfo buffer. +A numeric argument says how many words the braces should surround. +The default is not to surround any existing words with the braces." + "P" + (texinfo-insert-@-with-arg "samp")) + +(define-command texinfo-insert-@table + "Insert the string `@table' in a texinfo buffer." () - (lambda () - (insert-string "@example") - (insert-newline))) + (lambda () (insert-string "@table "))) -(define-command texinfo-insert-@item - "Insert the string @item in a texinfo buffer." - () - (lambda () - (insert-string "@item") - (insert-newline))) +(define-command texinfo-insert-@var + "Insert a `@var{...}' command in a texinfo buffer. +A numeric argument says how many words the braces should surround. +The default is not to surround any existing words with the braces." + "P" + (texinfo-insert-@-with-arg "var")) -(define-command texinfo-insert-@noindent - "Insert the string @noindent in a texinfo buffer." +(define-command texinfo-insert-@end + "Insert the matching `@end' for the last Texinfo command that needs one." () (lambda () - (insert-string "@noindent") - (insert-newline))) \ No newline at end of file + (let ((start (buffer-start (selected-buffer)))) + (let loop ((mark (current-point)) (depth 1)) + (let ((m + (re-search-backward texinfo-environment-regexp mark start #f))) + (if m + (cond ((match-forward "@end" m) + (loop m (+ depth 1))) + ((> depth 1) + (loop m (- depth 1))) + (else + (re-match-forward texinfo-environment-regexp m) + (insert-string "@end ") + (insert-region (re-match-start 1) + (re-match-end 1)) + (insert-newline))) + (insert-string "@end "))))))) + +(define texinfo-environment-regexp + (string-append + "^@\\(f?table\\|enumerate\\|itemize" + "\\|ifhtml\\|ifinfo\\|iftex\\|ifset\\|ifclear\\|format" + "\\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display" + "\\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|html\\|cartouche" + "\\|menu\\|titlepage\\|end\\|def[a-z]*[a-wyz]\\>\\)")) \ No newline at end of file