home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / LaTeXinfo.shar.3 / latexinfo-mode.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  6.8 KB  |  177 lines

  1. ;; Major mode for editing latexinfo files.
  2. ;; Copyright (C) 1985, 1988 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is distributed in the hope that it will be useful,
  7. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  8. ;; accepts responsibility to anyone for the consequences of using it
  9. ;; or for whether it serves any particular purpose or works at all,
  10. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  11. ;; License for full details.
  12.  
  13. ;; Everyone is granted permission to copy, modify and redistribute
  14. ;; GNU Emacs, but only under the conditions described in the
  15. ;; GNU Emacs General Public License.   A copy of this license is
  16. ;; supposed to have been given to you along with GNU Emacs so you
  17. ;; can know your rights and responsibilities.  It should be in a
  18. ;; file named COPYING.  Among other things, the copyright notice
  19. ;; and this notice must be preserved on all copies.
  20.  
  21.  
  22. (defvar latexinfo-mode-syntax-table nil)
  23.  
  24. (if latexinfo-mode-syntax-table
  25.     nil
  26.   (setq latexinfo-mode-syntax-table (make-syntax-table))
  27.   (modify-syntax-entry ?\" " " latexinfo-mode-syntax-table)
  28.   (modify-syntax-entry ?@ " " latexinfo-mode-syntax-table)
  29.   (modify-syntax-entry ?\\ "\\" latexinfo-mode-syntax-table)
  30.   (modify-syntax-entry ?\^q "\\" latexinfo-mode-syntax-table)
  31.   (modify-syntax-entry ?\[ "(]" latexinfo-mode-syntax-table)
  32.   (modify-syntax-entry ?\] ")[" latexinfo-mode-syntax-table)
  33.   (modify-syntax-entry ?{ "(}" latexinfo-mode-syntax-table)
  34.   (modify-syntax-entry ?} "){" latexinfo-mode-syntax-table)
  35.   (modify-syntax-entry ?\' "w" latexinfo-mode-syntax-table))
  36.  
  37. (defvar latexinfo-mode-map nil)
  38.  
  39. (if latexinfo-mode-map
  40.     nil
  41.   (setq latexinfo-mode-map (make-sparse-keymap))
  42.   (define-key latexinfo-mode-map "\C-c\C-f" 'latexinfo-format-region)
  43.   (define-key latexinfo-mode-map "\C-c\C-s" 'latexinfo-show-structure)
  44.   (define-key latexinfo-mode-map "\e}"          'up-list)
  45.   (define-key latexinfo-mode-map "\e{"          'latexinfo-insert-braces)
  46.   (define-key latexinfo-mode-map "\C-c\C-cv"    'latexinfo-insert-var)
  47.   (define-key latexinfo-mode-map "\C-c\C-cs"    'latexinfo-insert-samp)
  48.   (define-key latexinfo-mode-map "\C-c\C-cn"    'latexinfo-insert-node)
  49.   (define-key latexinfo-mode-map "\C-c\C-ci"    'latexinfo-insert-item)
  50.   (define-key latexinfo-mode-map "\C-c\C-ce"    'latexinfo-insert-end)
  51.   (define-key latexinfo-mode-map "\C-c\C-cd"    'latexinfo-insert-dfn)
  52.   (define-key latexinfo-mode-map "\C-c\C-cc"    'latexinfo-insert-code))
  53.  
  54. (defun latexinfo-insert-var ()
  55.   "Insert the string \\var{} in a latexinfo buffer."
  56.   (interactive)
  57.   (insert "\\var{}")
  58.   (backward-char))
  59.  
  60. (defun latexinfo-insert-samp ()
  61.   "Insert the string \\samp{} in a latexinfo buffer."
  62.   (interactive)
  63.   (insert "\\samp{}")
  64.   (backward-char))
  65.  
  66. (defun latexinfo-insert-node ()
  67.   "Insert the string \\node in a latexinfo buffer, 
  68. along with a comment indicating the arguments to \\node."
  69.   (interactive)
  70.   (insert "\\node     \n\\comment  node-name,  next,  previous,  up")
  71.   (forward-line -1)
  72.   (forward-char 6))
  73.  
  74. (defun latexinfo-insert-item ()
  75.   "Insert the string \\item in a latexinfo buffer."
  76.   (interactive)
  77.   (insert "\\item")
  78.   (newline))
  79.  
  80. (defun latexinfo-insert-end ()
  81.   "Insert the string \\end{} in a latexinfo buffer."
  82.   (interactive)
  83.   (insert "\\end{}"))
  84.  
  85. (defun latexinfo-insert-dfn ()
  86.   "Insert the string \\dfn{} in a latexinfo buffer."
  87.   (interactive)
  88.   (insert "\\dfn{}")
  89.   (backward-char))
  90.  
  91. (defun latexinfo-insert-code ()
  92.   "Insert the string \\code{} in a latexinfo buffer."
  93.   (interactive)
  94.   (insert "\\code{}")
  95.   (backward-char))
  96.  
  97. (defun latexinfo-insert-braces ()
  98.   "Make a pair of braces and be poised to type inside of them.
  99. Use \\[up-list] to move forward out of the braces."
  100.   (interactive)
  101.   (insert "{}")
  102.   (backward-char))
  103.  
  104. (defun latexinfo-mode ()
  105.   "Major mode for editing latexinfo files.
  106.  
  107.   It has these extra commands:
  108. \\{latexinfo-mode-map}
  109.  
  110.   These are files that are used as input for LaTeX to make printed manuals
  111. and also to be turned into Info files by \\[latexinfo-format-buffer].
  112. These files must be written in a very restricted and modified version
  113. of TeX input format.
  114.  
  115.   Editing commands are like text-mode except that the syntax table is
  116. set up so expression commands skip Latexinfo bracket groups.  To see
  117. what the Info version of a region of the Latexinfo file will look like,
  118. use \\[latexinfo-format-region].  This command runs Info on the current region
  119. of the Latexinfo file and formats it properly.
  120.  
  121.   You can show the structure of a Latexinfo file with \\[latexinfo-show-structure].
  122. This command shows the structure of a Latexinfo file by listing the
  123. lines with the commands for \\node, \\chapter, \\section and the
  124. like.  These lines are displayed in another window called the *Occur*
  125. window.  In that window, you can position the cursor over one of the
  126. lines and use \\[occur-mode-goto-occurrence], to jump to the
  127. corresponding spot in the Latexinfo file.
  128.  
  129.   In addition, Latexinfo mode provides commands that insert various
  130. frequently used commands into the buffer.  You can use these
  131. commands to save keystrokes.  And you can insert balanced braces with
  132. \\[latexinfo-insert-braces] and later use the command \\[up-list] to
  133. move forward past the closing brace.
  134.  
  135. Entering Latexinfo mode calls the value of text-mode-hook, and then the
  136. value of latexinfo-mode-hook."
  137.   (interactive)
  138.   (text-mode)
  139.   (setq mode-name "Latexinfo")
  140.   (setq major-mode 'latexinfo-mode)
  141.   (use-local-map latexinfo-mode-map)
  142.   (set-syntax-table latexinfo-mode-syntax-table)
  143.   (make-local-variable 'require-final-newline)
  144.   (setq require-final-newline t)
  145.   (make-local-variable 'paragraph-separate)
  146.   (setq paragraph-separate (concat "^\b\\|^\\\\[a-zA-Z{}]*[ \n]\\|" paragraph-separate))
  147.   (make-local-variable 'paragraph-start)
  148.   (setq paragraph-start    (concat "^\b\\|^\\\\[a-zA-Z{}]*[ \n]\\|" paragraph-start))
  149.   (make-local-variable 'fill-column)
  150.   (setq fill-column 72)
  151.   (make-local-variable 'comment-start)
  152.   (setq comment-start "\\c ")
  153.   (make-local-variable 'comment-start-skip)
  154.   (setq comment-start-skip "\\c +")
  155.   (run-hooks 'text-mode-hook 'latexinfo-mode-hook))
  156.  
  157. (defvar latexinfo-heading-pattern
  158.   "^\\\\\\(chapter\\|appendix\\|sect\\|sub\\|heading\\|major\\|node\\)"
  159.   "This is a regular expression to match Latexinfo lines that are chapter
  160. or sections headings or like such.")
  161.  
  162. (defun latexinfo-show-structure () 
  163.   "Show the structure of a Latexinfo file by listing the lines with the
  164. commands for \\node, \\chapter, \\section and the like.  Lines
  165. with structuring commands in them are displayed in another window
  166. called the *Occur* window.  In that window, you can position the
  167. cursor over one of the lines and use \\[occur-mode-goto-occurrence],
  168. to jump to the corresponding spot in the Latexinfo file."
  169.   (interactive)
  170.   (save-excursion 
  171.     (goto-char (point-min))
  172.     (occur latexinfo-heading-pattern))
  173.   (pop-to-buffer "*Occur*")
  174.   (goto-char (point-min))
  175.   (flush-lines "-----"))
  176.  
  177.