home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / extrnl / adamode.src < prev    next >
Encoding:
Text File  |  1988-05-03  |  29.5 KB  |  1,081 lines

  1. ::::::::::
  2. ada-mode.pro
  3. ::::::::::
  4.  
  5. -------- SIMTEL20 Ada Software Repository Prologue ------------
  6. --                                                           -*
  7. -- Unit name    : Ada mode for Gosling Emacs
  8. -- Version      : 5.5
  9. -- Author       : Steve Rosen
  10. --              : Siemens Research and Technology Laboratories
  11. --              : 105 College Road East
  12. --              : Princeton, NJ 08540
  13. -- DDN Address  : siemens!gypsy!rosen@TOPAZ
  14. -- Copyright    :
  15. -- Date created :  December 12, 1984
  16. -- Release date :  December 17, 1985
  17. -- Last update  :  Version 5.5 of December 17, 1985
  18. -- Machine/System Compiled/Run on : Vax 11/780 with Unix 4.2BSD
  19. --                  : Emacs version = Gosling #264
  20. --                                                           -*
  21. ---------------------------------------------------------------
  22. --                                                           -*
  23. -- Keywords     :  Emacs, Editor, Mode
  24. ----------------:  
  25. --
  26. -- Abstract     :  This set of files constitues a special
  27. ----------------:  'ada-mode' for use with the Emacs editor.
  28. ----------------:  See the file 'help-ada-mode.doc' for more
  29. ----------------:  information.
  30. ----------------:
  31. ------------------ Revision history ---------------------------
  32. --                                                           -*
  33. -- DATE         VERSION    AUTHOR                  HISTORY
  34. -- 12/17/85      5.5    Rosen            Second Release
  35. --                                                           -*
  36. ------------------ Distribution and Copyright -----------------
  37. --                                                           -*
  38. -- This prologue must be included in all copies of this software.
  39. --
  40. -- This software is copyright by the author.
  41. --
  42. -- This software is released to the Ada community.
  43. -- This software is released to the Public Domain (note:
  44. --   software released to the Public Domain is not subject
  45. --   to copyright protection).
  46. -- Restrictions on use or distribution:  NONE
  47. --                                                           -*
  48. ------------------ Disclaimer ---------------------------------
  49. --                                                           -*
  50. -- This software and its documentation are provided "AS IS" and
  51. -- without any expressed or implied warranties whatsoever.
  52. -- No warranties as to performance, merchantability, or fitness
  53. -- for a particular purpose exist.
  54. --
  55. -- Because of the diversity of conditions and hardware under
  56. -- which this software may be used, no warranty of fitness for
  57. -- a particular purpose is offered.  The user is advised to
  58. -- test the software thoroughly before relying on it.  The user
  59. -- must assume the entire risk and liability of using this
  60. -- software.
  61. --
  62. -- In no event shall any person or organization of people be
  63. -- held responsible for any direct, indirect, consequential
  64. -- or inconsequential damages or lost profits.
  65. --                                                           -*
  66. -------------------END-PROLOGUE--------------------------------
  67. ::::::::::
  68. ada-mode-help.doc
  69. ::::::::::
  70. ----------------------------------------------------------------------------
  71. ada-mode-help.doc - Help for Emacs Ada mode
  72. ----------------------------------------------------------------------------
  73.  
  74.             Ada Mode for Gosling Emacs
  75.  
  76.           (emacs-version) => Emacs #264 of Mon May 16
  77.   
  78.                  Steven M. Rosen
  79.  
  80.          Siemens Corporate Research and Support, Inc.
  81.             Research and Technology Laboratories
  82.                 Princeton, NJ 08540
  83.                   (609) 734-6538
  84.  
  85.                 -----------
  86.  
  87.             USENET:       adrvax\
  88.                     ihnp4 |
  89.                 princeton |-->!siemens!gypsy!rosen
  90.                     topaz |
  91.                    vrdxhq/
  92.  
  93.             ARPA:    siemens!gypsy!rosen@TOPAZ
  94.  
  95.  
  96. ------------------------------------------------------------------------------
  97.  
  98. *** What is it? ***
  99.  
  100. The Ada mode Mlisp code defines a special mode for the Gosling version of
  101. the Emacs editor.  How it works with other versions of Emacs is unclear,
  102. since it was written for and tested with the Gosling version.  The Ada mode
  103. is intended for use when editing Ada code and it is case insensitive when 
  104. dealing with reserved Ada words.
  105.  
  106. The information provided in this document is geared towards Unix, however,
  107. it may be possible to install "ada-mode" under other operation systems such
  108. as VMS which can also run Emacs.
  109.  
  110.  
  111. *** What components is it comprised of? ***
  112.  
  113. The current version of "ada-mode" utilizes two Mlisp files.  There is also a
  114. text file.  These files are as follows:
  115.  
  116.     o ada.ml
  117.  
  118.       -- All of the major functions used by ada-mode.
  119.  
  120.     o justify-Ada-comment.ml
  121.  
  122.       -- Special functions for justifying blocks of Ada comments.
  123.  
  124.     o ada-mode-help.doc
  125.  
  126.       -- This file.
  127.  
  128.  
  129. *** How do I install it? ***
  130.  
  131. Place the first two of the above files (the ones ending in '.ml' into your
  132. local Emacs Mlisp library.  Typically this is something like
  133. '/usr/lib/emacs/maclib'.  It is possible that it may be named something
  134. else.
  135.  
  136. As an alternative, you may place these files is some other directory and add
  137. this directory to your 'csh' environment variable, EPATH.  If you do this,
  138. your EPATH variable might be set like this:
  139.  
  140.     setenv EPATH :/usr/rosen/mlisp:/usr/lib/emacs/maclib
  141.  
  142. You can place this 'setenv' statement in your '.login' file.
  143.  
  144. Once you have installed the Mlisp files in the correct place, you can then
  145. have Emacs invoke the "ada-mode" automatically when editing Ada source code,
  146. place the following lines in your '.emacs_pro' profile script.  This profile
  147. script can be found in your home directory.
  148.  
  149.         (autoload "ada-mode" "ada.ml")
  150.         (auto-execute "ada-mode" "*.ada")
  151.  
  152. You can change the second line to have the Ada mode loaded when you are
  153. editing files with extensions other than ".ada" (such as "*.a" or "*.txt" or
  154. whatever).
  155.  
  156. You should now be able to utilize "ada-mode".
  157.  
  158. *** What it does ***
  159.  
  160. Ada mode automatically performs indenting while you are editing Ada code.
  161. Is assumes that you are using a style that is similar to that used in the
  162. Ada LRM (Language Reference Manual).  It automatically indents and dedents
  163. blocks of code by examing the syntax of the statements that you are writing.
  164. Using very unusually or ad hoc coding styles will not produce results that
  165. are anything spectacular.
  166.  
  167. Using this editing mode takes a bit of getting used to, but it shouldn't
  168. take long to become comfortable with it.  It is far from perfect, but I felt
  169. a strong need to write it because the power of Emacs is too good to put to
  170. waste and I was writing too much Ada code to be without it.  For those of
  171. you who attempt to make it run with other versions of Emacs please let me
  172. know since I know nothing of how other versions differ from the Gosling
  173. version.  If you have any questions or find very strange bugs, send them to
  174. the above address and I will attempt to fix them.  The comment mode was
  175. particularly hard to implement and might be considered somewhat of a hack,
  176. but it does work fairly well when writting most comments.  I can't promise
  177. that writting comments won't do strange stuff every so often.  If you fix a
  178. bug or make an enhancement send it to me so I can enjoy it as well.  Have
  179. fun!
  180.  
  181. ------------------------------------------------------------------------------
  182.  
  183. Variables and Functions
  184.     
  185.     o indent-change
  186.  
  187.             The number of spaces to use when indenting
  188.             statements.  This number can be changed to 4 or
  189.             whatever you like.  The default is 2. This
  190.             can be changed in the file 'ada.ml'.
  191.  
  192.     o ada-comment-header
  193.  
  194.             This is a string which designates what begins a
  195.             comment.  For Ada, this is always "--", but may
  196.             be changed to "--|" if you would like to extend
  197.             the comment designator.     The default is "--".  This
  198.             can be changed in the file 'ada.ml'
  199.  
  200.     o ^X->
  201.  
  202.             Indents a region of code from 'dot' to 'mark' by
  203.             the 'indent-change' spaces.
  204.  
  205.     o ^X-<
  206.  
  207.             Dedents a region of code from 'dot' to 'mark' by
  208.             the 'indent-change' spaces.
  209.  
  210.     o <ESC>-<TAB>
  211.  
  212.             Tab over to the column of the previous statement.
  213.             If at the beginning of a line, this will move the
  214.             cursor over to the same column as the most recent
  215.             line of code.  If the current column is greater
  216.             that the column of the most recent line of code,
  217.             then a <TAB> character is inserted.
  218.  
  219.     o <TAB>
  220.  
  221.             Same as above, but you can disable the key binding
  222.             if hitting a <TAB> does things that you don't like.
  223.  
  224.     o <ESC>-<CR>
  225.  
  226.             If at the end of a line. inserts a <CR> and dedents
  227.             by 'indent-change'.  If on a blank like, it just
  228.             dedents by 'indent-change'.  This is used, for
  229.             example, when you wish to dedent a block of code,
  230.             and insert an 'end' statement such as in a 'for'
  231.             loop.
  232.  
  233.             Example:
  234.  
  235.                   for i in 1 .. 100 loop
  236.                     j := x(1);
  237.                     z := sqrt(j); -- Type an <ESC>-<CR> here
  238.                   end loop;
  239.  
  240.             The <ESC>-<CR> is a signal that you want to close off
  241.             a block of code with and 'end' statement.  If you
  242.             have forgotten to type the <ESC>-<CR> sequence and
  243.             you are sitting on a blank line type it anyway and
  244.             you will be repositioned automatically!
  245.  
  246.  
  247.     o <ESC>-'-'    
  248.  
  249.             Comments out the region of statements between dot
  250.             and mark.
  251.  
  252.     o '--'
  253.  
  254.             Typing these two characters will automatically put
  255.             you into a special comment editing mode.  This mode
  256.             will wrap lines automatically when you are typing
  257.             long comments.     The characters '--' are
  258.             automatically created and inserted so the user does
  259.             not have to type them when writing a comment that
  260.             carries over to several lines.     Typing a <LF> on
  261.             a comment line will leave the comment mode and return
  262.             you to regular statement editing by repositioning
  263.             the cursor in the correct place.
  264.  
  265.     o <ESC>-'j'
  266.  
  267.             Justify a block of Ada comments.  This key
  268.             sequence can be typed while the cursor is anywhere
  269.             within a block of comments.  The entire block
  270.             will become justified.     A block of comments is
  271.             defines as a series of contiguous non-blank comment
  272.             statements.  This function may not be perfect, but it
  273.             does become extremely convient when editing large
  274.             chunks of text within part of an Ada program.
  275.  
  276. ------------------------------------------------------------------------------
  277. ::::::::::
  278. ada.ml
  279. ::::::::::
  280.  ----------------------------------------------------------------------------
  281. ; Ada.ml - Emacs Ada mode
  282. ; ----------------------------------------------------------------------------
  283. ;                        Ada Mode for Gosling Emacs
  284. ;          (emacs-version) => Emacs #264 of Mon May 16
  285. ;  
  286. ;                             Steven M. Rosen
  287. ;                 Siemens Corporate Research and Support, Inc.
  288. ;                    Research and Technology Laboratories
  289. ;                            Princeton, NJ 08540
  290. ;                              (609) 734-6538
  291. ;                -----------
  292. ;            USENET:    adrvax\
  293. ;                        ihnp4 |
  294. ;                    princeton |-->!siemens!gypsy!rosen
  295. ;                        topaz |
  296. ;                       vrdxhq/
  297. ;            ARPA:   siemens!gypsy!rosen@TOPAZ
  298. ;----------------------------------------------------------------------------
  299. ;     This code is public domain and may be used or modified at your site
  300. ;     in any fashion that you choose.  No support or capabilities are
  301. ;     implied or guaranteed by the release of this code.  This disclaimer
  302. ;    must be maintained in conjunction with the code.
  303. ; ----------------------------------------------------------------------------
  304. ;
  305. ; $Header: ada.ml,v 5.5 85/12/17 11:53:39 rosen Exp $
  306. ; Created 12-18-84
  307. ; Updated 12-13-85
  308. ; Bindings:
  309. ;     indent-change = size of indentation (default to 2)
  310. ;     Indent from (dot) to (mark)              ^X->
  311. ;     De-dent from (dot) to (mark)              ^X-<
  312. ;     Tab over to indent of most recent line of code      <TAB>, <ESC>-<TAB>
  313. ;     Decrease indent level and start newline          <ESC>-<CR>
  314. ;     Enter Ada comment mode                  "--"
  315. ;     Finish an Ada comment (leave comment mode)        <LF> or <ESC>-'-'
  316. ;     Comment out the region between dot and mark      ^X-'-'
  317. ;     Beautify an Ada comment                  <ESC>-'j'
  318. ;
  319. ; Features:
  320. ;   o    Automatically performs indentation while editing Ada code.
  321. ;   o    Automatically performs justification of Ada comments which
  322. ;     begin on a blank line.
  323. ;   o    Automatically matches parentheses.
  324. ;
  325.  
  326.  
  327. (defun
  328.     (ada-mode
  329.     (declare-buffer-specific in-comment-edit)
  330.     (declare-buffer-specific max-right-margin)
  331.     (declare-buffer-specific comment-header)
  332.     (setq mode-string "Ada")
  333.     (setq comment-header "--")
  334.     (setq-default indent-change 2)
  335.     (setq tab-size 8)
  336.     (setq max-right-margin 78)
  337.     (setq in-comment-edit 0)
  338.     (local-bind-to-key "Ada-comment" "-")
  339.     (local-bind-to-key "finish-Ada-comment" "\e-")
  340.     (local-bind-to-key "finish-Ada-comment" "\^J")
  341.     (local-bind-to-key "indent-region" "\^X>")
  342.     (local-bind-to-key "dedent-region" "\^X<")
  343.     (local-bind-to-key "tab-Ada" "\t")
  344.     (local-bind-to-key "tab-Ada" "\e\t")
  345.     (local-bind-to-key "indent-Ada" "\^M")
  346.     (local-bind-to-key "de-dent-Ada" "\e\^M")
  347.     (local-bind-to-key "comment-out-region" "\^X-")
  348.     (local-bind-to-key "show-matching-paren" ")")
  349.     (load "justify-Ada-comment.ml")
  350. ; The following two lines can be include to suit local naming 
  351. ; conventions:
  352. ;    (modify-syntax-entry "w    _")
  353. ;    (modify-syntax-entry "w    .")
  354.     (use-syntax-table "Ada")
  355.     (modify-syntax-entry "()   (")
  356.     (modify-syntax-entry ")(   )")
  357.     (modify-syntax-entry "     """)
  358.     (modify-syntax-entry "     '")
  359.     (modify-syntax-entry "  { --")
  360.     (modify-syntax-entry "   } \n")
  361.  
  362.     (error-occurred (Ada-mode-hook))
  363.     (novalue)
  364.     )
  365. )    
  366.  
  367. (defun 
  368.     (cond n running
  369.       (setq n 1)
  370.       (setq running 1)
  371.       (while (& running (< n (nargs)))
  372.          (if (arg n)
  373.              (setq running 0)
  374.              (setq n (+ n 2))
  375.          )
  376.       )
  377.       (arg (+ n 1))
  378.     )
  379. )
  380.     
  381. (defun 
  382.     (show-matching-paren
  383.     (insert-character (last-key-struck))
  384.     (save-excursion 
  385.         (backward-paren)
  386.         (if (dot-is-visible)
  387.         (sit-for 5)
  388.         (progn 
  389.                (beginning-of-line)
  390.                (set-mark)
  391.                (end-of-line)
  392.                (message (region-to-string))
  393.         )
  394.         )
  395.     )
  396.     )
  397. )
  398.  
  399.     
  400. (defun 
  401.     (leave-and-show
  402.     (setq abbrev-mode 1)
  403.     (show-matching-paren)
  404.     )
  405. )
  406.     
  407. (defun 
  408.     (change-indentation colno    ; indent by arg for region
  409.     (save-excursion 
  410.         (if (< (mark) (dot))
  411.         (progn 
  412.                (end-of-line)
  413.                (exchange-dot-and-mark)
  414.                (beginning-of-line))
  415.         (progn 
  416.                (beginning-of-line)
  417.                (exchange-dot-and-mark)
  418.                (end-of-line)))
  419.         (narrow-region)
  420.         (end-of-file)
  421.         (beginning-of-line)
  422.         (setq colno (+ (current-indent) (arg 1)))
  423.         (delete-white-space)
  424.         (if (> colno 1)
  425.         (to-col colno))
  426.         (beginning-of-line)
  427.         (while (! (bobp))
  428.            (previous-line)
  429.            (setq colno (+ (current-indent) (arg 1)))
  430.            (delete-white-space)
  431.            (if (> colno 1)
  432.                (to-col colno)
  433.            )
  434.            (beginning-of-line)
  435.         )
  436.         (widen-region)
  437.     )
  438.     )
  439. )
  440.     
  441. (defun 
  442.     (dedent-region         ; dedents region
  443.     (change-indentation (- 0 indent-change))
  444.     )
  445. )
  446.     
  447. (defun 
  448.     (indent-region colno    ; indents region
  449.     (change-indentation indent-change)
  450.     )
  451. )
  452.     
  453. (defun 
  454.     (tab-Ada dotab colno
  455.     (if 
  456.         (& (eobp) (eolp))
  457.         (progn 
  458.            (insert-character '\n')
  459.            (backward-character)
  460.         )
  461.     )
  462.     (if 
  463.         (| (& (bolp) (looking-at "[ \t]*\n"))
  464.            (< (current-column) (current-indent)))
  465.         (progn 
  466.            (save-excursion 
  467.                (while 
  468.                   (& (| (looking-at "[ \t]*\n") 
  469.                     (looking-at "[ \t]*--"))
  470.                  (! (bobp)))
  471.                   (progn 
  472.                      (previous-line)
  473.                      (beginning-of-line)
  474.                   )
  475.                )
  476.                (setq colno (current-indent))
  477.            )
  478.            (delete-white-space)
  479.            (to-col colno)
  480.         )
  481.         1
  482.         (insert-character '\t')
  483.     )
  484.     )
  485. )
  486.     
  487. (defun 
  488.     (de-dent-Ada colno
  489.     (setq colno (- (current-indent) indent-change))
  490.     (beginning-of-line)
  491.     (if 
  492.         (! (looking-at "[ \t]*\n"))
  493.             (progn 
  494.                 (end-of-line)
  495.                 (newline)
  496.             )
  497.     )
  498.     (delete-white-space)
  499.     (to-col colno)
  500.     )
  501. )
  502.  
  503. (defun 
  504.     (indent-Ada colno
  505.     (cond
  506.          (bolp)
  507.          (newline)
  508.          (! (eolp))
  509.          (newline-and-indent)
  510.          1
  511.          (progn
  512.            (save-excursion
  513.                (end-of-line)
  514.                (if (eobp)
  515.                (newline)))
  516.            (setq colno (current-indent))
  517.            (beginning-of-line)
  518.            (setq case-fold-search 1)
  519.            (cond
  520.             (& (= in-comment-edit 1)
  521.                (! (looking-at "[ \t]*--..")))
  522.             (progn 
  523.                    (end-of-line)
  524.                    (newline)
  525.                    (to-col comment-column)
  526.                    (insert-string prefix-string))
  527.             (& (= in-comment-edit 1)
  528.                (looking-at "[ \t]*--.."))
  529.             (progn 
  530.                    (set-prefix-string)
  531.                    (end-of-line)
  532.                    (newline-and-indent)
  533.                    (insert-string prefix-string))
  534.             (looking-at "[ \t]*--.*\n")
  535.             (progn 
  536.                    (end-of-line)
  537.                    (newline)
  538.                    (tab-Ada))
  539.             (looking-at "[ \t]*begin\\b")
  540.             (progn 
  541.                    (end-of-line)
  542.                    (newline)
  543.                    (to-col (+ colno indent-change)))
  544.             (looking-at "[ \t]*end\\b")
  545.             (progn 
  546.                    (end-of-line)
  547.                    (newline)
  548.                    (to-col (- colno indent-change)))
  549.             (looking-at "[ \t]*when\\b")
  550.             (progn 
  551.                    (end-of-line)
  552.                    (newline)
  553.                    (to-col (+ colno indent-change)))
  554.             (looking-at "[ \t]*generic\\b")
  555.             (progn 
  556.                    (end-of-line)
  557.                    (newline)
  558.                    (to-col (+ colno indent-change)))
  559.             (looking-at "[ \t]*declare\\b")
  560.             (progn 
  561.                    (end-of-line)
  562.                    (newline)
  563.                    (to-col (+ colno indent-change)))
  564.             (looking-at "[ \t]*loop\\b")
  565.             (progn 
  566.                    (end-of-line)
  567.                    (newline)
  568.                    (to-col (+ colno indent-change)))
  569.             (looking-at "[ \t]*if\\b")
  570.             (progn 
  571.                    (end-of-line)
  572.                    (newline)
  573.                    (to-col (+ colno indent-change)))
  574.             (looking-at "[ \t]*elsif\\b")
  575.             (progn 
  576.                    (end-of-line)
  577.                    (newline)
  578.                    (to-col (+ colno indent-change)))
  579.             (looking-at "[ \t]*else\\b")
  580.             (progn 
  581.                    (end-of-line)
  582.                    (newline)
  583.                    (to-col (+ colno indent-change)))
  584.             (looking-at "[ \t]*while\\b")
  585.             (progn 
  586.                    (end-of-line)
  587.                    (newline)
  588.                    (to-col (+ colno indent-change)))
  589.             (looking-at "[ \t]*case\\b")
  590.             (progn 
  591.                    (end-of-line)
  592.                    (newline)
  593.                    (to-col (+ colno indent-change)))
  594.             (looking-at "[ \t]*for\\b")
  595.             (progn 
  596.                    (end-of-line)
  597.                    (if (= (preceding-char) ';')
  598.                    (newline-and-indent)
  599.                    (progn 
  600.                       (newline)
  601.                       (to-col (+ colno indent-change)))))
  602.             (looking-at "[ \t]*loop\\b")
  603.             (progn 
  604.                    (end-of-line)
  605.                    (newline)
  606.                    (to-col (+ colno indent-change)))
  607.             (looking-at "[ \t]*or\\b")
  608.             (progn 
  609.                    (end-of-line)
  610.                    (newline)
  611.                    (to-col (+ colno indent-change)))
  612.             (looking-at "[ \t]*exception\\b")
  613.             (progn 
  614.                    (end-of-line)
  615.                    (newline)
  616.                    (to-col (+ colno indent-change)))
  617.             (looking-at "[ \t]*record\\b")
  618.             (progn 
  619.                    (end-of-line)
  620.                    (newline)
  621.                    (to-col (+ colno indent-change)))
  622.             (looking-at "[ \t]*private\\b")
  623.             (progn 
  624.                    (end-of-line)
  625.                    (newline)
  626.                    (to-col (+ colno indent-change)))
  627.             (| (looking-at "[ \t]*type\\b")
  628.                (looking-at "[ \t]*subtype\\b"))
  629.             (progn 
  630.                    (end-of-line)
  631.                    (backward-word)
  632.                    (if 
  633.                    (looking-at "record\\b")
  634.                    (progn 
  635.                       (setq colno (current-column))
  636.                       (end-of-line)
  637.                       (newline)
  638.                       (to-col (+ colno indent-change)))
  639.                    (looking-at "is\\b")
  640.                    (progn 
  641.                       (end-of-line)
  642.                       (newline)
  643.                       (to-col (+ colno indent-change)))
  644.                    1
  645.                    (progn 
  646.                       (end-of-line)
  647.                       (newline-and-indent))))
  648.             (looking-at "[ \t]*select\\b")
  649.             (progn 
  650.                    (end-of-line)
  651.                    (newline)
  652.                    (to-col (+ colno indent-change)))
  653.             (looking-at "[ \t]*accept\\b")
  654.             (progn 
  655.                    (end-of-line)
  656.                    (backward-word)
  657.                    (if (looking-at "do\\b")
  658.                    (progn 
  659.                       (end-of-line)
  660.                       (newline)
  661.                       (to-col (+ colno indent-change)))
  662.                    (progn 
  663.                       (end-of-line)
  664.                       (newline-and-indent))))
  665.             (looking-at "[ \t]*task\\b")
  666.             (progn 
  667.                    (end-of-line)
  668.                    (backward-word)
  669.                    (if (looking-at "is\\b")
  670.                    (progn 
  671.                       (end-of-line)
  672.                       (newline)
  673.                       (to-col (+ colno indent-change)))
  674.                    (progn 
  675.                       (end-of-line)
  676.                       (newline-and-indent))))
  677.             (| (looking-at "[ \t]*procedure\\b")
  678.                (looking-at "[ \t]*function\\b"))
  679.             (progn 
  680.                    (end-of-line)
  681.                    (backward-word)
  682.                    (if (looking-at "is\\b")
  683.                    (progn 
  684.                       (end-of-line)
  685.                       (newline)
  686.                       (to-col (+ colno indent-change)))
  687.                    (progn 
  688.                       (end-of-line)
  689.                       (newline-and-indent))))
  690.             (looking-at "[ \t]*package\\b")
  691.             (progn 
  692.                    (end-of-line)
  693.                    (backward-word)
  694.                    (if (looking-at "is\\b")
  695.                    (progn 
  696.                       (end-of-line)
  697.                       (newline)
  698.                       (to-col (+ colno indent-change)))
  699.                    (progn 
  700.                       (end-of-line)
  701.                       (newline-and-indent))))
  702.             (looking-at "[ \t]*.*:[^=][^;.]*\n")
  703.             (progn 
  704.                    (end-of-line)
  705.                    (newline)
  706.                    (to-col (+ colno indent-change)))
  707.             (looking-at "[ \t]*<<.*>>")
  708.             (progn 
  709.                    (end-of-line)
  710.                    (newline)
  711.                    (to-col (+ colno indent-change)))
  712.             1
  713.             (progn
  714.                   (setq colno (current-indent))
  715.                   (if (looking-at "[ \t][ \t]*\n")
  716.                   (kill-to-end-of-line))
  717.                   (end-of-line)
  718.                   (newline)
  719.                   (to-col colno)))
  720.            (setq case-fold-search 0)))))
  721.  
  722. (defun
  723.     (Ada-comment next-char
  724.     (insert-string "-")
  725.     (setq next-char (char-to-string (get-tty-character)))
  726.     (if (= next-char "-")
  727.         (progn
  728.           (insert-string (substr comment-header 2 -1))
  729.           (remove-local-binding "-")
  730.           (remove-local-binding "\t")
  731.           (setq in-comment-edit 1)
  732.           (setq comment-column (- (current-column) 2))
  733.           (setq left-margin comment-column)
  734.           (setq right-margin max-right-margin)
  735.           (message "Editing Ada comment")
  736.           (setq prefix-string comment-header)
  737.           (if (looking-at (concat "[ \t]*" comment-header "[ \t]*"))
  738.               (progn 
  739.                  (indent-Ada)
  740.                  (previous-line)
  741.                  (end-of-line)
  742.               )
  743.           )
  744.           (while (| 
  745.                 (= (setq next-char 
  746.                      (char-to-string (get-tty-character)))
  747.                    " ")
  748.                 (= next-char "\t")
  749.              )
  750.              (setq prefix-string (concat prefix-string next-char))
  751.              (insert-string next-char)
  752.           )
  753.           (if (= prefix-string comment-header)
  754.               (setq prefix-string (concat comment-header " "))
  755.           )
  756.           (push-back-string next-char)
  757.         )
  758.         (push-back-string next-char)
  759.     )
  760.     )
  761. )
  762.  
  763.  
  764. (defun 
  765.     (finish-Ada-comment
  766.     (setq in-comment-edit 0)
  767.     (beginning-of-line)
  768.     (if 
  769.         (looking-at "[ \t]*--")
  770.         (progn 
  771.            (kill-to-end-of-line)
  772.            (kill-to-end-of-line)
  773.         )
  774.     )
  775.     (if 
  776.         (looking-at "[ \t]*\n")
  777.         (tab-Ada)
  778.         1
  779.         (beginning-of-line)
  780.     )
  781.     (setq right-margin 1000)
  782.     (setq left-margin 1)
  783.     (setq prefix-string "")
  784.     (local-bind-to-key "Ada-comment" "-")
  785.     (local-bind-to-key "tab-Ada" "\t")
  786.     (message "Finished editing Ada comment")
  787.     )
  788. )
  789.  
  790.         
  791. (defun 
  792.     (set-prefix-string
  793.     (search-forward comment-header)
  794.     (setq prefix-string comment-header)
  795.     (while     
  796.         (looking-at "[ \t]")
  797.         (progn 
  798.                (if 
  799.                (looking-at " ")
  800.                (setq prefix-string (concat prefix-string " "))
  801.                1
  802.                (setq prefix-string (concat prefix-string "\t"))
  803.                )
  804.                (forward-character)
  805.         )
  806.     )
  807.     )
  808. )
  809.  
  810.  
  811. (defun
  812.     (end-Ada-comment
  813.         (setq in-comment-edit 0)
  814.         (setq right-margin 1000)
  815.         (if (!= (preceding-char) ' ') (insert-string " "))
  816.         (to-col comment-column)
  817.         (insert-string comment-header)
  818.         (newline)
  819.         (local-bind-to-key "tab-Ada" "\t")
  820.         (message "Finished editing Ada comment")
  821.     )
  822. )
  823.  
  824. (defun 
  825.     (comment-out-region
  826.     (save-excursion 
  827.         (if 
  828.         (> (dot) (mark))
  829.         (exchange-dot-and-mark)
  830.         )
  831.         (beginning-of-line)
  832.         (while 
  833.            (< (dot) (mark))
  834.            (progn 
  835.               (insert-string comment-header)
  836.               (next-line)
  837.               (beginning-of-line)
  838.            )
  839.         )
  840.     )
  841.     )
  842. )
  843. ; ----------------------------------------------------------------------------
  844. ::::::::::
  845. justify-Ada-comment.ml
  846. ::::::::::
  847. ; ----------------------------------------------------------------------------
  848. ; justify-Ada-comment.ml - Justify an Ada comment block
  849. ; ----------------------------------------------------------------------------
  850. ;                        Ada Mode for Gosling Emacs
  851. ;          (emacs-version) => Emacs #264 of Mon May 16
  852. ;  
  853. ;                             Steven M. Rosen
  854. ;                 Siemens Corporate Research and Support, Inc.
  855. ;                    Research and Technology Laboratories
  856. ;                            Princeton, NJ 08540
  857. ;                              (609) 734-6538
  858. ;                -----------
  859. ;            USENET:    adrvax\
  860. ;                        ihnp4 |
  861. ;                    princeton |-->!siemens!gypsy!rosen
  862. ;                        topaz |
  863. ;                       vrdxhq/
  864. ;            ARPA:   siemens!gypsy!rosen@TOPAZ
  865. ;----------------------------------------------------------------------------
  866. ;     This code is public domain and may be used or modified at your site
  867. ;     in any fashion that you choose.  No support or capabilities are
  868. ;     implied or guaranteed by the release of this code.  This disclaimer
  869. ;    must be maintained in conjunction with the code.
  870. ; ----------------------------------------------------------------------------
  871. ;
  872. ; Used with "Ada-Mode"
  873. ; Justify an Ada comment.  These is a severe hack, but it works more or less.
  874. ; The user must be on the last line of a block of comment statements for the
  875. ; justification to take place.  The functions runs kind of slow, but that is 
  876. ; because it attempts to space out every correctly.
  877.  
  878. (defun 
  879.     (justify-Ada-comment comment-start comment-leader null-comment any-comment
  880.              comment-front
  881.     (setq right-margin max-right-margin)
  882.     (setq null-comment (concat "[ \t]*" comment-header "[ \t]*\n"))
  883.     (setq any-comment (concat "[ \t]*" comment-header "[ \t]*.*"))
  884.     (setq comment-front (concat "[ \t]*" comment-header))
  885.     (save-excursion
  886.         (message "Justifying Ada comment...")
  887.         (sit-for 0)
  888.         (beginning-of-line)
  889.         (if 
  890.         (! (looking-at any-comment))
  891.         (error-message "Cannot find Ada comment boundary")
  892.         (novalue)
  893.         )
  894.         (while 
  895.            (& (looking-at any-comment)
  896.               (! (looking-at null-comment)))
  897.            (next-line)
  898.         )
  899.         (newline-and-backup)
  900.         (set-mark)
  901.         (previous-line)
  902.         (beginning-of-line)
  903.         (setq comment-leader comment-header)
  904.         (re-search-forward (concat "[ \t]*" comment-header))
  905.         (while 
  906.            (looking-at "[ \t]")
  907.            (progn 
  908.               (if (looking-at "\t")
  909.                   (setq comment-leader 
  910.                     (concat comment-leader "\t"))
  911.                   (looking-at " ")
  912.                   (setq comment-leader
  913.                     (concat comment-leader " ")))
  914.               (forward-character)
  915.            )
  916.         )
  917.         (beginning-of-line)
  918.         (while 
  919.            (& (looking-at any-comment)
  920.               (& (! (bobp))
  921.              (& (! (looking-at "[ \t]*--.*:[ \t]*\n"))
  922.                 (! (looking-at null-comment)))))
  923.            (previous-line))
  924.         (next-line)
  925.         (beginning-of-line)
  926.         (search-forward "-")
  927.         (backward-character)
  928.         (setq comment-start (current-column))
  929.         (while 
  930.            (< (dot) (mark))
  931.            (progn 
  932.               (if (= text-compression-on 1)
  933.                   (compress-text-line)
  934.               )
  935.               (end-of-line)
  936.               (if 
  937.                   (<= (current-column) right-margin)
  938.                   (progn 
  939.                      (next-line)
  940.                      (beginning-of-line)
  941.                      (if 
  942.                      (looking-at comment-front)
  943.                      (progn 
  944.                         (while 
  945.                             (looking-at comment-front)
  946.                             (delete-next-character)
  947.                         )
  948.                         (delete-previous-character)
  949.                         (while 
  950.                             (! (looking-at "[ \t]"))
  951.                             (delete-next-character)
  952.                         )
  953.                         (while 
  954.                                (looking-at "[ \t]")
  955.                                (delete-next-character)
  956.                         )
  957.                         (insert-character ' ')
  958.                         (beginning-of-line)
  959.                      )
  960.                      )
  961.                   )
  962.                   1
  963.                   (progn 
  964.                      (while 
  965.                         (> (current-column) right-margin)
  966.                         (progn 
  967.                            (backward-word)
  968.                            (backward-character)
  969.                            (while 
  970.                               (! (looking-at " "))
  971.                               (backward-character))
  972.                         )
  973.                      )
  974.                      (insert-character '\n')
  975.                      (while 
  976.                         (!= (current-column) comment-start)
  977.                         (insert-character ' ')
  978.                      )
  979.                      (while 
  980.                         (looking-at "[ \t]")
  981.                         (delete-next-character)
  982.                      )
  983.                      (insert-string comment-leader)
  984.                   )
  985.               )
  986.            )
  987.         )
  988.         (exchange-dot-and-mark)
  989.         (kill-to-end-of-line)
  990.     )
  991.     (message "Done!")
  992.     )
  993. )
  994.  
  995.  
  996.  
  997.             
  998. (defun 
  999.     (compress-text-line
  1000.     (save-excursion
  1001.         (end-of-line)
  1002.         (set-mark)
  1003.         (beginning-of-line)
  1004.         (while 
  1005.            (looking-at "[ \t]*--")
  1006.            (forward-word)
  1007.         )
  1008.         (while
  1009.           (< (dot) (mark))
  1010.           (while 
  1011.              (& (< (dot) (mark))
  1012.                 (! (looking-at "[ \t]")))
  1013.              (forward-character)
  1014.           )
  1015.           (while 
  1016.              (& (< (dot) (mark))
  1017.                 (looking-at "[ \t]"))
  1018.              (delete-next-character)
  1019.           )
  1020.           (if 
  1021.               (< (dot) (mark))
  1022.               (progn 
  1023.                  (backward-character)
  1024.                  (if 
  1025.                  (looking-at "[\.\?\!]")
  1026.                  (progn 
  1027.                     (forward-character)
  1028.                     (insert-character ' ')
  1029.                     (insert-character ' ')
  1030.                  )
  1031.                      1
  1032.                  (progn 
  1033.                     (forward-character)
  1034.                          (insert-character ' ')
  1035.                  )
  1036.                  )
  1037.                  (forward-word)
  1038.               )
  1039.           )
  1040.         )
  1041.     )
  1042.     )
  1043. )
  1044.  
  1045. (declare-buffer-specific text-compression-on)
  1046. (setq text-compression-on 0)
  1047. (local-bind-to-key "justify-Ada-comment" "\ej") 
  1048.