home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / edit / jade / lisp / texinfo-mode.jl < prev    next >
Lisp/Scheme  |  1994-09-20  |  5KB  |  153 lines

  1. ;;;; texinfo-mode.jl -- Mode for editing Texinfo files
  2. ;;;  Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. ;;; This file is part of Jade.
  5.  
  6. ;;; Jade is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;; any later version.
  10.  
  11. ;;; Jade is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;;; GNU General Public License for more details.
  15.  
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Jade; see the file COPYING.  If not, write to
  18. ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. (provide 'texinfo-mode)
  21.  
  22. (unless (boundp 'texinfo-keymap)
  23.   (setq texinfo-keymap (make-keylist)
  24.     texinfo-ctrl-c-keymap (make-keylist)
  25.     texinfo-ctrl-c-ctrl-c-keymap (make-keylist))
  26.   (bind-keys texinfo-keymap
  27.     "TAB" 'tab-with-spaces)
  28.   (bind-keys texinfo-ctrl-c-keymap
  29.     "Ctrl-c" '(setq next-keymap-path '(texinfo-ctrl-c-ctrl-c-keymap)))
  30.   (bind-keys texinfo-ctrl-c-ctrl-c-keymap
  31.     "c" '(texinfo-insert-braces "@code")
  32.     "d" '(texinfo-insert-braces "@dfn")
  33.     "e" 'texinfo-insert-@end
  34.     "f" '(texinfo-insert-braces "@file")
  35.     "i" '(texinfo-insert "@item")
  36.     "l" '(texinfo-insert "@lisp\n")
  37.     "m" '(texinfo-insert "@menu\n")
  38.     "Ctrl-m" 'texinfo-insert-menu-item
  39.     "n" 'texinfo-insert-@node
  40.     "s" '(texinfo-insert-braces "@samp")
  41.     "v" '(texinfo-insert-braces "@var")
  42.     "{" 'texinfo-insert-braces
  43.     "]" 'texinfo-move-over-braces
  44.     "}" 'texinfo-move-over-braces))
  45.  
  46. ;;;###autoload
  47. (defun texinfo-mode ()
  48.   "Texinfo Mode:\n
  49. Major mode for editing Texinfo source files.\n
  50. Special commands available are,\n
  51.   `Ctrl-c Ctrl-c c'    Insert `@code'
  52.   `Ctrl-c Ctrl-c d'    Insert `@dfn'
  53.   `Ctrl-c Ctrl-c e'    Insert the correct `@end' command for the current
  54.             context.
  55.   `Ctrl-c Ctrl-c f'    Insert `@file'
  56.   `Ctrl-c Ctrl-c i'    Insert `@item'
  57.   `Ctrl-c Ctrl-c l'    Insert `@lisp'
  58.   `Ctrl-c Ctrl-c m'    Insert `@menu'
  59.   `Ctrl-c Ctrl-c Ctrl-m' Insert a menu item.
  60.   `Ctrl-c Ctrl-c n'    Prompt for each part of an `@node' line and insert
  61.             the constructed line.
  62.   `Ctrl-c Ctrl-c s'    Insert `@samp'
  63.   `Ctrl-c Ctrl-c v'    Insert `@var'
  64.   `Ctrl-c Ctrl-c {'    Insert a pair of braces and place the cursor between
  65.             them.
  66.   `Ctrl-c Ctrl-c }',
  67.   `Ctrl-c Ctrl-c ]'    Move the cursor to the character after the next closing
  68.             brace."
  69.   (interactive)
  70.   (when major-mode-kill
  71.     (funcall major-mode-kill (current-buffer)))
  72.   (setq mode-name "Texinfo"
  73.     major-mode 'texinfo-mode
  74.     major-mode-kill 'texinfo-mode-kill
  75.     ctrl-c-keymap texinfo-ctrl-c-keymap
  76.     paragraph-regexp "^@node"
  77.     keymap-path (cons 'texinfo-keymap keymap-path))
  78.   (eval-hook 'text-mode-hook)
  79.   (eval-hook 'texinfo-mode-hook))
  80.  
  81. (defun texinfo-mode-kill ()
  82.   (setq mode-name nil
  83.     major-mode nil
  84.     major-mode-kill nil
  85.     keymap-path (delq 'texinfo-keymap keymap-path)))
  86.  
  87. (defun texinfo-insert-@end ()
  88.   (interactive)
  89.   (let
  90.       ((pos (line-end (prev-line)))
  91.        (depth 0))
  92.     (if (catch 'foo
  93.       (while (find-prev-regexp "^@(end |)(cartouche|deffn|defun|defmac\
  94. |defspec|defvr|defvar|defopt|deftypefn|deftypefun|deftypevr|deftypevar|defcv\
  95. |defivar|defop|defmethod|deftp|display|enumerate|example|flushleft|flushright\
  96. |format|ftable|group|ifclear|ifinfo|ifset|iftex|ignore|itemize|lisp|menu\
  97. |quotation|smallexample|smalllisp|table|tex|titlepage|vtable)" pos)
  98.         (if (equal (match-start 1) (match-end 1))
  99.         ;; no end
  100.         (if (zerop depth)
  101.             (throw 'foo t)
  102.           (setq depth (1- depth)))
  103.           (setq depth (1+ depth)))
  104.         (setq pos (prev-char 1 (match-start)))))
  105.     (format (current-buffer) "@end %s\n" (copy-area (match-start 2)
  106.                             (match-end 2)))
  107.       (insert "@end ")
  108.       (error "Can't find a command to @end"))))
  109.  
  110. (defun texinfo-insert (string)
  111.   (insert string))
  112.  
  113. (defun texinfo-insert-@node ()
  114.   (interactive)
  115.   (insert "@node ")
  116.   (let
  117.       ((tmp (prompt "Node name: ")))
  118.     (when tmp
  119.       (insert tmp)
  120.       (when (setq tmp (prompt "Next node: "))
  121.     (insert ", ")
  122.     (insert tmp)
  123.     (when (setq tmp (prompt "Previous node: "))
  124.       (insert ", ")
  125.       (insert tmp)
  126.       (when (setq tmp (prompt "Up node: "))
  127.         (insert ", ")
  128.         (insert tmp)))))))
  129.  
  130. (defun texinfo-insert-braces (&optional command)
  131.   (interactive)
  132.   (when command
  133.     (insert command))
  134.   (if current-prefix-arg
  135.       (progn
  136.     ;; Surround n words with braces
  137.     (insert "{")
  138.     (forward-word (prefix-numeric-argument current-prefix-arg) nil t)
  139.     (insert "}"))
  140.     (insert "{}")
  141.     (goto-prev-char)))
  142.  
  143. (defun texinfo-move-over-braces ()
  144.   (interactive)
  145.   (goto-char (next-char 1 (find-next-char ?}))))
  146.  
  147. (defun texinfo-insert-menu-item ()
  148.   (interactive)
  149.   (let
  150.       ((tmp (prompt "Item node: ")))
  151.     (when tmp
  152.       (insert (concat "* " tmp "::")))))
  153.