simula.el 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. ;;; simula.el --- SIMULA 87 code editing commands for Emacs
  2. ;; Copyright (C) 1992, 1994, 1996, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Hans Henrik Eriksen <hhe@ifi.uio.no>
  4. ;; Maintainer: simula-mode@ifi.uio.no
  5. ;; (above email addresses invalid as of April 2008)
  6. ;; Adapted-By: ESR
  7. ;; Keywords: languages
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; A major mode for editing the Simula language. It knows about Simula
  21. ;; syntax and standard indentation commands. It also provides convenient
  22. ;; abbrevs for Simula keywords.
  23. ;;
  24. ;; Hans Henrik Eriksen (the author) may be reached at:
  25. ;; Institutt for informatikk,
  26. ;; Universitetet i Oslo
  27. ;;; Code:
  28. (defgroup simula nil
  29. "Major mode for editing Simula code."
  30. :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
  31. :prefix "simula-"
  32. :group 'languages)
  33. (defconst simula-tab-always-indent-default nil
  34. "Non-nil means TAB in SIMULA mode should always reindent the current line.
  35. Otherwise TAB indents only when point is within
  36. the run of whitespace at the beginning of the line.")
  37. (defcustom simula-tab-always-indent simula-tab-always-indent-default
  38. "*Non-nil means TAB in SIMULA mode should always reindent the current line.
  39. Otherwise TAB indents only when point is within
  40. the run of whitespace at the beginning of the line."
  41. :type 'boolean
  42. :group 'simula)
  43. (defconst simula-indent-level-default 3
  44. "Indentation of SIMULA statements with respect to containing block.")
  45. (defcustom simula-indent-level simula-indent-level-default
  46. "*Indentation of SIMULA statements with respect to containing block."
  47. :type 'integer
  48. :group 'simula)
  49. (defconst simula-substatement-offset-default 3
  50. "Extra indentation after DO, THEN, ELSE, WHEN and OTHERWISE.")
  51. (defcustom simula-substatement-offset simula-substatement-offset-default
  52. "*Extra indentation after DO, THEN, ELSE, WHEN and OTHERWISE."
  53. :type 'integer
  54. :group 'simula)
  55. (defconst simula-continued-statement-offset-default 3
  56. "Extra indentation for lines not starting a statement or substatement.
  57. If value is a list, each line in a multipleline continued statement
  58. will have the car of the list extra indentation with respect to
  59. the previous line of the statement.")
  60. (defcustom simula-continued-statement-offset
  61. simula-continued-statement-offset-default
  62. "*Extra indentation for lines not starting a statement or substatement.
  63. If value is a list, each line in a multipleline continued statement
  64. will have the car of the list extra indentation with respect to
  65. the previous line of the statement."
  66. :type 'integer
  67. :group 'simula)
  68. (defconst simula-label-offset-default -4711
  69. "Offset of SIMULA label lines relative to usual indentation.")
  70. (defcustom simula-label-offset simula-label-offset-default
  71. "*Offset of SIMULA label lines relative to usual indentation."
  72. :type 'integer
  73. :group 'simula)
  74. (defconst simula-if-indent-default '(0 . 0)
  75. "Extra indentation of THEN and ELSE with respect to the starting IF.
  76. Value is a cons cell, the car is extra THEN indentation and the cdr
  77. extra ELSE indentation. IF after ELSE is indented as the starting IF.")
  78. (defcustom simula-if-indent simula-if-indent-default
  79. "*Extra indentation of THEN and ELSE with respect to the starting IF.
  80. Value is a cons cell, the car is extra THEN indentation and the cdr
  81. extra ELSE indentation. IF after ELSE is indented as the starting IF."
  82. :type '(cons integer integer)
  83. :group 'simula)
  84. (defconst simula-inspect-indent-default '(0 . 0)
  85. "Extra indentation of WHEN and OTHERWISE with respect to the INSPECT.
  86. Value is a cons cell, the car is extra WHEN indentation
  87. and the cdr extra OTHERWISE indentation.")
  88. (defcustom simula-inspect-indent simula-inspect-indent-default
  89. "*Extra indentation of WHEN and OTHERWISE with respect to the INSPECT.
  90. Value is a cons cell, the car is extra WHEN indentation
  91. and the cdr extra OTHERWISE indentation."
  92. :type '(cons integer integer)
  93. :group 'simula)
  94. (defconst simula-electric-indent-default nil
  95. "Non-nil means `simula-indent-line' function may reindent previous line.")
  96. (defcustom simula-electric-indent simula-electric-indent-default
  97. "*Non-nil means `simula-indent-line' function may reindent previous line."
  98. :type 'boolean
  99. :group 'simula)
  100. (defconst simula-abbrev-keyword-default 'upcase
  101. "Specify how to convert case for SIMULA keywords.
  102. Value is one of the symbols `upcase', `downcase', `capitalize',
  103. \(as in) `abbrev-table' or nil if they should not be changed.")
  104. (defcustom simula-abbrev-keyword simula-abbrev-keyword-default
  105. "*Specify how to convert case for SIMULA keywords.
  106. Value is one of the symbols `upcase', `downcase', `capitalize',
  107. \(as in) `abbrev-table' or nil if they should not be changed."
  108. :type '(choice (const upcase) (const downcase) (const capitalize)(const nil))
  109. :group 'simula)
  110. (defconst simula-abbrev-stdproc-default 'abbrev-table
  111. "Specify how to convert case for standard SIMULA procedure and class names.
  112. Value is one of the symbols `upcase', `downcase', `capitalize',
  113. \(as in) `abbrev-table', or nil if they should not be changed.")
  114. (defcustom simula-abbrev-stdproc simula-abbrev-stdproc-default
  115. "*Specify how to convert case for standard SIMULA procedure and class names.
  116. Value is one of the symbols `upcase', `downcase', `capitalize',
  117. \(as in) `abbrev-table', or nil if they should not be changed."
  118. :type '(choice (const upcase) (const downcase) (const capitalize)
  119. (const abbrev-table) (const nil))
  120. :group 'simula)
  121. (defcustom simula-abbrev-file nil
  122. "*File with extra abbrev definitions for use in SIMULA mode.
  123. These are used together with the standard abbrev definitions for SIMULA.
  124. Please note that the standard definitions are required
  125. for SIMULA mode to function correctly."
  126. :type '(choice file (const nil))
  127. :group 'simula)
  128. (defvar simula-mode-syntax-table nil
  129. "Syntax table in SIMULA mode buffers.")
  130. (defconst simula-syntax-propertize-function
  131. (syntax-propertize-rules
  132. ;; `comment' directive.
  133. ("\\<\\(c\\)omment\\>" (1 "<"))
  134. ;; end comments
  135. ((concat "\\<end\\>\\([^;\n]\\).*?\\(\n\\|\\(.\\)\\(;\\|"
  136. (regexp-opt '("end" "else" "when" "otherwise"))
  137. "\\)\\)")
  138. (1 "< b")
  139. (3 "> b"))
  140. ;; non-quoted single-quote char.
  141. ("'\\('\\)'" (1 "."))))
  142. ;; Regexps written with help from Alf-Ivar Holm <alfh@ifi.uio.no>.
  143. (defconst simula-font-lock-keywords-1
  144. '(;;
  145. ;; Compiler directives.
  146. ("^%\\([^ \t\n].*\\)" 1 font-lock-constant-face t)
  147. ;;
  148. ;; Class and procedure names.
  149. ("\\<\\(class\\|procedure\\)\\>[ \t]*\\(\\sw+\\)?"
  150. (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)))
  151. "Subdued level highlighting for Simula mode.")
  152. (defconst simula-font-lock-keywords-2
  153. (append simula-font-lock-keywords-1
  154. (list
  155. ;;
  156. ;; Constants.
  157. '("\\<\\(false\\|none\\|notext\\|true\\)\\>" . font-lock-constant-face)
  158. ;;
  159. ;; Keywords.
  160. (regexp-opt
  161. '("activate" "after" "and" "at" "before" "begin" "delay" "do"
  162. "else" "end" "eq" "eqv" "external" "for" "ge" "go" "goto" "gt"
  163. "hidden" "if" "imp" "in" "inner" "inspect" "is" "label" "le"
  164. "lt" "ne" "new" "not" "or" "otherwise" "prior" "protected"
  165. "qua" "reactivate" "step" "switch" "then" "this" "to" "until"
  166. "virtual" "when" "while") 'words)
  167. ;;
  168. ;; Types.
  169. (cons (regexp-opt
  170. '("array" "boolean" "character" "integer"
  171. "long" "name" "real" "short" "text" "value" "ref") 'words)
  172. 'font-lock-type-face)))
  173. "Medium level highlighting for Simula mode.")
  174. (defconst simula-font-lock-keywords-3
  175. (append simula-font-lock-keywords-2
  176. (list
  177. ;;
  178. ;; Super-class names and super-slow.
  179. '("\\<\\(\\sw+\\)[ \t]+class\\>" 1 font-lock-function-name-face)
  180. ;;
  181. ;; Types and their declarations.
  182. (list (concat "\\<\\(array\\|boolean\\|character\\|integer\\|"
  183. "long\\|name\\|real\\|short\\|text\\|value\\)\\>"
  184. "\\([ \t]+\\sw+\\>\\)*")
  185. '(font-lock-match-c-style-declaration-item-and-skip-to-next
  186. ;; Start with point after all type specifiers.
  187. (goto-char (or (match-beginning 2) (match-end 1)))
  188. ;; Finish with point after first type specifier.
  189. (goto-char (match-end 1))
  190. ;; Fontify as a variable name.
  191. (1 font-lock-variable-name-face)))
  192. ;;
  193. ;; Object references and their declarations.
  194. '("\\<\\(ref\\)\\>[ \t]*\\((\\(\\sw+\\))\\)?"
  195. (3 font-lock-function-name-face nil t)
  196. (font-lock-match-c-style-declaration-item-and-skip-to-next nil nil
  197. (1 font-lock-variable-name-face)))
  198. ))
  199. "Gaudy level highlighting for Simula mode.")
  200. (defvar simula-font-lock-keywords simula-font-lock-keywords-1
  201. "Default expressions to highlight in Simula mode.")
  202. ; The following function is taken from cc-mode.el,
  203. ; it determines the flavor of the Emacs running
  204. (defvar simula-mode-menu
  205. '(["Report Bug" simula-submit-bug-report t]
  206. ["Indent Line" simula-indent-line t]
  207. ["Backward Statement" simula-previous-statement t]
  208. ["Forward Statement" simula-next-statement t]
  209. ["Backward Up Level" simula-backward-up-level t]
  210. ["Forward Down Statement" simula-forward-down-level t])
  211. "Lucid Emacs menu for SIMULA mode.")
  212. (if simula-mode-syntax-table
  213. ()
  214. (setq simula-mode-syntax-table (copy-syntax-table (standard-syntax-table)))
  215. (modify-syntax-entry ?! "<" simula-mode-syntax-table)
  216. (modify-syntax-entry ?$ "." simula-mode-syntax-table)
  217. (modify-syntax-entry ?% "< b" simula-mode-syntax-table)
  218. (modify-syntax-entry ?\n "> b" simula-mode-syntax-table)
  219. (modify-syntax-entry ?' "\"" simula-mode-syntax-table)
  220. (modify-syntax-entry ?\( "()" simula-mode-syntax-table)
  221. (modify-syntax-entry ?\) ")(" simula-mode-syntax-table)
  222. (modify-syntax-entry ?\; ">" simula-mode-syntax-table)
  223. (modify-syntax-entry ?\[ "." simula-mode-syntax-table)
  224. (modify-syntax-entry ?\\ "." simula-mode-syntax-table)
  225. (modify-syntax-entry ?\] "." simula-mode-syntax-table)
  226. (modify-syntax-entry ?_ "_" simula-mode-syntax-table)
  227. (modify-syntax-entry ?\| "." simula-mode-syntax-table)
  228. (modify-syntax-entry ?\{ "." simula-mode-syntax-table)
  229. (modify-syntax-entry ?\} "." simula-mode-syntax-table))
  230. (defvar simula-mode-map
  231. (let ((map (make-sparse-keymap)))
  232. (define-key map "\C-c\C-u" 'simula-backward-up-level)
  233. (define-key map "\C-c\C-p" 'simula-previous-statement)
  234. (define-key map "\C-c\C-d" 'simula-forward-down-level)
  235. (define-key map "\C-c\C-n" 'simula-next-statement)
  236. ;; (define-key map "\C-c\C-g" 'simula-goto-definition)
  237. ;; (define-key map "\C-c\C-h" 'simula-standard-help)
  238. (define-key map "\177" 'backward-delete-char-untabify)
  239. (define-key map ":" 'simula-electric-label)
  240. (define-key map "\e\C-q" 'simula-indent-exp)
  241. (define-key map "\t" 'simula-indent-command)
  242. ;; Emacs 19 defines menus in the mode map
  243. (define-key map [menu-bar simula]
  244. (cons "SIMULA" (make-sparse-keymap "SIMULA")))
  245. (define-key map [menu-bar simula bug-report]
  246. '("Submit Bug Report" . simula-submit-bug-report))
  247. (define-key map [menu-bar simula separator-indent]
  248. '("--"))
  249. (define-key map [menu-bar simula indent-exp]
  250. '("Indent Expression" . simula-indent-exp))
  251. (define-key map [menu-bar simula indent-line]
  252. '("Indent Line" . simula-indent-command))
  253. (define-key map [menu-bar simula separator-navigate]
  254. '("--"))
  255. (define-key map [menu-bar simula backward-stmt]
  256. '("Previous Statement" . simula-previous-statement))
  257. (define-key map [menu-bar simula forward-stmt]
  258. '("Next Statement" . simula-next-statement))
  259. (define-key map [menu-bar simula backward-up]
  260. '("Backward Up Level" . simula-backward-up-level))
  261. (define-key map [menu-bar simula forward-down]
  262. '("Forward Down Statement" . simula-forward-down-level))
  263. (put 'simula-next-statement 'menu-enable '(not (eobp)))
  264. (put 'simula-previous-statement 'menu-enable '(not (bobp)))
  265. (put 'simula-forward-down-level 'menu-enable '(not (eobp)))
  266. (put 'simula-backward-up-level 'menu-enable '(not (bobp)))
  267. (put 'simula-indent-command 'menu-enable '(not buffer-read-only))
  268. (put 'simula-indent-exp 'menu-enable '(not buffer-read-only))
  269. ;; RMS: mouse-3 should not select this menu. mouse-3's global
  270. ;; definition is useful in SIMULA mode and we should not interfere
  271. ;; with that. The menu is mainly for beginners, and for them,
  272. ;; the menubar requires less memory than a special click.
  273. ;; in Lucid Emacs, we want the menu to popup when the 3rd button is
  274. ;; hit. In 19.10 and beyond this is done automatically if we put
  275. ;; the menu on mode-popup-menu variable, see c-common-init [cc-mode.el]
  276. ;;(if (not (boundp 'mode-popup-menu))
  277. ;; (define-key simula-mode-map 'button3 'simula-popup-menu))
  278. map)
  279. "Keymap used in `simula-mode'.")
  280. ;; menus for Lucid
  281. (defun simula-popup-menu (_e)
  282. "Pops up the SIMULA menu."
  283. (interactive "@e")
  284. (popup-menu (cons (concat mode-name " Mode Commands") simula-mode-menu)))
  285. ;;;###autoload
  286. (define-derived-mode simula-mode prog-mode "Simula"
  287. "Major mode for editing SIMULA code.
  288. \\{simula-mode-map}
  289. Variables controlling indentation style:
  290. `simula-tab-always-indent'
  291. Non-nil means TAB in SIMULA mode should always reindent the current line,
  292. regardless of where in the line point is when the TAB command is used.
  293. `simula-indent-level'
  294. Indentation of SIMULA statements with respect to containing block.
  295. `simula-substatement-offset'
  296. Extra indentation after DO, THEN, ELSE, WHEN and OTHERWISE.
  297. `simula-continued-statement-offset' 3
  298. Extra indentation for lines not starting a statement or substatement,
  299. e.g. a nested FOR-loop. If value is a list, each line in a multiple-
  300. line continued statement will have the car of the list extra indentation
  301. with respect to the previous line of the statement.
  302. `simula-label-offset' -4711
  303. Offset of SIMULA label lines relative to usual indentation.
  304. `simula-if-indent' '(0 . 0)
  305. Extra indentation of THEN and ELSE with respect to the starting IF.
  306. Value is a cons cell, the car is extra THEN indentation and the cdr
  307. extra ELSE indentation. IF after ELSE is indented as the starting IF.
  308. `simula-inspect-indent' '(0 . 0)
  309. Extra indentation of WHEN and OTHERWISE with respect to the
  310. corresponding INSPECT. Value is a cons cell, the car is
  311. extra WHEN indentation and the cdr extra OTHERWISE indentation.
  312. `simula-electric-indent' nil
  313. If this variable is non-nil, `simula-indent-line'
  314. will check the previous line to see if it has to be reindented.
  315. `simula-abbrev-keyword' 'upcase
  316. Determine how SIMULA keywords will be expanded. Value is one of
  317. the symbols `upcase', `downcase', `capitalize', (as in) `abbrev-table',
  318. or nil if they should not be changed.
  319. `simula-abbrev-stdproc' 'abbrev-table
  320. Determine how standard SIMULA procedure and class names will be
  321. expanded. Value is one of the symbols `upcase', `downcase', `capitalize',
  322. (as in) `abbrev-table', or nil if they should not be changed.
  323. Turning on SIMULA mode calls the value of the variable simula-mode-hook
  324. with no arguments, if that value is non-nil."
  325. (set (make-local-variable 'comment-column) 40)
  326. ;; (set (make-local-variable 'end-comment-column) 75)
  327. (set (make-local-variable 'paragraph-start) "[ \t]*$\\|\\f")
  328. (set (make-local-variable 'paragraph-separate) paragraph-start)
  329. (set (make-local-variable 'indent-line-function) 'simula-indent-line)
  330. (set (make-local-variable 'comment-start) "! ")
  331. (set (make-local-variable 'comment-end) " ;")
  332. (set (make-local-variable 'comment-start-skip) "!+ *")
  333. (set (make-local-variable 'parse-sexp-ignore-comments) nil)
  334. (set (make-local-variable 'comment-multi-line) t)
  335. (set (make-local-variable 'font-lock-defaults)
  336. '((simula-font-lock-keywords simula-font-lock-keywords-1
  337. simula-font-lock-keywords-2 simula-font-lock-keywords-3)
  338. nil t ((?_ . "w"))))
  339. (set (make-local-variable 'syntax-propertize-function)
  340. simula-syntax-propertize-function)
  341. (abbrev-mode 1))
  342. (defun simula-indent-exp ()
  343. "Indent SIMULA expression following point."
  344. (interactive)
  345. (let ((here (point))
  346. (simula-electric-indent nil)
  347. end)
  348. (simula-skip-comment-forward)
  349. (if (eobp)
  350. (goto-char here)
  351. (unwind-protect
  352. (progn
  353. (simula-next-statement 1)
  354. (setq end (point-marker))
  355. (simula-previous-statement 1)
  356. (beginning-of-line)
  357. (while (< (point) end)
  358. (if (not (looking-at "[ \t]*$"))
  359. (simula-indent-line))
  360. (forward-line 1)))
  361. (and end (set-marker end nil))))))
  362. (defun simula-indent-line ()
  363. "Indent this line as SIMULA code.
  364. If `simula-electric-indent' is non-nil, indent previous line if necessary."
  365. (let ((origin (- (point-max) (point)))
  366. (indent (simula-calculate-indent))
  367. (case-fold-search t))
  368. (unwind-protect
  369. (if simula-electric-indent
  370. (progn
  371. ;;
  372. ;; manually expand abbrev on last line, if any
  373. ;;
  374. (end-of-line 0)
  375. (expand-abbrev)
  376. ;; now maybe we should reindent that line
  377. (beginning-of-line)
  378. (skip-chars-forward " \t\f")
  379. (if (and
  380. (looking-at
  381. "\\(end\\|if\\|then\\|else\\|when\\|otherwise\\)\\>")
  382. (not (simula-context)))
  383. ;; yes - reindent
  384. (let ((post-indent (simula-calculate-indent)))
  385. (if (eq (current-indentation) post-indent)
  386. ()
  387. (delete-horizontal-space)
  388. (indent-to post-indent))))))
  389. (goto-char (- (point-max) origin))
  390. (if (eq (current-indentation) indent)
  391. (back-to-indentation)
  392. (delete-horizontal-space)
  393. (indent-to indent)))))
  394. (defun simula-indent-command (&optional whole-exp)
  395. "Indent current line as SIMULA code, or insert TAB character.
  396. If `simula-tab-always-indent' is non-nil, always indent current line.
  397. Otherwise, indent only if point is before any non-whitespace
  398. character on the line.
  399. A numeric argument, regardless of its value, means indent rigidly
  400. all the lines of the SIMULA statement after point so that this line
  401. becomes properly indented.
  402. The relative indentation among the lines of the statement are preserved."
  403. (interactive "P")
  404. (let ((case-fold-search t))
  405. (if (or whole-exp simula-tab-always-indent
  406. (save-excursion
  407. (skip-chars-backward " \t\f")
  408. (bolp)))
  409. ;; reindent current line
  410. (let ((indent (save-excursion
  411. (beginning-of-line)
  412. (simula-calculate-indent)))
  413. (current (current-indentation))
  414. (origin (- (point-max) (point)))
  415. (bol (save-excursion
  416. (skip-chars-backward " \t\f")
  417. (bolp)))
  418. beg end)
  419. (unwind-protect
  420. (if (eq current indent)
  421. (if (save-excursion
  422. (skip-chars-backward " \t\f")
  423. (bolp))
  424. (back-to-indentation))
  425. (beginning-of-line)
  426. (delete-horizontal-space)
  427. (indent-to indent))
  428. (if (not bol)
  429. (goto-char (- (point-max) origin))))
  430. (setq origin (point))
  431. (if whole-exp
  432. (save-excursion
  433. (beginning-of-line 2)
  434. (setq beg (point))
  435. (goto-char origin)
  436. (simula-next-statement 1)
  437. (setq end (point))
  438. (if (and (> end beg) (not (eq indent current)))
  439. (indent-code-rigidly beg end (- indent current) "%")))))
  440. (insert-tab))))
  441. (defun simula-context ()
  442. "Return value according to syntactic SIMULA context of point.
  443. 0 point inside COMMENT comment
  444. 1 point on SIMULA-compiler directive line
  445. 2 point inside END comment
  446. 3 point inside string
  447. 4 point inside character constant
  448. nil otherwise."
  449. ;; first, find out if this is a compiler directive line
  450. (if (save-excursion
  451. (beginning-of-line)
  452. (eq (following-char) ?%))
  453. ;; YES - return 1
  454. 1
  455. (save-excursion
  456. ;; The current line is NOT a compiler directive line.
  457. ;; Now, the strategy is to search backward to find a semicolon
  458. ;; that is NOT inside a string. The point after semicolon MUST be
  459. ;; outside a comment, since semicolons are comment-ending and
  460. ;; comments are non-recursive. We take advantage of the fact
  461. ;; that strings MUST end on the same line as they started, so
  462. ;; that we can easily decide whether we are inside a string or not.
  463. (let (return-value (origin (point)))
  464. (skip-chars-backward "^;" (point-min))
  465. ;; found semicolon or beginning of buffer
  466. (let (loopvalue (saved-point origin))
  467. (while (and (not (bobp))
  468. (if (progn
  469. (beginning-of-line)
  470. ;; compiler directive line? If so, cont searching..
  471. (eq (following-char) ?%))
  472. t
  473. (while (< (point) saved-point)
  474. (skip-chars-forward "^;\"'")
  475. (forward-char 1)
  476. (cond
  477. ((eq (preceding-char) ?\;)
  478. (setq saved-point (point)))
  479. ((eq (preceding-char) ?\")
  480. (skip-chars-forward "^\";")
  481. (if (eq (following-char) ?\;)
  482. (setq saved-point (point) loopvalue t)
  483. (forward-char 1)))
  484. (t
  485. (if (eq (following-char) ?')
  486. (forward-char 1))
  487. (skip-chars-forward "^';")
  488. (if (eq (following-char) ?\;)
  489. (setq saved-point (point) loopvalue t)
  490. (forward-char 1)))))
  491. loopvalue))
  492. (backward-char 1)
  493. (skip-chars-backward "^;")
  494. (setq saved-point (point) loopvalue nil)))
  495. ;; Now we are CERTAIN that we are outside comments and strings.
  496. ;; The job now is to search forward again towards the origin
  497. ;; skipping directives, comments and strings correctly,
  498. ;; so that we know what context we are in when we find the origin.
  499. (while (and
  500. (< (point) origin)
  501. (re-search-forward
  502. "\\<end\\>\\|!\\|\"\\|'\\|^%\\|\\<comment\\>" origin 'move))
  503. (cond
  504. ((memq (preceding-char) '(?d ?D))
  505. (setq return-value 2)
  506. (while (and (re-search-forward
  507. ";\\|\\<end\\>\\|\\<else\\>\\|\\<otherwise\\>\\|\\<when\\>\\|^%"
  508. origin 'move)
  509. ;; found another END?
  510. (or (memq (preceding-char) '(?d ?D))
  511. ;; if directive, skip line
  512. (and (eq (preceding-char) ?%)
  513. (beginning-of-line 2))
  514. ;; found other keyword, out of END comment
  515. (setq return-value nil))))
  516. (if (and (eq (char-syntax (preceding-char)) ?w)
  517. (eq (char-syntax (following-char)) ?w))
  518. (save-excursion
  519. (backward-word 1)
  520. (if (looking-at "end\\>\\|else\\>\\|otherwise\\>\\|when\\>")
  521. (setq return-value nil)))))
  522. ((memq (preceding-char) '(?! ?t ?T))
  523. ; skip comment
  524. (setq return-value 0)
  525. (skip-chars-forward "^%;" origin)
  526. (while (and return-value (< (point) origin))
  527. (if (eq (following-char) ?\;)
  528. (setq return-value nil)
  529. (if (bolp)
  530. (beginning-of-line 2) ; skip directive inside comment
  531. (forward-char 1)) ; or single '%'
  532. (skip-chars-forward "^%;" origin))))
  533. ((eq (preceding-char) ?\")
  534. (if (not (search-forward "\"" origin 'move))
  535. (setq return-value 3)))
  536. ((eq (preceding-char) ?\')
  537. (if (or (eq (point) origin) (eobp))
  538. (setq return-value 4)
  539. (forward-char 1)
  540. (if (not (search-forward "'" origin 'move))
  541. (setq return-value 4))))
  542. ;; compiler directive line - skip
  543. (t (beginning-of-line 2))))
  544. return-value)
  545. )))
  546. (defun simula-electric-label ()
  547. "If this is a label that starts the line, reindent the line."
  548. (interactive)
  549. (expand-abbrev)
  550. (insert ?:)
  551. (let ((origin (- (point-max) (point)))
  552. (case-fold-search t)
  553. ;; don't mix a label with an assignment operator := :-
  554. ;; therefore take a peek at next typed character...
  555. (next-char (read-event)))
  556. (unwind-protect
  557. (setq unread-command-events (append unread-command-events
  558. (list next-char)))
  559. ;; Problem: find out if character just read is a command char
  560. ;; that would insert something after ':' making it a label.
  561. ;; At least \n, \r (and maybe \t) falls into this category.
  562. ;; This is a real crock, it depends on traditional keymap
  563. ;; bindings, that is, printing characters doing self-insert,
  564. ;; and no other command sequence inserting '-' or '='.
  565. ;; simula-electric-label can be easily fooled...
  566. (if (and (not (memq next-char '(?= ?-)))
  567. (or (memq next-char '(?\n ?\r))
  568. (and (eq next-char ?\t)
  569. simula-tab-always-indent)
  570. (not (memq (following-char) '(?= ?-))))
  571. (not (simula-context))
  572. ;; label?
  573. (progn
  574. (backward-char 1)
  575. (skip-chars-backward " \t\f")
  576. (skip-chars-backward "a-zA-Z0-9_")
  577. (if (looking-at "virtual\\>")
  578. nil
  579. (skip-chars-backward " \t\f")
  580. (bolp))))
  581. (let ((amount (simula-calculate-indent)))
  582. (delete-horizontal-space)
  583. (indent-to amount)))
  584. (goto-char (- (point-max) origin)))))
  585. (defun simula-backward-up-level (count)
  586. "Move backward up COUNT block levels.
  587. If COUNT is negative, move forward up block level instead."
  588. (interactive "p")
  589. (let ((origin (point))
  590. (case-fold-search t))
  591. (condition-case ()
  592. (if (> count 0)
  593. (while (> count 0)
  594. (re-search-backward "\\<begin\\>\\|\\<end\\>")
  595. (if (not (simula-context))
  596. (setq count (if (memq (following-char) '(?b ?B))
  597. (1- count)
  598. (1+ count)))))
  599. (while (< count 0)
  600. (re-search-forward "\\<begin\\>\\|\\<end\\>")
  601. (backward-word 1)
  602. (if (not (simula-context))
  603. (setq count (if (memq (following-char) '(?e ?E))
  604. (1+ count)
  605. (1- count))))
  606. (backward-word -1)))
  607. ;; If block level not found, jump back to origin and signal an error
  608. (error (progn
  609. (goto-char origin)
  610. (error "No higher block level")))
  611. (quit (progn
  612. (goto-char origin)
  613. (signal 'quit nil))))))
  614. (defun simula-forward-down-level (count)
  615. "Move forward down COUNT block levels.
  616. If COUNT is negative, move backward down block level instead."
  617. (interactive "p")
  618. ;; When we search for a deeper block level, we must never
  619. ;; get out of the block where we started -> count >= start-count
  620. (let ((start-count count)
  621. (origin (point))
  622. (case-fold-search t))
  623. (condition-case ()
  624. (if (< count 0)
  625. (while (< count 0)
  626. (re-search-backward "\\<begin\\>\\|\\<end\\>")
  627. (if (not (simula-context))
  628. (setq count (if (memq (following-char) '(?e ?E))
  629. (1+ count)
  630. (1- count))))
  631. (if (< count start-count) (signal 'error nil)))
  632. (while (> count 0)
  633. (re-search-forward "\\<begin\\>\\|\\<end\\>")
  634. (backward-word 1)
  635. (if (not (simula-context))
  636. (setq count (if (memq (following-char) '(?b ?B))
  637. (1- count)
  638. (1+ count))))
  639. (backward-word -1)
  640. ;; deeper level has to be found within starting block
  641. (if (> count start-count) (signal 'error nil))))
  642. ;; If block level not found, jump back to origin and signal an error
  643. (error (progn
  644. (goto-char origin)
  645. (error "No containing block level")))
  646. (quit (progn
  647. (goto-char origin)
  648. (signal 'quit nil))))))
  649. (defun simula-previous-statement (count)
  650. "Move backward COUNT statements.
  651. If COUNT is negative, move forward instead."
  652. (interactive "p")
  653. (if (< count 0)
  654. (simula-next-statement (- count))
  655. (let (status
  656. (case-fold-search t)
  657. (origin (point)))
  658. (condition-case ()
  659. ;;
  660. (progn
  661. (simula-skip-comment-backward)
  662. (if (memq (preceding-char) '(?n ?N))
  663. (progn
  664. (backward-word 1)
  665. (if (not (looking-at "\\<begin\\>"))
  666. (backward-word -1)))
  667. (if (eq (preceding-char) ?\;)
  668. (backward-char 1))
  669. )
  670. (while (and (natnump (setq count (1- count)))
  671. (setq status (simula-search-backward
  672. ";\\|\\<begin\\>" nil 'move))))
  673. (if status
  674. (progn
  675. (if (eq (following-char) ?\;)
  676. (forward-char 1)
  677. (backward-word -1))))
  678. (simula-skip-comment-forward))
  679. (error (progn (goto-char origin)
  680. (error "Incomplete statement (too many ENDs)")))
  681. (quit (progn (goto-char origin) (signal 'quit nil)))))))
  682. (defun simula-next-statement (count)
  683. "Move forward COUNT statements.
  684. If COUNT is negative, move backward instead."
  685. (interactive "p")
  686. (if (< count 0)
  687. (simula-previous-statement (- count))
  688. (let (status
  689. (case-fold-search t)
  690. (origin (point)))
  691. (condition-case ()
  692. (progn
  693. (simula-skip-comment-forward)
  694. (if (looking-at "\\<end\\>") (forward-word 1))
  695. (while (and (natnump (setq count (1- count)))
  696. (setq status (simula-search-forward
  697. ";\\|\\<end\\>" (point-max) 'move))))
  698. (if (and status (/= (preceding-char) ?\;))
  699. (progn
  700. (backward-word 1)
  701. (simula-skip-comment-backward))))
  702. (error (progn (goto-char origin)
  703. (error "Incomplete statement (too few ENDs)")))
  704. (quit (progn (goto-char origin) (signal 'quit nil)))))))
  705. (defun simula-skip-comment-backward (&optional stop-at-end)
  706. "Search towards bob to find first char that is outside a comment."
  707. (interactive)
  708. (catch 'simula-out
  709. (let (context)
  710. (while t
  711. (skip-chars-backward " \t\n\f")
  712. (if (eq (preceding-char) ?\;)
  713. (save-excursion
  714. (backward-char 1)
  715. (setq context (simula-context))
  716. (if (and stop-at-end (eq context 2))
  717. (setq context nil)))
  718. (setq context (simula-context)))
  719. (cond
  720. ((memq context '(nil 3 4))
  721. ;; check to see if we found a label
  722. (if (and (eq (preceding-char) ?:)
  723. (not (memq (following-char) '(?- ?=)))
  724. (save-excursion
  725. (skip-chars-backward ": \t\fa-zA-Z0-9_")
  726. (not (looking-at "virtual\\>"))))
  727. (skip-chars-backward ": \t\fa-zA-Z0-9_")
  728. (throw 'simula-out nil)))
  729. ((eq context 0)
  730. ;; since we are inside a comment, it must start somewhere!
  731. (while (and (re-search-backward "!\\|\\<comment\\>")
  732. (memq (simula-context) '(0 1)))))
  733. ((eq context 1)
  734. (beginning-of-line)
  735. (if (bobp)
  736. (throw 'simula-out nil)
  737. (backward-char)))
  738. ((eq context 2)
  739. ;; an END-comment must belong to an END
  740. (re-search-backward "\\<end\\>")
  741. (forward-word 1)
  742. (throw 'simula-out nil))
  743. ;; should be impossible to get here..
  744. )))))
  745. (defun simula-skip-comment-forward ()
  746. "Search towards eob to find first char that is outside a comment."
  747. ;; this function assumes we start with point .outside a comment
  748. (interactive)
  749. (catch 'simula-out
  750. (while t
  751. (skip-chars-forward " \t\n\f")
  752. ;; BUG: the following (0 2) branches don't take into account intermixing
  753. ;; directive lines
  754. (cond
  755. ((looking-at "!\\|\\<comment\\>")
  756. (search-forward ";" nil 'move))
  757. ((and (bolp) (eq (following-char) ?%))
  758. (beginning-of-line 2))
  759. ((and (looking-at "[a-z0-9_]*[ \t\f]*:[^-=]")
  760. (not (looking-at "virtual\\>")))
  761. (skip-chars-forward "a-zA-Z0-9_ \t\f:"))
  762. (t
  763. (throw 'simula-out t))))))
  764. (defun simula-forward-up-level ()
  765. (let ((continue-loop t)
  766. (origin (point))
  767. (case-fold-search t)
  768. return-value
  769. temp)
  770. (while continue-loop
  771. (if (re-search-backward "\\<begin\\>\\|\\<end\\>" (point-min) 'move)
  772. (setq temp (simula-context)
  773. return-value (and (memq (preceding-char) '(?d ?D))
  774. (memq temp '(nil 2)))
  775. continue-loop (and (not return-value)
  776. (simula-forward-up-level)))
  777. (setq continue-loop nil)))
  778. (if return-value
  779. t
  780. (goto-char origin)
  781. nil)))
  782. (defun simula-calculate-indent ()
  783. (save-excursion
  784. (let ((where (simula-context))
  785. (origin (point))
  786. (indent 0)
  787. continued
  788. start-line
  789. temp
  790. found-end
  791. prev-cont)
  792. (cond
  793. ((eq where 0)
  794. ;;
  795. ;; Comment.
  796. ;; If comment started on previous non-blank line, indent to the
  797. ;; column where the comment started, else indent as that line.
  798. ;;
  799. (skip-chars-backward " \t\n\f")
  800. (while (and (not (bolp)) (eq (simula-context) 0))
  801. (re-search-backward "^\\|!\\|\\<comment\\>"))
  802. (skip-chars-forward " \t\n\f")
  803. (prog1
  804. (current-column)
  805. (goto-char origin)))
  806. ((eq where 1)
  807. ;;
  808. ;; Directive. Always 0.
  809. ;;
  810. 0)
  811. ;;
  812. ;; Detect missing string delimiters
  813. ;;
  814. ((eq where 3)
  815. (error "Inside string"))
  816. ((eq where 4)
  817. (error "Inside character constant"))
  818. ;;
  819. ;; check to see if inside ()'s
  820. ;;
  821. ((setq temp (simula-inside-parens))
  822. temp)
  823. ;;
  824. ;; Calculate non-comment indentation
  825. (t
  826. ;; first, find out if this line starts with something that needs
  827. ;; special indentation (END/IF/THEN/ELSE/WHEN/OTHERWISE or label)
  828. ;;
  829. (skip-chars-forward " \t\f")
  830. (cond
  831. ;;
  832. ;; END
  833. ;;
  834. ((looking-at "end\\>")
  835. (setq indent (- simula-indent-level)
  836. found-end t))
  837. ;;
  838. ;; IF/THEN/ELSE
  839. ;;
  840. ((looking-at "if\\>\\|then\\>\\|else\\>")
  841. ;; search for the *starting* IF
  842. (cond
  843. ((memq (following-char) '(?T ?t))
  844. (setq indent (car simula-if-indent)))
  845. ((memq (following-char) '(?E ?e))
  846. (setq indent (cdr simula-if-indent)))
  847. (t
  848. (forward-word 1)
  849. (setq indent 0)))
  850. (simula-find-if))
  851. ;;
  852. ;; WHEN/OTHERWISE
  853. ;;
  854. ((looking-at "when\\>\\|otherwise\\>")
  855. ;; search for corresponding INSPECT
  856. (if (memq (following-char) '(?W ?w))
  857. (setq indent (car simula-inspect-indent))
  858. (setq indent (cdr simula-inspect-indent)))
  859. (simula-find-inspect))
  860. ;;
  861. ;; label:
  862. ;;
  863. ((and (not (looking-at "virtual\\>"))
  864. (looking-at "[a-z0-9_]*[ \t\f]*:[^-=]"))
  865. (setq indent simula-label-offset)))
  866. ;; find line with non-comment text
  867. (simula-skip-comment-backward 'dont-skip-end)
  868. (if (and found-end
  869. (not (eq (preceding-char) ?\;))
  870. (if (memq (preceding-char) '(?N ?n))
  871. (save-excursion
  872. (backward-word 1)
  873. (not (looking-at "begin\\>")))
  874. t))
  875. (progn
  876. (simula-previous-statement 1)
  877. (simula-skip-comment-backward)))
  878. (setq start-line
  879. (line-beginning-position)
  880. ;; - perhaps this is a continued statement
  881. continued
  882. (save-excursion
  883. (and (not (bobp))
  884. ;; (not found-end)
  885. (if (eq (char-syntax (preceding-char)) ?w)
  886. (progn
  887. (backward-word 1)
  888. (not (looking-at
  889. "begin\\|then\\|else\\|when\\|otherwise\\|do"
  890. )))
  891. (not (memq (preceding-char) '(?: ?\;)))))))
  892. ;;
  893. ;; MAIN calculation loop - count BEGIN/DO etc.
  894. ;;
  895. (while (not (bolp))
  896. (if (re-search-backward
  897. ";\\|\\<\\(begin\\|end\\|if\\|else\\|then\\|when\\|otherwise\\|do\\)\\>"
  898. start-line 'move)
  899. (if (simula-context)
  900. ();; found something in a comment/string - ignore
  901. (setq temp (following-char))
  902. (cond
  903. ((eq temp ?\;)
  904. (simula-previous-statement 1))
  905. ((looking-at "begin\\>")
  906. (setq indent (+ indent simula-indent-level)))
  907. ((looking-at "end\\>")
  908. (forward-word 1)
  909. (simula-previous-statement 1))
  910. ((looking-at "do\\>")
  911. (setq indent (+ indent simula-substatement-offset))
  912. (simula-find-do-match))
  913. ((looking-at "\\(if\\|then\\|else\\)\\>")
  914. (if (memq temp '(?I ?i))
  915. (forward-word 1)
  916. (setq indent (+ indent
  917. simula-substatement-offset
  918. (if (memq temp '(?T ?t))
  919. (car simula-if-indent)
  920. (cdr simula-if-indent)))))
  921. (simula-find-if))
  922. ((looking-at "\\<when\\>\\|\\<otherwise\\>")
  923. (setq indent (+ indent
  924. simula-substatement-offset
  925. (if (memq temp '(?W ?w))
  926. (car simula-if-indent)
  927. (cdr simula-if-indent))))
  928. (simula-find-inspect)))
  929. ;; found the start of a [sub]statement
  930. ;; add indentation for continued statement
  931. (if continued
  932. (setq indent
  933. (+ indent
  934. (if (listp simula-continued-statement-offset)
  935. (car simula-continued-statement-offset)
  936. simula-continued-statement-offset))))
  937. (setq start-line
  938. (line-beginning-position)
  939. continued nil))
  940. ;; search failed .. point is at beginning of line
  941. ;; determine if we should continue searching
  942. ;; (at or before comment or label)
  943. ;; temp = t means finished
  944. (setq temp
  945. (and (not (simula-context))
  946. (save-excursion
  947. (skip-chars-forward " \t\f")
  948. (or (looking-at "virtual")
  949. (not
  950. (looking-at
  951. "!\\|comment\\>\\|[a-z0-9_]*[ \t\f]*:[^-=]")))))
  952. prev-cont continued)
  953. ;; if we are finished, find current line's indentation
  954. (if temp
  955. (setq indent (+ indent (current-indentation))))
  956. ;; find next line with non-comment SIMULA text
  957. ;; maybe indent extra if statement continues
  958. (simula-skip-comment-backward)
  959. (setq continued
  960. (and (not (bobp))
  961. (if (eq (char-syntax (preceding-char)) ?w)
  962. (save-excursion
  963. (backward-word 1)
  964. (not (looking-at
  965. "begin\\|then\\|else\\|when\\|otherwise\\|do")))
  966. (not (memq (preceding-char) '(?: ?\;))))))
  967. ;; if we the state of the continued-variable
  968. ;; changed, add indentation for continued statement
  969. (if (or (and prev-cont (not continued))
  970. (and continued
  971. (listp simula-continued-statement-offset)))
  972. (setq indent
  973. (+ indent
  974. (if (listp simula-continued-statement-offset)
  975. (car simula-continued-statement-offset)
  976. simula-continued-statement-offset))))
  977. ;; while ends if point is at beginning of line at loop test
  978. (if (not temp)
  979. (setq start-line (line-beginning-position))
  980. (beginning-of-line))))
  981. ;;
  982. ;; return indentation
  983. ;;
  984. indent)))))
  985. (defun simula-find-if ()
  986. "Find starting IF of a IF-THEN[-ELSE[-IF-THEN...]] statement."
  987. (catch 'simula-out
  988. (while t
  989. (if (and (simula-search-backward "\\<if\\>\\|;\\|\\<begin\\>"nil t)
  990. (memq (following-char) '(?I ?i)))
  991. (save-excursion
  992. ;;
  993. ;; find out if this IF was really the start of the IF statement
  994. ;;
  995. (simula-skip-comment-backward)
  996. (if (and (eq (char-syntax (preceding-char)) ?w)
  997. (progn
  998. (backward-word 1)
  999. (looking-at "else\\>")))
  1000. ()
  1001. (throw 'simula-out t)))
  1002. (if (not (looking-at "\\<if\\>"))
  1003. (error "Missing IF or misplaced BEGIN or ';' (can't find IF)")
  1004. ;;
  1005. ;; we were at the starting IF in the first place..
  1006. ;;
  1007. (throw 'simula-out t))))))
  1008. (defun simula-find-inspect ()
  1009. "Find INSPECT matching WHEN or OTHERWISE."
  1010. (catch 'simula-out
  1011. (let ((level 0))
  1012. ;;
  1013. ;; INSPECTs can be nested, have to find the corresponding one
  1014. ;;
  1015. (while t
  1016. (if (and (simula-search-backward "\\<inspect\\>\\|\\<otherwise\\>\\|;"
  1017. nil t)
  1018. (/= (following-char) ?\;))
  1019. (if (memq (following-char) '(?O ?o))
  1020. (setq level (1+ level))
  1021. (if (zerop level)
  1022. (throw 'simula-out t)
  1023. (setq level (1- level))))
  1024. (error "Missing INSPECT or misplaced ';' (can't find INSPECT)"))))))
  1025. (defun simula-find-do-match ()
  1026. "Find keyword matching DO: FOR, WHILE, INSPECT or WHEN."
  1027. (while (and (re-search-backward
  1028. "\\<\\(do\\|for\\|while\\|inspect\\|when\\|end\\|begin\\)\\>\\|;"
  1029. nil 'move)
  1030. (simula-context)))
  1031. (if (and (looking-at "\\<\\(for\\|while\\|inspect\\|when\\)\\>")
  1032. (not (simula-context)))
  1033. () ;; found match
  1034. (error "No matching FOR, WHILE or INSPECT for DO, or misplaced ';'")))
  1035. (defun simula-inside-parens ()
  1036. "Return position after `(' on line if inside parentheses, nil otherwise."
  1037. (save-excursion
  1038. (let ((parlevel 0))
  1039. (catch 'simula-out
  1040. (while t
  1041. (if (re-search-backward "(\\|)\\|;" nil t)
  1042. (if (eq (simula-context) nil)
  1043. ;; found something - check it out
  1044. (cond
  1045. ((eq (following-char) ?\;)
  1046. (if (zerop parlevel)
  1047. (throw 'simula-out nil)
  1048. (error "Parenthesis mismatch or misplaced ';'")))
  1049. ((eq (following-char) ?\()
  1050. (if (zerop parlevel)
  1051. (throw 'simula-out (1+ (current-column)))
  1052. (setq parlevel (1- parlevel))))
  1053. (t (setq parlevel (1+ parlevel))))
  1054. );; nothing - inside comment or string
  1055. ;; search failed
  1056. (throw 'simula-out nil)))))))
  1057. (defun simula-goto-definition ()
  1058. "Goto point of definition of variable, procedure or class."
  1059. (interactive))
  1060. (defun simula-expand-stdproc ()
  1061. (if (or (not simula-abbrev-stdproc) (simula-context))
  1062. (unexpand-abbrev)
  1063. (cond
  1064. ((eq simula-abbrev-stdproc 'upcase) (upcase-word -1))
  1065. ((eq simula-abbrev-stdproc 'downcase) (downcase-word -1))
  1066. ((eq simula-abbrev-stdproc 'capitalize) (capitalize-word -1))
  1067. ((eq simula-abbrev-stdproc 'abbrev-table)
  1068. ;; If not in lowercase, expansions are always capitalized.
  1069. ;; We then want to replace with the exact expansion.
  1070. (if (equal (symbol-name last-abbrev) last-abbrev-text)
  1071. ()
  1072. (downcase-word -1)
  1073. (expand-abbrev))))))
  1074. (defun simula-expand-keyword ()
  1075. (if (or (not simula-abbrev-keyword) (simula-context))
  1076. (unexpand-abbrev)
  1077. (cond
  1078. ((eq simula-abbrev-keyword 'upcase) (upcase-word -1))
  1079. ((eq simula-abbrev-keyword 'downcase) (downcase-word -1))
  1080. ((eq simula-abbrev-keyword 'capitalize) (capitalize-word -1))
  1081. ((eq simula-abbrev-stdproc 'abbrev-table)
  1082. (if (equal (symbol-name last-abbrev) last-abbrev-text)
  1083. ()
  1084. (downcase-word -1)
  1085. (expand-abbrev))))))
  1086. (defun simula-electric-keyword ()
  1087. "Expand SIMULA keyword. If it starts the line, reindent."
  1088. ;; redisplay
  1089. (let ((show-char (eq this-command 'self-insert-command)))
  1090. ;; If the abbrev expansion results in reindentation, the user may have
  1091. ;; to wait some time before the character he typed is displayed
  1092. ;; (the char causing the expansion is inserted AFTER the hook function
  1093. ;; is called). This is annoying in case of normal characters.
  1094. ;; However, if the user pressed a key bound to newline, it is better
  1095. ;; to have the line inserted after the begin-end match.
  1096. (if show-char
  1097. (progn
  1098. (insert-char last-command-event 1)
  1099. (sit-for 0)
  1100. (backward-char 1)))
  1101. (if (let ((where (simula-context))
  1102. (case-fold-search t))
  1103. (if where
  1104. (if (and (eq where 2) (eq (char-syntax (preceding-char)) ?w))
  1105. (save-excursion
  1106. (backward-word 1)
  1107. (not (looking-at "end\\>"))))))
  1108. (unexpand-abbrev)
  1109. (cond
  1110. ((not simula-abbrev-keyword) (unexpand-abbrev))
  1111. ((eq simula-abbrev-keyword 'upcase) (upcase-word -1))
  1112. ((eq simula-abbrev-keyword 'downcase) (downcase-word -1))
  1113. ((eq simula-abbrev-keyword 'capitalize) (capitalize-word -1)))
  1114. (let ((pos (- (point-max) (point)))
  1115. (case-fold-search t))
  1116. (condition-case nil
  1117. (progn
  1118. ;; check if the expanded word is on the beginning of the line.
  1119. (if (and (eq (char-syntax (preceding-char)) ?w)
  1120. (progn
  1121. (backward-word 1)
  1122. (if (looking-at "end\\>")
  1123. (save-excursion
  1124. (simula-backward-up-level 1)
  1125. (if (pos-visible-in-window-p)
  1126. (sit-for 1)
  1127. (message "Matches %s"
  1128. (buffer-substring
  1129. (point)
  1130. (+ (point) (window-width)))))))
  1131. (skip-chars-backward " \t\f")
  1132. (bolp)))
  1133. (let ((indent (simula-calculate-indent)))
  1134. (if (eq indent (current-indentation))
  1135. ()
  1136. (delete-horizontal-space)
  1137. (indent-to indent)))
  1138. (skip-chars-forward " \t\f"))
  1139. ;; check for END - blow whistles and ring bells
  1140. (goto-char (- (point-max) pos))
  1141. (if show-char
  1142. (delete-char 1)))
  1143. (quit (goto-char (- (point-max) pos))))))))
  1144. (defun simula-search-backward (regexp &optional bound noerror)
  1145. "Search backward from point for regular expression REGEXP,
  1146. ignoring matches found inside SIMULA comments, string literals,
  1147. and BEGIN..END blocks.
  1148. Set point to the end of the occurrence found, and return point.
  1149. An optional second argument BOUND bounds the search, it is a buffer position.
  1150. The match found must not extend after that position. Optional third argument
  1151. NOERROR, if t, means if fail just return nil (no error).
  1152. If not nil and not t, move to limit of search and return nil."
  1153. (let ((comb-regexp (concat regexp "\\|\\<end\\>"))
  1154. (start-point (point))
  1155. context match)
  1156. (catch 'simula-backward
  1157. (while (re-search-backward comb-regexp bound 1)
  1158. ;; We have a match, check SIMULA context at match-beginning
  1159. ;; to see if we are outside comments etc.
  1160. ;; Set MATCH to t if we found a true match,
  1161. ;; set MATCH to 'BLOCK if we found a BEGIN..END block,
  1162. ;; else set MATCH to nil.
  1163. (save-match-data
  1164. (setq context (simula-context))
  1165. (cond
  1166. ((eq context nil)
  1167. (setq match (if (looking-at regexp) t 'BLOCK)))
  1168. ;; A comment-ending `;' is part of the comment, and shouldn't match.
  1169. ;; ((eq context 0)
  1170. ;; (setq match (if (eq (following-char) ?\;) t nil)))
  1171. ((eq context 2)
  1172. (setq match (if (and (looking-at regexp)
  1173. (looking-at ";\\|\\<end\\>\\|\\<else\\>\\|\\<otherwise\\>\\|\\<when\\>"))
  1174. t
  1175. (if (looking-at "\\<end\\>") 'BLOCK nil))))
  1176. (t (setq match nil))))
  1177. ;; Exit if true match
  1178. (if (eq match t) (throw 'simula-backward (point)))
  1179. (if (eq match 'BLOCK)
  1180. ;; We found the END of a block
  1181. (let ((level 0))
  1182. (while (natnump level)
  1183. (if (re-search-backward "\\<begin\\>\\|\\<end\\>" bound 1)
  1184. (let ((context (simula-context)))
  1185. ;; We found a BEGIN -> decrease level count
  1186. (cond ((and (eq context nil)
  1187. (memq (following-char) '(?b ?B)))
  1188. (setq level (1- level)))
  1189. ;; END -> increase level count
  1190. ((and (memq context '(nil 2))
  1191. (memq (following-char) '(?e ?E)))
  1192. (setq level (1+ level)))))
  1193. ;; Block search failed. Action depends on noerror.
  1194. (if (or (not noerror) (eq noerror t))
  1195. (goto-char start-point))
  1196. (if (not noerror)
  1197. (signal 'search-failed (list regexp)))
  1198. (throw 'simula-backward nil))))))
  1199. ;; Search failed. Action depends on noerror.
  1200. (if (or (not noerror) (eq noerror t))
  1201. (goto-char start-point))
  1202. (if noerror
  1203. nil
  1204. (signal 'search-failed (list regexp))))))
  1205. (defun simula-search-forward (regexp &optional bound noerror)
  1206. "Search forward from point for regular expression REGEXP,
  1207. ignoring matches found inside SIMULA comments, string literals,
  1208. and BEGIN..END blocks.
  1209. Set point to the end of the occurrence found, and return point.
  1210. An optional second argument BOUND bounds the search, it is a buffer position.
  1211. The match found must not extend after that position. Optional third argument
  1212. NOERROR, if t, means if fail just return nil (no error).
  1213. If not nil and not t, move to limit of search and return nil."
  1214. (let ((comb-regexp (concat regexp "\\|\\<begin\\>"))
  1215. (start-point (point))
  1216. context match)
  1217. (catch 'simula-forward
  1218. (while (re-search-forward comb-regexp bound 1)
  1219. ;; We have a match, check SIMULA context at match-beginning
  1220. ;; to see if we are outside comments.
  1221. ;; Set MATCH to t if we found a true match,
  1222. ;; set MATCH to 'BLOCK if we found a BEGIN..END block,
  1223. ;; else set MATCH to nil.
  1224. (save-match-data
  1225. (save-excursion
  1226. (goto-char (match-beginning 0))
  1227. (setq context (simula-context))
  1228. (cond
  1229. ((not context)
  1230. (setq match (if (looking-at regexp) t 'BLOCK)))
  1231. ;; Comment-ending `;' is part of the comment, and shouldn't match.
  1232. ;; ((eq context 0)
  1233. ;; (setq match (if (eq (following-char) ?\;) t nil)))
  1234. ((eq context 2)
  1235. (setq match (if (and (looking-at regexp)
  1236. (looking-at ";\\|\\<end\\>\\|\\<else\\>\\|\\<otherwise\\>\\|\\<when\\>")) t nil)))
  1237. (t (setq match nil)))))
  1238. ;; Exit if true match
  1239. (if (eq match t) (throw 'simula-forward (point)))
  1240. (if (eq match 'BLOCK)
  1241. ;; We found the BEGINning of a block
  1242. (let ((level 0))
  1243. (while (natnump level)
  1244. (if (re-search-forward "\\<begin\\>\\|\\<end\\>" bound 1)
  1245. (let ((context (simula-context)))
  1246. ;; We found a BEGIN -> increase level count
  1247. (cond ((eq context nil) (setq level (1+ level)))
  1248. ;; END -> decrease level count
  1249. ((and (eq context 2)
  1250. ;; Don't match BEGIN inside END comment
  1251. (memq (preceding-char) '(?d ?D)))
  1252. (setq level (1- level)))))
  1253. ;; Block search failed. Action depends on noerror.
  1254. (if (or (not noerror) (eq noerror t))
  1255. (goto-char start-point))
  1256. (if (not noerror)
  1257. (signal 'search-failed (list regexp)))
  1258. (throw 'simula-forward nil))))))
  1259. ;; Search failed. Action depends on noerror.
  1260. (if (or (not noerror) (eq noerror t))
  1261. (goto-char start-point))
  1262. (if noerror
  1263. nil
  1264. (signal 'search-failed (list regexp))))))
  1265. (defun simula-install-standard-abbrevs ()
  1266. "Define Simula keywords, procedures and classes in local abbrev table."
  1267. ;; procedure and class names are as of the SIMULA 87 standard.
  1268. (interactive)
  1269. (dolist (args
  1270. '(("abs" "Abs" simula-expand-stdproc)
  1271. ("accum" "Accum" simula-expand-stdproc)
  1272. ("activate" "ACTIVATE" simula-expand-keyword)
  1273. ("addepsilon" "AddEpsilon" simula-expand-stdproc)
  1274. ("after" "AFTER" simula-expand-keyword)
  1275. ("and" "AND" simula-expand-keyword)
  1276. ("arccos" "ArcCos" simula-expand-stdproc)
  1277. ("arcsin" "ArcSin" simula-expand-stdproc)
  1278. ("arctan" "ArcTan" simula-expand-stdproc)
  1279. ("arctan2" "ArcTan2" simula-expand-stdproc)
  1280. ("array" "ARRAY" simula-expand-keyword)
  1281. ("at" "AT" simula-expand-keyword)
  1282. ("before" "BEFORE" simula-expand-keyword)
  1283. ("begin" "BEGIN" simula-expand-keyword)
  1284. ("blanks" "Blanks" simula-expand-stdproc)
  1285. ("boolean" "BOOLEAN" simula-expand-keyword)
  1286. ("breakoutimage" "BreakOutImage" simula-expand-stdproc)
  1287. ("bytefile" "ByteFile" simula-expand-stdproc)
  1288. ("call" "Call" simula-expand-stdproc)
  1289. ("cancel" "Cancel" simula-expand-stdproc)
  1290. ("cardinal" "Cardinal" simula-expand-stdproc)
  1291. ("char" "Char" simula-expand-stdproc)
  1292. ("character" "CHARACTER" simula-expand-keyword)
  1293. ("checkpoint" "CheckPoint" simula-expand-stdproc)
  1294. ("class" "CLASS" simula-expand-keyword)
  1295. ("clear" "Clear" simula-expand-stdproc)
  1296. ("clocktime" "ClockTime" simula-expand-stdproc)
  1297. ("close" "Close" simula-expand-stdproc)
  1298. ("comment" "COMMENT" simula-expand-keyword)
  1299. ("constant" "Constant" simula-expand-stdproc)
  1300. ("copy" "Copy" simula-expand-stdproc)
  1301. ("cos" "Cos" simula-expand-stdproc)
  1302. ("cosh" "CosH" simula-expand-stdproc)
  1303. ("cotan" "CoTan" simula-expand-stdproc)
  1304. ("cputime" "CpuTime" simula-expand-stdproc)
  1305. ("current" "Current" simula-expand-stdproc)
  1306. ("datetime" "DateTime" simula-expand-stdproc)
  1307. ("decimalmark" "DecimalMark" simula-expand-stdproc)
  1308. ("delay" "DELAY" simula-expand-keyword)
  1309. ("deleteimage" "DeleteImage" simula-expand-stdproc)
  1310. ("detach" "Detach" simula-expand-stdproc)
  1311. ("digit" "Digit" simula-expand-stdproc)
  1312. ("directbytefile" "DirectByteFile" simula-expand-stdproc)
  1313. ("directfile" "DirectFile" simula-expand-stdproc)
  1314. ("discrete" "Discrete" simula-expand-stdproc)
  1315. ("do" "DO" simula-expand-keyword)
  1316. ("downcase" "Downcase" simula-expand-stdproc)
  1317. ("draw" "Draw" simula-expand-stdproc)
  1318. ("eject" "Eject" simula-expand-stdproc)
  1319. ("else" "ELSE" simula-electric-keyword)
  1320. ("empty" "Empty" simula-expand-stdproc)
  1321. ("end" "END" simula-electric-keyword)
  1322. ("endfile" "Endfile" simula-expand-stdproc)
  1323. ("entier" "Entier" simula-expand-stdproc)
  1324. ("eq" "EQ" simula-expand-keyword)
  1325. ("eqv" "EQV" simula-expand-keyword)
  1326. ("erlang" "Erlang" simula-expand-stdproc)
  1327. ("error" "Error" simula-expand-stdproc)
  1328. ("evtime" "EvTime" simula-expand-stdproc)
  1329. ("exp" "Exp" simula-expand-stdproc)
  1330. ("external" "EXTERNAL" simula-expand-keyword)
  1331. ("false" "FALSE" simula-expand-keyword)
  1332. ("field" "Field" simula-expand-stdproc)
  1333. ("file" "File" simula-expand-stdproc)
  1334. ("first" "First" simula-expand-stdproc)
  1335. ("follow" "Follow" simula-expand-stdproc)
  1336. ("for" "FOR" simula-expand-keyword)
  1337. ("ge" "GE" simula-expand-keyword)
  1338. ("getchar" "GetChar" simula-expand-stdproc)
  1339. ("getfrac" "GetFrac" simula-expand-stdproc)
  1340. ("getint" "GetInt" simula-expand-stdproc)
  1341. ("getreal" "GetReal" simula-expand-stdproc)
  1342. ("go" "GO" simula-expand-keyword)
  1343. ("goto" "GOTO" simula-expand-keyword)
  1344. ("gt" "GT" simula-expand-keyword)
  1345. ("head" "Head" simula-expand-stdproc)
  1346. ("hidden" "HIDDEN" simula-expand-keyword)
  1347. ("histd" "HistD" simula-expand-stdproc)
  1348. ("histo" "Histo" simula-expand-stdproc)
  1349. ("hold" "Hold" simula-expand-stdproc)
  1350. ("idle" "Idle" simula-expand-stdproc)
  1351. ("if" "IF" simula-expand-keyword)
  1352. ("image" "Image" simula-expand-stdproc)
  1353. ("imagefile" "ImageFile" simula-expand-stdproc)
  1354. ("imp" "IMP" simula-expand-keyword)
  1355. ("in" "IN" simula-expand-keyword)
  1356. ("inbyte" "InByte" simula-expand-stdproc)
  1357. ("inbytefile" "InByteFile" simula-expand-stdproc)
  1358. ("inchar" "InChar" simula-expand-stdproc)
  1359. ("infile" "InFile" simula-expand-stdproc)
  1360. ("infrac" "InFrac" simula-expand-stdproc)
  1361. ("inimage" "InImage" simula-expand-stdproc)
  1362. ("inint" "InInt" simula-expand-stdproc)
  1363. ("inner" "INNER" simula-expand-keyword)
  1364. ("inreal" "InReal" simula-expand-stdproc)
  1365. ("inrecord" "InRecord" simula-expand-stdproc)
  1366. ("inspect" "INSPECT" simula-expand-keyword)
  1367. ("integer" "INTEGER" simula-expand-keyword)
  1368. ("intext" "InText" simula-expand-stdproc)
  1369. ("into" "Into" simula-expand-stdproc)
  1370. ("is" "IS" simula-expand-keyword)
  1371. ("isochar" "ISOChar" simula-expand-stdproc)
  1372. ("isopen" "IsOpen" simula-expand-stdproc)
  1373. ("isorank" "ISORank" simula-expand-stdproc)
  1374. ("label" "LABEL" simula-expand-keyword)
  1375. ("last" "Last" simula-expand-stdproc)
  1376. ("lastitem" "LastItem" simula-expand-stdproc)
  1377. ("lastloc" "LastLoc" simula-expand-stdproc)
  1378. ("le" "LE" simula-expand-keyword)
  1379. ("length" "Length" simula-expand-stdproc)
  1380. ("letter" "Letter" simula-expand-stdproc)
  1381. ("line" "Line" simula-expand-stdproc)
  1382. ("linear" "Linear" simula-expand-stdproc)
  1383. ("linesperpage" "LinesPerPage" simula-expand-stdproc)
  1384. ("link" "Link" simula-expand-stdproc)
  1385. ("linkage" "Linkage" simula-expand-stdproc)
  1386. ("ln" "Ln" simula-expand-stdproc)
  1387. ("locate" "Locate" simula-expand-stdproc)
  1388. ("location" "Location" simula-expand-stdproc)
  1389. ("lock" "Lock" simula-expand-stdproc)
  1390. ("locked" "Locked" simula-expand-stdproc)
  1391. ("log10" "Log10" simula-expand-stdproc)
  1392. ("long" "LONG" simula-expand-keyword)
  1393. ("lowcase" "LowCase" simula-expand-stdproc)
  1394. ("lowerbound" "LowerBound" simula-expand-stdproc)
  1395. ("lowten" "LowTen" simula-expand-stdproc)
  1396. ("lt" "LT" simula-expand-keyword)
  1397. ("main" "Main" simula-expand-stdproc)
  1398. ("max" "Max" simula-expand-stdproc)
  1399. ("maxint" "MaxInt" simula-expand-stdproc)
  1400. ("maxlongreal" "MaxLongReal" simula-expand-stdproc)
  1401. ("maxloc" "MaxLoc" simula-expand-stdproc)
  1402. ("maxrank" "MaxRank" simula-expand-stdproc)
  1403. ("maxreal" "MaxReal" simula-expand-stdproc)
  1404. ("min" "Min" simula-expand-stdproc)
  1405. ("minint" "MinInt" simula-expand-stdproc)
  1406. ("minlongreal" "MinLongReal" simula-expand-stdproc)
  1407. ("minrank" "MinRank" simula-expand-stdproc)
  1408. ("minreal" "MinReal" simula-expand-stdproc)
  1409. ("mod" "Mod" simula-expand-stdproc)
  1410. ("more" "More" simula-expand-stdproc)
  1411. ("name" "NAME" simula-expand-keyword)
  1412. ("ne" "NE" simula-expand-keyword)
  1413. ("negexp" "NegExp" simula-expand-stdproc)
  1414. ("new" "NEW" simula-expand-keyword)
  1415. ("nextev" "NextEv" simula-expand-stdproc)
  1416. ("none" "NONE" simula-expand-keyword)
  1417. ("normal" "Normal" simula-expand-stdproc)
  1418. ("not" "NOT" simula-expand-keyword)
  1419. ("notext" "NOTEXT" simula-expand-keyword)
  1420. ("open" "Open" simula-expand-stdproc)
  1421. ("or" "OR" simula-expand-keyword)
  1422. ("otherwise" "OTHERWISE" simula-electric-keyword)
  1423. ("out" "Out" simula-expand-stdproc)
  1424. ("outbyte" "OutByte" simula-expand-stdproc)
  1425. ("outbytefile" "OutByteFile" simula-expand-stdproc)
  1426. ("outchar" "OutChar" simula-expand-stdproc)
  1427. ("outfile" "OutFile" simula-expand-stdproc)
  1428. ("outfix" "OutFix" simula-expand-stdproc)
  1429. ("outfrac" "OutFrac" simula-expand-stdproc)
  1430. ("outimage" "OutImage" simula-expand-stdproc)
  1431. ("outint" "OutInt" simula-expand-stdproc)
  1432. ("outreal" "OutReal" simula-expand-stdproc)
  1433. ("outrecord" "OutRecord" simula-expand-stdproc)
  1434. ("outtext" "OutText" simula-expand-stdproc)
  1435. ("page" "Page" simula-expand-stdproc)
  1436. ("passivate" "Passivate" simula-expand-stdproc)
  1437. ("poisson" "Poisson" simula-expand-stdproc)
  1438. ("pos" "Pos" simula-expand-stdproc)
  1439. ("precede" "Precede" simula-expand-stdproc)
  1440. ("pred" "Pred" simula-expand-stdproc)
  1441. ("prev" "Prev" simula-expand-stdproc)
  1442. ("printfile" "PrintFile" simula-expand-stdproc)
  1443. ("prior" "PRIOR" simula-expand-keyword)
  1444. ("procedure" "PROCEDURE" simula-expand-keyword)
  1445. ("process" "Process" simula-expand-stdproc)
  1446. ("protected" "PROTECTED" simula-expand-keyword)
  1447. ("putchar" "PutChar" simula-expand-stdproc)
  1448. ("putfix" "PutFix" simula-expand-stdproc)
  1449. ("putfrac" "PutFrac" simula-expand-stdproc)
  1450. ("putint" "PutInt" simula-expand-stdproc)
  1451. ("putreal" "PutReal" simula-expand-stdproc)
  1452. ("qua" "QUA" simula-expand-keyword)
  1453. ("randint" "RandInt" simula-expand-stdproc)
  1454. ("rank" "Rank" simula-expand-stdproc)
  1455. ("reactivate" "REACTIVATE" simula-expand-keyword)
  1456. ("real" "REAL" simula-expand-keyword)
  1457. ("ref" "REF" simula-expand-keyword)
  1458. ("resume" "Resume" simula-expand-stdproc)
  1459. ("setaccess" "SetAccess" simula-expand-stdproc)
  1460. ("setpos" "SetPos" simula-expand-stdproc)
  1461. ("short" "SHORT" simula-expand-keyword)
  1462. ("sign" "Sign" simula-expand-stdproc)
  1463. ("simset" "SimSet" simula-expand-stdproc)
  1464. ("simulaid" "SimulaId" simula-expand-stdproc)
  1465. ("simulation" "Simulation" simula-expand-stdproc)
  1466. ("sin" "Sin" simula-expand-stdproc)
  1467. ("sinh" "SinH" simula-expand-stdproc)
  1468. ("sourceline" "SourceLine" simula-expand-stdproc)
  1469. ("spacing" "Spacing" simula-expand-stdproc)
  1470. ("sqrt" "Sqrt" simula-expand-stdproc)
  1471. ("start" "Start" simula-expand-stdproc)
  1472. ("step" "STEP" simula-expand-keyword)
  1473. ("strip" "Strip" simula-expand-stdproc)
  1474. ("sub" "Sub" simula-expand-stdproc)
  1475. ("subepsilon" "SubEpsilon" simula-expand-stdproc)
  1476. ("suc" "Suc" simula-expand-stdproc)
  1477. ("switch" "SWITCH" simula-expand-keyword)
  1478. ("sysin" "SysIn" simula-expand-stdproc)
  1479. ("sysout" "SysOut" simula-expand-stdproc)
  1480. ("tan" "Tan" simula-expand-stdproc)
  1481. ("tanh" "TanH" simula-expand-stdproc)
  1482. ("terminate_program" "Terminate_Program" simula-expand-stdproc)
  1483. ("terminated" "Terminated" simula-expand-stdproc)
  1484. ("text" "TEXT" simula-expand-keyword)
  1485. ("then" "THEN" simula-electric-keyword)
  1486. ("this" "THIS" simula-expand-keyword)
  1487. ("time" "Time" simula-expand-stdproc)
  1488. ("to" "TO" simula-expand-keyword)
  1489. ("true" "TRUE" simula-expand-keyword)
  1490. ("uniform" "Uniform" simula-expand-stdproc)
  1491. ("unlock" "Unlock" simula-expand-stdproc)
  1492. ("until" "UNTIL" simula-expand-keyword)
  1493. ("upcase" "Upcase" simula-expand-stdproc)
  1494. ("upperbound" "UpperBound" simula-expand-stdproc)
  1495. ("value" "VALUE" simula-expand-keyword)
  1496. ("virtual" "VIRTUAL" simula-expand-keyword)
  1497. ("wait" "Wait" simula-expand-stdproc)
  1498. ("when" "WHEN" simula-electric-keyword)
  1499. ("while" "WHILE" simula-expand-keyword)))
  1500. (define-abbrev simula-mode-abbrev-table
  1501. (nth 0 args) (nth 1 args) (nth 2 args) nil 'system)))
  1502. (if simula-abbrev-file
  1503. (read-abbrev-file simula-abbrev-file))
  1504. (let (abbrevs-changed)
  1505. (simula-install-standard-abbrevs))
  1506. ;; Hilit mode support.
  1507. (when (fboundp 'hilit-set-mode-patterns)
  1508. (when (and (boundp 'hilit-patterns-alist)
  1509. (not (assoc 'simula-mode hilit-patterns-alist)))
  1510. (hilit-set-mode-patterns
  1511. 'simula-mode
  1512. '(
  1513. ("^%\\([ \t\f].*\\)?$" nil comment)
  1514. ("^%include\\>" nil include)
  1515. ("\"[^\"\n]*\"\\|'.'\\|'![0-9]+!'" nil string)
  1516. ("\\<\\(ACTIVATE\\|AFTER\\|AND\\|ARRAY\\|AT\\|BEFORE\\|BEGIN\\|BOOLEAN\\|CHARACTER\\|CLASS\\|DELAY\\|DO\\|ELSE\\|END\\|EQ\\|EQV\\|EXTERNAL\\|FALSE\\|FOR\\|GE\\|GO\\|GOTO\\|GT\\|HIDDEN\\|IF\\|IMP\\|IN\\|INNER\\|INSPECT\\|INTEGER\\|IS\\|LABEL\\|LE\\|LONG\\|LT\\|NAME\\|NE\\|NEW\\|NONE\\|NOT\\|NOTEXT\\|OR\\|OTHERWISE\\|PRIOR\\|PROCEDURE\\|PROTECTED\\|QUA\\|REACTIVATE\\|REAL\\|REF\\|SHORT\\|STEP\\|SWITCH\\|TEXT\\|THEN\\|THIS\\|TO\\|TRUE\\|UNTIL\\|VALUE\\|VIRTUAL\\|WHEN\\|WHILE\\)\\>" nil keyword)
  1517. ("!\\|\\<COMMENT\\>" ";" comment))
  1518. nil 'case-insensitive)))
  1519. ;; defuns for submitting bug reports
  1520. (defconst simula-mode-help-address "bug-gnu-emacs@gnu.org"
  1521. "Address accepting submission of `simula-mode' bug reports.")
  1522. (defun simula-submit-bug-report ()
  1523. "Submit via mail a bug report on `simula-mode'."
  1524. (interactive)
  1525. (and
  1526. (y-or-n-p "Do you want to submit a report on simula-mode? ")
  1527. (reporter-submit-bug-report
  1528. simula-mode-help-address
  1529. (concat "simula-mode from Emacs " emacs-version)
  1530. (list
  1531. ;; report only the vars that affect indentation
  1532. 'simula-indent-level
  1533. 'simula-substatement-offset
  1534. 'simula-continued-statement-offset
  1535. 'simula-label-offset
  1536. 'simula-if-indent
  1537. 'simula-inspect-indent
  1538. 'simula-electric-indent
  1539. 'simula-abbrev-keyword
  1540. 'simula-abbrev-stdproc
  1541. 'simula-abbrev-file
  1542. 'simula-tab-always-indent
  1543. ))))
  1544. (provide 'simula)
  1545. ;;; simula.el ends here