home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / emacs / help / 4901 < prev    next >
Encoding:
Text File  |  1992-11-23  |  7.1 KB  |  218 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!fstop.csc.ti.com!fstop.csc!adam
  3. From: adam@dadhb1.ti.com (Adam Hudd)
  4. Subject: Re: OCCAM mode for EMACS?
  5. In-Reply-To: klemme@uni-paderborn.de's message of 22 Nov 1992 16:03:57 GMT
  6. Message-ID: <ADAM.92Nov23111350@node_48dc0.dadhb1.ti.com>
  7. Lines: 204
  8. Sender: usenet@csc.ti.com
  9. Nntp-Posting-Host: 192.48.249.30
  10. Organization: Texas Instruments, Inc., Houston, TX
  11. References: <1eob1dINN7ri@uni-paderborn.de>
  12. Date: Mon, 23 Nov 1992 17:13:50 GMT
  13.  
  14. I think I originally found this on the wuarchive...
  15.  
  16. ;; OCCAM mode for GNU emacs at DIKU
  17. ;; by Jesper Larsson Traff, DIKU autumn 1989.
  18. ;; Copyright (C) Jesper Larsson Traff and DIKU
  19.  
  20. ;; LCD Archive Entry:
  21. ;; occam-mode|Jesper Larsson Traff||
  22. ;; OCCAM programing mode.|
  23. ;; 89-09||~/modes/occam-mode.el.Z|
  24.  
  25. ;; GNU Emacs is distributed in the hope that it will be useful,
  26. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  27. ;; accepts responsibility to anyone for the consequences of using it
  28. ;; or for whether it serves any particular purpose or works at all,
  29. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  30. ;; License for full details.
  31.  
  32. ;; Everyone is granted permission to copy, modify and redistribute
  33. ;; GNU Emacs, but only under the conditions described in the
  34. ;; GNU Emacs General Public License.   A copy of this license is
  35. ;; supposed to have been given to you along with GNU Emacs so you
  36. ;; can know your rights and responsibilities.  It should be in a
  37. ;; file named COPYING.  Among other things, the copyright notice
  38. ;; and this notice must be preserved on all copies.
  39.  
  40. (defconst occam-indent 2 
  41.   "*OCCAM standard indentation (do not change!)")
  42.  
  43. (defconst occam-process-keywords
  44.   '("SEQ"                         ; sequential process
  45.     "PAR"                         ; parallel process
  46.     "IF"                          ; conditional process
  47.     "ALT"                         ; alternative (special) process
  48.     "WHILE"                       ; iterative process
  49.     "CASE"                        ; selection process
  50.     "ELSE"                        ; default process in selection
  51.     "VALOF"
  52.     "PROC"
  53.     "PROCESSOR"
  54.     "PLACED"
  55.     "PRI"
  56.     )
  57.   "*OCCAM proccess keywords")
  58.  
  59. (defconst occam-reserved-words
  60.   '("INT" "INT16""INT32" "INT64"  ; integer declarations
  61.     "REAL" "REAL32" "REAL64"      ; real declarations
  62.     "BYTE"                        ; byte (character) declaration
  63.     "BOOL" "TRUE" "FALSE"         ; boolean declaration and constants
  64.     "CHAN"                        ; channel declaration
  65.     "OF"
  66.     "PROTOCOL"                    ; protocol declaration
  67.     "TIMER"                       ; timer declaration
  68.     "VAL"
  69.     "IS"
  70.     "RESULT"
  71.     "FOR"                         ; replicator keyword
  72.     "AT"
  73.     "SIZE"                        ; size operator
  74.     "FROM"                        ; array selector keyword
  75.     "SKIP" "STOP"                 ; special processes
  76.     )
  77.   "*OCCAM reserved words (will be capitalized)")
  78.  
  79. (defvar occam-mode-syntax-table nil
  80.   "Syntax table in use in OCCAM mode buffers")
  81. (if occam-mode-syntax-table
  82.     ()
  83.   (setq occam-mode-syntax-table (make-syntax-table))
  84.   (modify-syntax-entry ?. "w" occam-mode-syntax-table)
  85.   (modify-syntax-entry ?+ "." occam-mode-syntax-table)
  86.   (modify-syntax-entry ?- "." occam-mode-syntax-table)
  87.   (modify-syntax-entry ?* "." occam-mode-syntax-table)
  88.   (modify-syntax-entry ?/ "." occam-mode-syntax-table)
  89.   (modify-syntax-entry ?\: "." occam-mode-syntax-table)
  90.   (modify-syntax-entry ?\? "." occam-mode-syntax-table)
  91.   (modify-syntax-entry ?\! "." occam-mode-syntax-table)
  92.   (modify-syntax-entry ?\r ">" occam-mode-syntax-table)
  93.   (modify-syntax-entry ?- ".12" occam-mode-syntax-table))
  94.  
  95. (defvar occam-mode-map ()
  96.   "Keymap used in OCCAM mode")
  97. (if occam-mode-map
  98.     ()
  99.   (setq occam-mode-map (make-sparse-keymap))
  100.   (define-key occam-mode-map " " 'uppercase-occam-keyword)
  101.   (define-key occam-mode-map "\r" 'occam-indent-newline)
  102.   (define-key occam-mode-map "\177" 'backward-delete-unindent))
  103.  
  104. (defun occam-mode ()
  105.   "Major mode for editing OCCAM programs.
  106. TAB and CR automatically indents.
  107. All OCCAM keywords (which are separated into process keywords which force 
  108. indentation and reserved words) are recognized and uppercase'd.
  109.  
  110. Variables and constants controlling case change:
  111.     occam-indentation :      indentation, default 2
  112.     occam-process-keywords : list of process keywords
  113.     occam-reserved-words :   list of reserved words
  114.  
  115. The value of the variable occam-mode-hook (must be a function name) is called 
  116. with no arguments prior to entering  OCCAM mode if the value of that variable
  117. is non-nil"
  118.   (interactive)
  119.   (kill-all-local-variables)
  120.   (use-local-map occam-mode-map)
  121.   (make-local-variable 'indent-line-function)
  122.   (setq indent-line-function 'occam-indent-line)
  123.   (setq mode-name "OCCAM")
  124.   (setq major-mode 'occam-mode)
  125.   (run-hooks 'occam-mode-hook))
  126.  
  127. (defun occam-indent-line ()
  128.   "Indents current OCCAM line"
  129.   (interactive)
  130.   (save-excursion
  131.     (beginning-of-line)
  132.     (let ((p (point)))
  133.       (indent-to (calculate-occam-indent))
  134.       (while (looking-at "[ \t]")
  135.     (delete-char 1))
  136.       (untabify p (point)))))
  137.  
  138. (defun calculate-occam-indent ()
  139.   "calculate indentation for current OCCAM line"
  140.   (interactive)
  141.   (save-excursion
  142.     (beginning-of-line 0)
  143.     (while (and (looking-at "[ \t]*$") (not (bobp)))
  144.       (beginning-of-line 0))
  145.     (if (looking-at "[ \t]*$")
  146.     0
  147.       (progn
  148.     (skip-chars-forward " \t")
  149.     (let ((col (current-column)))
  150.       (forward-word 1)
  151.       (if (occam-keyword occam-process-keywords)
  152.           (+ col occam-indent)
  153.         col))))))
  154.  
  155. (defun uppercase-occam-keyword ()
  156.   "check if last word was an OCCAM keyword"
  157.   (interactive)
  158.   (occam-keyword (append occam-process-keywords occam-reserved-words))
  159.   (insert " "))
  160.  
  161. (defun occam-indent-newline ()
  162.   "Indent new line to current indentation unless previous line contained 
  163. a process keyword"
  164.   (interactive)
  165.   (save-excursion
  166.     (let ((eol (point)))
  167.       (beginning-of-line)
  168.       (if (looking-at "[ \t]*$")
  169.       (delete-region (point) eol)
  170.     ())))
  171.   (occam-keyword (append occam-process-keywords occam-reserved-words))
  172.   (newline)
  173.   (occam-indent-line)
  174.   (end-of-line))
  175.  
  176. (defun backward-delete-unindent ()
  177.   "Delete and unindent"
  178.   (interactive)
  179.   (let ((p (point)))
  180.     (skip-chars-backward " \t" (- p (current-column)))
  181.     (if (bolp)
  182.     (progn
  183.       (goto-char p)
  184.       (if (bolp)
  185.           (delete-char -1)
  186.         (delete-char (- occam-indent))))
  187.       (progn
  188.     (goto-char p)
  189.     (delete-char -1)))))
  190.  
  191. (defun occam-keyword (keywords)
  192.   "upcase current word and if OCCAM keyword, t if keyword"
  193.   (save-excursion
  194.     (let ((eow (point)))
  195.       (forward-word -1)
  196.       (let ((bow (point)))
  197.     (if (re-search-backward "\s<" (- bow (current-column)) t)
  198.         nil
  199.       (if (word-in-list (upcase (buffer-substring bow eow))
  200.                 keywords)
  201.           (not (upcase-region bow eow))
  202.         nil))))))
  203.  
  204. (defun word-in-list (word words)
  205.   "t if word occurs in words, nil otherwise"
  206.   (if (null words)
  207.       nil
  208.     (if (string-equal word (car words))
  209.     t
  210.       (word-in-list word (cdr words)))))
  211.  
  212.  
  213. --
  214. Cheers,
  215. Adam Hudd               adam@dadhb1.ti.com             __o
  216. Texas Instruments Inc,                                -\<,
  217. Houston, TX                                     .....O / O
  218.