diff options
| author | Stefan Monnier | 2005-10-10 17:14:02 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-10-10 17:14:02 +0000 |
| commit | 86ac52df4968ab702ebd907393ae87d5cb1b4579 (patch) | |
| tree | 50eb835b5d58a0340eec27ec04f216b6d8f2ea10 | |
| parent | a05fcb7d84188fa404e21e3f73ac4de8d697c446 (diff) | |
| download | emacs-86ac52df4968ab702ebd907393ae87d5cb1b4579.tar.gz emacs-86ac52df4968ab702ebd907393ae87d5cb1b4579.zip | |
(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.
| -rw-r--r-- | lisp/progmodes/pascal.el | 184 |
1 files changed, 86 insertions, 98 deletions
diff --git a/lisp/progmodes/pascal.el b/lisp/progmodes/pascal.el index b84fa87a0de..3cd243580e2 100644 --- a/lisp/progmodes/pascal.el +++ b/lisp/progmodes/pascal.el | |||
| @@ -69,36 +69,34 @@ | |||
| 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)) |
| @@ -132,28 +130,31 @@ | |||
| 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 |
| @@ -327,7 +328,7 @@ Other useful functions are: | |||
| 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 | ||
| @@ -792,8 +793,7 @@ on the line which ends a function or procedure named NAME." | |||
| 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))) |
| @@ -971,7 +971,7 @@ Do not count labels, case-statements or records." | |||
| 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) |
| @@ -986,7 +986,6 @@ Do not count labels, case-statements or records." | |||
| 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 |
| @@ -999,7 +998,6 @@ Do not count labels, case-statements or records." | |||
| 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 | ||
| @@ -1490,30 +1488,20 @@ The default is a name found in the buffer around point." | |||
| 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> |
| @@ -1531,26 +1519,26 @@ Pascal Outline mode provides some additional commands. | |||
| 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." |
| @@ -1628,5 +1616,5 @@ Pascal Outline mode provides some additional commands. | |||
| 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 |