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

  1. ::::::::::
  2. adaemacs.doc
  3. ::::::::::
  4. The files MICRO:<ADA.EXTERNAL-TOOLS>ADA-EMACS.PART1, ADA-EMACS.PART2
  5. contain this tool.
  6.  
  7. Date: Monday, 29 April 1985  07:48-MDT
  8. From: ihnp4!siemens!rosen at Ucb-Vax.ARPA
  9. Re:   Ada Mode for Emacs Editor
  10.  
  11.     I have available an Ada mode for use with the Emacs editor.  It is
  12. written in Mlisp, so I can only vouch for the Gosling version.  If anybody
  13. is interested in it let me know and I will send it along to them.  If there
  14. is enough interest, I will just post it to the net.  It is intended for use
  15. when editing Ada code and it has various features which help make writing
  16. Ada programs easier.
  17.  
  18.  
  19. Steve Rosen
  20. Siemens Research and Technology Laboratories
  21. Princeton, NJ
  22.  
  23. USENET: {ihnp4|princeton|adrvax}!siemens!rosen
  24. ARPA:   princeton!siemens!rosen@TOPAZ
  25.  
  26.  
  27. ::::::::::
  28. adaemacs.p1
  29. ::::::::::
  30.  
  31.  
  32. ------------------------------------------------------------------------------
  33.  
  34.                         Ada Mode for Gosling Emacs
  35.  
  36.                              Steven M. Rosen
  37.  
  38.                  Siemens Corporate Research and Support, Inc.
  39.                     Research and Technology Laboratories
  40.                             Princeton, NJ 08540
  41.                               (609) 734-6538
  42.  
  43.                                rosen@siemens
  44.  
  45. ------------------------------------------------------------------------------
  46.  
  47. The Ada mode Mlisp code defines a special mode for the Gosling version of
  48. the Emacs editor.  How it works with other versions of Emacs are unclear,
  49. since it was written for and tested with the Gosling version.  The Ada mode
  50. is intended for use when editing Ada code and it is case insensitive when 
  51. dealing with reserved Ada words.
  52.  
  53. Place the file 'ada.ml' in your local Emacs Mlisp code library directory.
  54. This is usually something like '/usr/lib/emacs/maclib'.
  55.  
  56. To have the editor invoke the Ada mode when editing Ada source code, place
  57. the following lines in your '.emacs_pro' profile script.
  58.  
  59.         (autoload "ada-mode" "ada.ml")
  60.         (auto-execute "ada-mode" "*.ada")
  61.  
  62. You can change the second line to have the Ada mode loaded when you are
  63. editing files with extensions other than ".ada"
  64.  
  65. Ada mode automatically performs indenting while you are editing Ada code.
  66. Is assumes that you are using a style that is similar to that used in the
  67. Ada LRM (Language Reference Manual).  It automatically indents and dedents
  68. blocks of code by examing the syntax of the statements that you are writing.
  69. Using very unusually or ad hoc coding styles will not produce results that
  70. are anything spectacular.
  71.  
  72. Using this editing mode takes a bit of getting used to, but it shouldn't take
  73. long to become comfortable with it.  It is far from perfect, but I felt a 
  74. strong need to write it because the power of Emacs is too good to put to
  75. waste and I was writting too much Ada code to be without it.
  76. For those of you who attempt to make it run with other versions of Emacs
  77. please let me know since I know nothing of how other versions differ from the
  78. Gosling version.  If you have any questions or find very strange bugs, send
  79. them to the above address and I will attempt to fix them.  The comment mode
  80. was particularly hard to implement, but it does work fairly well when
  81. writting most comments.  I can't promise that writting comments won't do
  82. strange stuff every so often.  If you fix a bug or make an enhancement send
  83. it to me so I can enjoy it as well.  Have fun!
  84.  
  85. ------------------------------------------------------------------------------
  86.  
  87. Variables and Functions
  88.         
  89.         indent-change    The number of spaces to use when indenting
  90.                          statements.  This number can be changed to 4 or
  91.                          whatever you like.  The default is 2.
  92.  
  93.         ^X->             Indents a region of code from 'dot' to 'mark' by
  94.                          the value 'indent-change'.
  95.  
  96.         ^X-<             Dedents a region of code from 'dot' to 'mark' by
  97.                          the value 'indent-change'.
  98.  
  99.         <ESC>-<TAB>      Tab over to the column of the previous statement.
  100.                          If at the beginning of a line, this will move the
  101.                          cursor over to the same column as the most recent
  102.                          line of code.  If the current column is greater
  103.                          that the column of the most recent line of code,
  104.                          then a <TAB> character is inserted.
  105.  
  106.         <TAB>            Same as above, but you can disable the key binding
  107.                          if hitting a <TAB> does things that you don't like.
  108.  
  109.         <ESC>-<CR>       If at the end of a line. inserts a <CR> and dedents
  110.                          by 'indent-change'.  If on a blank like, it just
  111.                          dedents by 'indent-change'.  This is used, for
  112.                          example, when you wish to dedent a block of code,
  113.                          and insert an 'end' statement such as in a 'for'
  114.                          loop;
  115.  
  116.                          Example:
  117.  
  118.                                   for i in 1 .. 100 loop
  119.                                     j := x(1);
  120.                                     z := sqrt(j); -- Type an <ESC>-<CR> here
  121.                                   end loop;
  122.  
  123.                          The <ESC>-<CR> is a signal that you want to close off
  124.                          a block of code with and 'end' statement.  If you
  125.                          have forgotten to type the <ESC>-<CR> sequence and
  126.                          you are sitting on a blank line type it anyway and
  127.                          you will be repositioned automatically!
  128.  
  129.  
  130.         '--'             Typing these two characters will automatically put
  131.                          you into a special comment editing mode.  This mode
  132.                          will wrap lines automatically when you are typing
  133.                          long comments.  The characters '--' are
  134.                          automatically created and inserted so the user does
  135.                          not have to type them when writing a comment that
  136.                          carries over to several lines.  Typing a <CR> on
  137.                          a blank line (after a '--' has been automatically
  138.                          inserted), will leave the comment mode and return
  139.                          you to editing statement editing by repositioning
  140.                          the cursor in the correct place.
  141.  
  142. ------------------------------------------------------------------------------
  143.  
  144.  
  145. ::::::::::
  146. adaemacs.p2
  147. ::::::::::
  148.  
  149.  
  150. ; ----------------------------------------------------------------------------
  151. ; ada.ml - Ada mode for Emacs
  152. ; ----------------------------------------------------------------------------
  153. ;  
  154. ;                         Ada Mode for Gosling Emacs
  155. ;  
  156. ;                              Steven M. Rosen
  157. ;  
  158. ;                  Siemens Corporate Research and Support, Inc.
  159. ;                     Research and Technology Laboratories
  160. ;                             Princeton, NJ 08540
  161. ;                                (609) 734-6538
  162. ;  
  163. ;                                 rosen@siemens
  164. ; ----------------------------------------------------------------------------
  165. ;     This code is public domain and may be used or modified at your site
  166. ;     in any fashion that you choose.  No support or capabilities are
  167. ;     implied or guaranteed by the release of this code.  This disclaimer
  168. ;    must be maintained in conjunction with the code.
  169. ; ----------------------------------------------------------------------------
  170. ;
  171. ; $Header: ada.ml,v 4.1 85/04/15 08:33:06 rosen Exp $
  172. ; Created 12-18-84
  173. ; Updated 04-15-85
  174. ; Bindings:
  175. ;     indent-change = size of indentation (default to 2)
  176. ;     Indent from (dot) to (mark)              ^X->
  177. ;     De-dent from (dot) to (mark)              ^X-<
  178. ;     Tab over to indent of most recent line of code      <TAB>,<ESC><TAB>
  179. ;     Decrease indent level and start newline          <ESC>-<CR>
  180. ;     Enter Ada comment mode                  "--"
  181. ; Features:
  182. ;   o    Automatically performs indentation while editing Ada code.
  183. ;   o    Automatically performs justification of Ada comments which
  184. ;     begin on a blank line.
  185. ;   o    Automatically matches parentheses.
  186.  
  187.  
  188. (defun
  189.     (ada-mode
  190.     (declare-buffer-specific in-comment-edit)
  191.     (setq-default indent-change 2)
  192.     (setq tab-size 8)
  193.     (setq in-comment-edit 0)
  194.     (setq mode-string "Ada")
  195.     (use-syntax-table "Ada")
  196.     (setq abbrev-mode 1)
  197.     (local-bind-to-key "begin-ada-comment" "-")
  198.     (local-bind-to-key "indent-region" "\^X>")
  199.     (local-bind-to-key "dedent-region" "\^X<")
  200.     (local-bind-to-key "tab-ada" "\t")
  201.     (local-bind-to-key "tab-ada" "\e\t")
  202.     (local-bind-to-key "indent-ada" "\^M")
  203.     (local-bind-to-key "de-dent-ada" "\e\^M")
  204.     (local-bind-to-key "show-matching-paren" ")")
  205. ; The following two lines can be include to suit local naming 
  206. ; conventions:
  207. ;    (modify-syntax-entry "w    _")
  208. ;    (modify-syntax-entry "w    .")
  209. ;
  210.     (modify-syntax-entry "()   (")
  211.     (modify-syntax-entry ")(   )")
  212.     (modify-syntax-entry "\"    \"")
  213.     (modify-syntax-entry "  { --")
  214.     (modify-syntax-entry "   } \n")
  215.     (error-occurred (ada-mode-hook))
  216.     (novalue)
  217.     )
  218. )    
  219.  
  220. (defun 
  221.     (cond n running
  222.       (setq n 1)
  223.       (setq running 1)
  224.       (while (& running (< n (nargs)))
  225.          (if (arg n)
  226.              (setq running 0)
  227.              (setq n (+ n 2))))
  228.       (arg (+ n 1))))
  229.     
  230. (defun 
  231.     (show-matching-paren
  232.     (insert-character (last-key-struck))
  233.     (save-excursion 
  234.         (backward-paren)
  235.         (if (dot-is-visible)
  236.         (sit-for 5)
  237.         (progn 
  238.                (beginning-of-line)
  239.                (set-mark)
  240.                (end-of-line)
  241.                (message (region-to-string)))))))
  242.     
  243. (defun 
  244.     (leave-and-show
  245.     (setq abbrev-mode 1)
  246.     (show-matching-paren)))
  247.     
  248. (defun 
  249.     (change-indentation colno    ; indent by arg for region
  250.     (save-excursion 
  251.         (if (< (mark) (dot))
  252.         (progn 
  253.                (end-of-line)
  254.                (exchange-dot-and-mark)
  255.                (beginning-of-line))
  256.         (progn 
  257.                (beginning-of-line)
  258.                (exchange-dot-and-mark)
  259.                (end-of-line)))
  260.         (narrow-region)
  261.         (end-of-file)
  262.         (beginning-of-line)
  263.         (setq colno (+ (current-indent) (arg 1)))
  264.         (delete-white-space)
  265.         (if (> colno 1)
  266.         (to-col colno))
  267.         (beginning-of-line)
  268.         (while (! (bobp))
  269.            (previous-line)
  270.            (setq colno (+ (current-indent) (arg 1)))
  271.            (delete-white-space)
  272.            (if (> colno 1)
  273.                (to-col colno))
  274.            (beginning-of-line))
  275.         (widen-region))))
  276.     
  277. (defun 
  278.     (dedent-region         ; dedents region
  279.     (change-indentation (- 0 indent-change))))
  280.     
  281. (defun 
  282.     (indent-region colno    ; indents region
  283.     (change-indentation indent-change)))
  284.     
  285.     
  286. (defun 
  287.     (tab-ada dotab colno
  288.     (if 
  289.         (& (eobp) (eolp))
  290.         (progn 
  291.            (insert-character '\n')
  292.            (backward-character))
  293.     )
  294.     (if 
  295.         (| (& (bolp) (looking-at "[ \t]*\n"))
  296.            (< (current-column) (current-indent)))
  297.         (progn 
  298.            (save-excursion 
  299.                (while 
  300.                   (& (| (looking-at "[ \t]*\n") 
  301.                     (looking-at "[ \t]*--"))
  302.                  (! (bobp)))
  303.                   (progn 
  304.                      (previous-line)
  305.                      (beginning-of-line)))
  306.                (setq colno (current-indent)))
  307.            (delete-white-space)
  308.            (to-col colno))
  309.         1
  310.         (insert-character '\t'))))
  311.     
  312. (defun 
  313.     (de-dent-ada colno
  314.     (setq colno (- (current-indent) indent-change))
  315.     (beginning-of-line)
  316.     (if 
  317.         (! (looking-at "[ \t]*\n"))
  318.             (progn 
  319.                 (end-of-line)
  320.                 (newline)))
  321.     (delete-white-space)
  322.     (to-col colno)))
  323.  
  324. (defun 
  325.     (indent-ada colno
  326.     (cond
  327.          (bolp)
  328.          (newline)
  329.          (! (eolp))
  330.          (newline-and-indent)
  331.          1
  332.          (progn
  333.            (save-excursion
  334.                (end-of-line)
  335.                (if (eobp)
  336.                (newline)))
  337.            (setq colno (current-indent))
  338.            (beginning-of-line)
  339.            (setq case-fold-search 1)
  340.            (cond
  341.             (& (= in-comment-edit 1)
  342.                (looking-at "[ \t]*-- \n"))
  343.             (progn 
  344.                    (setq in-comment-edit 0)
  345.                    (beginning-of-line)
  346.                    (kill-to-end-of-line)
  347.                    (kill-to-end-of-line)
  348.                    (if 
  349.                    (looking-at "[ \t]*\n")
  350.                    (tab-ada)
  351.                    1
  352.                    (beginning-of-line))
  353.                    (setq right-margin 1000)
  354.                    (setq left-margin 1)
  355.                    (setq prefix-string "")
  356.                    (local-bind-to-key "begin-ada-comment" "-")
  357.                    (local-bind-to-key "tab-ada" "\t")
  358.                    (message "Finished editing ada comment"))
  359.             (& (= in-comment-edit 1)
  360.                (! (looking-at "[ \t]*--[ \t]*..")))
  361.             (progn 
  362.                    (end-of-line)
  363.                    (newline)
  364.                    (to-col comment-column)
  365.                    (insert-string "-- "))
  366.             (& (= in-comment-edit 1)
  367.                (looking-at "[ \t]*--[ \t]*.."))
  368.             (progn 
  369.                    (end-of-line)
  370.                    (newline-and-indent)
  371.                    (insert-string "-- "))
  372.             (looking-at "[ \t]*--.*\n")
  373.             (progn 
  374.                    (end-of-line)
  375.                    (newline)
  376.                    (tab-ada))
  377.             (looking-at "[ \t]*begin\\b")
  378.             (progn 
  379.                    (end-of-line)
  380.                    (newline)
  381.                    (to-col (+ colno indent-change)))
  382.             (looking-at "[ \t]*end\\b")
  383.             (progn 
  384.                    (end-of-line)
  385.                    (newline)
  386.                    (to-col (- colno indent-change)))
  387.             (looking-at "[ \t]*when\\b")
  388.             (progn 
  389.                    (end-of-line)
  390.                    (newline)
  391.                    (to-col (+ colno indent-change)))
  392.             (looking-at "[ \t]*generic\\b")
  393.             (progn 
  394.                    (end-of-line)
  395.                    (newline)
  396.                    (to-col (+ colno indent-change)))
  397.             (looking-at "[ \t]*declare\\b")
  398.             (progn 
  399.                    (end-of-line)
  400.                    (newline)
  401.                    (to-col (+ colno indent-change)))
  402.             (looking-at "[ \t]*loop\\b")
  403.             (progn 
  404.                    (end-of-line)
  405.                    (newline)
  406.                    (to-col (+ colno indent-change)))
  407.             (looking-at "[ \t]*if\\b")
  408.             (progn 
  409.                    (end-of-line)
  410.                    (newline)
  411.                    (to-col (+ colno indent-change)))
  412.             (looking-at "[ \t]*elsif\\b")
  413.             (progn 
  414.                    (end-of-line)
  415.                    (newline)
  416.                    (to-col (+ colno indent-change)))
  417.             (looking-at "[ \t]*else\\b")
  418.             (progn 
  419.                    (end-of-line)
  420.                    (newline)
  421.                    (to-col (+ colno indent-change)))
  422.             (looking-at "[ \t]*while\\b")
  423.             (progn 
  424.                    (end-of-line)
  425.                    (newline)
  426.                    (to-col (+ colno indent-change)))
  427.             (looking-at "[ \t]*case\\b")
  428.             (progn 
  429.                    (end-of-line)
  430.                    (newline)
  431.                    (to-col (+ colno indent-change)))
  432.             (looking-at "[ \t]*for\\b")
  433.             (progn 
  434.                    (end-of-line)
  435.                    (if (= (preceding-char) ';')
  436.                    (newline-and-indent)
  437.                    (progn 
  438.                       (newline)
  439.                       (to-col (+ colno indent-change)))))
  440.             (looking-at "[ \t]*loop\\b")
  441.             (progn 
  442.                    (end-of-line)
  443.                    (newline)
  444.                    (to-col (+ colno indent-change)))
  445.             (looking-at "[ \t]*or\\b")
  446.             (progn 
  447.                    (end-of-line)
  448.                    (newline)
  449.                    (to-col (+ colno indent-change)))
  450.             (looking-at "[ \t]*exception\\b")
  451.             (progn 
  452.                    (end-of-line)
  453.                    (newline)
  454.                    (to-col (+ colno indent-change)))
  455.             (looking-at "[ \t]*record\\b")
  456.             (progn 
  457.                    (end-of-line)
  458.                    (newline)
  459.                    (to-col (+ colno indent-change)))
  460.             (looking-at "[ \t]*private\\b")
  461.             (progn 
  462.                    (end-of-line)
  463.                    (newline)
  464.                    (to-col (+ colno indent-change)))
  465.             (| (looking-at "[ \t]*type\\b")
  466.                (looking-at "[ \t]*subtype\\b"))
  467.             (progn 
  468.                    (end-of-line)
  469.                    (backward-word)
  470.                    (if 
  471.                    (looking-at "record\\b")
  472.                    (progn 
  473.                       (setq colno (current-column))
  474.                       (end-of-line)
  475.                       (newline)
  476.                       (to-col (+ colno indent-change)))
  477.                    (looking-at "is\\b")
  478.                    (progn 
  479.                       (end-of-line)
  480.                       (newline)
  481.                       (to-col (+ colno indent-change)))
  482.                    1
  483.                    (progn 
  484.                       (end-of-line)
  485.                       (newline-and-indent))))
  486.             (looking-at "[ \t]*select\\b")
  487.             (progn 
  488.                    (end-of-line)
  489.                    (newline)
  490.                    (to-col (+ colno indent-change)))
  491.             (looking-at "[ \t]*accept\\b")
  492.             (progn 
  493.                    (end-of-line)
  494.                    (backward-word)
  495.                    (if (looking-at "do\\b")
  496.                    (progn 
  497.                       (end-of-line)
  498.                       (newline)
  499.                       (to-col (+ colno indent-change)))
  500.                    (progn 
  501.                       (end-of-line)
  502.                       (newline-and-indent))))
  503.             (looking-at "[ \t]*task\\b")
  504.             (progn 
  505.                    (end-of-line)
  506.                    (backward-word)
  507.                    (if (looking-at "is\\b")
  508.                    (progn 
  509.                       (end-of-line)
  510.                       (newline)
  511.                       (to-col (+ colno indent-change)))
  512.                    (progn 
  513.                       (end-of-line)
  514.                       (newline-and-indent))))
  515.             (| (looking-at "[ \t]*procedure\\b")
  516.                (looking-at "[ \t]*function\\b"))
  517.             (progn 
  518.                    (end-of-line)
  519.                    (backward-word)
  520.                    (if (looking-at "is\\b")
  521.                    (progn 
  522.                       (end-of-line)
  523.                       (newline)
  524.                       (to-col (+ colno indent-change)))
  525.                    (progn 
  526.                       (end-of-line)
  527.                       (newline-and-indent))))
  528.             (looking-at "[ \t]*package\\b")
  529.             (progn 
  530.                    (end-of-line)
  531.                    (backward-word)
  532.                    (if (looking-at "is\\b")
  533.                    (progn 
  534.                       (end-of-line)
  535.                       (newline)
  536.                       (to-col (+ colno indent-change)))
  537.                    (progn 
  538.                       (end-of-line)
  539.                       (newline-and-indent))))
  540.             (|  (looking-at "[ \t]*.*:[^=].*[^;]\n")
  541.                 (looking-at "[ \t]*.*:[ \t]*\n"))
  542.             (progn 
  543.                    (end-of-line)
  544.                    (newline)
  545.                    (to-col (+ colno indent-change)))
  546.             (looking-at "[ \t]*<<.*>>")
  547.             (progn 
  548.                    (end-of-line)
  549.                    (newline)
  550.                    (to-col (+ colno indent-change)))
  551.             1
  552.             (progn
  553.                   (setq colno (current-indent))
  554.                   (if (looking-at "[ \t][ \t]*\n")
  555.                   (kill-to-end-of-line))
  556.                   (end-of-line)
  557.                   (newline)
  558.                   (to-col colno)))
  559.            (setq case-fold-search 0)))))
  560.  
  561. (defun
  562.     (begin-ada-comment c
  563.     (insert-character (last-key-struck))
  564.     (remove-local-binding "-")
  565.     (remove-local-binding "\t")
  566.     (setq c (get-tty-character))
  567.     (insert-character c)
  568.     (if 
  569.         (&
  570.           (= c 45)
  571.           (looking-at "[ \t]*\n"))
  572.         (progn 
  573.            (setq in-comment-edit 1)
  574.            (setq comment-column (- (current-column) 2))
  575.            (move-to-comment-column)
  576.            (setq left-margin comment-column)
  577.            (setq right-margin 76)
  578.            (setq prefix-string "-- ")
  579.            (cond 
  580.              (looking-at "[ \t]*--")
  581.              (progn 
  582.                 (end-of-line)
  583.                 (newline)
  584.                 (to-col comment-column)
  585.                 (insert-string "-- "))
  586.              1
  587.              (end-of-line))
  588.            (message "Editing ada comment")
  589.         )
  590.         1
  591.         (progn 
  592.            (local-bind-to-key "begin-ada-comment" "-")
  593.            (local-bind-to-key "tab-ada" "\t")
  594.         ))
  595.     )
  596. )
  597.  
  598. (defun
  599.     (end-ada-comment
  600.         (setq in-comment-edit 0)
  601.         (setq right-margin 1000)
  602.         (if (!= (preceding-char) ' ') (insert-string " "))
  603.         (to-col comment-column)
  604.         (insert-string "--")
  605.         (newline)
  606.         (local-bind-to-key "tab-ada" "\t")
  607.         (message "Finished editing ada comment")
  608.     )
  609. )
  610. ; ----------------------------------------------------------------------------
  611.