Mercurial > emacs
comparison lisp/progmodes/pascal.el @ 65981:4a74f7c2bd7b
(pascal-mode-map): Move init into declaration.
(pascal-mode-syntax-table): Make (* *) markers same class as { ... }.
(pascal-indent-command): Remove unused var `ind'.
(pascal-indent-case): Remove unused var `oldpos'.
(pascal-outline-map): Don't inherit from pascal-mode-map anymore,
since it's now used as a proper minor mode map.
(pascal-outline): Rename to pascal-outline-mode.
(pascal-outline-mode): Use define-minor-mode.
(pascal-outline-mode, pascal-outline-change): Use overlays rather than
selective-display.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 10 Oct 2005 17:14:02 +0000 |
parents | ed770a0a7846 |
children | 13abee3a9bc6 5e2d3828e89f |
comparison
equal
deleted
inserted
replaced
65980:4520ae2624f2 | 65981:4a74f7c2bd7b |
---|---|
67 | 67 |
68 (defvar pascal-mode-abbrev-table nil | 68 (defvar pascal-mode-abbrev-table nil |
69 "Abbrev table in use in Pascal-mode buffers.") | 69 "Abbrev table in use in Pascal-mode buffers.") |
70 (define-abbrev-table 'pascal-mode-abbrev-table ()) | 70 (define-abbrev-table 'pascal-mode-abbrev-table ()) |
71 | 71 |
72 (defvar pascal-mode-map () | 72 (defvar pascal-mode-map |
73 (let ((map (make-sparse-keymap))) | |
74 (define-key map ";" 'electric-pascal-semi-or-dot) | |
75 (define-key map "." 'electric-pascal-semi-or-dot) | |
76 (define-key map ":" 'electric-pascal-colon) | |
77 (define-key map "=" 'electric-pascal-equal) | |
78 (define-key map "#" 'electric-pascal-hash) | |
79 (define-key map "\r" 'electric-pascal-terminate-line) | |
80 (define-key map "\t" 'electric-pascal-tab) | |
81 (define-key map "\M-\t" 'pascal-complete-word) | |
82 (define-key map "\M-?" 'pascal-show-completions) | |
83 (define-key map "\177" 'backward-delete-char-untabify) | |
84 (define-key map "\M-\C-h" 'pascal-mark-defun) | |
85 (define-key map "\C-c\C-b" 'pascal-insert-block) | |
86 (define-key map "\M-*" 'pascal-star-comment) | |
87 (define-key map "\C-c\C-c" 'pascal-comment-area) | |
88 (define-key map "\C-c\C-u" 'pascal-uncomment-area) | |
89 (define-key map "\M-\C-a" 'pascal-beg-of-defun) | |
90 (define-key map "\M-\C-e" 'pascal-end-of-defun) | |
91 (define-key map "\C-c\C-d" 'pascal-goto-defun) | |
92 (define-key map "\C-c\C-o" 'pascal-outline-mode) | |
93 ;; A command to change the whole buffer won't be used terribly | |
94 ;; often, so no need for a key binding. | |
95 ;; (define-key map "\C-cd" 'pascal-downcase-keywords) | |
96 ;; (define-key map "\C-cu" 'pascal-upcase-keywords) | |
97 ;; (define-key map "\C-cc" 'pascal-capitalize-keywords) | |
98 map) | |
73 "Keymap used in Pascal mode.") | 99 "Keymap used in Pascal mode.") |
74 (if pascal-mode-map | |
75 () | |
76 (setq pascal-mode-map (make-sparse-keymap)) | |
77 (define-key pascal-mode-map ";" 'electric-pascal-semi-or-dot) | |
78 (define-key pascal-mode-map "." 'electric-pascal-semi-or-dot) | |
79 (define-key pascal-mode-map ":" 'electric-pascal-colon) | |
80 (define-key pascal-mode-map "=" 'electric-pascal-equal) | |
81 (define-key pascal-mode-map "#" 'electric-pascal-hash) | |
82 (define-key pascal-mode-map "\r" 'electric-pascal-terminate-line) | |
83 (define-key pascal-mode-map "\t" 'electric-pascal-tab) | |
84 (define-key pascal-mode-map "\M-\t" 'pascal-complete-word) | |
85 (define-key pascal-mode-map "\M-?" 'pascal-show-completions) | |
86 (define-key pascal-mode-map "\177" 'backward-delete-char-untabify) | |
87 (define-key pascal-mode-map "\M-\C-h" 'pascal-mark-defun) | |
88 (define-key pascal-mode-map "\C-c\C-b" 'pascal-insert-block) | |
89 (define-key pascal-mode-map "\M-*" 'pascal-star-comment) | |
90 (define-key pascal-mode-map "\C-c\C-c" 'pascal-comment-area) | |
91 (define-key pascal-mode-map "\C-c\C-u" 'pascal-uncomment-area) | |
92 (define-key pascal-mode-map "\M-\C-a" 'pascal-beg-of-defun) | |
93 (define-key pascal-mode-map "\M-\C-e" 'pascal-end-of-defun) | |
94 (define-key pascal-mode-map "\C-c\C-d" 'pascal-goto-defun) | |
95 (define-key pascal-mode-map "\C-c\C-o" 'pascal-outline) | |
96 ;;; A command to change the whole buffer won't be used terribly | |
97 ;;; often, so no need for a key binding. | |
98 ; (define-key pascal-mode-map "\C-cd" 'pascal-downcase-keywords) | |
99 ; (define-key pascal-mode-map "\C-cu" 'pascal-upcase-keywords) | |
100 ; (define-key pascal-mode-map "\C-cc" 'pascal-capitalize-keywords) | |
101 ) | |
102 | 100 |
103 (defvar pascal-imenu-generic-expression | 101 (defvar pascal-imenu-generic-expression |
104 '((nil "^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" 2)) | 102 '((nil "^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" 2)) |
105 "Imenu expression for Pascal-mode. See `imenu-generic-expression'.") | 103 "Imenu expression for Pascal-mode. See `imenu-generic-expression'.") |
106 | 104 |
130 | 128 |
131 ;;; Strings used to mark beginning and end of excluded text | 129 ;;; Strings used to mark beginning and end of excluded text |
132 (defconst pascal-exclude-str-start "{-----\\/----- EXCLUDED -----\\/-----") | 130 (defconst pascal-exclude-str-start "{-----\\/----- EXCLUDED -----\\/-----") |
133 (defconst pascal-exclude-str-end " -----/\\----- EXCLUDED -----/\\-----}") | 131 (defconst pascal-exclude-str-end " -----/\\----- EXCLUDED -----/\\-----}") |
134 | 132 |
135 (defvar pascal-mode-syntax-table nil | 133 (defvar pascal-mode-syntax-table |
134 (let ((st (make-syntax-table))) | |
135 (modify-syntax-entry ?\\ "." st) | |
136 (modify-syntax-entry ?\( "()1" st) | |
137 (modify-syntax-entry ?\) ")(4" st) | |
138 ;; This used to use comment-syntax `b'. But the only document I could | |
139 ;; find about the syntax of Pascal's comments said that (* ... } is | |
140 ;; a valid comment, just as { ... *) or (* ... *) or { ... }. | |
141 (modify-syntax-entry ?* ". 23" st) | |
142 (modify-syntax-entry ?{ "<" st) | |
143 (modify-syntax-entry ?} ">" st) | |
144 (modify-syntax-entry ?+ "." st) | |
145 (modify-syntax-entry ?- "." st) | |
146 (modify-syntax-entry ?= "." st) | |
147 (modify-syntax-entry ?% "." st) | |
148 (modify-syntax-entry ?< "." st) | |
149 (modify-syntax-entry ?> "." st) | |
150 (modify-syntax-entry ?& "." st) | |
151 (modify-syntax-entry ?| "." st) | |
152 (modify-syntax-entry ?_ "_" st) | |
153 (modify-syntax-entry ?\' "\"" st) | |
154 st) | |
136 "Syntax table in use in Pascal-mode buffers.") | 155 "Syntax table in use in Pascal-mode buffers.") |
137 | 156 |
138 (if pascal-mode-syntax-table | 157 |
139 () | |
140 (setq pascal-mode-syntax-table (make-syntax-table)) | |
141 (modify-syntax-entry ?\\ "." pascal-mode-syntax-table) | |
142 (modify-syntax-entry ?( "()1" pascal-mode-syntax-table) | |
143 (modify-syntax-entry ?) ")(4" pascal-mode-syntax-table) | |
144 (modify-syntax-entry ?* ". 23b" pascal-mode-syntax-table) | |
145 (modify-syntax-entry ?{ "<" pascal-mode-syntax-table) | |
146 (modify-syntax-entry ?} ">" pascal-mode-syntax-table) | |
147 (modify-syntax-entry ?+ "." pascal-mode-syntax-table) | |
148 (modify-syntax-entry ?- "." pascal-mode-syntax-table) | |
149 (modify-syntax-entry ?= "." pascal-mode-syntax-table) | |
150 (modify-syntax-entry ?% "." pascal-mode-syntax-table) | |
151 (modify-syntax-entry ?< "." pascal-mode-syntax-table) | |
152 (modify-syntax-entry ?> "." pascal-mode-syntax-table) | |
153 (modify-syntax-entry ?& "." pascal-mode-syntax-table) | |
154 (modify-syntax-entry ?| "." pascal-mode-syntax-table) | |
155 (modify-syntax-entry ?_ "_" pascal-mode-syntax-table) | |
156 (modify-syntax-entry ?\' "\"" pascal-mode-syntax-table)) | |
157 | 158 |
158 (defconst pascal-font-lock-keywords (purecopy | 159 (defconst pascal-font-lock-keywords (purecopy |
159 (list | 160 (list |
160 '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\([a-z]\\)" | 161 '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\([a-z]\\)" |
161 1 font-lock-keyword-face) | 162 1 font-lock-keyword-face) |
325 \\[pascal-uncomment-area]\t- Uncomment an area commented with \ | 326 \\[pascal-uncomment-area]\t- Uncomment an area commented with \ |
326 \\[pascal-comment-area]. | 327 \\[pascal-comment-area]. |
327 \\[pascal-beg-of-defun]\t- Move to beginning of current function. | 328 \\[pascal-beg-of-defun]\t- Move to beginning of current function. |
328 \\[pascal-end-of-defun]\t- Move to end of current function. | 329 \\[pascal-end-of-defun]\t- Move to end of current function. |
329 \\[pascal-goto-defun]\t- Goto function prompted for in the minibuffer. | 330 \\[pascal-goto-defun]\t- Goto function prompted for in the minibuffer. |
330 \\[pascal-outline]\t- Enter pascal-outline-mode (see also pascal-outline). | 331 \\[pascal-outline-mode]\t- Enter `pascal-outline-mode'. |
331 | 332 |
332 Variables controlling indentation/edit style: | 333 Variables controlling indentation/edit style: |
333 | 334 |
334 pascal-indent-level (default 3) | 335 pascal-indent-level (default 3) |
335 Indentation of Pascal statements with respect to containing block. | 336 Indentation of Pascal statements with respect to containing block. |
790 (unknown . ind) (string . 0) (progbeg . 0))) | 791 (unknown . ind) (string . 0) (progbeg . 0))) |
791 | 792 |
792 (defun pascal-indent-command () | 793 (defun pascal-indent-command () |
793 "Indent for special part of code." | 794 "Indent for special part of code." |
794 (let* ((indent-str (pascal-calculate-indent)) | 795 (let* ((indent-str (pascal-calculate-indent)) |
795 (type (car indent-str)) | 796 (type (car indent-str))) |
796 (ind (car (cdr indent-str)))) | |
797 (cond ((and (eq type 'paramlist) | 797 (cond ((and (eq type 'paramlist) |
798 (or (memq 'all pascal-auto-lineup) | 798 (or (memq 'all pascal-auto-lineup) |
799 (memq 'paramlist pascal-auto-lineup))) | 799 (memq 'paramlist pascal-auto-lineup))) |
800 (pascal-indent-paramlist) | 800 (pascal-indent-paramlist) |
801 (pascal-indent-paramlist)) | 801 (pascal-indent-paramlist)) |
969 (let ((savepos (point-marker)) | 969 (let ((savepos (point-marker)) |
970 (end (prog2 | 970 (end (prog2 |
971 (end-of-line) | 971 (end-of-line) |
972 (point-marker) | 972 (point-marker) |
973 (re-search-backward "\\<case\\>" nil t))) | 973 (re-search-backward "\\<case\\>" nil t))) |
974 (beg (point)) oldpos | 974 (beg (point)) |
975 (ind 0)) | 975 (ind 0)) |
976 ;; Get right indent | 976 ;; Get right indent |
977 (while (< (point) end) | 977 (while (< (point) end) |
978 (if (re-search-forward | 978 (if (re-search-forward |
979 "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" | 979 "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" |
984 (delete-horizontal-space) | 984 (delete-horizontal-space) |
985 (if (> (current-column) ind) | 985 (if (> (current-column) ind) |
986 (setq ind (current-column))) | 986 (setq ind (current-column))) |
987 (pascal-end-of-statement)))) | 987 (pascal-end-of-statement)))) |
988 (goto-char beg) | 988 (goto-char beg) |
989 (setq oldpos (marker-position end)) | |
990 ;; Indent all case statements | 989 ;; Indent all case statements |
991 (while (< (point) end) | 990 (while (< (point) end) |
992 (if (re-search-forward | 991 (if (re-search-forward |
993 "^[ \t]*[^][ \t,\\.:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" | 992 "^[ \t]*[^][ \t,\\.:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" |
994 (marker-position end) 'move) | 993 (marker-position end) 'move) |
997 (if (/= (following-char) ?:) | 996 (if (/= (following-char) ?:) |
998 () | 997 () |
999 (forward-char 1) | 998 (forward-char 1) |
1000 (delete-horizontal-space) | 999 (delete-horizontal-space) |
1001 (insert " ")) | 1000 (insert " ")) |
1002 (setq oldpos (point)) | |
1003 (pascal-end-of-statement)) | 1001 (pascal-end-of-statement)) |
1004 (goto-char savepos))) | 1002 (goto-char savepos))) |
1005 | 1003 |
1006 (defun pascal-indent-paramlist (&optional arg) | 1004 (defun pascal-indent-paramlist (&optional arg) |
1007 "Indent current line in parameterlist. | 1005 "Indent current line in parameterlist. |
1488 | 1486 |
1489 | 1487 |
1490 ;;; | 1488 ;;; |
1491 ;;; Pascal-outline-mode | 1489 ;;; Pascal-outline-mode |
1492 ;;; | 1490 ;;; |
1493 (defvar pascal-outline-map nil "Keymap used in Pascal Outline mode.") | 1491 (defvar pascal-outline-map |
1494 | 1492 (let ((map (make-sparse-keymap))) |
1495 (if pascal-outline-map | 1493 (if (fboundp 'set-keymap-name) |
1496 nil | 1494 (set-keymap-name pascal-outline-map 'pascal-outline-map)) |
1497 (if (fboundp 'set-keymap-name) | 1495 (define-key map "\M-\C-a" 'pascal-outline-prev-defun) |
1498 (set-keymap-name pascal-outline-map 'pascal-outline-map)) | 1496 (define-key map "\M-\C-e" 'pascal-outline-next-defun) |
1499 (if (fboundp 'set-keymap-parent) | 1497 (define-key map "\C-c\C-d" 'pascal-outline-goto-defun) |
1500 (set-keymap-parent (setq pascal-outline-map (make-sparse-keymap)) | 1498 (define-key map "\C-c\C-s" 'pascal-show-all) |
1501 pascal-mode-map) | 1499 (define-key map "\C-c\C-h" 'pascal-hide-other-defuns) |
1502 (setq pascal-outline-map (copy-keymap pascal-mode-map))) | 1500 map) |
1503 (define-key pascal-outline-map "\M-\C-a" 'pascal-outline-prev-defun) | 1501 "Keymap used in Pascal Outline mode.") |
1504 (define-key pascal-outline-map "\M-\C-e" 'pascal-outline-next-defun) | 1502 |
1505 (define-key pascal-outline-map "\C-c\C-d" 'pascal-outline-goto-defun) | 1503 (define-obsolete-function-alias 'pascal-outline 'pascal-outline-mode) |
1506 (define-key pascal-outline-map "\C-c\C-s" 'pascal-show-all) | 1504 (define-minor-mode pascal-outline-mode |
1507 (define-key pascal-outline-map "\C-c\C-h" 'pascal-hide-other-defuns)) | |
1508 | |
1509 (defvar pascal-outline-mode nil "Non-nil while using Pascal Outline mode.") | |
1510 (make-variable-buffer-local 'pascal-outline-mode) | |
1511 (set-default 'pascal-outline-mode nil) | |
1512 (if (not (assoc 'pascal-outline-mode minor-mode-alist)) | |
1513 (setq minor-mode-alist (append minor-mode-alist | |
1514 (list '(pascal-outline-mode " Outl"))))) | |
1515 | |
1516 (defun pascal-outline (&optional arg) | |
1517 "Outline-line minor mode for Pascal mode. | 1505 "Outline-line minor mode for Pascal mode. |
1518 When in Pascal Outline mode, portions | 1506 When in Pascal Outline mode, portions |
1519 of the text being edited may be made invisible. \\<pascal-outline-map> | 1507 of the text being edited may be made invisible. \\<pascal-outline-map> |
1520 | 1508 |
1521 Pascal Outline mode provides some additional commands. | 1509 Pascal Outline mode provides some additional commands. |
1529 \t hide all other functions. | 1517 \t hide all other functions. |
1530 \\[pascal-show-all]\t- Show the whole buffer. | 1518 \\[pascal-show-all]\t- Show the whole buffer. |
1531 \\[pascal-hide-other-defuns]\ | 1519 \\[pascal-hide-other-defuns]\ |
1532 \t- Hide everything but the current function (function under the cursor). | 1520 \t- Hide everything but the current function (function under the cursor). |
1533 \\[pascal-outline]\t- Leave pascal-outline-mode." | 1521 \\[pascal-outline]\t- Leave pascal-outline-mode." |
1534 (interactive "P") | 1522 :init-value nil :lighter " Outl" :keymap pascal-outline-map |
1535 (setq pascal-outline-mode | 1523 (add-to-invisibility-spec '(pascal . t)) |
1536 (if (null arg) (not pascal-outline-mode) t)) | 1524 (unless pascal-outline-mode |
1537 (if (fboundp 'redraw-mode-line) | 1525 (pascal-show-all))) |
1538 (redraw-mode-line)) | |
1539 (if pascal-outline-mode | |
1540 (progn | |
1541 (setq selective-display t) | |
1542 (use-local-map pascal-outline-map)) | |
1543 (progn | |
1544 (setq selective-display nil) | |
1545 (pascal-show-all) | |
1546 (use-local-map pascal-mode-map)))) | |
1547 | 1526 |
1548 (defun pascal-outline-change (b e pascal-flag) | 1527 (defun pascal-outline-change (b e pascal-flag) |
1549 (let ((modp (buffer-modified-p))) | 1528 (save-excursion |
1550 (unwind-protect | 1529 ;; This used to use selective display so the boundaries used by the |
1551 (subst-char-in-region b e (if (= pascal-flag ?\n) | 1530 ;; callers didn't have to be precise, since it just looked for \n or \^M |
1552 ?\^M ?\n) pascal-flag) | 1531 ;; and switched them. |
1553 (set-buffer-modified-p modp)))) | 1532 (goto-char b) (setq b (line-end-position)) |
1533 (goto-char e) (setq e (line-end-position))) | |
1534 (when (> e b) | |
1535 ;; We could try and optimize this in the case where the region is | |
1536 ;; already hidden. But I'm not sure it's worth the trouble. | |
1537 (remove-overlays b e 'invisible 'pascal) | |
1538 (when (eq pascal-flag ?\^M) | |
1539 (let ((ol (make-overlay b e nil t nil))) | |
1540 (overlay-put ol 'invisible 'pascal) | |
1541 (overlay-put ol 'evaporate t))))) | |
1554 | 1542 |
1555 (defun pascal-show-all () | 1543 (defun pascal-show-all () |
1556 "Show all of the text in the buffer." | 1544 "Show all of the text in the buffer." |
1557 (interactive) | 1545 (interactive) |
1558 (pascal-outline-change (point-min) (point-max) ?\n)) | 1546 (pascal-outline-change (point-min) (point-max) ?\n)) |
1626 (pascal-goto-defun) | 1614 (pascal-goto-defun) |
1627 (pascal-hide-other-defuns)) | 1615 (pascal-hide-other-defuns)) |
1628 | 1616 |
1629 (provide 'pascal) | 1617 (provide 'pascal) |
1630 | 1618 |
1631 ;;; arch-tag: 04535136-fd93-40b4-a505-c9bebdc051f5 | 1619 ;; arch-tag: 04535136-fd93-40b4-a505-c9bebdc051f5 |
1632 ;;; pascal.el ends here | 1620 ;;; pascal.el ends here |