| 1 |
;From: Razvan Diaconescu <[email protected]> |
| 2 |
;Date: Wed, 24 Sep 97 04:14:00 GMT |
| 3 |
;Message-Id: <[email protected]> |
| 4 |
;To: [email protected], [email protected] |
| 5 |
;Subject: cafeobj-mode again |
| 6 |
;Content-Type: text |
| 7 |
;Content-Length: 63479 |
| 8 |
|
| 9 |
;Dear Toshimi and Dorel, |
| 10 |
|
| 11 |
;If you are fed up it my messages on the cafeobj-mode topic please |
| 12 |
;ignore this. |
| 13 |
|
| 14 |
;I just fixed a couple of small bugs in the kb7 part of the |
| 15 |
;cfeobj-mode. Now, if you move between fields with TAB you get |
| 16 |
;automatic pluralisation for var/op/bop (when necessary, of course) and |
| 17 |
;a warning message in the minibuffer if for an operation the number of |
| 18 |
;underscores doesnt agree with the number of sorts in the arity. |
| 19 |
|
| 20 |
;Remember also that my menu works only with FSF version of emacs. |
| 21 |
|
| 22 |
;Best regards, |
| 23 |
;Razvan |
| 24 |
;-------------------------cut here----------- |
| 25 |
;;; cafeobj-mode.el --- CafeOBJ code editing and Interaction with |
| 26 |
;;; CafeOBJ interpreter. |
| 27 |
;;; Copyleft: verbatim copies of this file may be freely redistributed. |
| 28 |
;;; This file is distributed `as is', without warranties of any kind. |
| 29 |
;;; |
| 30 |
;;; Toshimi Sawada <[email protected]> |
| 31 |
;;; |
| 32 |
;;; $Id: cafeobj-mode-new.el,v 1.1 2003-12-13 12:43:03 sawada Exp $ |
| 33 |
;;; ++ KB7 style commands for CafeOBJ constructs by Razvan Diaconescu |
| 34 |
;;; Keywords: cafeobj chaos languages processes tools |
| 35 |
;;; |
| 36 |
;;; BRIEF DESCRIPTION: |
| 37 |
;;; CafeOBJ-mode supports formatting CafeOBJ source codes and sending of |
| 38 |
;;; declarations/regions/files to a CafeOBJ interpreter. An interpreter |
| 39 |
;;; (see variable `cafeobj-default-application') will be started if you try |
| 40 |
;;; to send some code and none is running. You can use the process-buffer |
| 41 |
;;; (named after the application you chose) as if it were an |
| 42 |
;;; interactive shell. See the documentation for `comint.el' for |
| 43 |
;;; details. |
| 44 |
;;; *NOTE* : This mode supports Chaos with CafeOBJ syntax only. |
| 45 |
|
| 46 |
;;; ====== DESCRIPTION ========================================================= |
| 47 |
;;; |
| 48 |
;;; USAGE: |
| 49 |
;;; The following statements, placed in your .emacs file or |
| 50 |
;;; site-init.el, will cause this file to be autoloaded, and |
| 51 |
;;; cafeobj-mode invoked, when visiting .mod files (assuming this file is |
| 52 |
;;; in your load-path): |
| 53 |
;;; |
| 54 |
;;; (autoload 'cafeobj-mode "cafeobj-mode" "CafeOBJ mode." t) |
| 55 |
;;; (setq auto-mode-alist |
| 56 |
;;; (cons '("\\.mod$" . cafeobj-mode) auto-mode-alist)) |
| 57 |
;;; |
| 58 |
;;; and, also the following is handy for running CafeOBJ interpreter: |
| 59 |
;;; |
| 60 |
;;; (autoload 'cafeobj "cafeobj-mode" "Run CafeOBJ interpreter." t) |
| 61 |
;;; |
| 62 |
;;; If you want font-lock support for CafeOBJ source code (a.k.a. syntax |
| 63 |
;;; coloring, highlighting), add this to your .emacs file: |
| 64 |
;;; (cond ((string-match "XEmacs\\Lucid" emacs-version) |
| 65 |
;;; ;; XEmacs |
| 66 |
;;; (add-hook 'cafeobj-mode-hook 'turn-on-font-lock)) |
| 67 |
;;; (t ;; FSF19.XX, assumes the version better than 19.28.. |
| 68 |
;;; (add-hook 'cafeobj-mode-hook (function |
| 69 |
;;; (lambda () (font-lock-mode 1)))))) |
| 70 |
;;; |
| 71 |
;;; Notes on FONT-LOCK: |
| 72 |
;;; You better be sure you're version of Emacs supports |
| 73 |
;;; font-lock-mode! As of this writing, the latest Emacs and XEmacs |
| 74 |
;;; 19's do. This file is known to be run on Emacs19.28(Mule 2.3), and |
| 75 |
;;; XEmacs(20.02). |
| 76 |
;;; |
| 77 |
;;; KEY BINDINGS: |
| 78 |
;;; To see all the keybindings for folding mode, look at `cafeobj-setup-keymap' |
| 79 |
;;; or start `cafeobj-mode' and type `\C-h m'. |
| 80 |
;;; The keybindings are defined with prefixed by 'cafeobj-prefix-key', |
| 81 |
;;; the default for `cafeobj-prefix-key' is `\C-c', which is the conventional |
| 82 |
;;; prefix for major-mode commands. |
| 83 |
;;; You can customise the keybindings either by setting `choas-prefix-key' |
| 84 |
;;; or by putting the following in your .emacs |
| 85 |
;;; (setq cafeobj-mode-map (make-sparse-keymap)) |
| 86 |
;;; and |
| 87 |
;;; (define-key cafeobj-mode-map <your-key> <function>) |
| 88 |
;;; for all the functions you need. |
| 89 |
;;; |
| 90 |
;;; ABBRIVE-MODE: |
| 91 |
;;; CafeOBJ mode provides a mode-specific abbrev table 'cafeobj-mode-abbrev-table', |
| 92 |
;;; and there defined some abbriviations already. |
| 93 |
;;; You can use abbrev by `M-x abbrev-mode' or putting the following in your |
| 94 |
;;; .emacs |
| 95 |
;;; (add-hook 'cafeobj-mode-hook (function (lambda () (abbrev-mode 1)))) |
| 96 |
;;; |
| 97 |
;;; The predefined abbribiations are minimum, these are derived from my own |
| 98 |
;;; experience. I want these definitions to be useful for most of the users, |
| 99 |
;;; but ofcourse, you may feel it does not match to your taste. In that case, |
| 100 |
;;; add your own definitions for preventing my deinitions. |
| 101 |
;;; To edit the entire table, `M-x edit-abbrevs' and `M-x write-abbrev-file' |
| 102 |
;;; are handy. Here is an example of adding some extra abbreviations: |
| 103 |
;;; I want the following abbreviations: |
| 104 |
;;; "mod" -> "module" |
| 105 |
;;; "mod*" -> "module*" |
| 106 |
;;; "mod!" -> "module!" |
| 107 |
;;; "obj" -> "module!" |
| 108 |
;;; "th" -> "module*" |
| 109 |
;;; For this, we can use `M-x edit-abbrevs' and adds the above definitions in |
| 110 |
;;; cafeobj-abbrev-table like this: |
| 111 |
;;; |
| 112 |
;;; (cafeobj-mode-abbrev-table) |
| 113 |
;;; |
| 114 |
;;; "mod" 0 "module" |
| 115 |
;;; "m*" 0 "module* " |
| 116 |
;;; "m!" 0 "module! " |
| 117 |
;;; "obj" 0 "module!" |
| 118 |
;;; "th" 0 "module*" |
| 119 |
;;; "comm" 0 "commutative" |
| 120 |
;;; : |
| 121 |
;;; : |
| 122 |
;;; After editting, type `C-c C-c'(M-x edit-abbrevs-redefine) to install |
| 123 |
;;; abbrev definitions as specified. |
| 124 |
;;; Then use `M-x write-abbrev-file' specifying ~/.abbrev_deffs to |
| 125 |
;;; the target file name, and adds a line in my .emacs |
| 126 |
;;; (read-abbrev-file "~/.abbrev_defs"). |
| 127 |
;;; See Emacs manual of Infos for detail. |
| 128 |
;;; |
| 129 |
;;; CUTOMIZABLE VARIABLES: |
| 130 |
;;; You may want to customize the following variables, see the comment strings |
| 131 |
;;; for the descriptions of these variables. |
| 132 |
;;; |
| 133 |
;;; cafeobj-always-show |
| 134 |
;;; cafeobj-mode-map |
| 135 |
;;; cafeobj-prefix-key |
| 136 |
;;; cafeobj-mode-hook |
| 137 |
;;; cafeobj-default-application |
| 138 |
;;; cafeobj-default-command-switches |
| 139 |
;;; cafeobj-decl-keyword-face |
| 140 |
;;; cafeobj-keyword-face |
| 141 |
;;; cafeobj-command-face |
| 142 |
;;; cafeobj-comment-face |
| 143 |
;;; cafeobj-indent-level |
| 144 |
;;; cafeobj-brace-imaginary-offset |
| 145 |
;;; cafeobj-brace-offset |
| 146 |
;;; cafeobj-psort-indent |
| 147 |
;;; cafeobj-continued-statement-offset |
| 148 |
;;; cafeobj-continued-brace-offset |
| 149 |
;;; |
| 150 |
;;; see document strings for some brief description of each variable. |
| 151 |
;;; |
| 152 |
|
| 153 |
(require 'comint) |
| 154 |
|
| 155 |
;;; ----------------------- |
| 156 |
;;; Customizable variables _____________________________________________________ |
| 157 |
;;; ----------------------- |
| 158 |
|
| 159 |
(defvar cafeobj-always-show t |
| 160 |
"*Non-nil means display cafeobj-process-buffer after sending a command.") |
| 161 |
|
| 162 |
(defvar cafeobj-mode-map nil |
| 163 |
"Keymap used with cafeobj mode.") |
| 164 |
|
| 165 |
(defvar cafeobj-prefix-key "\C-c" |
| 166 |
"Prefix for all cafeobj-mode commands.") |
| 167 |
|
| 168 |
(defvar cafeobj-mode-hook nil |
| 169 |
"Hooks called when cafeobj mode fires up.") |
| 170 |
|
| 171 |
(defvar cafeobj-default-application "cafeobj" |
| 172 |
"Default Chaos (CafeOBJ) dialect to run in chaos subprocess.") |
| 173 |
|
| 174 |
(defvar cafeobj-default-command-switches nil |
| 175 |
"Command switches for `cafeobj-default-application'. |
| 176 |
Should be a list of strings which will be given to the cafeobj process when star up.") |
| 177 |
|
| 178 |
;;; below, we define `faces' of various CafeOBJ syntactic categories. |
| 179 |
;;; these are used in font-lock mode for displaying CafeOBJ sources. |
| 180 |
;;; You may wish to change these values to suit your taste; set them |
| 181 |
;;; in your .emacs or elsewhere which is evaluated BEFORE this file. |
| 182 |
|
| 183 |
(defvar cafeobj-decl-keyword-face 'bold |
| 184 |
"a face used for top level declaration keywords, such as module, view.") |
| 185 |
(defvar cafeobj-keyword-face font-lock-function-name-face |
| 186 |
"a face used for displaying keywords of module constructs, ex. op, eq ..") |
| 187 |
(defvar cafeobj-command-face font-lock-keyword-face |
| 188 |
"a face used for displaying top-level commands, show, describe, open, and so on.") |
| 189 |
(defvar cafeobj-comment-face font-lock-comment-face |
| 190 |
"a face for comment lines.") |
| 191 |
|
| 192 |
;;; INDENTATION CONTROL |
| 193 |
|
| 194 |
(defvar cafeobj-indent-level 2 |
| 195 |
"*Indentation of CafeOBJ statements with respect to containing block.") |
| 196 |
(defvar cafeobj-brace-imaginary-offset 0 |
| 197 |
"*Imagined indentation of a CafeOBJ open brace that actually follows a statement.") |
| 198 |
(defvar cafeobj-brace-offset 0 |
| 199 |
"*Extra indentation for braces, compared with other text in same context.") |
| 200 |
(defvar cafeobj-psort-indent 5 |
| 201 |
"*Indentation level of principal-sort declaration of CafeOBJ.") |
| 202 |
(defvar cafeobj-continued-statement-offset 2 |
| 203 |
"*Extra indent for lines not starting new statements.") |
| 204 |
(defvar cafeobj-continued-brace-offset 0 |
| 205 |
"*Extra indent for substatements that start with open-braces. |
| 206 |
This is in addition to cafeobj-continued-statement-offset.") |
| 207 |
|
| 208 |
;;; --------------------------------- |
| 209 |
;;; globals for internal use only.... |
| 210 |
;;; --------------------------------- |
| 211 |
|
| 212 |
(defvar cafeobj-process nil |
| 213 |
"The active chaos subprocess corresponding to current buffer.") |
| 214 |
|
| 215 |
(defvar cafeobj-process-buffer nil |
| 216 |
"Buffer used for communication with chaos subprocess for current buffer.") |
| 217 |
|
| 218 |
(defvar cafeobj-region-start (make-marker) |
| 219 |
"Start of special region for chaos communication.") |
| 220 |
|
| 221 |
(defvar cafeobj-region-end (make-marker) |
| 222 |
"End of special region for chaos communication.") |
| 223 |
|
| 224 |
;;; ----------------- |
| 225 |
;;; Portability stuff___________________________________________________________ |
| 226 |
;;; ----------------- |
| 227 |
|
| 228 |
(defconst cafeobj-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version)) |
| 229 |
|
| 230 |
(defmacro cafeobj-define-key (fsf-key definition &optional xemacs-key) |
| 231 |
`(define-key cafeobj-mode-map |
| 232 |
,(if xemacs-key |
| 233 |
`(if cafeobj-xemacs-p ,xemacs-key ,fsf-key) |
| 234 |
fsf-key) |
| 235 |
,definition)) |
| 236 |
|
| 237 |
(defvar del-back-ch (car (append (where-is-internal 'delete-backward-char) |
| 238 |
(where-is-internal 'backward-delete-char-untabify))) |
| 239 |
"Character generated by key bound to delete-backward-char.") |
| 240 |
|
| 241 |
(and (vectorp del-back-ch) (= (length del-back-ch) 1) |
| 242 |
(setq del-back-ch (aref del-back-ch 0))) |
| 243 |
|
| 244 |
;;;--------------------------- |
| 245 |
;;; CafeOBJ Keywords/Commands __________________________________________________ |
| 246 |
;;; essential syntactic structures are defined here. |
| 247 |
;;;--------------------------- |
| 248 |
|
| 249 |
(defconst cafeobj-comment-pat "\\(--\\|\\*\\*\\)[ \t\n]+") |
| 250 |
|
| 251 |
(defconst cafeobj-keywords |
| 252 |
'("op" "ops" "\\[" "\\]" "\\*\\[" "\\]\\*" |
| 253 |
"bop" "pred" "bops" "bpred" |
| 254 |
"imports" "protecting" "pr" |
| 255 |
"extending" "ex" "using" "us" |
| 256 |
"signature" "axioms" |
| 257 |
"var" "vars" |
| 258 |
"eq" "cq" "ceq" |
| 259 |
"bq" "beq" "bcq" "bceq" |
| 260 |
"trans" "trns" "ctrans" "ctrns" |
| 261 |
"btrans" "btrns" "bctrans" "bctrns" |
| 262 |
"class" "record" "attr" |
| 263 |
"view" |
| 264 |
"sort" "hsort" |
| 265 |
"psort" "principal-sort") |
| 266 |
"keywords appearing inside module declaration or view declaration." |
| 267 |
) |
| 268 |
|
| 269 |
(defconst cafeobj-keyword-pat |
| 270 |
(mapconcat 'identity cafeobj-keywords "\\|")) |
| 271 |
|
| 272 |
(defun looking-at-cafeobj-keyword-pat () |
| 273 |
(looking-at cafeobj-keyword-pat)) |
| 274 |
|
| 275 |
(defconst cafeobj-commands |
| 276 |
'("let" "red" "reduce" "input" "in" |
| 277 |
"execute" "exec" "make" |
| 278 |
"apply" "start" "match" |
| 279 |
"parse" |
| 280 |
"select" |
| 281 |
"set" |
| 282 |
"show" |
| 283 |
"describe" |
| 284 |
"sh" |
| 285 |
"choose" "open" "close" |
| 286 |
"desc" "eof" |
| 287 |
"require" "provide") |
| 288 |
"CafeOBJ top-level commands") |
| 289 |
|
| 290 |
(defconst cafeobj-command-pat |
| 291 |
(mapconcat 'identity cafeobj-commands "\\|")) |
| 292 |
|
| 293 |
(defun looking-at-cafeobj-command-pat () |
| 294 |
(looking-at cafeobj-command-pat)) |
| 295 |
|
| 296 |
(defconst cafeobj-top-keywords |
| 297 |
'("op" "ops" "bop" "bops" "pred" "bpred" |
| 298 |
"var" "vars" |
| 299 |
"eq" "cq" "ceq" |
| 300 |
"bq" "beq" "bcq" "bceq" |
| 301 |
"trans" "trns" "ctrans" "ctrns" |
| 302 |
"btrans" "btrns" "bctrans" "bctrns" |
| 303 |
"class" "record" "attr" |
| 304 |
"\\[" "\\]") |
| 305 |
"CafeOBJ keyowrds may apper at top-level.") |
| 306 |
|
| 307 |
(defun looking-at-cafeobj-top-keywords () |
| 308 |
(looking-at cafeobj-top-keywords)) |
| 309 |
|
| 310 |
(defconst cafeobj-top-key-pat |
| 311 |
(mapconcat 'identity cafeobj-top-keywords "\\|")) |
| 312 |
|
| 313 |
(defconst cafeobj-top-decl-pat |
| 314 |
"^\\(module\\|mod\\|module\*\\|mod\*\\|module!\\|mod!\\|view\\)") |
| 315 |
|
| 316 |
(defun looking-at-cafeobj-top-decl () |
| 317 |
(looking-at "\\(module\\|mod\\|module\*\\|mod\*\\|module!\\|mod!\\|view\\)") |
| 318 |
) |
| 319 |
|
| 320 |
(defconst cafeobj-block-start-pat |
| 321 |
"\\(signature\\|axioms\\|imports\\|record\\|class\\)") |
| 322 |
|
| 323 |
(defun looking-at-cafeobj-block-start-pat () |
| 324 |
(looking-at "\\(signature\\|axioms\\|imports\\|record\\|class\\)")) |
| 325 |
|
| 326 |
(defun looking-at-cafeobj-module-decl () |
| 327 |
(looking-at "module\\|mod\\|module\*\\|mod\*\\|module!\\|mod!")) |
| 328 |
|
| 329 |
(defun looking-at-cafeobj-view-decl () |
| 330 |
(looking-at "view")) |
| 331 |
|
| 332 |
;;;---------- |
| 333 |
;;; FONT-LOCK___________________________________________________________________ |
| 334 |
;;;---------- |
| 335 |
|
| 336 |
(defun get-cafeobj-face (name) |
| 337 |
(cond (cafeobj-xemacs-p (symbol-value name)) |
| 338 |
(t (identity name)))) |
| 339 |
|
| 340 |
(defvar cafeobj-font-lock-keywords nil |
| 341 |
"Additional expressions to highlight in CafeOBJ mode.") |
| 342 |
(setq cafeobj-font-lock-keywords |
| 343 |
(list |
| 344 |
;; comments |
| 345 |
(cons "^--.*" (get-cafeobj-face 'cafeobj-comment-face)) |
| 346 |
(cons "^\\*\\*.*" (get-cafeobj-face 'cafeobj-comment-face)) |
| 347 |
(cons "\\s-\\(--\\|\\*\\*\\|-->\\|\\*\\*>\\)[ \n\t].*" |
| 348 |
(get-cafeobj-face 'cafeobj-comment-face)) |
| 349 |
;; keywords not at beginning of line |
| 350 |
(cons (concat "\\s-\\(" cafeobj-keyword-pat "\\)[ \n\t]") |
| 351 |
(get-cafeobj-face 'cafeobj-keyword-face)) |
| 352 |
;; commands at beginning of line |
| 353 |
(cons (concat "^\\(" cafeobj-command-pat "\\)[ \n\t]") |
| 354 |
(get-cafeobj-face 'cafeobj-command-face)) |
| 355 |
;; module |
| 356 |
(cons "^mod[a-z\!\*]*[ \t]" |
| 357 |
(get-cafeobj-face 'cafeobj-decl-keyword-face)) |
| 358 |
;; view |
| 359 |
(cons "^view" (get-cafeobj-face 'cafeobj-decl-keyword-face)) |
| 360 |
;; declaration appering at the top level. |
| 361 |
(cons (concat "^\\(" cafeobj-top-key-pat "\\)[ \n\t]") |
| 362 |
(get-cafeobj-face 'cafeobj-keyword-face)) |
| 363 |
;; module name |
| 364 |
;; '("\\bmod[a-z\!\*]*[ \t]+\\([a-zA-Z0-9_-\!\*\$\%\&\#\=]*\\)" |
| 365 |
;; . font-lock-function-name-face) |
| 366 |
;; view name |
| 367 |
;;'("\\bview[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_-\!\*\$\%\&\#\=]*\\)" |
| 368 |
;; . font-lock-type-face) |
| 369 |
)) |
| 370 |
|
| 371 |
;;; XEmacs handles the following, but FSF19 not |
| 372 |
(cond (cafeobj-xemacs-p |
| 373 |
(put 'cafeobj-mode 'font-lock-defaults '(cafeobj-font-lock-keywords))) |
| 374 |
(t |
| 375 |
;; FSF19, we must explicitry set the value of 'font-lock-keywords' |
| 376 |
;; this will be done in 'cafeobj-mode'. |
| 377 |
)) |
| 378 |
|
| 379 |
;;; -------------------- |
| 380 |
;;; Default Key Bindings________________________________________________________ |
| 381 |
;;; -------------------- |
| 382 |
|
| 383 |
(defun cafeobj-setup-keymap () |
| 384 |
"Set up keymap for cafeobj mode. |
| 385 |
If the variable `cafeobj-prefix-key' is nil, the bindings go directly |
| 386 |
to `cafeobj-mode-map', otherwise they are prefixed with `cafeobj-prefix-key'." |
| 387 |
(setq cafeobj-mode-map (make-sparse-keymap)) |
| 388 |
;; |
| 389 |
(let ((map (if cafeobj-prefix-key |
| 390 |
(make-sparse-keymap) |
| 391 |
cafeobj-mode-map))) |
| 392 |
;; indentation |
| 393 |
(define-key cafeobj-mode-map [?}] 'cafeobj-electric-brace) |
| 394 |
;; communication |
| 395 |
(define-key map "i" 'cafeobj-send-line) |
| 396 |
(define-key map "e" 'cafeobj-send-decl) |
| 397 |
(define-key map "r" 'cafeobj-send-region) |
| 398 |
(define-key map "l" 'cafeobj-send-buffer) |
| 399 |
(define-key map "[" 'cafeobj-beginning-of-decl) |
| 400 |
(define-key map "]" 'cafeobj-end-of-decl) |
| 401 |
(define-key map "q" 'cafeobj-kill-process) |
| 402 |
(define-key map "s" 'cafeobj-show-process-buffer) |
| 403 |
(define-key map "h" 'cafeobj-hide-process-buffer) |
| 404 |
;; |
| 405 |
(if cafeobj-prefix-key |
| 406 |
(define-key cafeobj-mode-map cafeobj-prefix-key map)) |
| 407 |
)) |
| 408 |
|
| 409 |
(cafeobj-setup-keymap) |
| 410 |
|
| 411 |
;;; ------------- |
| 412 |
;;; MENU SUPPORTS_______________________________________________________________ |
| 413 |
;;; ------------- |
| 414 |
|
| 415 |
;; For XEmacs |
| 416 |
(defvar cafeobj-mode-popup-menu nil) |
| 417 |
(defvar cafeobj-mode-menubar-menu nil) |
| 418 |
|
| 419 |
;; For FSF19 |
| 420 |
(defvar cafeobj-mode-menu nil |
| 421 |
"Keymap for cafeobj-mode's menu.") |
| 422 |
(defvar cafeobj-edit-menu nil |
| 423 |
"Keymap for cafeobj edit menu.") |
| 424 |
(defvar cafeobj-trans-menu nil |
| 425 |
"keymap for transitions editing") |
| 426 |
(defvar cafeobj-eq-menu nil |
| 427 |
"keymap for equations editing") |
| 428 |
(defvar cafeobj-op-menu nil |
| 429 |
"keymap for operations editing") |
| 430 |
(defvar cafeobj-sort-menu nil |
| 431 |
"keymap for sort editing") |
| 432 |
(defvar cafeobj-import-menu nil |
| 433 |
"keymap for module imports editing") |
| 434 |
(defvar cafeobj-view-menu nil |
| 435 |
"keymap for view editing") |
| 436 |
(defvar cafeobj-module-menu nil |
| 437 |
"keymap for module definition editing") |
| 438 |
|
| 439 |
(cond (cafeobj-xemacs-p |
| 440 |
(setq cafeobj-mode-popup-menu |
| 441 |
(purecopy '("CafeOBJ Interaction Menu" |
| 442 |
["Evaluate This Declaration" |
| 443 |
cafeobj-send-decl t] |
| 444 |
["Evaluate Current Line" cafeobj-send-line t] |
| 445 |
["Evaluate Entire Buffer" cafeobj-send-buffer t] |
| 446 |
["Evaluate Region" cafeobj-send-region |
| 447 |
(region-exists-p)] |
| 448 |
"---" |
| 449 |
["Comment Out Region" comment-region (region-exists-p)] |
| 450 |
["Indent Region" indent-region (region-exists-p)] |
| 451 |
["Indent Line" cafeobj-indent-line t] |
| 452 |
["Beginning of Declaration" |
| 453 |
cafeobj-beginning-of-decl t] |
| 454 |
))) |
| 455 |
(setq cafeobj-mode-menubar-menu |
| 456 |
(purecopy (cons "CafeOBJ" (cdr cafeobj-mode-popup-menu))))) |
| 457 |
(t ;; |
| 458 |
(setq cafeobj-mode-menu (make-sparse-keymap "CafeOBJ-Eval")) |
| 459 |
;; Interaction menu |
| 460 |
;; interaction with CafeOBJ interpreter. |
| 461 |
;; |
| 462 |
(define-key cafeobj-mode-map [menu-bar cafeobj-mode] |
| 463 |
(cons "CafeOBJ" cafeobj-mode-menu)) |
| 464 |
(define-key cafeobj-mode-map [menu-bar cafeobj-mode send-current-line] |
| 465 |
'("Evaluate Current Line" . cafeobj-send-line)) |
| 466 |
(define-key cafeobj-mode-map [menu-bar cafeobj-mode send-region] |
| 467 |
'("Evaluate CafeOBJ-Region" . cafeobj-send-region)) |
| 468 |
(define-key cafeobj-mode-map [menu-bar cafeobj-mode send-proc] |
| 469 |
'("Evaluate This Declaration" . cafeobj-send-decl)) |
| 470 |
(define-key cafeobj-mode-map [menu-bar cafeobj-mode send-buffer] |
| 471 |
'("Send Buffer" . cafeobj-send-buffer)) |
| 472 |
;; |
| 473 |
;; edit menu |
| 474 |
;; |
| 475 |
(setq cafeobj-edit-menu (make-sparse-keymap "CafeOBJ-Edit")) |
| 476 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit] |
| 477 |
(cons "CafeOBJ-Edit" cafeobj-edit-menu)) |
| 478 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit beginning-of-decl] |
| 479 |
'("Beginning Of Proc" . cafeobj-beginning-of-decl)) |
| 480 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit comment-region] |
| 481 |
'("Comment Out Region" . comment-region)) |
| 482 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit indent-region] |
| 483 |
'("Indent Region" . indent-region)) |
| 484 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit indent-line] |
| 485 |
'("Indent Line" . cafeobj-indent-command)) |
| 486 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit beginning-of-decl] |
| 487 |
'("Beginning of Declaration" . cafeobj-beginning-of-decl)) |
| 488 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit undo] |
| 489 |
'("Undo" . cafeobj-kb7-undo)) |
| 490 |
;; |
| 491 |
;; kb7-style syntax-oriented editing commands |
| 492 |
;; |
| 493 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit separator-trans] |
| 494 |
'("--")) |
| 495 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit trans] |
| 496 |
'("Transition" . cafeobj-trans-menu)) |
| 497 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit eq] |
| 498 |
'("Equation" . cafeobj-eq-menu)) |
| 499 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit var] |
| 500 |
'("Variable" . var)) |
| 501 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit op] |
| 502 |
'("Operation" . cafeobj-op-menu)) |
| 503 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit sort] |
| 504 |
'("Sort" . cafeobj-sort-menu)) |
| 505 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit import] |
| 506 |
'("Import" . cafeobj-import-menu)) |
| 507 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit separator-view] |
| 508 |
'("--")) |
| 509 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit view] |
| 510 |
'("View" . cafeobj-view-menu)) |
| 511 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit module] |
| 512 |
'("Module" . cafeobj-module-menu)) |
| 513 |
)) |
| 514 |
|
| 515 |
;;; transition menu (FSF) |
| 516 |
(setq cafeobj-trans-menu (make-sparse-keymap "Transition")) |
| 517 |
(defalias 'cafeobj-trans-menu (symbol-value 'cafeobj-trans-menu)) |
| 518 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit] |
| 519 |
(cons "Transition" cafeobj-trans-menu)) |
| 520 |
(define-key cafeobj-trans-menu [ctrans] |
| 521 |
'("conditional..." . ctrans)) |
| 522 |
(define-key cafeobj-trans-menu [trans] |
| 523 |
'("simple..." . trans)) |
| 524 |
|
| 525 |
;;; equation menu (FSF) |
| 526 |
(setq cafeobj-eq-menu (make-sparse-keymap "Equation")) |
| 527 |
(defalias 'cafeobj-eq-menu (symbol-value 'cafeobj-eq-menu)) |
| 528 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit] |
| 529 |
(cons "Equation" cafeobj-eq-menu)) |
| 530 |
(define-key cafeobj-eq-menu [bcq] |
| 531 |
'("cond behavioural..." . bcq)) |
| 532 |
(define-key cafeobj-eq-menu [beq] |
| 533 |
'("behavioural..." . beq)) |
| 534 |
(define-key cafeobj-eq-menu [cq] |
| 535 |
'("conditional..." . cq)) |
| 536 |
(define-key cafeobj-eq-menu [eqq] |
| 537 |
'("simple..." . eqq)) |
| 538 |
|
| 539 |
;;; operation menu (FSF) |
| 540 |
(setq cafeobj-op-menu (make-sparse-keymap "Operation")) |
| 541 |
(defalias 'cafeobj-op-menu (symbol-value 'cafeobj-op-menu)) |
| 542 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit] |
| 543 |
(cons "Operation" cafeobj-op-menu)) |
| 544 |
(define-key cafeobj-op-menu [bop] |
| 545 |
'("behavioural..." . bop)) |
| 546 |
(define-key cafeobj-op-menu [op] |
| 547 |
'("algebraic..." . op)) |
| 548 |
|
| 549 |
;;; sort menu (FSF) |
| 550 |
(setq cafeobj-sort-menu (make-sparse-keymap "Sort")) |
| 551 |
(defalias 'cafeobj-sort-menu (symbol-value 'cafeobj-sort-menu)) |
| 552 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit] |
| 553 |
(cons "Sort" cafeobj-sort-menu)) |
| 554 |
(define-key cafeobj-sort-menu [hsort] |
| 555 |
'("hidden..." . hsort)) |
| 556 |
(define-key cafeobj-sort-menu [vsort] |
| 557 |
'("visible..." . vsort)) |
| 558 |
|
| 559 |
;;; import menu (FSF) |
| 560 |
(setq cafeobj-import-menu (make-sparse-keymap "Import")) |
| 561 |
(defalias 'cafeobj-import-menu (symbol-value 'cafeobj-import-menu)) |
| 562 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit] |
| 563 |
(cons "Import" cafeobj-import-menu)) |
| 564 |
(define-key cafeobj-import-menu [using] |
| 565 |
'("using..." . using)) |
| 566 |
(define-key cafeobj-import-menu [ex] |
| 567 |
'("extending..." . ex)) |
| 568 |
(define-key cafeobj-import-menu [pr] |
| 569 |
'("protecting..." . pr)) |
| 570 |
|
| 571 |
;;; view menu (FSF) |
| 572 |
(setq cafeobj-view-menu (make-sparse-keymap "View")) |
| 573 |
(defalias 'cafeobj-view-menu (symbol-value 'cafeobj-view-menu)) |
| 574 |
|
| 575 |
;;; module menu (FSF) |
| 576 |
(setq cafeobj-module-menu (make-sparse-keymap "Module")) |
| 577 |
(defalias 'cafeobj-module-menu (symbol-value 'cafeobj-module-menu)) |
| 578 |
(define-key cafeobj-module-menu [modd] |
| 579 |
'("either..." . modd)) |
| 580 |
(define-key cafeobj-module-menu [mod*] |
| 581 |
'("loose semantics..." . mod*)) |
| 582 |
(define-key cafeobj-module-menu [mod!] |
| 583 |
'("initial semantics..." . mod!)) |
| 584 |
|
| 585 |
;;; ------------ |
| 586 |
;;; CafeOBJ Mode________________________________________________________________ |
| 587 |
;;; ------------ |
| 588 |
|
| 589 |
(defvar cafeobj-mode-abbrev-table nil |
| 590 |
"Abbrev table in use in CafeOBJ mode.") |
| 591 |
;;; some default abbreviations define here |
| 592 |
(if cafeobj-mode-abbrev-table |
| 593 |
nil |
| 594 |
(define-abbrev-table 'cafeobj-mode-abbrev-table |
| 595 |
'(("btrns" "btrans" nil 0) |
| 596 |
("bcq" "bceq" nil 0) |
| 597 |
("compat" "compatibility" nil 0) |
| 598 |
("psort" "principal-sort" nil 0) |
| 599 |
("req" "require" nil 0) |
| 600 |
("sh" "show" nil 0) |
| 601 |
("verb" "verbose" nil 0) |
| 602 |
("reg" "regularize" nil 0) |
| 603 |
("import" "imports" nil 0) |
| 604 |
("cq" "ceq" nil 0) |
| 605 |
("red" "reduce" nil 0) |
| 606 |
("strat" "strategy" nil 0) |
| 607 |
("us" "using" nil 0) |
| 608 |
("btrn" "btrans" nil 0) |
| 609 |
("btr" "btrans" nil 0) |
| 610 |
("reconst" "reconstruct" nil 0) |
| 611 |
("chk" "check" nil 0) |
| 612 |
("trns" "trans" nil 0) |
| 613 |
("swit" "swithces" nil 0) |
| 614 |
("bq" "beq" nil 0) |
| 615 |
("desc" "describe" nil 0) |
| 616 |
("bctr" "bctrans" nil 0) |
| 617 |
("incl" "include" nil 0) |
| 618 |
("bctrn" "bctrans" nil 0) |
| 619 |
("ex" "extending" nil 0) |
| 620 |
("axs" "axioms" nil 0) |
| 621 |
("pr" "protecting" nil 0) |
| 622 |
("bctrns" "bctrans" nil 0) |
| 623 |
("pat" "pattern" nil 0) |
| 624 |
("recon" "reconstruct" nil 0) |
| 625 |
("prov" "provide" nil 0) |
| 626 |
("sel" "select" nil 0) |
| 627 |
("sig" "signature" nil 0) |
| 628 |
("sign" "signature" nil 1) |
| 629 |
("cond" "conditions" nil 0) |
| 630 |
("imp" "imports" nil 0) |
| 631 |
("comp" "compatibility" nil 0) |
| 632 |
("swi" "switch" nil 0) |
| 633 |
("reconstr" "reconstruct" nil 0) |
| 634 |
)) |
| 635 |
) |
| 636 |
|
| 637 |
|
| 638 |
(defvar cafeobj-mode-syntax-table nil |
| 639 |
"Syntax table in use in cafeobj-mode buffers.") |
| 640 |
|
| 641 |
(if cafeobj-mode-syntax-table |
| 642 |
() |
| 643 |
(setq cafeobj-mode-syntax-table (make-syntax-table)) |
| 644 |
(mapcar (function |
| 645 |
(lambda (x) (modify-syntax-entry |
| 646 |
(car x) (cdr x) cafeobj-mode-syntax-table))) |
| 647 |
'(( ?\( . "()" ) ( ?\) . ")(" ) |
| 648 |
( ?\[ . "(]" ) ( ?\] . ")[" ) |
| 649 |
( ?\{ . "(}" ) ( ?\} . "){" ) |
| 650 |
;; underscore is word class |
| 651 |
( ?\_ . "w" ) |
| 652 |
( ?\" . "\"" ) ; double quote is string quote too |
| 653 |
( ?\n . ">")) |
| 654 |
)) |
| 655 |
|
| 656 |
(defun cafeobj-mode () |
| 657 |
"Major mode for editing CafeOBJ programs. |
| 658 |
The following keys are bound: |
| 659 |
\\{cafeobj-mode-map} |
| 660 |
" |
| 661 |
(interactive) |
| 662 |
(let (s) |
| 663 |
(kill-all-local-variables) |
| 664 |
(setq major-mode 'cafeobj-mode) |
| 665 |
(setq mode-name "CafeOBJ") |
| 666 |
;; keymap |
| 667 |
(or cafeobj-mode-map (cafeobj-setup-keymap)) |
| 668 |
(use-local-map cafeobj-mode-map) |
| 669 |
;; abbrev |
| 670 |
(setq local-abbrev-table cafeobj-mode-abbrev-table) |
| 671 |
;; settting menu. |
| 672 |
(if cafeobj-xemacs-p |
| 673 |
(setq mode-popup-menu |
| 674 |
cafeobj-mode-popup-menu) |
| 675 |
(progn |
| 676 |
(define-key cafeobj-mode-map [menu-bar cafeobj-mode] |
| 677 |
(cons "CafeOBJ-Eval" cafeobj-mode-menu)) |
| 678 |
(define-key cafeobj-mode-map [menu-bar cafeobj-edit] |
| 679 |
(cons "CafeOBJ-Edit" cafeobj-edit-menu)) |
| 680 |
)) |
| 681 |
;; |
| 682 |
(set (make-local-variable 'cafeobj-process) nil) |
| 683 |
(set (make-local-variable 'cafeobj-process-buffer) nil) |
| 684 |
(make-local-variable 'cafeobj-default-command-switches) |
| 685 |
;; |
| 686 |
(cond (cafeobj-xemacs-p |
| 687 |
(make-local-variable 'font-lock-defaults)) |
| 688 |
(t (set (make-local-variable 'font-lock-keywords) |
| 689 |
cafeobj-font-lock-keywords))) |
| 690 |
;; |
| 691 |
(set (make-local-variable 'indent-line-function) 'cafeobj-indent-line) |
| 692 |
(set (make-local-variable 'comment-start) "-- ") ; obsolate? ... should be fixed. |
| 693 |
;; todo -- |
| 694 |
(set (make-local-variable 'comment-start-skip) "\\(\\(^\\|;\\)[ \t]*\\)--") |
| 695 |
;; syntax------- |
| 696 |
(set-syntax-table cafeobj-mode-syntax-table) |
| 697 |
;; (modify-syntax-entry ?# "<") |
| 698 |
(modify-syntax-entry ?\n ">") |
| 699 |
;; |
| 700 |
(make-local-variable 'require-final-newline) |
| 701 |
(setq require-final-newline t) |
| 702 |
;; |
| 703 |
(setq comment-column 32) |
| 704 |
(make-local-variable 'comment-start-skip) |
| 705 |
(make-local-variable 'parse-sexp-ignore-comments) |
| 706 |
(setq parse-sexp-ignore-comments t) |
| 707 |
;; look for a #!.../cafeobj -f line at bob |
| 708 |
(save-excursion |
| 709 |
(goto-char (point-min)) |
| 710 |
(if (looking-at "#![ \t]*\\([^ \t]*\\)[ \t]\\(.*[ \t]\\)-f") |
| 711 |
(progn |
| 712 |
(set (make-local-variable 'cafeobj-default-application) |
| 713 |
(buffer-substring (match-beginning 1) |
| 714 |
(match-end 1))) |
| 715 |
(if (match-beginning 2) |
| 716 |
(progn |
| 717 |
(goto-char (match-beginning 2)) |
| 718 |
(set (make-local-variable 'cafeobj-default-command-switches) nil) |
| 719 |
(while (< (point) (match-end 2)) |
| 720 |
(setq s (read (current-buffer))) |
| 721 |
(if (<= (point) (match-end 2)) |
| 722 |
(setq cafeobj-default-command-switches |
| 723 |
(append cafeobj-default-command-switches |
| 724 |
(list (prin1-to-string s))))))))) |
| 725 |
;; if this fails, look for the #!/bin/csh ... exec hack |
| 726 |
(while (eq (following-char) ?#) |
| 727 |
(forward-line 1)) |
| 728 |
(or (bobp) |
| 729 |
(forward-char -1)) |
| 730 |
(if (eq (preceding-char) ?\\) |
| 731 |
(progn |
| 732 |
(forward-char 1) |
| 733 |
(if (looking-at "exec[ \t]+\\([^ \t]*\\)[ \t]\\(.*[ \t]\\)*-f") |
| 734 |
(progn |
| 735 |
(set (make-local-variable 'cafeobj-default-application) |
| 736 |
(buffer-substring (match-beginning 1) |
| 737 |
(match-end 1))) |
| 738 |
(if (match-beginning 2) |
| 739 |
(progn |
| 740 |
(goto-char (match-beginning 2)) |
| 741 |
(set (make-local-variable |
| 742 |
'cafeobj-default-command-switches) |
| 743 |
nil) |
| 744 |
(while (< (point) (match-end 2)) |
| 745 |
(setq s (read (current-buffer))) |
| 746 |
(if (<= (point) (match-end 2)) |
| 747 |
(setq cafeobj-default-command-switches |
| 748 |
(append cafeobj-default-command-switches |
| 749 |
(list (prin1-to-string s))))))))) |
| 750 |
))))) |
| 751 |
;; |
| 752 |
(if (and (featurep 'menubar) |
| 753 |
current-menubar) |
| 754 |
(progn |
| 755 |
;; make a local copy of the menubar, so our modes don't |
| 756 |
;; change the global menubar |
| 757 |
(set-buffer-menubar current-menubar) |
| 758 |
(add-submenu nil cafeobj-mode-menubar-menu))) |
| 759 |
;; |
| 760 |
(run-hooks 'cafeobj-mode-hook))) |
| 761 |
|
| 762 |
|
| 763 |
;;; ---------------- |
| 764 |
;;; CafeOBJ Editting____________________________________________________________ |
| 765 |
;;; ---------------- |
| 766 |
|
| 767 |
(defconst cafeobj-auto-newline nil |
| 768 |
"*Non-nil means automatically newline before and after braces, |
| 769 |
and after colons and semicolons, inserted in CafeOBJ code.") |
| 770 |
|
| 771 |
(defconst cafeobj-tab-always-indent t |
| 772 |
"*Non-nil means TAB in C mode should always reindent the current line, |
| 773 |
regardless of where in the line point is when the TAB command is used.") |
| 774 |
|
| 775 |
(defun cafeobj-electric-brace (arg) |
| 776 |
"Insert character and correct line's indentation." |
| 777 |
(interactive "P") |
| 778 |
(let (insertpos) |
| 779 |
(if (and (not arg) |
| 780 |
(eolp) |
| 781 |
(or (save-excursion |
| 782 |
(skip-chars-backward " \t") |
| 783 |
(bolp)) |
| 784 |
(if cafeobj-auto-newline |
| 785 |
(progn (cafeobj-indent-line) (newline) t) |
| 786 |
nil))) |
| 787 |
(progn |
| 788 |
(insert last-command-char) |
| 789 |
(cafeobj-indent-line) |
| 790 |
(if cafeobj-auto-newline |
| 791 |
(progn |
| 792 |
(newline) |
| 793 |
;; (newline) may have done auto-fill |
| 794 |
(setq insertpos (- (point) 2)) |
| 795 |
(cafeobj-indent-line))) |
| 796 |
(save-excursion |
| 797 |
(if insertpos (goto-char (1+ insertpos))) |
| 798 |
(delete-char -1)))) |
| 799 |
(if insertpos |
| 800 |
(save-excursion |
| 801 |
(goto-char insertpos) |
| 802 |
(self-insert-command (prefix-numeric-value arg))) |
| 803 |
(self-insert-command (prefix-numeric-value arg))))) |
| 804 |
|
| 805 |
(defun cafeobj-beginning-of-block (&optional arg) |
| 806 |
"Move backward to the beginning of a CafeOBJ block structure. |
| 807 |
With argument, do it that many times. Negative arg -N |
| 808 |
means move forward to Nth following beginning of declaration. |
| 809 |
Returns t unless search stops due to beginning or end of buffer." |
| 810 |
(interactive "P") |
| 811 |
(or arg (setq arg 1)) |
| 812 |
(let ((found nil) |
| 813 |
(ret t)) |
| 814 |
(if (and (< arg 0) |
| 815 |
(looking-at-cafeobj-block-start-pat)) |
| 816 |
(forward-char 1)) |
| 817 |
(while (< arg 0) |
| 818 |
(if (re-search-forward cafeobj-block-start-pat nil t) |
| 819 |
(setq arg (1+ arg) |
| 820 |
found t) |
| 821 |
(setq ret nil |
| 822 |
arg 0))) |
| 823 |
(if found |
| 824 |
(beginning-of-line)) |
| 825 |
(while (> arg 0) |
| 826 |
(if (re-search-backward cafeobj-block-start-pat nil t) |
| 827 |
(setq arg (1- arg)) |
| 828 |
(setq ret nil |
| 829 |
arg 0))) |
| 830 |
ret)) |
| 831 |
|
| 832 |
(defun cafeobj-beginning-of-decl (&optional arg) |
| 833 |
"Move backward to the beginning of a CafeOBJ top-level decl. |
| 834 |
With argument, do it that many times. Negative arg -N |
| 835 |
means move forward to Nth following beginning of declaration. |
| 836 |
Returns t unless search stops due to beginning or end of buffer." |
| 837 |
(interactive "P") |
| 838 |
(or arg (setq arg 1)) |
| 839 |
(let ((found nil) |
| 840 |
(ret t)) |
| 841 |
(if (and (< arg 0) |
| 842 |
(looking-at cafeobj-top-decl-pat)) |
| 843 |
(forward-char 1)) |
| 844 |
(while (< arg 0) |
| 845 |
(if (re-search-forward cafeobj-top-decl-pat nil t) |
| 846 |
(setq arg (1+ arg) |
| 847 |
found t) |
| 848 |
(setq ret nil |
| 849 |
arg 0))) |
| 850 |
(if found |
| 851 |
(beginning-of-line)) |
| 852 |
(while (> arg 0) |
| 853 |
(if (re-search-backward cafeobj-top-decl-pat nil t) |
| 854 |
(setq arg (1- arg)) |
| 855 |
(setq ret nil |
| 856 |
arg 0))) |
| 857 |
ret)) |
| 858 |
|
| 859 |
(defun cafeobj-end-of-decl (&optional arg) |
| 860 |
"Move forward to next end of chaos declaration (or similar). |
| 861 |
With argument, do it that many times. Negative argument -N means move |
| 862 |
back to Nth preceding end of proc. |
| 863 |
|
| 864 |
This function just searches for a `}' at the beginning of a line." |
| 865 |
(interactive "P") |
| 866 |
(or arg |
| 867 |
(setq arg 1)) |
| 868 |
(let ((found nil) |
| 869 |
(ret t)) |
| 870 |
(if (and (< arg 0) |
| 871 |
(not (bolp)) |
| 872 |
(save-excursion |
| 873 |
(beginning-of-line) |
| 874 |
(eq (following-char) ?}))) |
| 875 |
(forward-char -1)) |
| 876 |
(while (> arg 0) |
| 877 |
(if (re-search-forward "^}" nil t) |
| 878 |
(setq arg (1- arg) |
| 879 |
found t) |
| 880 |
(setq ret nil |
| 881 |
arg 0))) |
| 882 |
(while (< arg 0) |
| 883 |
(if (re-search-backward "^}" nil t) |
| 884 |
(setq arg (1+ arg) |
| 885 |
found t) |
| 886 |
(setq ret nil |
| 887 |
arg 0))) |
| 888 |
(if found |
| 889 |
(end-of-line)) |
| 890 |
ret)) |
| 891 |
|
| 892 |
(defun cafeobj-outline-level () |
| 893 |
(save-excursion |
| 894 |
(skip-chars-forward "\t ") |
| 895 |
(current-column))) |
| 896 |
|
| 897 |
(defun cafeobj-inside-parens-p () |
| 898 |
(condition-case () |
| 899 |
(save-excursion |
| 900 |
(save-restriction |
| 901 |
(narrow-to-region (point) |
| 902 |
(progn (cafeobj-beginning-of-decl) (point))) |
| 903 |
(goto-char (point-max)) |
| 904 |
(= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\())) |
| 905 |
(error nil))) |
| 906 |
|
| 907 |
(defun cafeobj-indent-command (&optional whole-exp) |
| 908 |
"Indent current line as CafeOBJ code, or in some cases insert a tab character. |
| 909 |
If `cafeobj-tab-always-indent' is non-nil (the default), always indent current line. |
| 910 |
Otherwise, indent the current line only if point is at the left margin or |
| 911 |
in the line's indentation; otherwise insert a tab. |
| 912 |
|
| 913 |
A numeric argument, regardless of its value, means indent rigidly all the |
| 914 |
lines of the expression starting after point so that this line becomes |
| 915 |
properly indented. The relative indentation among the lines of the |
| 916 |
expression are preserved." |
| 917 |
(interactive "P") |
| 918 |
(if whole-exp |
| 919 |
;; If arg, always indent this line as CafeOBJ |
| 920 |
;; and shift remaining lines of expression the same amount. |
| 921 |
(let ((shift-amt (cafeobj-indent-line)) |
| 922 |
beg end) |
| 923 |
(save-excursion |
| 924 |
(if cafeobj-tab-always-indent |
| 925 |
(beginning-of-line)) |
| 926 |
;; Find beginning of following line. |
| 927 |
(save-excursion |
| 928 |
(forward-line 1) (setq beg (point))) |
| 929 |
;; Find first beginning-of-sexp for sexp extending past this line. |
| 930 |
(while (< (point) beg) |
| 931 |
(forward-sexp 1) |
| 932 |
(setq end (point)) |
| 933 |
(skip-chars-forward " \t\n"))) |
| 934 |
(if (> end beg) |
| 935 |
(indent-code-rigidly beg end shift-amt "#"))) |
| 936 |
(if (and (not cafeobj-tab-always-indent) |
| 937 |
(save-excursion |
| 938 |
(skip-chars-backward " \t") |
| 939 |
(not (bolp)))) |
| 940 |
(insert-tab) |
| 941 |
(cafeobj-indent-line)))) |
| 942 |
|
| 943 |
(defun cafeobj-indent-line () |
| 944 |
"Indent current line as CafeOBJ code. |
| 945 |
Return the amount the indentation changed by." |
| 946 |
(let ((indent (calculate-cafeobj-indent nil)) |
| 947 |
beg shift-amt |
| 948 |
(case-fold-search nil) |
| 949 |
(pos (- (point-max) (point)))) |
| 950 |
(beginning-of-line) |
| 951 |
(setq beg (point)) |
| 952 |
(cond ((eq indent nil) |
| 953 |
(setq indent (current-indentation))) |
| 954 |
((eq indent t) |
| 955 |
(setq indent (current-indentation))) |
| 956 |
(t |
| 957 |
(skip-chars-forward " \t") |
| 958 |
(if (listp indent) (setq indent (car indent))) |
| 959 |
(cond ((= (following-char) ?}) |
| 960 |
(setq indent (- indent cafeobj-indent-level))) |
| 961 |
((= (following-char) ?{) |
| 962 |
(setq indent (+ indent cafeobj-brace-offset)))))) |
| 963 |
(skip-chars-forward " \t") |
| 964 |
(setq shift-amt (- indent (current-column))) |
| 965 |
(if (zerop shift-amt) |
| 966 |
(if (> (- (point-max) pos) (point)) |
| 967 |
(goto-char (- (point-max) pos))) |
| 968 |
(delete-region beg (point)) |
| 969 |
(indent-to indent) |
| 970 |
;; If initial point was within line's indentation, |
| 971 |
;; position after the indentation. Else stay at same point in text. |
| 972 |
(if (> (- (point-max) pos) (point)) |
| 973 |
(goto-char (- (point-max) pos)))) |
| 974 |
shift-amt)) |
| 975 |
|
| 976 |
(defun calculate-cafeobj-indent (&optional parse-start) |
| 977 |
"Return appropriate indentation for current line as CafeOBJ code. |
| 978 |
In usual case returns an integer: the column to indent to. |
| 979 |
Returns nil if line starts inside a string, t if in a comment." |
| 980 |
(save-excursion |
| 981 |
(beginning-of-line) |
| 982 |
(let ((indent-point (point)) |
| 983 |
(case-fold-search nil) |
| 984 |
state |
| 985 |
containing-sexp) |
| 986 |
(if parse-start |
| 987 |
(goto-char parse-start) |
| 988 |
(cafeobj-beginning-of-decl)) |
| 989 |
(while (< (point) indent-point) |
| 990 |
(setq parse-start (point)) |
| 991 |
(setq state (parse-partial-sexp (point) indent-point 0)) |
| 992 |
(setq containing-sexp (car (cdr state)))) |
| 993 |
;; |
| 994 |
(cond ((or (nth 3 state) (nth 4 state)) |
| 995 |
;; return nil or t if should not change this line |
| 996 |
(nth 4 state)) ; t if inside a comment, else nil. |
| 997 |
;; |
| 998 |
((null containing-sexp) ; we are at top-level |
| 999 |
;; -- TOP-LEVEL------------------------------------------------ |
| 1000 |
;; Line is at top level. May be module/view declaration or |
| 1001 |
;; top-level commands. |
| 1002 |
(goto-char indent-point) ; start from original pos. |
| 1003 |
(skip-chars-forward " \t") |
| 1004 |
(cond ((= (following-char) ?{) 0) |
| 1005 |
((looking-at cafeobj-top-decl-pat) 0) |
| 1006 |
((looking-at cafeobj-comment-pat) (current-column)) |
| 1007 |
(t |
| 1008 |
(cafeobj-backward-to-noncomment (or parse-start (point-min))) |
| 1009 |
;; Look at previous line that's at column 0 |
| 1010 |
;; to determine whether we are in top-level decl. |
| 1011 |
(let ((basic-indent |
| 1012 |
(save-excursion |
| 1013 |
(re-search-backward "^[^ \^L\t\n]" nil 'move) |
| 1014 |
(if (and (looking-at cafeobj-top-decl-pat) |
| 1015 |
(not (progn |
| 1016 |
(condition-case nil |
| 1017 |
(progn |
| 1018 |
(search-forward "\{" parse-start) |
| 1019 |
(forward-list)) |
| 1020 |
(error nil)) |
| 1021 |
(looking-at "\}")))) |
| 1022 |
cafeobj-psort-indent |
| 1023 |
0)))) |
| 1024 |
basic-indent)))) |
| 1025 |
;; NON TOPLEVEL ---------------------------------------------- |
| 1026 |
((and (/= (char-after containing-sexp) ?{) |
| 1027 |
(< (car state) 2)) |
| 1028 |
;; indent to just after the surrounding open. |
| 1029 |
(goto-char (+ 2 containing-sexp)) |
| 1030 |
(current-column)) |
| 1031 |
;; WITHIN A BRACE -------------------------------------------- |
| 1032 |
(t |
| 1033 |
(goto-char indent-point) |
| 1034 |
(if (and (not (is-cafeobj-beginning-of-statement)) |
| 1035 |
(progn (cafeobj-backward-to-noncomment containing-sexp) |
| 1036 |
(not (memq (preceding-char) |
| 1037 |
'(0 ?\, ?\} ?\{ ?\. ?\] ?\))))) |
| 1038 |
;; don't treat a line with a close-brace |
| 1039 |
;; as a continuation. It is probably the |
| 1040 |
;; end of a block. |
| 1041 |
(save-excursion |
| 1042 |
(goto-char indent-point) |
| 1043 |
(skip-chars-forward " \t") |
| 1044 |
(not (= (following-char) ?}))) |
| 1045 |
) |
| 1046 |
;; This line is continuation of preceding line's statement; |
| 1047 |
;; indent cafeobj-continued-statement-offset more than the |
| 1048 |
;; previous line of the statement. |
| 1049 |
(progn |
| 1050 |
(cafeobj-backward-to-start-of-continued-exp containing-sexp) |
| 1051 |
(+ cafeobj-continued-statement-offset (current-column) |
| 1052 |
(if (save-excursion (goto-char indent-point) |
| 1053 |
(skip-chars-forward " \t") |
| 1054 |
(eq (following-char) ?{)) |
| 1055 |
cafeobj-continued-brace-offset |
| 1056 |
0))) |
| 1057 |
;; This line starts a new statement. |
| 1058 |
;; if we are looking at a comment line, leave it as is. |
| 1059 |
(if (progn |
| 1060 |
(goto-char indent-point) |
| 1061 |
(skip-chars-forward " \t") |
| 1062 |
(looking-at cafeobj-comment-pat)) |
| 1063 |
(current-column) |
| 1064 |
(progn |
| 1065 |
;; Position following last unclosed open-brace. |
| 1066 |
(goto-char containing-sexp) |
| 1067 |
;; Is line first statement after an open-brace? |
| 1068 |
(or |
| 1069 |
;; If no, find that first statement and indent like it. |
| 1070 |
(save-excursion |
| 1071 |
(forward-char 1) |
| 1072 |
(while (progn (skip-chars-forward " \t\n") |
| 1073 |
(looking-at "--[ \t].*\\|\*\*[ \t].*")) |
| 1074 |
(forward-line 1)) |
| 1075 |
;; The first following code counts |
| 1076 |
;; if it is before the line we want to indent. |
| 1077 |
(skip-chars-forward " \t\n") |
| 1078 |
(and (< (point) indent-point) |
| 1079 |
(- (current-column) |
| 1080 |
;; If prev stmt starts with open-brace, that |
| 1081 |
;; open brace was offset by cafeobj-brace-offset. |
| 1082 |
;; Compensate to get the column where |
| 1083 |
;; an ordinary statement would start. |
| 1084 |
(if (= (following-char) ?\{) |
| 1085 |
cafeobj-brace-offset |
| 1086 |
0)) |
| 1087 |
)) |
| 1088 |
;; If no previous statement, |
| 1089 |
;; indent it relative to line brace is on. |
| 1090 |
;; For open brace in column zero, don't let statement |
| 1091 |
;; start there too. If cafeobj-indent-level is zero, |
| 1092 |
;; use cafeobj-brace-offset + |
| 1093 |
;; cafeobj-continued-statement-offset instead. |
| 1094 |
;; For open-braces not the first thing in a line, |
| 1095 |
;; add in cafeobj-brace-imaginary-offset. |
| 1096 |
(+ (if (and (bolp) (zerop cafeobj-indent-level)) |
| 1097 |
(+ cafeobj-brace-offset |
| 1098 |
cafeobj-continued-statement-offset) |
| 1099 |
cafeobj-indent-level) |
| 1100 |
;; Move back over whitespace before the openbrace. |
| 1101 |
;; If openbrace is not first nonwhite thing on the line, |
| 1102 |
;; add the cafeobj-brace-imaginary-offset. |
| 1103 |
(progn (skip-chars-backward " \t") |
| 1104 |
(if (bolp) |
| 1105 |
0 |
| 1106 |
cafeobj-brace-imaginary-offset)) |
| 1107 |
;; If the openbrace is preceded by a parenthesized exp, |
| 1108 |
;; move to the beginning of that; |
| 1109 |
;; possibly a different line |
| 1110 |
(progn |
| 1111 |
(if (memq (preceding-char) '(?\) \])) |
| 1112 |
(forward-sexp -1)) |
| 1113 |
;; Get initial indentation of the line we are on. |
| 1114 |
(current-indentation)))))))))))) |
| 1115 |
|
| 1116 |
(defun is-cafeobj-beginning-of-statement () |
| 1117 |
(save-excursion |
| 1118 |
(beginning-of-line) |
| 1119 |
(skip-chars-forward " \t") |
| 1120 |
(or (looking-at cafeobj-keyword-pat) |
| 1121 |
(looking-at cafeobj-command-pat) |
| 1122 |
(looking-at cafeobj-comment-pat)))) |
| 1123 |
|
| 1124 |
(defun cafeobj-backward-to-noncomment (lim) |
| 1125 |
(let (stop) |
| 1126 |
(while (not stop) |
| 1127 |
(skip-chars-backward " \t\n\f" lim) |
| 1128 |
(setq stop (or (<= (point) lim) |
| 1129 |
(save-excursion |
| 1130 |
(beginning-of-line) |
| 1131 |
(skip-chars-forward " \t") |
| 1132 |
(not (looking-at cafeobj-comment-pat))))) |
| 1133 |
(or stop (beginning-of-line))))) |
| 1134 |
|
| 1135 |
(defun cafeobj-backward-to-start-of-continued-exp (lim) |
| 1136 |
(if (memq (preceding-char) '(?\) ?\" ?\])) |
| 1137 |
(forward-sexp -1)) |
| 1138 |
(beginning-of-line) |
| 1139 |
(if (<= (point) lim) |
| 1140 |
(goto-char (1+ lim))) |
| 1141 |
(skip-chars-forward " \t")) |
| 1142 |
|
| 1143 |
|
| 1144 |
;;; ----------------------- |
| 1145 |
;;; RUN CafeOBJ Interpreter_____________________________________________________ |
| 1146 |
;;; and Interact with it |
| 1147 |
;;; ----------------------- |
| 1148 |
(defvar cafeobj-prompt-pattern "^[A-Za-z0-9!#$%']+> ") |
| 1149 |
|
| 1150 |
(defun cafeobj-process-mode () |
| 1151 |
(interactive) |
| 1152 |
(comint-mode) |
| 1153 |
(setq major-mode 'CafeOBJ-process-mode) |
| 1154 |
(setq mode-name "CafeOBJ process") |
| 1155 |
(make-local-variable 'comint-prompt-regexp) |
| 1156 |
;;(cond (cafeobj-xemacs-p |
| 1157 |
;; (make-local-variable 'font-lock-defaults) |
| 1158 |
;; (put 'cafeobj-process-mode 'font-lock-defaults |
| 1159 |
;; '(cafeobj-font-lock-keywords))) |
| 1160 |
;; |
| 1161 |
;; (t (set (make-local-variable 'font-lock-keywords) |
| 1162 |
;; cafeobj-font-lock-keywords))) |
| 1163 |
(setq comint-prompt-regexp cafeobj-prompt-pattern) |
| 1164 |
(setq local-abbrev-table cafeobj-mode-abbrev-table) |
| 1165 |
(comint-read-input-ring t) |
| 1166 |
) |
| 1167 |
|
| 1168 |
(defun cafeobj-start-process (name program &optional startfile &rest switches) |
| 1169 |
"Start a chaos process named NAME, running PROGRAM." |
| 1170 |
(or switches |
| 1171 |
(setq switches cafeobj-default-command-switches)) |
| 1172 |
(setq cafeobj-process-buffer (apply 'make-comint name program startfile switches)) |
| 1173 |
(setq cafeobj-process (get-buffer-process cafeobj-process-buffer)) |
| 1174 |
(save-excursion |
| 1175 |
(set-buffer cafeobj-process-buffer) |
| 1176 |
(cafeobj-process-mode) |
| 1177 |
)) |
| 1178 |
|
| 1179 |
(defun cafeobj (&rest ignore) |
| 1180 |
(interactive) |
| 1181 |
(if (and cafeobj-process |
| 1182 |
(eq (process-status cafeobj-process) 'run)) |
| 1183 |
(switch-to-buffer cafeobj-process-buffer) |
| 1184 |
(progn |
| 1185 |
(cafeobj-start-process cafeobj-default-application cafeobj-default-application) |
| 1186 |
(switch-to-buffer-other-window cafeobj-process-buffer)))) |
| 1187 |
|
| 1188 |
(defun cafeobj-kill-process () |
| 1189 |
"Kill chaos subprocess and its buffer." |
| 1190 |
(interactive) |
| 1191 |
(if cafeobj-process-buffer |
| 1192 |
(kill-buffer cafeobj-process-buffer))) |
| 1193 |
|
| 1194 |
(defun cafeobj-set-cafeobj-region-start (&optional arg) |
| 1195 |
"Set start of region for use with `cafeobj-send-cafeobj-region'." |
| 1196 |
(interactive) |
| 1197 |
(set-marker cafeobj-region-start (or arg (point)))) |
| 1198 |
|
| 1199 |
(defun cafeobj-set-cafeobj-region-end (&optional arg) |
| 1200 |
"Set end of region for use with `cafeobj-send-cafeobj-region'." |
| 1201 |
(interactive) |
| 1202 |
(set-marker cafeobj-region-end (or arg (point)))) |
| 1203 |
|
| 1204 |
(defun cafeobj-send-line () |
| 1205 |
"Send current line to chaos subprocess, found in `cafeobj-process'. |
| 1206 |
If `cafeobj-process' is nil or dead, start a new process first." |
| 1207 |
(interactive) |
| 1208 |
(let ((start (save-excursion (beginning-of-line) (point))) |
| 1209 |
(end (save-excursion (end-of-line) (point)))) |
| 1210 |
(or (and cafeobj-process |
| 1211 |
(eq (process-status cafeobj-process) 'run)) |
| 1212 |
(cafeobj-start-process cafeobj-default-application cafeobj-default-application)) |
| 1213 |
(comint-simple-send cafeobj-process (buffer-substring start end)) |
| 1214 |
(forward-line 1) |
| 1215 |
(if cafeobj-always-show |
| 1216 |
(display-buffer cafeobj-process-buffer)))) |
| 1217 |
|
| 1218 |
(defun cafeobj-send-region (start end) |
| 1219 |
"Send region to chaos subprocess." |
| 1220 |
(interactive "r") |
| 1221 |
(or (and cafeobj-process |
| 1222 |
(comint-check-proc cafeobj-process-buffer)) |
| 1223 |
(cafeobj-start-process cafeobj-default-application cafeobj-default-application)) |
| 1224 |
(comint-simple-send cafeobj-process |
| 1225 |
(concat (buffer-substring start end) "\n")) |
| 1226 |
(if cafeobj-always-show |
| 1227 |
(display-buffer cafeobj-process-buffer))) |
| 1228 |
|
| 1229 |
(defun cafeobj-send-decl () |
| 1230 |
"Send proc around point to chaos subprocess." |
| 1231 |
(interactive) |
| 1232 |
(let (beg end) |
| 1233 |
(save-excursion |
| 1234 |
(cafeobj-beginning-of-decl) |
| 1235 |
(setq beg (point)) |
| 1236 |
(cafeobj-end-of-decl) |
| 1237 |
(setq end (point))) |
| 1238 |
(or (and cafeobj-process |
| 1239 |
(comint-check-proc cafeobj-process-buffer)) |
| 1240 |
(cafeobj-start-process cafeobj-default-application cafeobj-default-application)) |
| 1241 |
(comint-simple-send cafeobj-process |
| 1242 |
(concat (buffer-substring beg end) "\n")) |
| 1243 |
(if cafeobj-always-show |
| 1244 |
(display-buffer cafeobj-process-buffer)))) |
| 1245 |
|
| 1246 |
(defun cafeobj-send-buffer () |
| 1247 |
"Send whole buffer to chaos subprocess." |
| 1248 |
(interactive) |
| 1249 |
(or (and cafeobj-process |
| 1250 |
(comint-check-proc cafeobj-process-buffer)) |
| 1251 |
(cafeobj-start-process cafeobj-default-application cafeobj-default-application)) |
| 1252 |
(if (buffer-modified-p) |
| 1253 |
(comint-simple-send cafeobj-process |
| 1254 |
(concat |
| 1255 |
(buffer-substring (point-min) (point-max)) |
| 1256 |
"\n")) |
| 1257 |
(comint-simple-send cafeobj-process |
| 1258 |
(concat "input " |
| 1259 |
(buffer-file-name) |
| 1260 |
"\n"))) |
| 1261 |
(if cafeobj-always-show |
| 1262 |
(display-buffer cafeobj-process-buffer))) |
| 1263 |
|
| 1264 |
(defun cafeobj-show-process-buffer () |
| 1265 |
"Make sure `cafeobj-process-buffer' is being displayed." |
| 1266 |
(interactive) |
| 1267 |
(display-buffer cafeobj-process-buffer)) |
| 1268 |
|
| 1269 |
(defun cafeobj-hide-process-buffer () |
| 1270 |
"Delete all windows that display `cafeobj-process-buffer'." |
| 1271 |
(interactive) |
| 1272 |
(delete-windows-on cafeobj-process-buffer)) |
| 1273 |
|
| 1274 |
;;; KB7 style commands for syntax-oriented editing of CafeOBJ constructs |
| 1275 |
;;; |
| 1276 |
|
| 1277 |
|
| 1278 |
(defvar cafeobj-kb7-indent-to " " |
| 1279 |
"tells how much to indent to, and is user settable") |
| 1280 |
|
| 1281 |
(defvar cafeobj-kb7-mark-1st-field nil |
| 1282 |
"marking the 1st field in the current template") |
| 1283 |
|
| 1284 |
(defvar cafeobj-kb7-template-markers nil |
| 1285 |
"this is a history of pairs of markers, the 1st marking the |
| 1286 |
beginning of the template, and the second the end") |
| 1287 |
|
| 1288 |
(defun modd () (interactive) |
| 1289 |
(beginning-of-line) (cafeobj-kb7-template-create "mod") |
| 1290 |
) |
| 1291 |
(defun mod! () (interactive) |
| 1292 |
(beginning-of-line) (cafeobj-kb7-template-create "mod!") |
| 1293 |
) |
| 1294 |
(defun mod* () (interactive) |
| 1295 |
(beginning-of-line) (cafeobj-kb7-template-create "mod*") |
| 1296 |
) |
| 1297 |
(defun pr () (interactive) |
| 1298 |
(beginning-of-line) (cafeobj-kb7-template-create "protecting") |
| 1299 |
) |
| 1300 |
(defun ex () (interactive) |
| 1301 |
(beginning-of-line) (cafeobj-kb7-template-create "extending") |
| 1302 |
) |
| 1303 |
(defun using () (interactive) |
| 1304 |
(beginning-of-line) (cafeobj-kb7-template-create "using") |
| 1305 |
) |
| 1306 |
(defun vsort () (interactive) |
| 1307 |
(beginning-of-line) (cafeobj-kb7-template-create "vsort") |
| 1308 |
) |
| 1309 |
(defun hsort () (interactive) |
| 1310 |
(beginning-of-line) (cafeobj-kb7-template-create "hsort") |
| 1311 |
) |
| 1312 |
(defun op () (interactive) |
| 1313 |
(beginning-of-line) (cafeobj-kb7-template-create "op") |
| 1314 |
) |
| 1315 |
(defun bop () (interactive) |
| 1316 |
(beginning-of-line) (cafeobj-kb7-template-create "bop") |
| 1317 |
) |
| 1318 |
(defun var () (interactive) |
| 1319 |
(beginning-of-line) (cafeobj-kb7-template-create "var") |
| 1320 |
) |
| 1321 |
(defun eqq () (interactive) |
| 1322 |
(beginning-of-line) (cafeobj-kb7-template-create "eq") |
| 1323 |
) |
| 1324 |
(defun cq () (interactive) |
| 1325 |
(beginning-of-line) (cafeobj-kb7-template-create "cq") |
| 1326 |
) |
| 1327 |
(defun beq () (interactive) |
| 1328 |
(beginning-of-line) (cafeobj-kb7-template-create "beq") |
| 1329 |
) |
| 1330 |
(defun trans () (interactive) |
| 1331 |
(beginning-of-line) (cafeobj-kb7-template-create "trans") |
| 1332 |
) |
| 1333 |
(defun ctrans () (interactive) |
| 1334 |
(beginning-of-line) (cafeobj-kb7-template-create "ctrans") |
| 1335 |
) |
| 1336 |
(defun bcq () (interactive) |
| 1337 |
(beginning-of-line) (cafeobj-kb7-template-create "bcq") |
| 1338 |
) |
| 1339 |
(defun btrans () (interactive) |
| 1340 |
(beginning-of-line) (cafeobj-kb7-template-create "btrans") |
| 1341 |
) |
| 1342 |
(defun view () (interactive) |
| 1343 |
(beginning-of-line) (cafeobj-kb7-template-create "view") |
| 1344 |
) |
| 1345 |
(defun make () (interactive) |
| 1346 |
(beginning-of-line) (cafeobj-kb7-template-create "make") |
| 1347 |
) |
| 1348 |
|
| 1349 |
(defun cafeobj-kb7-template-create (command) |
| 1350 |
"constructs the template corresponding to 'command' and moves the |
| 1351 |
cursor at the beginning of the 1st field of the template. It also |
| 1352 |
marks both the beginning of the template and the position immediately |
| 1353 |
after the template" |
| 1354 |
(let ( (keyword (cafeobj-kb7-keyword command)) |
| 1355 |
(cafeobj-kb7-template-beg (make-marker)) |
| 1356 |
(cafeobj-kb7-template-end (make-marker)) |
| 1357 |
) |
| 1358 |
(set-marker cafeobj-kb7-template-beg (point-marker)) |
| 1359 |
(cafeobj-kb7-intpr-schema (cafeobj-kb7-schema-create command) keyword) |
| 1360 |
(set-marker cafeobj-kb7-template-end (- (point-marker) 1)) |
| 1361 |
(cafeobj-kb7-history-join |
| 1362 |
(cafeobj-kb7-marker-pair-new cafeobj-kb7-template-beg cafeobj-kb7-template-end) |
| 1363 |
cafeobj-kb7-template-markers |
| 1364 |
) |
| 1365 |
(goto-char (1+ cafeobj-kb7-mark-1st-field)) |
| 1366 |
)) |
| 1367 |
|
| 1368 |
(defun cafeobj-kb7-keyword (command) |
| 1369 |
"gets the keyword of the respective command. this is the string from |
| 1370 |
the begining of the command to the 1st '-' " |
| 1371 |
(concat (cafeobj-kb7-kill-after-minus (append command nil))) |
| 1372 |
) |
| 1373 |
|
| 1374 |
(defun cafeobj-kb7-1st-identif (beg end) |
| 1375 |
"returns the 1st identifier of the construct delimitated by beg and end" |
| 1376 |
(let* ( (i (cafeobj-kb7-cross-blanks beg end)) |
| 1377 |
(begining-of-identifier i) |
| 1378 |
) |
| 1379 |
(setq i (cafeobj-kb7-cross-identif i)) |
| 1380 |
(buffer-substring begining-of-identifier i) |
| 1381 |
)) |
| 1382 |
|
| 1383 |
(defun cafeobj-kb7-kill-after-minus (list-of-int) |
| 1384 |
"delets the rest of the string from the 1st '-' on. the string is |
| 1385 |
represented as a list of integers representing the code of the |
| 1386 |
characters of the respective string. the result is given in the same |
| 1387 |
form of a list of integers." |
| 1388 |
(cond ( (null list-of-int) |
| 1389 |
nil |
| 1390 |
) |
| 1391 |
( (= (car list-of-int) 45) |
| 1392 |
nil |
| 1393 |
) |
| 1394 |
(t |
| 1395 |
(cons (car list-of-int) |
| 1396 |
(cafeobj-kb7-kill-after-minus (cdr list-of-int))) |
| 1397 |
) |
| 1398 |
) |
| 1399 |
) |
| 1400 |
|
| 1401 |
(defun cafeobj-kb7-schema-create (command) |
| 1402 |
"constructs the schema for the template corresponding to 'command'" |
| 1403 |
(cond ( (equal command "module") |
| 1404 |
'(keyword 2 "{" nl nl "}" nl) |
| 1405 |
) |
| 1406 |
( (equal command "mod!") |
| 1407 |
'(keyword 2 "{" nl nl "}" nl) |
| 1408 |
) |
| 1409 |
( (equal command "mod*") |
| 1410 |
'(keyword 2 "{" nl nl "}" nl) |
| 1411 |
) |
| 1412 |
( (equal command "protecting") |
| 1413 |
'(ind keyword "(" ")" nl) |
| 1414 |
) |
| 1415 |
( (equal command "extending") |
| 1416 |
'(ind keyword "(" ")" nl) |
| 1417 |
) |
| 1418 |
( (equal command "using") |
| 1419 |
'(ind keyword "(" ")" nl) |
| 1420 |
) |
| 1421 |
( (equal command "vsort") |
| 1422 |
'(ind "[" " ]" nl) |
| 1423 |
) |
| 1424 |
( (equal command "hsort") |
| 1425 |
'(ind "*[" " ]*" nl) |
| 1426 |
) |
| 1427 |
( (equal command "op") |
| 1428 |
'(ind keyword 2 ":" 2 "->" 2 nl) |
| 1429 |
) |
| 1430 |
( (equal command "bop") |
| 1431 |
'(ind keyword 2 ":" 2 "->" 2 nl) |
| 1432 |
) |
| 1433 |
( (equal command "var") |
| 1434 |
'(ind keyword 2 ":" 2 nl) |
| 1435 |
) |
| 1436 |
( (equal command "eq") |
| 1437 |
'(ind keyword 2 "=" 2 "." nl) |
| 1438 |
) |
| 1439 |
( (equal command "cq") |
| 1440 |
'(ind keyword 2 "=" 2 nl ind 3 "if" 2 "." nl) |
| 1441 |
) |
| 1442 |
( (equal command "beq") |
| 1443 |
'(ind keyword 2 "=" 2 "." nl) |
| 1444 |
) |
| 1445 |
( (equal command "trans") |
| 1446 |
'(ind keyword 2 "=>" 2 "." nl) |
| 1447 |
) |
| 1448 |
( (equal command "ctrans") |
| 1449 |
'(ind keyword 2 "=>" 2 nl ind 3 "if" 2 "." nl) |
| 1450 |
) |
| 1451 |
( (equal command "bcq") |
| 1452 |
'(ind keyword 2 "=>" 2 nl ind 3 "if" 2 "." nl) |
| 1453 |
) |
| 1454 |
( (equal command "btrans") |
| 1455 |
'(ind keyword 2 "=>" 2 "." nl) |
| 1456 |
) |
| 1457 |
( (equal command "view") |
| 1458 |
'(keyword 2 "from" 2 "to" 2 "is" nl nl "endv" nl) |
| 1459 |
) |
| 1460 |
( (equal command "make") |
| 1461 |
'(keyword 2 "is" nl nl "endm" nl) |
| 1462 |
) |
| 1463 |
(t nil) |
| 1464 |
) |
| 1465 |
) |
| 1466 |
|
| 1467 |
(defun cafeobj-kb7-intpr-schema (schema keyword) |
| 1468 |
"interprets the template schema into code printing the respective |
| 1469 |
template. After it has done so it marks the end of the template." |
| 1470 |
(if schema |
| 1471 |
(progn |
| 1472 |
(cafeobj-kb7-intpr-item (car schema) keyword) |
| 1473 |
(cafeobj-kb7-intpr-schema (cdr schema) keyword) |
| 1474 |
) |
| 1475 |
;else |
| 1476 |
nil |
| 1477 |
) |
| 1478 |
) |
| 1479 |
|
| 1480 |
(defun cafeobj-kb7-intpr-item (item keyword) |
| 1481 |
"interprets an item from a template schema as printing code. It also |
| 1482 |
marks the beginning of the keyword of the template." |
| 1483 |
(cond ( (stringp item) |
| 1484 |
(insert item) |
| 1485 |
(cond ( (equal item "[") |
| 1486 |
(setq cafeobj-kb7-mark-1st-field (point)) |
| 1487 |
) |
| 1488 |
( (equal item "*[") |
| 1489 |
(setq cafeobj-kb7-mark-1st-field (point)) |
| 1490 |
) |
| 1491 |
(t nil) |
| 1492 |
) |
| 1493 |
) |
| 1494 |
( (numberp item) |
| 1495 |
(cafeobj-kb7-indent-nr item) |
| 1496 |
) |
| 1497 |
( (equal item 'ind) |
| 1498 |
(insert cafeobj-kb7-indent-to) |
| 1499 |
) |
| 1500 |
( (equal item 'nl) |
| 1501 |
(newline) |
| 1502 |
) |
| 1503 |
( (equal item 'keyword) |
| 1504 |
(insert keyword) |
| 1505 |
(setq cafeobj-kb7-mark-1st-field (point)) |
| 1506 |
) |
| 1507 |
(t nil) |
| 1508 |
) |
| 1509 |
) |
| 1510 |
|
| 1511 |
(defun cafeobj-kb7-indent-nr (n) |
| 1512 |
"inserts n blank spaces" |
| 1513 |
(let ( (m n) |
| 1514 |
) |
| 1515 |
(while (/= m 0) (insert " ") (setq m (- m 1))) |
| 1516 |
)) |
| 1517 |
|
| 1518 |
|
| 1519 |
; This section of the code also sets up a local keymode, within which the |
| 1520 |
; TAB key can be redefined. |
| 1521 |
|
| 1522 |
(defconst cafeobj-kb7-keywords-for-TAB |
| 1523 |
'("op" "ops" |
| 1524 |
"bop" "pred" "bops" "bpred" |
| 1525 |
"imports" "protecting" "pr" |
| 1526 |
"extending" "ex" "using" "us" |
| 1527 |
"signature" "axioms" |
| 1528 |
"var" "vars" |
| 1529 |
"eq" "cq" "ceq" |
| 1530 |
"bq" "beq" "bcq" "bceq" |
| 1531 |
"trans" "trns" "ctrans" "ctrns" |
| 1532 |
"btrans" "btrns" "bctrans" "bctrns" |
| 1533 |
"class" "record" "attr" |
| 1534 |
"view" |
| 1535 |
"sort" "hsort" |
| 1536 |
"psort" "principal-sort" |
| 1537 |
"let" "red" "reduce" "input" "in" |
| 1538 |
"execute" "exec" "make" |
| 1539 |
"apply" "start" "match" |
| 1540 |
"parse" |
| 1541 |
"select" |
| 1542 |
"set" |
| 1543 |
"show" |
| 1544 |
"describe" |
| 1545 |
"sh" |
| 1546 |
"choose" "open" "close" |
| 1547 |
"desc" "eof" |
| 1548 |
"require" "provide" |
| 1549 |
"mod" "mod!" "mod*" "module" "module!" "module*" |
| 1550 |
"if" ":" "->" "=" "=>" "<" "." "[" "]" "*[" "]*" "{" "}" "(" ")") |
| 1551 |
"OBJ keywords to be found by cafeobj-kb7-scan-forward (TAB key)") |
| 1552 |
|
| 1553 |
;;; If the file is being loaded for the 1st time, cafeobj-mode-map |
| 1554 |
;;; will be nil: set it to a new keymap and define the TAB key in |
| 1555 |
;;; it. Otherwise, use the existing one. |
| 1556 |
;;; |
| 1557 |
(if cafeobj-mode-map |
| 1558 |
() |
| 1559 |
;else |
| 1560 |
(setq cafeobj-mode-map (make-sparse-keymap))) |
| 1561 |
(define-key cafeobj-mode-map "\t" 'cafeobj-kb7-scan-forward) |
| 1562 |
|
| 1563 |
(defun cafeobj-kb7-strings-to-re (strings) |
| 1564 |
"converts a list of strings into a regular expression which matches |
| 1565 |
any one of these strings preceded by space or newline and followed by |
| 1566 |
space, newline, or end-of-file." |
| 1567 |
(let ((main-re (cafeobj-kb7-strings-to-re-1 strings)) |
| 1568 |
) |
| 1569 |
(concat "\\(^\\| \\)\\(" main-re "\\)\\(\n\\|$\\| \\)" ) |
| 1570 |
)) |
| 1571 |
|
| 1572 |
|
| 1573 |
(defun cafeobj-kb7-strings-to-re-1 (strings) |
| 1574 |
"converts a list of strings s1...sn into the string |
| 1575 |
<s1>\\|<s2>...\\|<sn> ." |
| 1576 |
(mapconcat 'regexp-quote strings "\\|") |
| 1577 |
) |
| 1578 |
|
| 1579 |
|
| 1580 |
(defvar cafeobj-kb7-keywords-re nil |
| 1581 |
"Regular expression that matches the keywords") |
| 1582 |
|
| 1583 |
;;; If the file is being loaded for the 1st time, set cafeobj-kb7-keywords-re |
| 1584 |
;;; to the regular expression corresponding to cafeobj-kb7-keywords. |
| 1585 |
;;; |
| 1586 |
(if cafeobj-kb7-keywords-re |
| 1587 |
() |
| 1588 |
;else |
| 1589 |
(setq cafeobj-kb7-keywords-re |
| 1590 |
(cafeobj-kb7-strings-to-re cafeobj-kb7-keywords-for-TAB)) |
| 1591 |
) |
| 1592 |
|
| 1593 |
(defun cafeobj-kb7-scan-forward () |
| 1594 |
"searches forward for the next OBJ keyword" |
| 1595 |
(interactive) |
| 1596 |
(setq cafeobj-kb7-plural-position nil) |
| 1597 |
(if (cafeobj-kb7-var/op/bop) |
| 1598 |
(if cafeobj-kb7-plural-position |
| 1599 |
(if (< 1 (cafeobj-kb7-sorts-count cafeobj-kb7-plural-position |
| 1600 |
(point))) |
| 1601 |
(cafeobj-kb7-pluralise-1st-keyword) |
| 1602 |
;else nothing |
| 1603 |
) |
| 1604 |
;else |
| 1605 |
(cafeobj-kb7-underscores-agree-arity) |
| 1606 |
) |
| 1607 |
;else nothing |
| 1608 |
) |
| 1609 |
(re-search-forward cafeobj-kb7-keywords-re) |
| 1610 |
) |
| 1611 |
|
| 1612 |
(defvar cafeobj-kb7-beg-1st-field-current-template nil) |
| 1613 |
|
| 1614 |
(defvar cafeobj-kb7-plural-position nil |
| 1615 |
"the position of the s to be inserted for pluralisation") |
| 1616 |
|
| 1617 |
(defun cafeobj-kb7-var/op/bop () |
| 1618 |
(let* ( (position (cafeobj-kb7-position-of-current-construct)) |
| 1619 |
(beg (+ (length cafeobj-kb7-indent-to) |
| 1620 |
(cafeobj-kb7-beg-position-pair position))) |
| 1621 |
(end (cafeobj-kb7-end-position-pair position)) |
| 1622 |
(keyword (cafeobj-kb7-1st-identif beg end)) |
| 1623 |
(i (cafeobj-kb7-cross-blanks (point) end)) |
| 1624 |
) |
| 1625 |
(cond ( (null position) |
| 1626 |
nil |
| 1627 |
) |
| 1628 |
( (string-equal keyword "var") |
| 1629 |
(setq cafeobj-kb7-plural-position (+ beg (length keyword))) |
| 1630 |
(cafeobj-kb7-next-separator-is-: i) |
| 1631 |
) |
| 1632 |
( (or (string-equal keyword "op") |
| 1633 |
(string-equal keyword "bop")) |
| 1634 |
(cond ( (cafeobj-kb7-next-separator-is-: i) |
| 1635 |
(setq cafeobj-kb7-plural-position |
| 1636 |
(+ beg (length keyword))) |
| 1637 |
t |
| 1638 |
) |
| 1639 |
( (cafeobj-kb7-next-separator-is--> i) |
| 1640 |
(setq cafeobj-kb7-beg-1st-field-current-template |
| 1641 |
(+ (length keyword) beg 1)) |
| 1642 |
t |
| 1643 |
) |
| 1644 |
(t nil) |
| 1645 |
) |
| 1646 |
) |
| 1647 |
(t nil) |
| 1648 |
))) |
| 1649 |
|
| 1650 |
(defun cafeobj-kb7-next-separator-is-: (position) |
| 1651 |
(and (char-equal (char-after position) 58) |
| 1652 |
(char-equal (char-after (1+ position)) 32) |
| 1653 |
) |
| 1654 |
) |
| 1655 |
|
| 1656 |
(defun cafeobj-kb7-next-separator-is--> (position) |
| 1657 |
(and (char-equal (char-after position) 45) |
| 1658 |
(char-equal (char-after (1+ position)) 62) |
| 1659 |
) |
| 1660 |
) |
| 1661 |
|
| 1662 |
(defun cafeobj-kb7-pluralise-1st-keyword () |
| 1663 |
"appends s to 1st keyword of current construct" |
| 1664 |
(let ( (current-point (point)) |
| 1665 |
) |
| 1666 |
(goto-char cafeobj-kb7-plural-position) |
| 1667 |
(insert "s") |
| 1668 |
(goto-char (1+ current-point)) |
| 1669 |
)) |
| 1670 |
|
| 1671 |
(defun cafeobj-kb7-underscores-agree-arity () |
| 1672 |
(let* ( (underscores-count |
| 1673 |
(cafeobj-kb7-underscores-count |
| 1674 |
cafeobj-kb7-beg-1st-field-current-template)) |
| 1675 |
(nr-of-underscores (car underscores-count)) |
| 1676 |
(position-of-: (cdr underscores-count)) |
| 1677 |
) |
| 1678 |
(if (/= nr-of-underscores (cafeobj-kb7-sorts-count (1+ position-of-:) |
| 1679 |
(point))) |
| 1680 |
(princ "number of underscores doesnt agree with arity") |
| 1681 |
) |
| 1682 |
)) |
| 1683 |
|
| 1684 |
|
| 1685 |
(defun cafeobj-kb7-cross-blanks (start end) |
| 1686 |
"crosses a string of blanks starting with position start and up to |
| 1687 |
position end. It returns the 1st non-blank position after the string, |
| 1688 |
or end if it doesn't finish before end" |
| 1689 |
(let ( (i start) |
| 1690 |
) |
| 1691 |
(while (and (< i end) (char-equal (char-after i) 32)) |
| 1692 |
(setq i (1+ i)) |
| 1693 |
) |
| 1694 |
i |
| 1695 |
)) |
| 1696 |
|
| 1697 |
(defun cafeobj-kb7-cross-identif (start) |
| 1698 |
"crosses an identifier (i.e., string of non-blank characters). It returns |
| 1699 |
the 1st blank position after the identifier." |
| 1700 |
(let ( (i start) |
| 1701 |
) |
| 1702 |
(while (not (char-equal (char-after i) 32)) |
| 1703 |
(setq i (1+ i)) |
| 1704 |
) |
| 1705 |
i |
| 1706 |
)) |
| 1707 |
|
| 1708 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1709 |
(defun cafeobj-kb7-undo () |
| 1710 |
"if the cursor is within one of the templates in cafeobj-kb7-template-markers |
| 1711 |
then delete the corresponding text, and also delete the template from |
| 1712 |
cafeobj-kb7-template-markers." |
| 1713 |
(interactive) |
| 1714 |
(let ( (current-region) |
| 1715 |
) |
| 1716 |
(if (= (cafeobj-kb7-history-length cafeobj-kb7-template-markers) 0) |
| 1717 |
(princ "no template history left") |
| 1718 |
;else |
| 1719 |
(setq current-region |
| 1720 |
(cafeobj-kb7-delete-if-satisfies |
| 1721 |
'cafeobj-kb7-marker-pair-surrounds-point |
| 1722 |
cafeobj-kb7-template-markers) |
| 1723 |
) |
| 1724 |
;;; This sets current-region to the 1st marker-pair in |
| 1725 |
;;; cafeobj-kb7-history-markers which the cursor is inside, |
| 1726 |
;;; and deletes that |
| 1727 |
;;; marker-pair from cafeobj-kb7-template-markers. |
| 1728 |
;;; It will be nil if their is no such marker-pair. |
| 1729 |
|
| 1730 |
(if current-region |
| 1731 |
(delete-region (cafeobj-kb7-marker-pair-beg current-region) |
| 1732 |
(cafeobj-kb7-marker-pair-end current-region)) |
| 1733 |
;else |
| 1734 |
(princ "template not found") |
| 1735 |
) |
| 1736 |
) |
| 1737 |
) |
| 1738 |
) |
| 1739 |
|
| 1740 |
|
| 1741 |
(defun cafeobj-kb7-underscores-count (start) |
| 1742 |
"counts the number of underscores from start position to ` : '" |
| 1743 |
(let ( (p start) |
| 1744 |
(n 0) |
| 1745 |
) |
| 1746 |
(while (not (char-equal (char-after p) 58)) |
| 1747 |
(if (char-equal (char-after p) 95) |
| 1748 |
(setq n (1+ n)) |
| 1749 |
;else () |
| 1750 |
) |
| 1751 |
(setq p (1+ p)) |
| 1752 |
) |
| 1753 |
(cons n p) |
| 1754 |
)) |
| 1755 |
|
| 1756 |
(defun cafeobj-kb7-sorts-count (start end) |
| 1757 |
"counts the number of sorts appearing in the arity of an operation |
| 1758 |
declaration or in a [sub]sort declaration. The arity lies between the marker |
| 1759 |
positions start and end, and the sorts are taken to be separated by blanks" |
| 1760 |
(let ( (i start) |
| 1761 |
(f start) |
| 1762 |
(sort-count 0) |
| 1763 |
) |
| 1764 |
(while (< i end) |
| 1765 |
(setq f i) |
| 1766 |
(setq i (cafeobj-kb7-cross-identif i)) |
| 1767 |
(if (< f i) |
| 1768 |
(setq sort-count (1+ sort-count)) |
| 1769 |
) |
| 1770 |
(setq i (cafeobj-kb7-cross-blanks i end)) |
| 1771 |
) |
| 1772 |
sort-count |
| 1773 |
)) |
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1778 |
(defun cafeobj-kb7-marker-pair-new (beg end) |
| 1779 |
"returns a new marker pair <beg,end>." |
| 1780 |
(cons beg end) |
| 1781 |
) |
| 1782 |
|
| 1783 |
(defun cafeobj-kb7-marker-pair-beg (pair) |
| 1784 |
"returns the beginning marker from a pair." |
| 1785 |
(car pair) |
| 1786 |
) |
| 1787 |
|
| 1788 |
(defun cafeobj-kb7-marker-pair-end (pair) |
| 1789 |
"returns the end marker from a pair." |
| 1790 |
(cdr pair) |
| 1791 |
) |
| 1792 |
|
| 1793 |
(defun cafeobj-kb7-marker-pair-surrounds-point (pair) |
| 1794 |
"true if the cursor lies within the text represented by pair." |
| 1795 |
(if (null pair) |
| 1796 |
nil |
| 1797 |
;else |
| 1798 |
(and (<= (marker-position (car pair)) (point) ) |
| 1799 |
(< (point) (marker-position (cdr pair)) ) |
| 1800 |
) |
| 1801 |
) |
| 1802 |
) |
| 1803 |
|
| 1804 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1805 |
(defvar cafeobj-kb7-history-bound 50 |
| 1806 |
"bounds the histories. Use same bound for each at present" |
| 1807 |
) |
| 1808 |
|
| 1809 |
(defun cafeobj-kb7-history-new () |
| 1810 |
"returns a new empty history" |
| 1811 |
(cons 0 nil) |
| 1812 |
) |
| 1813 |
|
| 1814 |
(defun cafeobj-kb7-history-length (history) |
| 1815 |
"returns the length of history" |
| 1816 |
(car history) |
| 1817 |
) |
| 1818 |
|
| 1819 |
(defun cafeobj-kb7-history-join (item history) |
| 1820 |
"makes item join the history. If the history is full the element at |
| 1821 |
the front leaves the history. it returns nothing but changes the |
| 1822 |
original history as a side-effect" |
| 1823 |
(let ( (number-of-elements (car history)) |
| 1824 |
(contents (cdr history)) |
| 1825 |
) |
| 1826 |
(if (= number-of-elements cafeobj-kb7-history-bound) |
| 1827 |
(progn |
| 1828 |
(butlast contents) |
| 1829 |
(setq contents (cons item contents)) |
| 1830 |
) |
| 1831 |
;else |
| 1832 |
(setq contents (cons item contents)) |
| 1833 |
(setq number-of-elements (1+ number-of-elements)) |
| 1834 |
) |
| 1835 |
(setcdr history contents) |
| 1836 |
(setcar history number-of-elements) |
| 1837 |
) |
| 1838 |
) |
| 1839 |
|
| 1840 |
(defun cafeobj-kb7-delete-if-satisfies (pred history) |
| 1841 |
"deletes elements from history which satisfy pred" |
| 1842 |
(let ( (contents (cdr history)) |
| 1843 |
(result) |
| 1844 |
) |
| 1845 |
(if (funcall pred (car contents)) |
| 1846 |
(progn |
| 1847 |
(setq result (car contents)) |
| 1848 |
(setcdr history (cdr history)) |
| 1849 |
(setcar history (- (car history) 1)) |
| 1850 |
result |
| 1851 |
) |
| 1852 |
;else |
| 1853 |
(while (and (not (funcall pred (cadr contents))) |
| 1854 |
(cdr contents) |
| 1855 |
) |
| 1856 |
(setq contents (cdr contents)) |
| 1857 |
) |
| 1858 |
(if (null (cdr contents)) |
| 1859 |
; no element present |
| 1860 |
nil |
| 1861 |
;else |
| 1862 |
(setq result (cadr contents)) |
| 1863 |
(setcdr contents (cddr contents)) |
| 1864 |
(setcar history (- (car history) 1)) |
| 1865 |
result |
| 1866 |
) |
| 1867 |
) |
| 1868 |
) |
| 1869 |
) |
| 1870 |
|
| 1871 |
(defun cafeobj-kb7-find-marker-pair (stack-of-marker-pairs) |
| 1872 |
"finds the marker pair surrounding the point in a stack of marker pairs" |
| 1873 |
(cond ( (null stack-of-marker-pairs) |
| 1874 |
(princ "template not found") |
| 1875 |
nil |
| 1876 |
) |
| 1877 |
( (cafeobj-kb7-marker-pair-surrounds-point (car stack-of-marker-pairs)) |
| 1878 |
(car stack-of-marker-pairs) |
| 1879 |
) |
| 1880 |
(t (cafeobj-kb7-find-marker-pair (cdr stack-of-marker-pairs)) |
| 1881 |
) |
| 1882 |
)) |
| 1883 |
|
| 1884 |
(defun cafeobj-kb7-position-of-current-construct () |
| 1885 |
(let* ( (current-template-markers |
| 1886 |
(cafeobj-kb7-find-marker-pair (cdr cafeobj-kb7-template-markers))) |
| 1887 |
) |
| 1888 |
(if current-template-markers |
| 1889 |
(cons (marker-position |
| 1890 |
(cafeobj-kb7-marker-pair-beg current-template-markers)) |
| 1891 |
(marker-position |
| 1892 |
(cafeobj-kb7-marker-pair-end current-template-markers)) |
| 1893 |
) |
| 1894 |
;else nothing |
| 1895 |
) |
| 1896 |
)) |
| 1897 |
|
| 1898 |
(defun cafeobj-kb7-beg-position-pair (pair) |
| 1899 |
(car pair) |
| 1900 |
) |
| 1901 |
|
| 1902 |
(defun cafeobj-kb7-end-position-pair (pair) |
| 1903 |
(cdr pair) |
| 1904 |
) |
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
; SOME USEFUL FUNCTIONS NOT AVAILABLE IN ELISP |
| 1912 |
; -------------------------------------------- |
| 1913 |
|
| 1914 |
(defun cddr (list) |
| 1915 |
"usual lisp function" |
| 1916 |
(cdr (cdr list)) |
| 1917 |
) |
| 1918 |
|
| 1919 |
(defun cdddr (list) |
| 1920 |
"usual lisp function" |
| 1921 |
(cdr (cddr list)) |
| 1922 |
) |
| 1923 |
|
| 1924 |
(defun cadr (list) |
| 1925 |
"usual lisp function" |
| 1926 |
(car (cdr list)) |
| 1927 |
) |
| 1928 |
|
| 1929 |
(defun caar (list) |
| 1930 |
"usual lisp function" |
| 1931 |
(car (car list)) |
| 1932 |
) |
| 1933 |
|
| 1934 |
(defun cadar (list) |
| 1935 |
"usual lisp function" |
| 1936 |
(car (cdr (car list))) |
| 1937 |
) |
| 1938 |
|
| 1939 |
(defun caadr (list) |
| 1940 |
"usual lisp function" |
| 1941 |
(car (car (cdr list))) |
| 1942 |
) |
| 1943 |
|
| 1944 |
(defun cadadr (list) |
| 1945 |
"usual lisp function" |
| 1946 |
(car (cdr (car (cdr list)))) |
| 1947 |
) |
| 1948 |
|
| 1949 |
(defun butlast (list) |
| 1950 |
"removes last element in list as a side-effect, and returns nothing. |
| 1951 |
This is apparently unavailable in Elisp" |
| 1952 |
(let ( (a list) |
| 1953 |
) |
| 1954 |
(if (and a (cdr a)) |
| 1955 |
(progn |
| 1956 |
(while (cddr a) |
| 1957 |
(setq a (cdr a)) |
| 1958 |
) |
| 1959 |
(setcdr a nil) |
| 1960 |
) |
| 1961 |
;else |
| 1962 |
nil |
| 1963 |
) |
| 1964 |
) |
| 1965 |
) |
| 1966 |
|
| 1967 |
|
| 1968 |
;;; Initialisations |
| 1969 |
;;; --------------- |
| 1970 |
;;; |
| 1971 |
;;; Some variables have to be set to values returned from various ADT |
| 1972 |
;;; functions. Since this can't be done until the functions are defined, |
| 1973 |
;;; which is near the end of the file, we put the initialisations right |
| 1974 |
;;; at the end, here. |
| 1975 |
;;; |
| 1976 |
(setq cafeobj-kb7-template-markers (cafeobj-kb7-history-new)) |
| 1977 |
|
| 1978 |
|
| 1979 |
(provide 'cafeobj-mode) |
| 1980 |
|
| 1981 |
;; Local Variables: |
| 1982 |
;; folded-file: t |
| 1983 |
;; End: |
| 1984 |
|
| 1985 |
;;; cafeobj-mode.el ends here |
| 1986 |
|
| 1987 |
|