home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / pascal.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  11.3 KB  |  397 lines

  1. ;Article 517 of comp.emacs
  2. ;Path: ark1!uakari.primate.wisc.edu!ginosko!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!ucdavis!ccs015
  3. ;From: ccs015@mr-ranger.ucdavis.edu (Kambiz Aghaiepour)
  4. ;Newsgroups: comp.emacs
  5. ;Subject: Re: Pascal mode
  6. ;Message-ID: <CCS015.89Sep29192649@mr-ranger.ucdavis.edu>
  7. ;Date: 30 Sep 89 02:26:49 GMT
  8. ;References: <45ee7b24.1032a@hi-csc.UUCP>
  9. ;Sender: uucp@ucdavis.ucdavis.edu
  10. ;Reply-To: ccs015@bullwinkle.ucdavis.edu
  11. ;Distribution: na
  12. ;Organization: University of California, Davis
  13. ;Lines: 381
  14. ;In-Reply-To: foslien@hi-csc.UUCP's message of 29 Sep 89 17:59:00 GMT
  15.  
  16. ; Pascal editing support package
  17. ; Author Mick Jordan for Modula-2
  18. ; amended Peter Robinson
  19. ; ported to GNU Michael Schmidt <michael@pbinfo.uucp>
  20. ; Modified by tom Perrine <Perrin@LOGICON.ARPA> (TEP)
  21. ; analogue for pascal by Vincent Broman <broman@bugs.nosc.mil>
  22.  
  23. (setq auto-mode-alist (cons (cons "\\.p$" 'pascal-mode) auto-mode-alist))
  24. (setq auto-mode-alist (cons (cons "\\.h$" 'pascal-mode) auto-mode-alist))
  25.  
  26. ;;; Added by TEP
  27. (defvar pascal-mode-syntax-table nil
  28.   "Syntax table in use in Pascal-mode buffers.")
  29.  
  30. (if pascal-mode-syntax-table
  31.     ()
  32.   (let ((table (make-syntax-table)))
  33.     (modify-syntax-entry ?\\ "." table)
  34.     (modify-syntax-entry ?\{ "<" table)
  35.     (modify-syntax-entry ?\} ">" table)
  36.     (modify-syntax-entry ?\( "()1" table)
  37.     (modify-syntax-entry ?\) ")(4" table)
  38.     (modify-syntax-entry ?\[ "(]" table)
  39.     (modify-syntax-entry ?\] ")[" table)
  40.     (modify-syntax-entry ?* ". 23" table)
  41.     (modify-syntax-entry ?/ "." table)
  42.     (modify-syntax-entry ?+ "." table)
  43.     (modify-syntax-entry ?- "." table)
  44.     (modify-syntax-entry ?= "." table)
  45.     (modify-syntax-entry ?% "." table)
  46.     (modify-syntax-entry ?\& "." table)
  47.     (modify-syntax-entry ?\| "." table)
  48.     (modify-syntax-entry ?\$ "_" table)
  49.     (modify-syntax-entry ?< "." table)
  50.     (modify-syntax-entry ?> "." table)
  51.     (modify-syntax-entry ?\' "\"" table)
  52.     (modify-syntax-entry ?\" "\"" table)
  53.     (setq pascal-mode-syntax-table table)))
  54.  
  55. ;;; Added by TEP
  56. (defvar pascal-mode-map nil
  57.   "Keymap used in Pascal mode.")
  58.  
  59. (if pascal-mode-map ()
  60.   (let ((map (make-sparse-keymap)))
  61.     (define-key map "\C-i" 'pascal-tab)
  62.     (define-key map "\C-m" 'pascal-newline)
  63.     (define-key map "\C-cb" 'pascal-begin)
  64.     (define-key map "\C-cc" 'pascal-case)
  65.     (define-key map "\C-c\C-c" 'pascal-const)
  66.     (define-key map "\C-ce" 'pascal-else)
  67.     (define-key map "\C-cf" 'pascal-for)
  68.     (define-key map "\C-c\C-f" 'pascal-function)
  69.     (define-key map "\C-ch" 'pascal-header)
  70.     (define-key map "\C-ci" 'pascal-if)
  71.     (define-key map "\C-c\C-i" 'pascal-include)
  72.     (define-key map "\C-c\C-p" 'pascal-procedure)
  73.     (define-key map "\C-cp" 'pascal-program)
  74.     (define-key map "\C-cr" 'pascal-repeat)
  75.     (define-key map "\C-c\C-r" 'pascal-record)
  76.     (define-key map "\C-c\C-t" 'pascal-type)
  77.     (define-key map "\C-c\C-v" 'pascal-var)
  78.     (define-key map "\C-cw" 'pascal-while)
  79.     (define-key map "\C-c\C-w" 'pascal-with)
  80.     (define-key map "\C-c*" 'pascal-star-display-comment)
  81.     (define-key map "\C-c{" 'pascal-display-comment)
  82.     (define-key map "\C-c}" 'pascal-inline-comment)
  83.     (define-key map "\C-c(" 'pascal-paired-parens)
  84.     (define-key map "\C-c[" 'pascal-paired-brackets)
  85.     (define-key map "\C-ct" 'pascal-toggle)
  86.     (define-key map "\C-cL" 'pascal-link)
  87.     (define-key map "\C-cC" 'pascal-compile)
  88.     (setq pascal-mode-map map)))
  89.  
  90. (defvar pascal-indent 4 "*This variable gives the indentation in Pascal-Mode")
  91.   
  92. (defun pascal-mode ()
  93. "This is a mode intended to support program development in Pascal.
  94. Most control constructs of Pascal can be created by typing
  95. Control-C followed by the first character of the construct.
  96.  
  97. C-c p    program        C-c b    begin-end
  98. C-c C-c  const          C-c c    case-do
  99. C-c C-t  type           C-c t    toggle between .p-.h
  100. C-c C-v  var            C-c {    enter matched braces
  101. C-c C-r  record         C-c r    repeat-until
  102. C-c C-w  with-do        C-c w    while-do
  103. C-c C-i  #include       C-c i    if-then
  104. C-c C-p  procedure      C-c e    else
  105. C-c C-f  function       C-c f    for-do
  106.  
  107. \\{pascal-mode-map}
  108.  
  109. variable pascal-indent controls the number of spaces for each indentation."
  110.   (interactive)
  111.   (kill-all-local-variables)
  112.   (use-local-map pascal-mode-map)
  113.   (setq major-mode 'pascal-mode)
  114.   (setq mode-name "Pascal")
  115.   (make-local-variable 'comment-column)
  116.   (setq comment-column 41)
  117.   (make-local-variable 'end-comment-column)
  118.   (setq end-comment-column 72)
  119.   (set-syntax-table pascal-mode-syntax-table)
  120.   (make-local-variable 'paragraph-start)
  121.   (setq paragraph-start (concat "^$\\|" page-delimiter))
  122.   (make-local-variable 'paragraph-separate)
  123.   (setq paragraph-separate paragraph-start)
  124. ;  (make-local-variable 'indent-line-function)
  125. ;  (setq indent-line-function 'c-indent-line)
  126.   (make-local-variable 'require-final-newline)
  127.   (setq require-final-newline t)
  128.   (make-local-variable 'comment-start)
  129.   (setq comment-start "{\n")
  130.   (make-local-variable 'comment-end)
  131.   (setq comment-end "\n}")
  132.   (make-local-variable 'comment-column)
  133.   (setq comment-column 41)
  134.   (make-local-variable 'comment-start-skip)
  135.   (setq comment-start-skip "/\\*+ *")
  136.   (make-local-variable 'comment-indent-hook)
  137.   (setq comment-indent-hook 'c-comment-indent)
  138.   (make-local-variable 'parse-sexp-ignore-comments)
  139.   (setq parse-sexp-ignore-comments t)
  140.   (run-hooks 'pascal-mode-hook))
  141.  
  142. (defun pascal-newline ()
  143.   "Start new line and indent to current tab stop."
  144.   (interactive)
  145.   (setq cc (current-indentation))
  146.   (newline)
  147.   (indent-to cc)
  148.   )
  149.  
  150. (defun pascal-tab ()
  151.   "Indent to next tab stop."
  152.   (interactive)
  153.   (indent-to (* (1+ (/ (current-indentation) pascal-indent)) pascal-indent)))
  154.  
  155. (defun pascal-begin ()
  156.   "Insert a begin-end pair and indent for the line between."
  157.   (interactive)
  158.   (insert "begin")
  159.   (pascal-newline)
  160.   (pascal-newline)
  161.   (insert "end;")
  162.   (let ((comment (read-string "comment about block: ")))
  163.     (cond ((not (string-equal comment "")) (insert " {" comment "}"))))
  164.   (end-of-line 0))
  165.  
  166. (defun pascal-case ()
  167.   "Build skeleton case statment, prompting for the <expression>."
  168.   (interactive)
  169.   (insert "case ")
  170.   (let ((selector (read-string "selector-expr: ")))
  171.     (progn
  172.       (insert selector " of")
  173.       (pascal-newline)
  174.       (pascal-newline)
  175.       (insert "end; {case " selector "}")))
  176.   (end-of-line 0)
  177.   (pascal-tab))
  178.  
  179. (defun pascal-else ()
  180.   "Insert else keyword and indent for next line."
  181.   (interactive)
  182.   (insert "else")
  183.   (pascal-newline)
  184.   (pascal-tab))
  185.  
  186. (defun pascal-for ()
  187.   "Build skeleton for loop statment, prompting for the loop parameters."
  188.   (interactive)
  189.   (insert "for ")
  190.   (insert (read-string "init: ") " to ")
  191.   (insert (read-string "limit: ") " do")
  192.   (pascal-newline)
  193.   (pascal-tab))
  194.  
  195. (defun pascal-header ()
  196.   "Insert a comment block containing the module title, author, etc."
  197.   (interactive)
  198.   (insert "(*\n    Title: \t")
  199.   (insert (read-string "Title: "))
  200.   (insert "\n    Created:\t")
  201.   (insert (current-time-string))
  202.   (insert "\n    Author: \t")
  203.   (insert (user-full-name))
  204.   (insert (concat "\n\t\t<" (user-login-name) "@" (system-name) ">\n"))
  205.   (insert "*)\n\n"))
  206.  
  207. (defun pascal-if ()
  208.   "Insert skeleton if statment, prompting for a boolean-expression."
  209.   (interactive)
  210.   (insert "if ")
  211.   (insert (read-string "condition: ") " then")
  212.   (pascal-newline)
  213.   (pascal-tab))
  214.  
  215. (defun pascal-program ()
  216.   (interactive)
  217.   (insert "program ")
  218.   (let ((name (read-string "Program name: " )))
  219.     (insert name " (input, output")
  220.     (let ((arglist (read-string "other file vars: ")))
  221.       (cond ((not (string-equal "" arglist)) (insert ", " arglist)))
  222.       (insert ");"))
  223.     (pascal-newline)
  224.     (pascal-newline)
  225.     (insert "begin")
  226.     (pascal-newline)
  227.     (pascal-newline)
  228.     (insert "end. {")
  229.     (insert name)
  230.     (insert "}")
  231.     (end-of-line 0)
  232.     (pascal-tab)))
  233.  
  234. (defun pascal-procedure ()
  235.   (interactive)
  236.   (insert "procedure ")
  237.   (let ((name (read-string "Name: " )))
  238.     (insert name "(")
  239.     (insert (read-string "argument list: ") ");")
  240.     (pascal-newline)
  241.     (pascal-newline)
  242.     (pascal-tab)
  243.     (insert "begin")
  244.     (pascal-newline)
  245.     (pascal-newline)
  246.     (insert "end; {")
  247.     (insert name)
  248.     (insert "}")
  249.     (end-of-line 0)
  250.     (pascal-tab)))
  251.  
  252. (defun pascal-function ()
  253.   (interactive)
  254.   (insert "function ")
  255.   (let ((name (read-string "name: " )))
  256.     (insert name "(")
  257.     (insert (read-string "argument list: ") "): ")
  258.     (insert (read-string "result type: ") ";")
  259.     (pascal-newline)
  260.     (pascal-newline)
  261.     (pascal-tab)
  262.     (insert "begin")
  263.     (pascal-newline)
  264.     (pascal-newline)
  265.     (insert "end; {")
  266.     (insert name)
  267.     (insert "}")
  268.     (end-of-line 0)
  269.     (pascal-tab)))
  270.  
  271. (defun pascal-with ()
  272.   (interactive)
  273.   (insert "with ")
  274.   (insert (read-string "idents: "))
  275.   (insert " do")
  276.   (pascal-newline)
  277.   (pascal-tab))
  278.  
  279. (defun pascal-record ()
  280.   (interactive)
  281.   (insert "record")
  282.   (pascal-newline)
  283.   (pascal-newline)
  284.   (insert "end;")
  285.   (let ((comment (read-string "comment about record: ")))
  286.     (cond ((not (string-equal comment "")) (insert " {" comment "}"))))
  287.   (end-of-line 0)
  288.   (pascal-tab))
  289.  
  290. (defun pascal-type ()
  291.   (interactive)
  292.   (insert "type")
  293.   (pascal-newline)
  294.   (pascal-tab))
  295.  
  296. (defun pascal-const ()
  297.   (interactive)
  298.   (insert "const")
  299.   (pascal-newline)
  300.   (pascal-tab))
  301.  
  302. (defun pascal-repeat ()
  303.   (interactive)
  304.   (insert "repeat")
  305.   (pascal-newline)
  306.   (pascal-newline)
  307.   (insert "until ")
  308.   (insert (read-string "exit cond: ") ";")
  309.   (end-of-line 0)
  310.   (pascal-tab))
  311.  
  312. (defun pascal-var ()
  313.   (interactive)
  314.   (insert "var")
  315.   (pascal-newline)
  316.   (pascal-tab))
  317.  
  318. (defun pascal-while ()
  319.   (interactive)
  320.   (insert "while ")
  321.   (insert (read-string "entry cond: "))
  322.   (insert " do")
  323.   (pascal-newline)
  324.   (pascal-tab))
  325.  
  326. (defun pascal-include ()
  327.   (interactive)
  328.   (insert "\n#include \"")
  329.   (insert (read-string "header file: "))
  330.   (insert "\"")
  331.   (pascal-newline)
  332.   (pascal-newline))
  333.  
  334.  
  335. (defun pascal-paired-parens ()
  336.   (interactive)
  337.   (insert "()")
  338.   (backward-char))
  339.  
  340.  
  341. (defun pascal-paired-brackets ()
  342.   (interactive)
  343.   (insert "[]")
  344.   (backward-char))
  345.  
  346. (defun pascal-inline-comment ()
  347.   (interactive)
  348.   (insert "{}")
  349.   (backward-char))
  350.  
  351. (defun pascal-display-comment ()
  352. "puts comment delimiters around a blank line, making a display comment."
  353.   (interactive)
  354.   (insert "{\n\n}")
  355.   (end-of-line 0))
  356.  
  357. (defun pascal-star-display-comment ()
  358. "starts a UNIX-style display comment."
  359.   (interactive)
  360.   (insert "(*\n *\n *)")
  361.   (end-of-line 0)
  362.   (pascal-tab))
  363.  
  364. (defun pascal-compile ()
  365.   (interactive)
  366.   (setq modulename (buffer-name))
  367.   (compile (concat "pc -c " modulename)))
  368.  
  369. (defun pascal-link ()
  370.   (interactive)
  371.   (compile "make"))
  372.  
  373. ;UNUSED?
  374. ;(defun execute-monitor-command (command)
  375. ;  (let* ((shell shell-file-name)
  376. ;     (csh (equal (file-name-nondirectory shell) "csh")))
  377. ;    (call-process shell nil t t "-cf" (concat "exec " command))))
  378.  
  379. (defun pascal-toggle ()
  380.   "toggle between .p and .h files for the module."
  381.   (interactive)
  382.   (cond ((string-equal (substring (buffer-name) -2) ".h")
  383.      (find-file-other-window
  384.        (concat (substring (buffer-name) 0 -2) ".p")))
  385.     ((string-equal (substring (buffer-name) -2) ".p")
  386.      (find-file-other-window
  387.        (concat (substring (buffer-name) 0 -2)  ".h")))))
  388.  
  389.  
  390.  
  391. (put 'eval-expression 'disabled nil)
  392. ;--
  393. ;Kambiz Aghaiepour                   Internet :  ccs015@bullwinkle.ucdavis.edu
  394. ;Computing Services  -*-                 UUCP :  ucdavis!bullwinkle!ccs015, or
  395. ;University of California, Davis                 ucdavis!kaghaiepour
  396. ;Work : (916) 752-3994                 BITNET :  kaghaiepour@ucdavis.edu  
  397.