• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/progmodes/

Lines Matching defs:pascal

0 ;;; pascal.el --- major mode for editing pascal source in Emacs
40 ;; (setq pascal-indent-level 3
41 ;; pascal-case-indent 2
42 ;; pascal-auto-newline nil
43 ;; pascal-tab-always-indent t
44 ;; pascal-auto-endcomments t
45 ;; pascal-auto-lineup '(all)
46 ;; pascal-toggle-completions nil
47 ;; pascal-type-keywords '("array" "file" "packed" "char"
49 ;; pascal-start-keywords '("begin" "end" "function" "procedure"
52 ;; pascal-separator-keywords '("downto" "else" "mod" "div" "then"))
65 (defgroup pascal nil
70 (defvar pascal-mode-abbrev-table nil
72 (define-abbrev-table 'pascal-mode-abbrev-table ())
74 (defvar pascal-mode-map
76 (define-key map ";" 'electric-pascal-semi-or-dot)
77 (define-key map "." 'electric-pascal-semi-or-dot)
78 (define-key map ":" 'electric-pascal-colon)
79 (define-key map "=" 'electric-pascal-equal)
80 (define-key map "#" 'electric-pascal-hash)
81 (define-key map "\r" 'electric-pascal-terminate-line)
82 (define-key map "\t" 'electric-pascal-tab)
83 (define-key map "\M-\t" 'pascal-complete-word)
84 (define-key map "\M-?" 'pascal-show-completions)
86 (define-key map "\M-\C-h" 'pascal-mark-defun)
87 (define-key map "\C-c\C-b" 'pascal-insert-block)
88 (define-key map "\M-*" 'pascal-star-comment)
89 (define-key map "\C-c\C-c" 'pascal-comment-area)
90 (define-key map "\C-c\C-u" 'pascal-uncomment-area)
91 (define-key map "\M-\C-a" 'pascal-beg-of-defun)
92 (define-key map "\M-\C-e" 'pascal-end-of-defun)
93 (define-key map "\C-c\C-d" 'pascal-goto-defun)
94 (define-key map "\C-c\C-o" 'pascal-outline-mode)
97 ;; (define-key map "\C-cd" 'pascal-downcase-keywords)
98 ;; (define-key map "\C-cu" 'pascal-upcase-keywords)
99 ;; (define-key map "\C-cc" 'pascal-capitalize-keywords)
103 (defvar pascal-imenu-generic-expression
107 (defvar pascal-keywords
112 ;; The following are not standard in pascal, but widely used.
119 (defconst pascal-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
120 (defconst pascal-beg-block-re "\\<\\(begin\\|case\\|record\\|repeat\\)\\>")
121 (defconst pascal-end-block-re "\\<\\(end\\|until\\)\\>")
122 (defconst pascal-declaration-re "\\<\\(const\\|label\\|type\\|var\\)\\>")
123 (defconst pascal-progbeg-re "\\<\\program\\>")
124 (defconst pascal-defun-re "\\<\\(function\\|procedure\\|program\\)\\>")
125 (defconst pascal-sub-block-re "\\<\\(if\\|else\\|for\\|while\\|with\\)\\>")
126 (defconst pascal-noindent-re "\\<\\(begin\\|end\\|until\\|else\\)\\>")
127 (defconst pascal-nosemi-re "\\<\\(begin\\|repeat\\|then\\|do\\|else\\)\\>")
128 (defconst pascal-autoindent-lines-re
132 (defconst pascal-exclude-str-start "{-----\\/----- EXCLUDED -----\\/-----")
133 (defconst pascal-exclude-str-end " -----/\\----- EXCLUDED -----/\\-----}")
135 (defvar pascal-mode-syntax-table
161 (defconst pascal-font-lock-keywords (purecopy
185 (put 'pascal-mode 'font-lock-defaults '(pascal-font-lock-keywords nil t))
187 (defcustom pascal-indent-level 3
190 :group 'pascal)
192 (defcustom pascal-case-indent 2
195 :group 'pascal)
197 (defcustom pascal-auto-newline nil
201 :group 'pascal)
203 (defcustom pascal-indent-nested-functions t
206 :group 'pascal)
208 (defcustom pascal-tab-always-indent t
213 :group 'pascal)
215 (defcustom pascal-auto-endcomments t
220 :group 'pascal)
222 (defcustom pascal-auto-lineup '(all)
234 :group 'pascal)
236 (defcustom pascal-toggle-completions nil
237 "*Non-nil means \\<pascal-mode-map>\\[pascal-complete-word] should try all possible completions one by one.
238 Repeated use of \\[pascal-complete-word] will show you all of them.
242 :group 'pascal)
244 (defcustom pascal-type-keywords
251 :group 'pascal)
253 (defcustom pascal-start-keywords
261 :group 'pascal)
263 (defcustom pascal-separator-keywords
270 :group 'pascal)
277 (defsubst pascal-get-beg-of-line (&optional arg)
282 (defsubst pascal-get-end-of-line (&optional arg)
287 (defun pascal-declaration-end ()
298 (defun pascal-declaration-beg ()
301 (re-search-backward "[:=]\\|\\<\\(type\\|var\\|label\\|const\\)\\>\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)" (pascal-get-beg-of-line 0) t))
308 (defsubst pascal-within-string ()
310 (nth 3 (parse-partial-sexp (pascal-get-beg-of-line) (point)))))
314 (defun pascal-mode ()
315 "Major mode for editing Pascal code. \\<pascal-mode-map>
318 \\[pascal-complete-word] completes the word around current point with respect \
320 \\[pascal-show-completions] shows all possible completions at this point.
324 \\[pascal-mark-defun]\t- Mark function.
325 \\[pascal-insert-block]\t- insert begin ... end;
326 \\[pascal-star-comment]\t- insert (* ... *)
327 \\[pascal-comment-area]\t- Put marked area in a comment, fixing nested comments.
328 \\[pascal-uncomment-area]\t- Uncomment an area commented with \
329 \\[pascal-comment-area].
330 \\[pascal-beg-of-defun]\t- Move to beginning of current function.
331 \\[pascal-end-of-defun]\t- Move to end of current function.
332 \\[pascal-goto-defun]\t- Goto function prompted for in the minibuffer.
333 \\[pascal-outline-mode]\t- Enter `pascal-outline-mode'.
337 pascal-indent-level (default 3)
339 pascal-case-indent (default 2)
341 pascal-auto-newline (default nil)
344 pascal-indent-nested-functions (default t)
346 pascal-tab-always-indent (default t)
349 pascal-auto-endcomments (default t)
352 pascal-auto-lineup (default t)
355 See also the user variables pascal-type-keywords, pascal-start-keywords and
356 pascal-separator-keywords.
358 Turning on Pascal mode calls the value of the variable pascal-mode-hook with
362 (use-local-map pascal-mode-map)
363 (setq major-mode 'pascal-mode)
365 (setq local-abbrev-table pascal-mode-abbrev-table)
366 (set-syntax-table pascal-mode-syntax-table)
368 (setq indent-line-function 'pascal-indent-line)
370 (setq comment-indent-function 'pascal-indent-comment)
385 (setq font-lock-defaults '(pascal-font-lock-keywords nil t))
388 (setq imenu-generic-expression pascal-imenu-generic-expression)
390 (run-mode-hooks 'pascal-mode-hook))
398 (defun electric-pascal-terminate-line ()
405 (if (looking-at pascal-autoindent-lines-re)
406 (pascal-indent-line)))
410 (pascal-indent-line)
412 (if pascal-auto-endcomments
413 (pascal-set-auto-comments))
425 (search-forward "*)" (pascal-get-end-of-line) t))))
429 (pascal-indent-line)
433 (defun electric-pascal-semi-or-dot ()
439 (pascal-indent-line))
440 (if pascal-auto-newline
441 (electric-pascal-terminate-line)))
443 (defun electric-pascal-colon ()
448 (if (pascal-within-string)
452 (pascal-indent-line))
453 (let ((pascal-tab-always-indent nil))
454 (pascal-indent-command))))
456 (defun electric-pascal-equal ()
460 (if (eq (car (pascal-calculate-indent)) 'declaration)
461 (let ((pascal-tab-always-indent nil))
462 (pascal-indent-command))))
464 (defun electric-pascal-hash ()
472 (defun electric-pascal-tab ()
476 (if (or (pascal-within-string)
480 ;; If pascal-tab-always-indent, indent the beginning of the line.
481 (if pascal-tab-always-indent
484 (pascal-indent-line))
488 (pascal-indent-line)
490 (pascal-indent-command)))
498 (defun pascal-insert-block ()
502 (electric-pascal-terminate-line)
507 (pascal-indent-line)))
509 (defun pascal-star-comment ()
512 (pascal-indent-line)
514 (electric-pascal-terminate-line)
516 (electric-pascal-terminate-line)
521 (defun pascal-mark-defun ()
522 "Mark the current pascal function (or procedure).
526 (pascal-end-of-defun)
528 (pascal-beg-of-defun)
532 (defun pascal-comment-area (start end)
537 \\[pascal-uncomment-area] to undo the commenting.
539 The commented area starts with `pascal-exclude-str-start', and ends with
540 `pascal-include-str-end'. But if you change these variables,
541 \\[pascal-uncomment-area] won't recognize the comments."
550 (insert pascal-exclude-str-end)
555 (insert pascal-exclude-str-start)
566 (defun pascal-uncomment-area ()
569 area. See also `pascal-comment-area'."
576 (setq start (progn (search-backward pascal-exclude-str-start nil t)
578 (setq end (progn (search-forward pascal-exclude-str-end nil t)
604 (defun pascal-beg-of-defun ()
608 (if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re)))
611 (reg (concat pascal-beg-block-re "\\|"
612 pascal-end-block-re "\\|"
613 pascal-defun-re)))
634 (defun pascal-end-of-defun ()
639 (if (not (looking-at pascal-defun-re))
640 (pascal-beg-of-defun))
643 (reg (concat pascal-beg-block-re "\\|"
644 pascal-end-block-re "\\|"
645 pascal-defun-re)))
666 (defun pascal-end-of-statement ()
671 (regexp (concat "\\(" pascal-beg-block-re "\\)\\|\\("
672 pascal-end-block-re "\\)")))
674 (or (looking-at pascal-beg-block-re)
685 (looking-at pascal-beg-block-re))
701 (throw 'found (pascal-end-of-statement))))))
704 (defun pascal-downcase-keywords ()
707 (pascal-change-keywords 'downcase-word))
709 (defun pascal-upcase-keywords ()
712 (pascal-change-keywords 'upcase-word))
714 (defun pascal-capitalize-keywords ()
717 (pascal-change-keywords 'capitalize-word))
720 (defun pascal-change-keywords (change-word)
723 (mapconcat 'identity pascal-keywords "\\|")
735 (defun pascal-set-auto-comments ()
746 (search-backward "{" (pascal-get-beg-of-line) t))))
747 (let ((type (car (pascal-calculate-indent))))
759 (while (not (or (looking-at pascal-defun-re) (bobp)))
761 (cond ((looking-at pascal-beg-block-re)
763 ((looking-at pascal-end-block-re)
774 (setq b (progn (pascal-beg-of-defun)
789 (defconst pascal-indent-alist
790 '((block . (+ ind pascal-indent-level))
791 (case . (+ ind pascal-case-indent))
793 (declaration . (+ ind pascal-indent-level))
794 (paramlist . (pascal-indent-paramlist t))
795 (comment . (pascal-indent-comment))
799 (defun pascal-indent-command ()
801 (let* ((indent-str (pascal-calculate-indent))
804 (or (memq 'all pascal-auto-lineup)
805 (memq 'paramlist pascal-auto-lineup)))
806 (pascal-indent-paramlist)
807 (pascal-indent-paramlist))
809 (or (memq 'all pascal-auto-lineup)
810 (memq 'declaration pascal-auto-lineup)))
811 (pascal-indent-declaration))
813 (or (memq 'all pascal-auto-lineup)
814 (memq 'case pascal-auto-lineup)))
815 (pascal-indent-case)))
819 (defun pascal-indent-line ()
821 (let* ((indent-str (pascal-calculate-indent))
830 (or (and (eq type 'declaration) (looking-at pascal-declaration-re))
834 (looking-at pascal-noindent-re)
837 (looking-at pascal-defun-re)
838 (if (and pascal-indent-nested-functions
840 (indent-to (+ ind pascal-indent-level))
843 (indent-to (eval (cdr (assoc type pascal-indent-alist))))
846 (defun pascal-calculate-indent ()
883 (looking-at pascal-progbeg-re)
889 (looking-at pascal-beg-block-re)
900 (looking-at pascal-end-block-re)
909 (and (looking-at pascal-defun-re)
929 (and (looking-at pascal-declaration-re)
940 (looking-at pascal-sub-block-re))
951 (list type (pascal-indent-level))))))
953 (defun pascal-indent-level ()
965 (defun pascal-indent-comment ()
973 (defun pascal-indent-case ()
993 (pascal-end-of-statement))))
1007 (pascal-end-of-statement))
1010 (defun pascal-indent-paramlist (&optional arg)
1018 (edpos (progn (pascal-declaration-end)
1019 (search-backward ")" (pascal-get-beg-of-line) t)
1033 (pascal-indent-declaration nil stpos edpos)))))
1035 (defun pascal-indent-declaration (&optional arg start end)
1038 (if (and (not (or arg start)) (not (pascal-declaration-beg)))
1046 (max (progn (pascal-declaration-end)
1059 (indent-to (+ arg pascal-indent-level)))
1063 (setq ind (pascal-get-lineup-indent stpos edpos lineup))
1066 (if (search-forward lineup (pascal-get-end-of-line) 'move)
1077 (pascal-indent-declaration (current-column)))
1086 (defun pascal-get-lineup-indent (b e str)
1089 (reg (concat str "\\|\\(\\<record\\>\\)\\|" pascal-defun-re)))
1093 (and (re-search-forward reg (min e (pascal-get-end-of-line 2)) 'move)
1096 (pascal-declaration-end))
1123 (defvar pascal-str nil)
1124 (defvar pascal-all nil)
1125 (defvar pascal-pred nil)
1126 (defvar pascal-buffer-to-use nil)
1127 (defvar pascal-flag nil)
1129 (defun pascal-string-diff (str1 str2)
1145 (defun pascal-func-completion (type)
1147 (if (string= pascal-str "")
1148 (setq pascal-str "[a-zA-Z_]"))
1149 (let ((pascal-str (concat (cond
1153 "\\<\\(" pascal-str "[a-zA-Z0-9_.]*\\)\\>"))
1161 (while (pascal-beg-of-defun)
1162 (if (re-search-forward pascal-str (pascal-get-end-of-line) t)
1165 (if (or (null pascal-pred)
1166 (funcall pascal-pred match))
1167 (setq pascal-all (cons match pascal-all)))))
1170 (defun pascal-get-completion-decl ()
1173 (let ((end (save-excursion (pascal-declaration-end)
1178 (if (re-search-forward "[:=]" (pascal-get-end-of-line) t)
1182 pascal-symbol-re)
1183 (pascal-get-beg-of-line) t)
1186 (if (string-match (concat "\\<" pascal-str) match)
1187 (if (or (null pascal-pred)
1188 (funcall pascal-pred match))
1189 (setq pascal-all (cons match pascal-all))))))
1190 (if (re-search-forward "\\<record\\>" (pascal-get-end-of-line) t)
1191 (pascal-declaration-end)
1194 (defun pascal-type-completion ()
1199 (while (or (pascal-beg-of-defun)
1202 (if (and (< start (prog1 (save-excursion (pascal-end-of-defun)
1210 (pascal-get-completion-decl))))))
1212 (defun pascal-var-completion ()
1217 (while (or (pascal-beg-of-defun)
1220 (if (> start (prog1 (save-excursion (pascal-end-of-defun)
1223 (if (search-forward "(" (pascal-get-end-of-line) t)
1225 (pascal-get-completion-decl))
1234 (pascal-get-completion-decl))
1239 (defun pascal-keyword-completion (keyword-list)
1242 (if (string-match (concat "\\<" pascal-str) s)
1243 (if (or (null pascal-pred)
1244 (funcall pascal-pred s))
1245 (setq pascal-all (cons s pascal-all)))))
1257 (defun pascal-completion (pascal-str pascal-pred pascal-flag)
1259 (let ((pascal-all nil))
1261 ;; within functions which use pascal-completions
1262 (set-buffer pascal-buffer-to-use)
1265 (let ((state (car (pascal-calculate-indent))))
1271 (pascal-get-beg-of-line) t))))
1273 (pascal-beg-of-defun))
1274 (pascal-type-completion)
1275 (pascal-keyword-completion pascal-type-keywords))
1281 (or (looking-at pascal-nosemi-re)
1285 (save-excursion (pascal-var-completion))
1286 (pascal-func-completion 'procedure)
1287 (pascal-keyword-completion pascal-start-keywords))
1289 (save-excursion (pascal-var-completion))
1290 (pascal-func-completion 'function)
1291 (pascal-keyword-completion pascal-separator-keywords))))
1294 (pascal-completion-response))))
1296 (defun pascal-completion-response ()
1297 (cond ((or (equal pascal-flag 'lambda) (null pascal-flag))
1299 (if (null pascal-all)
1303 (let* ((elm (cdr pascal-all))
1304 (match (car pascal-all))
1307 (if (string= match pascal-str)
1312 (if (< (setq tmp (pascal-string-diff match (car elm))) min)
1317 (if (string= (car elm) pascal-str)
1323 (if (and (equal pascal-flag 'lambda) (not (equal match 't)))
1328 (pascal-flag
1329 pascal-all)))
1331 (defvar pascal-last-word-numb 0)
1332 (defvar pascal-last-word-shown nil)
1333 (defvar pascal-last-completions nil)
1335 (defun pascal-complete-word ()
1337 \(See also `pascal-toggle-completions', `pascal-type-keywords',
1338 `pascal-start-keywords' and `pascal-separator-keywords'.)"
1342 (pascal-str (buffer-substring b e))
1343 ;; The following variable is used in pascal-completion
1344 (pascal-buffer-to-use (current-buffer))
1345 (allcomp (if (and pascal-toggle-completions
1346 (string= pascal-last-word-shown pascal-str))
1347 pascal-last-completions
1348 (all-completions pascal-str 'pascal-completion)))
1349 (match (if pascal-toggle-completions
1351 pascal-str (mapcar '(lambda (elm)
1357 (if pascal-toggle-completions
1360 (setq pascal-last-completions allcomp
1361 pascal-last-word-numb
1362 (if (>= pascal-last-word-numb (1- (length allcomp)))
1364 (1+ pascal-last-word-numb)))
1365 (setq pascal-last-word-shown (elt allcomp pascal-last-word-numb))
1368 (insert "" pascal-last-word-shown)
1369 (insert "" pascal-str)
1375 (progn (insert "" pascal-str)
1385 ((and (not (null (cdr allcomp))) (= (length pascal-str)
1388 (display-completion-list allcomp pascal-str))
1394 (defun pascal-show-completions ()
1399 (pascal-str (buffer-substring b e))
1400 ;; The following variable is used in pascal-completion
1401 (pascal-buffer-to-use (current-buffer))
1402 (allcomp (if (and pascal-toggle-completions
1403 (string= pascal-last-word-shown pascal-str))
1404 pascal-last-completions
1405 (all-completions pascal-str 'pascal-completion))))
1408 (display-completion-list allcomp pascal-str))
1414 (defun pascal-get-default-symbol ()
1425 (defun pascal-build-defun-re (str &optional arg)
1441 (defun pascal-comp-defun (pascal-str pascal-pred pascal-flag)
1443 (let ((pascal-all nil)
1447 ;; within functions which use pascal-completions
1448 (set-buffer pascal-buffer-to-use)
1450 (let ((pascal-str pascal-str))
1452 (if (string= pascal-str "")
1453 (setq pascal-str (pascal-build-defun-re "[a-zA-Z_]"))
1454 (setq pascal-str (pascal-build-defun-re pascal-str)))
1458 (while (re-search-forward pascal-str nil t)
1460 (if (or (null pascal-pred)
1461 (funcall pascal-pred match))
1462 (setq pascal-all (cons match pascal-all)))))
1465 (pascal-completion-response))))
1467 (defun pascal-goto-defun ()
1471 (let* ((default (pascal-get-default-symbol))
1472 ;; The following variable is used in pascal-comp-function
1473 (pascal-buffer-to-use (current-buffer))
1474 (default (if (pascal-comp-defun default nil 'lambda)
1479 'pascal-comp-defun nil t "")
1482 'pascal-comp-defun nil t ""))))
1490 (re-search-forward (pascal-build-defun-re label t))
1499 (defvar pascal-outline-map
1502 (set-keymap-name pascal-outline-map 'pascal-outline-map))
1503 (define-key map "\M-\C-a" 'pascal-outline-prev-defun)
1504 (define-key map "\M-\C-e" 'pascal-outline-next-defun)
1505 (define-key map "\C-c\C-d" 'pascal-outline-goto-defun)
1506 (define-key map "\C-c\C-s" 'pascal-show-all)
1507 (define-key map "\C-c\C-h" 'pascal-hide-other-defuns)
1511 (define-obsolete-function-alias 'pascal-outline 'pascal-outline-mode)
1512 (define-minor-mode pascal-outline-mode
1515 of the text being edited may be made invisible. \\<pascal-outline-map>
1519 \\[pascal-outline-prev-defun]\
1521 \\[pascal-outline-next-defun]\
1523 \\[pascal-outline-goto-defun]\
1526 \\[pascal-show-all]\t- Show the whole buffer.
1527 \\[pascal-hide-other-defuns]\
1529 \\[pascal-outline]\t- Leave pascal-outline-mode."
1530 :init-value nil :lighter " Outl" :keymap pascal-outline-map
1531 (add-to-invisibility-spec '(pascal . t))
1532 (unless pascal-outline-mode
1533 (pascal-show-all)))
1535 (defun pascal-outline-change (b e pascal-flag)
1545 (remove-overlays b e 'invisible 'pascal)
1546 (when (eq pascal-flag ?\^M)
1548 (overlay-put ol 'invisible 'pascal)
1551 (defun pascal-show-all ()
1554 (pascal-outline-change (point-min) (point-max) ?\n))
1556 (defun pascal-hide-other-defuns ()
1561 (pascal-beg-of-defun))
1563 (end (progn (pascal-end-of-defun)
1572 (pascal-outline-change opoint (1- (match-beginning 0)) ?\^M)
1575 (if (> (progn (pascal-end-of-defun) (point)) beg)
1578 (pascal-outline-change opoint (1- beg) ?\^M))
1581 (pascal-outline-change beg end ?\n)
1586 (pascal-end-of-defun)
1587 (pascal-outline-change opoint (point) ?\^M))
1594 (pascal-outline-change opoint (1- (match-beginning 0)) ?\^M)
1596 (pascal-end-of-defun))
1597 (pascal-outline-change opoint (point-max) ?\^M)
1603 (pascal-end-of-defun)
1605 (pascal-outline-change (point) (point-max) ?\^M))))))
1607 (defun pascal-outline-next-defun ()
1610 (pascal-end-of-defun)
1611 (pascal-hide-other-defuns))
1613 (defun pascal-outline-prev-defun ()
1616 (pascal-beg-of-defun)
1617 (pascal-hide-other-defuns))
1619 (defun pascal-outline-goto-defun ()
1622 (pascal-goto-defun)
1623 (pascal-hide-other-defuns))
1625 (provide 'pascal)
1628 ;;; pascal.el ends here