diff options
| author | Stefan Monnier | 2013-01-30 20:58:24 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2013-01-30 20:58:24 -0500 |
| commit | c4f268a1373f4f247e22e103a8655e06c7129c22 (patch) | |
| tree | a14c0837f11315f0d7d7d55e3346422e756f3aa0 | |
| parent | 9ca243c631deac62bbfa9d39df4a715e6e134aeb (diff) | |
| download | emacs-c4f268a1373f4f247e22e103a8655e06c7129c22.tar.gz emacs-c4f268a1373f4f247e22e103a8655e06c7129c22.zip | |
* lisp/progmodes/opascal.el: Rename from delphi.el. Use lexical-binding.
(opascal-newline-always-indents): Remove custom.
(opascal-tab, opascal-newline): Remove commands.
(opascal-new-comment-line): Insert "\n" instead of calling newline.
(opascal-mode-map): Keep default bindings for RET and TAB and DEL.
(opascal-save-match-data): Remove, use save-match-data instead.
(opascal-save-state): Use with-silent-modifications.
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/progmodes/opascal.el (renamed from lisp/progmodes/delphi.el) | 1563 | ||||
| -rw-r--r-- | test/indent/pascal.pas | 2 |
4 files changed, 761 insertions, 818 deletions
| @@ -71,6 +71,12 @@ bound to <f11> and M-<f10>, respectively. | |||
| 71 | 71 | ||
| 72 | * Changes in Specialized Modes and Packages in Emacs 24.4 | 72 | * Changes in Specialized Modes and Packages in Emacs 24.4 |
| 73 | 73 | ||
| 74 | ** Delphi mode is now called OPascal mode. | ||
| 75 | *** All delphi-* variables and functions have been renamed to opascal-*. | ||
| 76 | *** `delphi-newline-always-indents' is not supported any more | ||
| 77 | use `electric-indent-mode' instead. | ||
| 78 | *** `delphi-tab' is gone, replaced by `indent-for-tab-command'. | ||
| 79 | |||
| 74 | ** jit-lock-debug-mode lets you use the debuggers on code run via jit-lock. | 80 | ** jit-lock-debug-mode lets you use the debuggers on code run via jit-lock. |
| 75 | 81 | ||
| 76 | ** completing-read-multiple's separator can now be a regexp. | 82 | ** completing-read-multiple's separator can now be a regexp. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e71240efd97..fff6e772c42 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2013-01-31 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2013-01-31 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * progmodes/opascal.el: Rename from delphi.el. Use lexical-binding. | ||
| 4 | (opascal-newline-always-indents): Remove custom. | ||
| 5 | (opascal-tab, opascal-newline): Remove commands. | ||
| 6 | (opascal-new-comment-line): Insert "\n" instead of calling newline. | ||
| 7 | (opascal-mode-map): Keep default bindings for RET and TAB and DEL. | ||
| 8 | (opascal-save-match-data): Remove, use save-match-data instead. | ||
| 9 | (opascal-save-state): Use with-silent-modifications. | ||
| 10 | |||
| 3 | * progmodes/pascal.el (pascal-mode-syntax-table): Accept //..\n comments | 11 | * progmodes/pascal.el (pascal-mode-syntax-table): Accept //..\n comments |
| 4 | (bug#13585). | 12 | (bug#13585). |
| 5 | 13 | ||
diff --git a/lisp/progmodes/delphi.el b/lisp/progmodes/opascal.el index 85cdaa06322..5f78b770936 100644 --- a/lisp/progmodes/delphi.el +++ b/lisp/progmodes/opascal.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs | 1 | ;;; opascal.el --- major mode for editing Object Pascal source in Emacs -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998-1999, 2001-2013 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998-1999, 2001-2013 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -24,74 +24,55 @@ | |||
| 24 | 24 | ||
| 25 | ;;; Commentary: | 25 | ;;; Commentary: |
| 26 | 26 | ||
| 27 | ;; To enter Delphi mode when you find a Delphi source file, one must override | 27 | ;; To enter OPascal mode when you find an Object Pascal source file, one must |
| 28 | ;; the auto-mode-alist to associate Delphi with .pas (and .dpr and .dpk) | 28 | ;; override the auto-mode-alist to associate OPascal with .pas (and .dpr and |
| 29 | ;; files. Emacs, by default, will otherwise enter Pascal mode. E.g. | 29 | ;; .dpk) files. Emacs, by default, will otherwise enter Pascal mode. E.g. |
| 30 | ;; | 30 | ;; |
| 31 | ;; (autoload 'delphi-mode "delphi") | 31 | ;; (autoload 'opascal-mode "opascal") |
| 32 | ;; (setq auto-mode-alist | 32 | ;; (add-to-list 'auto-mode-alist |
| 33 | ;; (cons '("\\.\\(pas\\|dpr\\|dpk\\)$" . delphi-mode) auto-mode-alist)) | 33 | ;; '("\\.\\(pas\\|dpr\\|dpk\\)\\'" . opascal-mode)) |
| 34 | 34 | ||
| 35 | ;; To get keyword, comment, and string literal coloring, be sure that font-lock | 35 | ;; When you have entered OPascal mode, you may get more info by pressing |
| 36 | ;; is running. One can manually do M-x font-lock-mode in a Delphi buffer, or | ||
| 37 | ;; one can put in .emacs: | ||
| 38 | ;; | ||
| 39 | ;; (add-hook 'delphi-mode-hook 'turn-on-font-lock) | ||
| 40 | |||
| 41 | ;; If font-lock is not loaded by default, you might have to do: | ||
| 42 | ;; | ||
| 43 | ;; (autoload 'font-lock-mode "font-lock") | ||
| 44 | ;; (autoload 'turn-on-font-lock "font-lock") | ||
| 45 | ;; (setq font-lock-support-mode 'lazy-lock-mode) | ||
| 46 | ;; | ||
| 47 | ;; Lazy lock is very necessary for faster screen updates. | ||
| 48 | |||
| 49 | ;; For good performance, be sure to byte-compile delphi.el, e.g. | ||
| 50 | ;; | ||
| 51 | ;; M-x byte-compile-file <give the path to delphi.el when prompted> | ||
| 52 | |||
| 53 | ;; This will generate delphi.elc, which will be loaded instead of delphi.el | ||
| 54 | ;; when delphi-mode is autoloaded. | ||
| 55 | |||
| 56 | ;; When you have entered Delphi mode, you may get more info by pressing | ||
| 57 | ;; C-h m. | 36 | ;; C-h m. |
| 58 | 37 | ||
| 59 | ;; This Delphi mode implementation is fairly tolerant of syntax errors, relying | 38 | ;; This OPascal mode implementation is fairly tolerant of syntax errors, |
| 60 | ;; as much as possible on the indentation of the previous statement. This also | 39 | ;; relying as much as possible on the indentation of the previous statement. |
| 61 | ;; makes it faster and simpler, since there is less searching for properly | 40 | ;; This also makes it faster and simpler, since there is less searching for |
| 62 | ;; constructed beginnings. | 41 | ;; properly constructed beginnings. |
| 63 | 42 | ||
| 64 | ;;; Code: | 43 | ;;; Code: |
| 65 | 44 | ||
| 66 | (provide 'delphi) | 45 | (defgroup opascal nil |
| 67 | 46 | "Major mode for editing OPascal source in Emacs." | |
| 68 | (defgroup delphi nil | 47 | :version "24.4" |
| 69 | "Major mode for editing Delphi source in Emacs." | ||
| 70 | :version "21.1" | ||
| 71 | :group 'languages) | 48 | :group 'languages) |
| 72 | 49 | ||
| 73 | (defconst delphi-debug nil | 50 | (defconst opascal-debug nil |
| 74 | "True if in debug mode.") | 51 | "True if in debug mode.") |
| 75 | 52 | ||
| 76 | (defcustom delphi-search-path "." | 53 | (define-obsolete-variable-alias |
| 54 | 'delphi-search-path 'opascal-search-path "24.4") | ||
| 55 | (defcustom opascal-search-path "." | ||
| 77 | "Directories to search when finding external units. | 56 | "Directories to search when finding external units. |
| 78 | It is a list of directory strings. If only a single directory, | 57 | It is a list of directory strings. If only a single directory, |
| 79 | it can be a single string instead of a list. If a directory | 58 | it can be a single string instead of a list. If a directory |
| 80 | ends in \"...\" then that directory is recursively searched." | 59 | ends in \"...\" then that directory is recursively searched." |
| 81 | :type 'string | 60 | :type 'string) |
| 82 | :group 'delphi) | ||
| 83 | 61 | ||
| 84 | (defcustom delphi-indent-level 3 | 62 | (define-obsolete-variable-alias |
| 85 | "Indentation of Delphi statements with respect to containing block. | 63 | 'delphi-indent-level 'opascal-indent-level "24.4") |
| 64 | (defcustom opascal-indent-level 3 | ||
| 65 | "Indentation of OPascal statements with respect to containing block. | ||
| 86 | E.g. | 66 | E.g. |
| 87 | 67 | ||
| 88 | begin | 68 | begin |
| 89 | // This is an indent of 3. | 69 | // This is an indent of 3. |
| 90 | end;" | 70 | end;" |
| 91 | :type 'integer | 71 | :type 'integer) |
| 92 | :group 'delphi) | ||
| 93 | 72 | ||
| 94 | (defcustom delphi-compound-block-indent 0 | 73 | (define-obsolete-variable-alias |
| 74 | 'delphi-compound-block-indent 'opascal-compound-block-indent "24.4") | ||
| 75 | (defcustom opascal-compound-block-indent 0 | ||
| 95 | "Extra indentation for blocks in compound statements. E.g. | 76 | "Extra indentation for blocks in compound statements. E.g. |
| 96 | 77 | ||
| 97 | // block indent = 0 vs // block indent = 2 | 78 | // block indent = 0 vs // block indent = 2 |
| @@ -101,10 +82,11 @@ end else begin end | |||
| 101 | end; else | 82 | end; else |
| 102 | begin | 83 | begin |
| 103 | end;" | 84 | end;" |
| 104 | :type 'integer | 85 | :type 'integer) |
| 105 | :group 'delphi) | ||
| 106 | 86 | ||
| 107 | (defcustom delphi-case-label-indent delphi-indent-level | 87 | (define-obsolete-variable-alias |
| 88 | 'delphi-case-label-indent 'opascal-case-label-indent "24.4") | ||
| 89 | (defcustom opascal-case-label-indent opascal-indent-level | ||
| 108 | "Extra indentation for case statement labels. E.g. | 90 | "Extra indentation for case statement labels. E.g. |
| 109 | 91 | ||
| 110 | // case indent = 0 vs // case indent = 3 | 92 | // case indent = 0 vs // case indent = 3 |
| @@ -114,58 +96,52 @@ v2: process_v2; v2: process_v2; | |||
| 114 | else else | 96 | else else |
| 115 | process_else; process_else; | 97 | process_else; process_else; |
| 116 | end; end;" | 98 | end; end;" |
| 117 | :type 'integer | 99 | :type 'integer) |
| 118 | :group 'delphi) | ||
| 119 | 100 | ||
| 120 | (defcustom delphi-verbose t ; nil | 101 | (define-obsolete-variable-alias 'delphi-verbose 'opascal-verbose "24.4") |
| 121 | "If true then Delphi token processing progress is reported to the user." | 102 | (defcustom opascal-verbose t ; nil |
| 122 | :type 'boolean | 103 | "If true then OPascal token processing progress is reported to the user." |
| 123 | :group 'delphi) | 104 | :type 'boolean) |
| 124 | 105 | ||
| 125 | (defcustom delphi-tab-always-indents t | 106 | (define-obsolete-variable-alias |
| 126 | "Non-nil means TAB in Delphi mode should always reindent the current line, | 107 | 'delphi-tab-always-indents 'opascal-tab-always-indents "24.4") |
| 108 | (defcustom opascal-tab-always-indents tab-always-indent | ||
| 109 | "Non-nil means TAB in OPascal mode should always reindent the current line, | ||
| 127 | regardless of where in the line point is when the TAB command is used." | 110 | regardless of where in the line point is when the TAB command is used." |
| 128 | :type 'boolean | 111 | :type 'boolean) |
| 129 | :group 'delphi) | 112 | |
| 130 | 113 | (define-obsolete-variable-alias | |
| 131 | (defcustom delphi-newline-always-indents t | 114 | 'delphi-comment-face 'opascal-comment-face "24.4") |
| 132 | "Non-nil means NEWLINE in Delphi mode should always reindent the current | 115 | (defcustom opascal-comment-face 'font-lock-comment-face |
| 133 | line, insert a blank line and move to the default indent column of the blank | 116 | "Face used to color OPascal comments." |
| 134 | line. If nil, then no indentation occurs, and NEWLINE does the usual | 117 | :type 'face) |
| 135 | behavior. This is useful when one needs to do customized indentation that | 118 | |
| 136 | differs from the default." | 119 | (define-obsolete-variable-alias |
| 137 | :type 'boolean | 120 | 'delphi-string-face 'opascal-string-face "24.4") |
| 138 | :group 'delphi) | 121 | (defcustom opascal-string-face 'font-lock-string-face |
| 139 | 122 | "Face used to color OPascal strings." | |
| 140 | (defcustom delphi-comment-face 'font-lock-comment-face | 123 | :type 'face) |
| 141 | "Face used to color Delphi comments." | 124 | |
| 142 | :type 'face | 125 | (define-obsolete-variable-alias |
| 143 | :group 'delphi) | 126 | 'delphi-keyword-face 'opascal-keyword-face "24.4") |
| 144 | 127 | (defcustom opascal-keyword-face 'font-lock-keyword-face | |
| 145 | (defcustom delphi-string-face 'font-lock-string-face | 128 | "Face used to color OPascal keywords." |
| 146 | "Face used to color Delphi strings." | 129 | :type 'face) |
| 147 | :type 'face | 130 | |
| 148 | :group 'delphi) | 131 | (define-obsolete-variable-alias 'delphi-other-face 'opascal-other-face "24.4") |
| 149 | 132 | (defcustom opascal-other-face nil | |
| 150 | (defcustom delphi-keyword-face 'font-lock-keyword-face | ||
| 151 | "Face used to color Delphi keywords." | ||
| 152 | :type 'face | ||
| 153 | :group 'delphi) | ||
| 154 | |||
| 155 | (defcustom delphi-other-face nil | ||
| 156 | "Face used to color everything else." | 133 | "Face used to color everything else." |
| 157 | :type '(choice (const :tag "None" nil) face) | 134 | :type '(choice (const :tag "None" nil) face)) |
| 158 | :group 'delphi) | ||
| 159 | 135 | ||
| 160 | (defconst delphi-directives | 136 | (defconst opascal-directives |
| 161 | '(absolute abstract assembler automated cdecl default dispid dynamic | 137 | '(absolute abstract assembler automated cdecl default dispid dynamic |
| 162 | export external far forward index inline message name near nodefault | 138 | export external far forward index inline message name near nodefault |
| 163 | overload override pascal private protected public published read readonly | 139 | overload override pascal private protected public published read readonly |
| 164 | register reintroduce resident resourcestring safecall stdcall stored | 140 | register reintroduce resident resourcestring safecall stdcall stored |
| 165 | virtual write writeonly) | 141 | virtual write writeonly) |
| 166 | "Delphi4 directives.") | 142 | "OPascal4 directives.") |
| 167 | 143 | ||
| 168 | (defconst delphi-keywords | 144 | (defconst opascal-keywords |
| 169 | (append | 145 | (append |
| 170 | '(;; Keywords. | 146 | '(;; Keywords. |
| 171 | and array as asm at begin case class const constructor contains | 147 | and array as asm at begin case class const constructor contains |
| @@ -180,261 +156,241 @@ differs from the default." | |||
| 180 | break exit) | 156 | break exit) |
| 181 | 157 | ||
| 182 | ;; We want directives to look like keywords. | 158 | ;; We want directives to look like keywords. |
| 183 | delphi-directives) | 159 | opascal-directives) |
| 184 | "Delphi4 keywords.") | 160 | "OPascal4 keywords.") |
| 185 | 161 | ||
| 186 | (defconst delphi-previous-terminators `(semicolon comma) | 162 | (defconst opascal-previous-terminators `(semicolon comma) |
| 187 | "Expression/statement terminators that denote a previous expression.") | 163 | "Expression/statement terminators that denote a previous expression.") |
| 188 | 164 | ||
| 189 | (defconst delphi-comments | 165 | (defconst opascal-comments |
| 190 | '(comment-single-line comment-multi-line-1 comment-multi-line-2) | 166 | '(comment-single-line comment-multi-line-1 comment-multi-line-2) |
| 191 | "Tokens that represent comments.") | 167 | "Tokens that represent comments.") |
| 192 | 168 | ||
| 193 | (defconst delphi-strings | 169 | (defconst opascal-strings |
| 194 | '(string double-quoted-string) | 170 | '(string double-quoted-string) |
| 195 | "Tokens that represent string literals.") | 171 | "Tokens that represent string literals.") |
| 196 | 172 | ||
| 197 | (defconst delphi-whitespace `(space newline ,@delphi-comments) | 173 | (defconst opascal-whitespace `(space newline ,@opascal-comments) |
| 198 | "Tokens that are considered whitespace.") | 174 | "Tokens that are considered whitespace.") |
| 199 | 175 | ||
| 200 | (defconst delphi-routine-statements | 176 | (defconst opascal-routine-statements |
| 201 | '(procedure function constructor destructor property) | 177 | '(procedure function constructor destructor property) |
| 202 | "Marks the start of a routine, or routine-ish looking expression.") | 178 | "Marks the start of a routine, or routine-ish looking expression.") |
| 203 | 179 | ||
| 204 | (defconst delphi-body-expr-statements '(if while for on) | 180 | (defconst opascal-body-expr-statements '(if while for on) |
| 205 | "Statements that have either a single statement or a block as a body and also | 181 | "Statements that have either a single statement or a block as a body and also |
| 206 | are followed by an expression.") | 182 | are followed by an expression.") |
| 207 | 183 | ||
| 208 | (defconst delphi-expr-statements `(case ,@delphi-body-expr-statements) | 184 | (defconst opascal-expr-statements `(case ,@opascal-body-expr-statements) |
| 209 | "Expression statements contain expressions after their keyword.") | 185 | "Expression statements contain expressions after their keyword.") |
| 210 | 186 | ||
| 211 | (defconst delphi-body-statements `(else ,@delphi-body-expr-statements) | 187 | (defconst opascal-body-statements `(else ,@opascal-body-expr-statements) |
| 212 | "Statements that have either a single statement or a block as a body.") | 188 | "Statements that have either a single statement or a block as a body.") |
| 213 | 189 | ||
| 214 | (defconst delphi-expr-delimiters '(then do of) | 190 | (defconst opascal-expr-delimiters '(then do of) |
| 215 | "Expression delimiter tokens.") | 191 | "Expression delimiter tokens.") |
| 216 | 192 | ||
| 217 | (defconst delphi-binary-ops | 193 | (defconst opascal-binary-ops |
| 218 | '(plus minus equals not-equals times divides div mod and or xor) | 194 | '(plus minus equals not-equals times divides div mod and or xor) |
| 219 | "Delphi binary operations.") | 195 | "OPascal binary operations.") |
| 220 | 196 | ||
| 221 | (defconst delphi-visibilities '(public private protected published automated) | 197 | (defconst opascal-visibilities '(public private protected published automated) |
| 222 | "Class visibilities.") | 198 | "Class visibilities.") |
| 223 | 199 | ||
| 224 | (defconst delphi-block-statements | 200 | (defconst opascal-block-statements |
| 225 | '(begin try case repeat initialization finalization asm) | 201 | '(begin try case repeat initialization finalization asm) |
| 226 | "Statements that contain multiple substatements.") | 202 | "Statements that contain multiple substatements.") |
| 227 | 203 | ||
| 228 | (defconst delphi-mid-block-statements | 204 | (defconst opascal-mid-block-statements |
| 229 | `(except finally ,@delphi-visibilities) | 205 | `(except finally ,@opascal-visibilities) |
| 230 | "Statements that mark mid sections of the enclosing block.") | 206 | "Statements that mark mid sections of the enclosing block.") |
| 231 | 207 | ||
| 232 | (defconst delphi-end-block-statements `(end until) | 208 | (defconst opascal-end-block-statements `(end until) |
| 233 | "Statements that end block sections.") | 209 | "Statements that end block sections.") |
| 234 | 210 | ||
| 235 | (defconst delphi-match-block-statements | 211 | (defconst opascal-match-block-statements |
| 236 | `(,@delphi-end-block-statements ,@delphi-mid-block-statements) | 212 | `(,@opascal-end-block-statements ,@opascal-mid-block-statements) |
| 237 | "Statements that match the indentation of the parent block.") | 213 | "Statements that match the indentation of the parent block.") |
| 238 | 214 | ||
| 239 | (defconst delphi-decl-sections '(type const var label resourcestring) | 215 | (defconst opascal-decl-sections '(type const var label resourcestring) |
| 240 | "Denotes the start of a declaration section.") | 216 | "Denotes the start of a declaration section.") |
| 241 | 217 | ||
| 242 | (defconst delphi-interface-types '(dispinterface interface) | 218 | (defconst opascal-interface-types '(dispinterface interface) |
| 243 | "Interface types.") | 219 | "Interface types.") |
| 244 | 220 | ||
| 245 | (defconst delphi-class-types '(class object) | 221 | (defconst opascal-class-types '(class object) |
| 246 | "Class types.") | 222 | "Class types.") |
| 247 | 223 | ||
| 248 | (defconst delphi-composite-types | 224 | (defconst opascal-composite-types |
| 249 | `(,@delphi-class-types ,@delphi-interface-types record) | 225 | `(,@opascal-class-types ,@opascal-interface-types record) |
| 250 | "Types that contain declarations within them.") | 226 | "Types that contain declarations within them.") |
| 251 | 227 | ||
| 252 | (defconst delphi-unit-sections | 228 | (defconst opascal-unit-sections |
| 253 | '(interface implementation program library package) | 229 | '(interface implementation program library package) |
| 254 | "Unit sections within which the indent is 0.") | 230 | "Unit sections within which the indent is 0.") |
| 255 | 231 | ||
| 256 | (defconst delphi-use-clauses `(uses requires exports contains) | 232 | (defconst opascal-use-clauses `(uses requires exports contains) |
| 257 | "Statements that refer to foreign symbols.") | 233 | "Statements that refer to foreign symbols.") |
| 258 | 234 | ||
| 259 | (defconst delphi-unit-statements | 235 | (defconst opascal-unit-statements |
| 260 | `(,@delphi-use-clauses ,@delphi-unit-sections initialization finalization) | 236 | `(,@opascal-use-clauses ,@opascal-unit-sections initialization finalization) |
| 261 | "Statements indented at level 0.") | 237 | "Statements indented at level 0.") |
| 262 | 238 | ||
| 263 | (defconst delphi-decl-delimiters | 239 | (defconst opascal-decl-delimiters |
| 264 | `(,@delphi-decl-sections ,@delphi-unit-statements | 240 | `(,@opascal-decl-sections ,@opascal-unit-statements |
| 265 | ,@delphi-routine-statements) | 241 | ,@opascal-routine-statements) |
| 266 | "Statements that a declaration statement should align with.") | 242 | "Statements that a declaration statement should align with.") |
| 267 | 243 | ||
| 268 | (defconst delphi-decl-matchers | 244 | (defconst opascal-decl-matchers |
| 269 | `(begin ,@delphi-decl-sections) | 245 | `(begin ,@opascal-decl-sections) |
| 270 | "Statements that should match to declaration statement indentation.") | 246 | "Statements that should match to declaration statement indentation.") |
| 271 | 247 | ||
| 272 | (defconst delphi-enclosing-statements | 248 | (defconst opascal-enclosing-statements |
| 273 | `(,@delphi-block-statements ,@delphi-mid-block-statements | 249 | `(,@opascal-block-statements ,@opascal-mid-block-statements |
| 274 | ,@delphi-decl-sections ,@delphi-use-clauses ,@delphi-routine-statements) | 250 | ,@opascal-decl-sections ,@opascal-use-clauses ,@opascal-routine-statements) |
| 275 | "Delimits an enclosing statement.") | 251 | "Delimits an enclosing statement.") |
| 276 | 252 | ||
| 277 | (defconst delphi-previous-statements | 253 | (defconst opascal-previous-statements |
| 278 | `(,@delphi-unit-statements ,@delphi-routine-statements) | 254 | `(,@opascal-unit-statements ,@opascal-routine-statements) |
| 279 | "Delimits a previous statement.") | 255 | "Delimits a previous statement.") |
| 280 | 256 | ||
| 281 | (defconst delphi-previous-enclosing-statements | 257 | (defconst opascal-previous-enclosing-statements |
| 282 | `(,@delphi-block-statements ,@delphi-mid-block-statements | 258 | `(,@opascal-block-statements ,@opascal-mid-block-statements |
| 283 | ,@delphi-decl-sections) | 259 | ,@opascal-decl-sections) |
| 284 | "Delimits a previous enclosing statement.") | 260 | "Delimits a previous enclosing statement.") |
| 285 | 261 | ||
| 286 | (defconst delphi-begin-enclosing-tokens | 262 | (defconst opascal-begin-enclosing-tokens |
| 287 | `(,@delphi-block-statements ,@delphi-mid-block-statements) | 263 | `(,@opascal-block-statements ,@opascal-mid-block-statements) |
| 288 | "Tokens that a begin token indents from.") | 264 | "Tokens that a begin token indents from.") |
| 289 | 265 | ||
| 290 | (defconst delphi-begin-previous-tokens | 266 | (defconst opascal-begin-previous-tokens |
| 291 | `(,@delphi-decl-sections ,@delphi-routine-statements) | 267 | `(,@opascal-decl-sections ,@opascal-routine-statements) |
| 292 | "Tokens that a begin token aligns with, but only if not part of a nested | 268 | "Tokens that a begin token aligns with, but only if not part of a nested |
| 293 | routine.") | 269 | routine.") |
| 294 | 270 | ||
| 295 | (defconst delphi-space-chars "\000-\011\013- ") ; all except \n | 271 | (defconst opascal-space-chars "\000-\011\013- ") ; all except \n |
| 296 | (defconst delphi-non-space-chars (concat "^" delphi-space-chars)) | 272 | (defconst opascal-non-space-chars (concat "^" opascal-space-chars)) |
| 297 | (defconst delphi-spaces-re (concat "[" delphi-space-chars "]*")) | 273 | (defconst opascal-spaces-re (concat "[" opascal-space-chars "]*")) |
| 298 | (defconst delphi-leading-spaces-re (concat "^" delphi-spaces-re)) | 274 | (defconst opascal-leading-spaces-re (concat "^" opascal-spaces-re)) |
| 299 | (defconst delphi-word-chars "a-zA-Z0-9_") | 275 | (defconst opascal-word-chars "a-zA-Z0-9_") |
| 300 | 276 | ||
| 301 | (defmacro delphi-save-match-data (&rest forms) | 277 | (defmacro opascal-save-excursion (&rest forms) |
| 302 | ;; Executes the forms such that the current match data is preserved, so as | ||
| 303 | ;; not to disturb any existing search results. | ||
| 304 | `(let ((data (match-data))) | ||
| 305 | (unwind-protect | ||
| 306 | (progn ,@forms) | ||
| 307 | (set-match-data data)))) | ||
| 308 | |||
| 309 | (defmacro delphi-save-excursion (&rest forms) | ||
| 310 | ;; Executes the forms such that any movements have no effect, including | 278 | ;; Executes the forms such that any movements have no effect, including |
| 311 | ;; searches. | 279 | ;; searches. |
| 312 | `(save-excursion | 280 | `(save-excursion |
| 313 | (delphi-save-match-data | 281 | (save-match-data |
| 314 | (let ((inhibit-point-motion-hooks t) | 282 | (let ((inhibit-point-motion-hooks t) |
| 315 | (deactivate-mark nil)) | 283 | (deactivate-mark nil)) |
| 316 | (progn ,@forms))))) | 284 | (progn ,@forms))))) |
| 317 | 285 | ||
| 318 | (defmacro delphi-save-state (&rest forms) | 286 | (defmacro opascal-save-state (&rest forms) |
| 319 | ;; Executes the forms such that any buffer modifications do not have any side | 287 | ;; Executes the forms such that any buffer modifications do not have any side |
| 320 | ;; effects beyond the buffer's actual content changes. | 288 | ;; effects beyond the buffer's actual content changes. |
| 321 | `(let ((delphi-ignore-changes t) | 289 | `(let ((opascal--ignore-changes t)) |
| 322 | (old-supersession-threat | 290 | (with-silent-modifications |
| 323 | (symbol-function 'ask-user-about-supersession-threat)) | 291 | ,@forms))) |
| 324 | (buffer-read-only nil) | 292 | |
| 325 | (inhibit-read-only t) | 293 | (defsubst opascal-is (element in-set) |
| 326 | (buffer-undo-list t) | ||
| 327 | (before-change-functions nil) | ||
| 328 | (after-change-functions nil) | ||
| 329 | (modified (buffer-modified-p))) | ||
| 330 | ;; Disable any queries about editing obsolete files. | ||
| 331 | (fset 'ask-user-about-supersession-threat (lambda (_fn))) | ||
| 332 | (unwind-protect | ||
| 333 | (progn ,@forms) | ||
| 334 | (set-buffer-modified-p modified) | ||
| 335 | (fset 'ask-user-about-supersession-threat old-supersession-threat)))) | ||
| 336 | |||
| 337 | (defsubst delphi-is (element in-set) | ||
| 338 | ;; If the element is in the set, the element cdr is returned, otherwise nil. | 294 | ;; If the element is in the set, the element cdr is returned, otherwise nil. |
| 339 | (memq element in-set)) | 295 | (memq element in-set)) |
| 340 | 296 | ||
| 341 | (defun delphi-string-of (start end) | 297 | (defun opascal-string-of (start end) |
| 342 | ;; Returns the buffer string from start to end. | 298 | ;; Returns the buffer string from start to end. |
| 343 | (buffer-substring-no-properties start end)) | 299 | (buffer-substring-no-properties start end)) |
| 344 | 300 | ||
| 345 | (defun delphi-looking-at-string (p s) | 301 | (defun opascal-looking-at-string (p s) |
| 346 | ;; True if point p marks the start of string s. s is not a regular | 302 | ;; True if point p marks the start of string s. s is not a regular |
| 347 | ;; expression. | 303 | ;; expression. |
| 348 | (let ((limit (+ p (length s)))) | 304 | (let ((limit (+ p (length s)))) |
| 349 | (and (<= limit (point-max)) | 305 | (and (<= limit (point-max)) |
| 350 | (string= s (delphi-string-of p limit))))) | 306 | (string= s (opascal-string-of p limit))))) |
| 351 | 307 | ||
| 352 | (defun delphi-token-of (kind start end) | 308 | (defun opascal-token-of (kind start end) |
| 353 | ;; Constructs a token from a kind symbol and its start/end points. | 309 | ;; Constructs a token from a kind symbol and its start/end points. |
| 354 | `[,kind ,start ,end]) | 310 | `[,kind ,start ,end]) |
| 355 | 311 | ||
| 356 | (defsubst delphi-token-kind (token) | 312 | (defsubst opascal-token-kind (token) |
| 357 | ;; Returns the kind symbol of the token. | 313 | ;; Returns the kind symbol of the token. |
| 358 | (if token (aref token 0) nil)) | 314 | (if token (aref token 0) nil)) |
| 359 | 315 | ||
| 360 | (defun delphi-set-token-kind (token to-kind) | 316 | (defun opascal-set-token-kind (token to-kind) |
| 361 | ;; Sets the kind symbol of the token. | 317 | ;; Sets the kind symbol of the token. |
| 362 | (if token (aset token 0 to-kind))) | 318 | (if token (aset token 0 to-kind))) |
| 363 | 319 | ||
| 364 | (defsubst delphi-token-start (token) | 320 | (defsubst opascal-token-start (token) |
| 365 | ;; Returns the start point of the token. | 321 | ;; Returns the start point of the token. |
| 366 | (if token (aref token 1) (point-min))) | 322 | (if token (aref token 1) (point-min))) |
| 367 | 323 | ||
| 368 | (defsubst delphi-token-end (token) | 324 | (defsubst opascal-token-end (token) |
| 369 | ;; Returns the end point of the token. | 325 | ;; Returns the end point of the token. |
| 370 | (if token (aref token 2) (point-min))) | 326 | (if token (aref token 2) (point-min))) |
| 371 | 327 | ||
| 372 | (defun delphi-set-token-start (token start) | 328 | (defun opascal-set-token-start (token start) |
| 373 | ;; Sets the start point of the token. | 329 | ;; Sets the start point of the token. |
| 374 | (if token (aset token 1 start))) | 330 | (if token (aset token 1 start))) |
| 375 | 331 | ||
| 376 | (defun delphi-set-token-end (token end) | 332 | (defun opascal-set-token-end (token end) |
| 377 | ;; Sets the end point of the token. | 333 | ;; Sets the end point of the token. |
| 378 | (if token (aset token 2 end))) | 334 | (if token (aset token 2 end))) |
| 379 | 335 | ||
| 380 | (defun delphi-token-string (token) | 336 | (defun opascal-token-string (token) |
| 381 | ;; Returns the string image of the token. | 337 | ;; Returns the string image of the token. |
| 382 | (if token | 338 | (if token |
| 383 | (delphi-string-of (delphi-token-start token) (delphi-token-end token)) | 339 | (opascal-string-of (opascal-token-start token) (opascal-token-end token)) |
| 384 | "")) | 340 | "")) |
| 385 | 341 | ||
| 386 | (defun delphi-in-token (p token) | 342 | (defun opascal-in-token (p token) |
| 387 | ;; Returns true if the point p is within the token's start/end points. | 343 | ;; Returns true if the point p is within the token's start/end points. |
| 388 | (and (<= (delphi-token-start token) p) (< p (delphi-token-end token)))) | 344 | (and (<= (opascal-token-start token) p) (< p (opascal-token-end token)))) |
| 389 | 345 | ||
| 390 | (defun delphi-column-of (p) | 346 | (defun opascal-column-of (p) |
| 391 | ;; Returns the column of the point p. | 347 | ;; Returns the column of the point p. |
| 392 | (save-excursion (goto-char p) (current-column))) | 348 | (save-excursion (goto-char p) (current-column))) |
| 393 | 349 | ||
| 394 | (defun delphi-face-of (token-kind) | 350 | (defun opascal-face-of (token-kind) |
| 395 | ;; Returns the face property appropriate for the token kind. | 351 | ;; Returns the face property appropriate for the token kind. |
| 396 | (cond ((delphi-is token-kind delphi-comments) delphi-comment-face) | 352 | (cond ((opascal-is token-kind opascal-comments) opascal-comment-face) |
| 397 | ((delphi-is token-kind delphi-strings) delphi-string-face) | 353 | ((opascal-is token-kind opascal-strings) opascal-string-face) |
| 398 | ((delphi-is token-kind delphi-keywords) delphi-keyword-face) | 354 | ((opascal-is token-kind opascal-keywords) opascal-keyword-face) |
| 399 | (delphi-other-face))) | 355 | (opascal-other-face))) |
| 400 | 356 | ||
| 401 | (defvar delphi-progress-last-reported-point nil | 357 | (defvar opascal-progress-last-reported-point nil |
| 402 | "The last point at which progress was reported.") | 358 | "The last point at which progress was reported.") |
| 403 | 359 | ||
| 404 | (defconst delphi-parsing-progress-step 16384 | 360 | (defconst opascal-parsing-progress-step 16384 |
| 405 | "Number of chars to process before the next parsing progress report.") | 361 | "Number of chars to process before the next parsing progress report.") |
| 406 | (defconst delphi-scanning-progress-step 2048 | 362 | (defconst opascal-scanning-progress-step 2048 |
| 407 | "Number of chars to process before the next scanning progress report.") | 363 | "Number of chars to process before the next scanning progress report.") |
| 408 | (defconst delphi-fontifying-progress-step delphi-scanning-progress-step | 364 | (defconst opascal-fontifying-progress-step opascal-scanning-progress-step |
| 409 | "Number of chars to process before the next fontification progress report.") | 365 | "Number of chars to process before the next fontification progress report.") |
| 410 | 366 | ||
| 411 | (defun delphi-progress-start () | 367 | (defun opascal-progress-start () |
| 412 | ;; Initializes progress reporting. | 368 | ;; Initializes progress reporting. |
| 413 | (setq delphi-progress-last-reported-point nil)) | 369 | (setq opascal-progress-last-reported-point nil)) |
| 414 | 370 | ||
| 415 | (defun delphi-progress-done (&rest msgs) | 371 | (defun opascal-progress-done (&rest msgs) |
| 416 | ;; Finalizes progress reporting. | 372 | ;; Finalizes progress reporting. |
| 417 | (setq delphi-progress-last-reported-point nil) | 373 | (setq opascal-progress-last-reported-point nil) |
| 418 | (when delphi-verbose | 374 | (when opascal-verbose |
| 419 | (if (null msgs) | 375 | (if (null msgs) |
| 420 | (message "") | 376 | (message "") |
| 421 | (apply #'message msgs)))) | 377 | (apply #'message msgs)))) |
| 422 | 378 | ||
| 423 | (defun delphi-step-progress (p desc step-size) | 379 | (defun opascal-step-progress (p desc step-size) |
| 424 | ;; If enough distance has elapsed since the last reported point, then report | 380 | ;; If enough distance has elapsed since the last reported point, then report |
| 425 | ;; the current progress to the user. | 381 | ;; the current progress to the user. |
| 426 | (cond ((null delphi-progress-last-reported-point) | 382 | (cond ((null opascal-progress-last-reported-point) |
| 427 | ;; This is the first progress step. | 383 | ;; This is the first progress step. |
| 428 | (setq delphi-progress-last-reported-point p)) | 384 | (setq opascal-progress-last-reported-point p)) |
| 429 | 385 | ||
| 430 | ((and delphi-verbose | 386 | ((and opascal-verbose |
| 431 | (>= (abs (- p delphi-progress-last-reported-point)) step-size)) | 387 | (>= (abs (- p opascal-progress-last-reported-point)) step-size)) |
| 432 | ;; Report the percentage complete. | 388 | ;; Report the percentage complete. |
| 433 | (setq delphi-progress-last-reported-point p) | 389 | (setq opascal-progress-last-reported-point p) |
| 434 | (message "%s %s ... %d%%" | 390 | (message "%s %s ... %d%%" |
| 435 | desc (buffer-name) (/ (* 100 p) (point-max)))))) | 391 | desc (buffer-name) (/ (* 100 p) (point-max)))))) |
| 436 | 392 | ||
| 437 | (defun delphi-next-line-start (&optional from-point) | 393 | (defun opascal-next-line-start (&optional from-point) |
| 438 | ;; Returns the first point of the next line. | 394 | ;; Returns the first point of the next line. |
| 439 | (let ((curr-point (point)) | 395 | (let ((curr-point (point)) |
| 440 | (next nil)) | 396 | (next nil)) |
| @@ -444,24 +400,24 @@ routine.") | |||
| 444 | (goto-char curr-point) | 400 | (goto-char curr-point) |
| 445 | next)) | 401 | next)) |
| 446 | 402 | ||
| 447 | (defvar delphi-ignore-changes t | 403 | (defvar opascal--ignore-changes t |
| 448 | "Internal flag to control if the Delphi mode responds to buffer changes. | 404 | "Internal flag to control if the OPascal mode responds to buffer changes. |
| 449 | Defaults to t in case the `delphi-after-change' function is called on a | 405 | Defaults to t in case the `opascal-after-change' function is called on a |
| 450 | non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | 406 | non-OPascal buffer. Set to nil in OPascal buffers. To override, just do: |
| 451 | (let ((delphi-ignore-changes t)) ...)") | 407 | (let ((opascal--ignore-changes t)) ...)") |
| 452 | 408 | ||
| 453 | (defun delphi-set-text-properties (from to properties) | 409 | (defun opascal-set-text-properties (from to properties) |
| 454 | ;; Like `set-text-properties', except we do not consider this to be a buffer | 410 | ;; Like `set-text-properties', except we do not consider this to be a buffer |
| 455 | ;; modification. | 411 | ;; modification. |
| 456 | (delphi-save-state | 412 | (opascal-save-state |
| 457 | (set-text-properties from to properties))) | 413 | (set-text-properties from to properties))) |
| 458 | 414 | ||
| 459 | (defun delphi-literal-kind (p) | 415 | (defun opascal-literal-kind (p) |
| 460 | ;; Returns the literal kind the point p is in (or nil if not in a literal). | 416 | ;; Returns the literal kind the point p is in (or nil if not in a literal). |
| 461 | (if (and (<= (point-min) p) (<= p (point-max))) | 417 | (if (and (<= (point-min) p) (<= p (point-max))) |
| 462 | (get-text-property p 'token))) | 418 | (get-text-property p 'token))) |
| 463 | 419 | ||
| 464 | (defun delphi-literal-start-pattern (literal-kind) | 420 | (defun opascal-literal-start-pattern (literal-kind) |
| 465 | ;; Returns the start pattern of the literal kind. | 421 | ;; Returns the start pattern of the literal kind. |
| 466 | (cdr (assoc literal-kind | 422 | (cdr (assoc literal-kind |
| 467 | '((comment-single-line . "//") | 423 | '((comment-single-line . "//") |
| @@ -470,7 +426,7 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 470 | (string . "'") | 426 | (string . "'") |
| 471 | (double-quoted-string . "\""))))) | 427 | (double-quoted-string . "\""))))) |
| 472 | 428 | ||
| 473 | (defun delphi-literal-end-pattern (literal-kind) | 429 | (defun opascal-literal-end-pattern (literal-kind) |
| 474 | ;; Returns the end pattern of the literal kind. | 430 | ;; Returns the end pattern of the literal kind. |
| 475 | (cdr (assoc literal-kind | 431 | (cdr (assoc literal-kind |
| 476 | '((comment-single-line . "\n") | 432 | '((comment-single-line . "\n") |
| @@ -479,7 +435,7 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 479 | (string . "'") | 435 | (string . "'") |
| 480 | (double-quoted-string . "\""))))) | 436 | (double-quoted-string . "\""))))) |
| 481 | 437 | ||
| 482 | (defun delphi-literal-stop-pattern (literal-kind) | 438 | (defun opascal-literal-stop-pattern (literal-kind) |
| 483 | ;; Returns the pattern that delimits end of the search for the literal kind. | 439 | ;; Returns the pattern that delimits end of the search for the literal kind. |
| 484 | ;; These are regular expressions. | 440 | ;; These are regular expressions. |
| 485 | (cdr (assoc literal-kind | 441 | (cdr (assoc literal-kind |
| @@ -490,69 +446,69 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 490 | (string . "['\n]") | 446 | (string . "['\n]") |
| 491 | (double-quoted-string . "[\"\n]"))))) | 447 | (double-quoted-string . "[\"\n]"))))) |
| 492 | 448 | ||
| 493 | (defun delphi-is-literal-start (p) | 449 | (defun opascal-is-literal-start (p) |
| 494 | ;; True if the point p is at the start point of a (completed) literal. | 450 | ;; True if the point p is at the start point of a (completed) literal. |
| 495 | (let* ((kind (delphi-literal-kind p)) | 451 | (let* ((kind (opascal-literal-kind p)) |
| 496 | (pattern (delphi-literal-start-pattern kind))) | 452 | (pattern (opascal-literal-start-pattern kind))) |
| 497 | (or (null kind) ; Non-literals are considered as start points. | 453 | (or (null kind) ; Non-literals are considered as start points. |
| 498 | (delphi-looking-at-string p pattern)))) | 454 | (opascal-looking-at-string p pattern)))) |
| 499 | 455 | ||
| 500 | (defun delphi-is-literal-end (p) | 456 | (defun opascal-is-literal-end (p) |
| 501 | ;; True if the point p is at the end point of a (completed) literal. | 457 | ;; True if the point p is at the end point of a (completed) literal. |
| 502 | (let* ((kind (delphi-literal-kind (1- p))) | 458 | (let* ((kind (opascal-literal-kind (1- p))) |
| 503 | (pattern (delphi-literal-end-pattern kind))) | 459 | (pattern (opascal-literal-end-pattern kind))) |
| 504 | (or (null kind) ; Non-literals are considered as end points. | 460 | (or (null kind) ; Non-literals are considered as end points. |
| 505 | 461 | ||
| 506 | (and (delphi-looking-at-string (- p (length pattern)) pattern) | 462 | (and (opascal-looking-at-string (- p (length pattern)) pattern) |
| 507 | (or (not (delphi-is kind delphi-strings)) | 463 | (or (not (opascal-is kind opascal-strings)) |
| 508 | ;; Special case: string delimiters are start/end ambiguous. | 464 | ;; Special case: string delimiters are start/end ambiguous. |
| 509 | ;; We have an end only if there is some string content (at | 465 | ;; We have an end only if there is some string content (at |
| 510 | ;; least a starting delimiter). | 466 | ;; least a starting delimiter). |
| 511 | (not (delphi-is-literal-end (1- p))))) | 467 | (not (opascal-is-literal-end (1- p))))) |
| 512 | 468 | ||
| 513 | ;; Special case: strings cannot span lines. | 469 | ;; Special case: strings cannot span lines. |
| 514 | (and (delphi-is kind delphi-strings) (eq ?\n (char-after (1- p))))))) | 470 | (and (opascal-is kind opascal-strings) (eq ?\n (char-after (1- p))))))) |
| 515 | 471 | ||
| 516 | (defun delphi-is-stable-literal (p) | 472 | (defun opascal-is-stable-literal (p) |
| 517 | ;; True if the point p marks a stable point. That is, a point outside of a | 473 | ;; True if the point p marks a stable point. That is, a point outside of a |
| 518 | ;; literal region, inside of a literal region, or adjacent to completed | 474 | ;; literal region, inside of a literal region, or adjacent to completed |
| 519 | ;; literal regions. | 475 | ;; literal regions. |
| 520 | (let ((at-start (delphi-is-literal-start p)) | 476 | (let ((at-start (opascal-is-literal-start p)) |
| 521 | (at-end (delphi-is-literal-end p))) | 477 | (at-end (opascal-is-literal-end p))) |
| 522 | (or (>= p (point-max)) | 478 | (or (>= p (point-max)) |
| 523 | (and at-start at-end) | 479 | (and at-start at-end) |
| 524 | (and (not at-start) (not at-end) | 480 | (and (not at-start) (not at-end) |
| 525 | (eq (delphi-literal-kind (1- p)) (delphi-literal-kind p)))))) | 481 | (eq (opascal-literal-kind (1- p)) (opascal-literal-kind p)))))) |
| 526 | 482 | ||
| 527 | (defun delphi-complete-literal (literal-kind limit) | 483 | (defun opascal-complete-literal (literal-kind limit) |
| 528 | ;; Continues the search for a literal's true end point and returns the | 484 | ;; Continues the search for a literal's true end point and returns the |
| 529 | ;; point past the end pattern (if found) or the limit (if not found). | 485 | ;; point past the end pattern (if found) or the limit (if not found). |
| 530 | (let ((pattern (delphi-literal-stop-pattern literal-kind))) | 486 | (let ((pattern (opascal-literal-stop-pattern literal-kind))) |
| 531 | (if (not (stringp pattern)) | 487 | (if (not (stringp pattern)) |
| 532 | (error "Invalid literal kind %S" literal-kind) | 488 | (error "Invalid literal kind %S" literal-kind) |
| 533 | ;; Search up to the limit. | 489 | ;; Search up to the limit. |
| 534 | (re-search-forward pattern limit 'goto-limit-on-fail) | 490 | (re-search-forward pattern limit 'goto-limit-on-fail) |
| 535 | (point)))) | 491 | (point)))) |
| 536 | 492 | ||
| 537 | (defun delphi-literal-text-properties (kind) | 493 | (defun opascal-literal-text-properties (kind) |
| 538 | ;; Creates a list of text properties for the literal kind. | 494 | ;; Creates a list of text properties for the literal kind. |
| 539 | (if (and (boundp 'font-lock-mode) | 495 | (if (and (boundp 'font-lock-mode) |
| 540 | font-lock-mode) | 496 | font-lock-mode) |
| 541 | (list 'token kind 'face (delphi-face-of kind) 'lazy-lock t) | 497 | (list 'token kind 'face (opascal-face-of kind) 'lazy-lock t) |
| 542 | (list 'token kind))) | 498 | (list 'token kind))) |
| 543 | 499 | ||
| 544 | (defun delphi-parse-next-literal (limit) | 500 | (defun opascal-parse-next-literal (limit) |
| 545 | ;; Searches for the next literal region (i.e. comment or string) and sets the | 501 | ;; Searches for the next literal region (i.e. comment or string) and sets the |
| 546 | ;; the point to its end (or the limit, if not found). The literal region is | 502 | ;; the point to its end (or the limit, if not found). The literal region is |
| 547 | ;; marked as such with a text property, to speed up tokenizing during face | 503 | ;; marked as such with a text property, to speed up tokenizing during face |
| 548 | ;; coloring and indentation scanning. | 504 | ;; coloring and indentation scanning. |
| 549 | (let ((search-start (point))) | 505 | (let ((search-start (point))) |
| 550 | (cond ((not (delphi-is-literal-end search-start)) | 506 | (cond ((not (opascal-is-literal-end search-start)) |
| 551 | ;; We are completing an incomplete literal. | 507 | ;; We are completing an incomplete literal. |
| 552 | (let ((kind (delphi-literal-kind (1- search-start)))) | 508 | (let ((kind (opascal-literal-kind (1- search-start)))) |
| 553 | (delphi-complete-literal kind limit) | 509 | (opascal-complete-literal kind limit) |
| 554 | (delphi-set-text-properties | 510 | (opascal-set-text-properties |
| 555 | search-start (point) (delphi-literal-text-properties kind)))) | 511 | search-start (point) (opascal-literal-text-properties kind)))) |
| 556 | 512 | ||
| 557 | ((re-search-forward | 513 | ((re-search-forward |
| 558 | "\\(//\\)\\|\\({\\)\\|\\((\\*\\)\\|\\('\\)\\|\\(\"\\)" | 514 | "\\(//\\)\\|\\({\\)\\|\\((\\*\\)\\|\\('\\)\\|\\(\"\\)" |
| @@ -564,34 +520,34 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 564 | ((match-beginning 4) 'string) | 520 | ((match-beginning 4) 'string) |
| 565 | ((match-beginning 5) 'double-quoted-string))) | 521 | ((match-beginning 5) 'double-quoted-string))) |
| 566 | (start (match-beginning 0))) | 522 | (start (match-beginning 0))) |
| 567 | (delphi-set-text-properties search-start start nil) | 523 | (opascal-set-text-properties search-start start nil) |
| 568 | (delphi-complete-literal kind limit) | 524 | (opascal-complete-literal kind limit) |
| 569 | (delphi-set-text-properties | 525 | (opascal-set-text-properties |
| 570 | start (point) (delphi-literal-text-properties kind)))) | 526 | start (point) (opascal-literal-text-properties kind)))) |
| 571 | 527 | ||
| 572 | ;; Nothing found. Mark it as a non-literal. | 528 | ;; Nothing found. Mark it as a non-literal. |
| 573 | ((delphi-set-text-properties search-start limit nil))) | 529 | ((opascal-set-text-properties search-start limit nil))) |
| 574 | (delphi-step-progress (point) "Parsing" delphi-parsing-progress-step))) | 530 | (opascal-step-progress (point) "Parsing" opascal-parsing-progress-step))) |
| 575 | 531 | ||
| 576 | (defun delphi-literal-token-at (p) | 532 | (defun opascal-literal-token-at (p) |
| 577 | ;; Returns the literal token surrounding the point p, or nil if none. | 533 | ;; Returns the literal token surrounding the point p, or nil if none. |
| 578 | (let ((kind (delphi-literal-kind p))) | 534 | (let ((kind (opascal-literal-kind p))) |
| 579 | (when kind | 535 | (when kind |
| 580 | (let ((start (previous-single-property-change (1+ p) 'token)) | 536 | (let ((start (previous-single-property-change (1+ p) 'token)) |
| 581 | (end (next-single-property-change p 'token))) | 537 | (end (next-single-property-change p 'token))) |
| 582 | (delphi-token-of kind (or start (point-min)) (or end (point-max))))))) | 538 | (opascal-token-of kind (or start (point-min)) (or end (point-max))))))) |
| 583 | 539 | ||
| 584 | (defun delphi-point-token-at (p kind) | 540 | (defun opascal-point-token-at (p kind) |
| 585 | ;; Returns the single character token at the point p. | 541 | ;; Returns the single character token at the point p. |
| 586 | (delphi-token-of kind p (1+ p))) | 542 | (opascal-token-of kind p (1+ p))) |
| 587 | 543 | ||
| 588 | (defsubst delphi-char-token-at (p char kind) | 544 | (defsubst opascal-char-token-at (p char kind) |
| 589 | ;; Returns the token at the point p that describes the specified character. | 545 | ;; Returns the token at the point p that describes the specified character. |
| 590 | ;; If not actually over such a character, nil is returned. | 546 | ;; If not actually over such a character, nil is returned. |
| 591 | (when (eq char (char-after p)) | 547 | (when (eq char (char-after p)) |
| 592 | (delphi-token-of kind p (1+ p)))) | 548 | (opascal-token-of kind p (1+ p)))) |
| 593 | 549 | ||
| 594 | (defun delphi-charset-token-at (p charset kind) | 550 | (defun opascal-charset-token-at (p charset kind) |
| 595 | ;; Returns the token surrounding point p that contains only members of the | 551 | ;; Returns the token surrounding point p that contains only members of the |
| 596 | ;; character set. | 552 | ;; character set. |
| 597 | (let ((currp (point)) | 553 | (let ((currp (point)) |
| @@ -602,293 +558,293 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 602 | (setq end (point)) | 558 | (setq end (point)) |
| 603 | (goto-char (1+ p)) | 559 | (goto-char (1+ p)) |
| 604 | (skip-chars-backward charset) | 560 | (skip-chars-backward charset) |
| 605 | (setq token (delphi-token-of kind (point) end))) | 561 | (setq token (opascal-token-of kind (point) end))) |
| 606 | (goto-char currp) | 562 | (goto-char currp) |
| 607 | token)) | 563 | token)) |
| 608 | 564 | ||
| 609 | (defun delphi-space-token-at (p) | 565 | (defun opascal-space-token-at (p) |
| 610 | ;; If point p is surrounded by space characters, then return the token of the | 566 | ;; If point p is surrounded by space characters, then return the token of the |
| 611 | ;; contiguous spaces. | 567 | ;; contiguous spaces. |
| 612 | (delphi-charset-token-at p delphi-space-chars 'space)) | 568 | (opascal-charset-token-at p opascal-space-chars 'space)) |
| 613 | 569 | ||
| 614 | (defun delphi-word-token-at (p) | 570 | (defun opascal-word-token-at (p) |
| 615 | ;; If point p is over a word (i.e. identifier characters), then return a word | 571 | ;; If point p is over a word (i.e. identifier characters), then return a word |
| 616 | ;; token. If the word is actually a keyword, then return the keyword token. | 572 | ;; token. If the word is actually a keyword, then return the keyword token. |
| 617 | (let ((word (delphi-charset-token-at p delphi-word-chars 'word))) | 573 | (let ((word (opascal-charset-token-at p opascal-word-chars 'word))) |
| 618 | (when word | 574 | (when word |
| 619 | (let* ((word-image (downcase (delphi-token-string word))) | 575 | (let* ((word-image (downcase (opascal-token-string word))) |
| 620 | (keyword (intern-soft word-image))) | 576 | (keyword (intern-soft word-image))) |
| 621 | (when (and (or keyword (string= "nil" word-image)) | 577 | (when (and (or keyword (string= "nil" word-image)) |
| 622 | (delphi-is keyword delphi-keywords)) | 578 | (opascal-is keyword opascal-keywords)) |
| 623 | (delphi-set-token-kind word keyword)) | 579 | (opascal-set-token-kind word keyword)) |
| 624 | word)))) | 580 | word)))) |
| 625 | 581 | ||
| 626 | (defun delphi-explicit-token-at (p token-string kind) | 582 | (defun opascal-explicit-token-at (p token-string kind) |
| 627 | ;; If point p is anywhere in the token string then returns the resulting | 583 | ;; If point p is anywhere in the token string then returns the resulting |
| 628 | ;; token. | 584 | ;; token. |
| 629 | (let ((token (delphi-charset-token-at p token-string kind))) | 585 | (let ((token (opascal-charset-token-at p token-string kind))) |
| 630 | (when (and token (string= token-string (delphi-token-string token))) | 586 | (when (and token (string= token-string (opascal-token-string token))) |
| 631 | token))) | 587 | token))) |
| 632 | 588 | ||
| 633 | (defun delphi-token-at (p) | 589 | (defun opascal-token-at (p) |
| 634 | ;; Returns the token from parsing text at point p. | 590 | ;; Returns the token from parsing text at point p. |
| 635 | (when (and (<= (point-min) p) (<= p (point-max))) | 591 | (when (and (<= (point-min) p) (<= p (point-max))) |
| 636 | (cond ((delphi-char-token-at p ?\n 'newline)) | 592 | (cond ((opascal-char-token-at p ?\n 'newline)) |
| 637 | 593 | ||
| 638 | ((delphi-literal-token-at p)) | 594 | ((opascal-literal-token-at p)) |
| 639 | 595 | ||
| 640 | ((delphi-space-token-at p)) | 596 | ((opascal-space-token-at p)) |
| 641 | 597 | ||
| 642 | ((delphi-word-token-at p)) | 598 | ((opascal-word-token-at p)) |
| 643 | 599 | ||
| 644 | ((delphi-char-token-at p ?\( 'open-group)) | 600 | ((opascal-char-token-at p ?\( 'open-group)) |
| 645 | ((delphi-char-token-at p ?\) 'close-group)) | 601 | ((opascal-char-token-at p ?\) 'close-group)) |
| 646 | ((delphi-char-token-at p ?\[ 'open-group)) | 602 | ((opascal-char-token-at p ?\[ 'open-group)) |
| 647 | ((delphi-char-token-at p ?\] 'close-group)) | 603 | ((opascal-char-token-at p ?\] 'close-group)) |
| 648 | ((delphi-char-token-at p ?\; 'semicolon)) | 604 | ((opascal-char-token-at p ?\; 'semicolon)) |
| 649 | ((delphi-char-token-at p ?. 'dot)) | 605 | ((opascal-char-token-at p ?. 'dot)) |
| 650 | ((delphi-char-token-at p ?, 'comma)) | 606 | ((opascal-char-token-at p ?, 'comma)) |
| 651 | ((delphi-char-token-at p ?= 'equals)) | 607 | ((opascal-char-token-at p ?= 'equals)) |
| 652 | ((delphi-char-token-at p ?+ 'plus)) | 608 | ((opascal-char-token-at p ?+ 'plus)) |
| 653 | ((delphi-char-token-at p ?- 'minus)) | 609 | ((opascal-char-token-at p ?- 'minus)) |
| 654 | ((delphi-char-token-at p ?* 'times)) | 610 | ((opascal-char-token-at p ?* 'times)) |
| 655 | ((delphi-char-token-at p ?/ 'divides)) | 611 | ((opascal-char-token-at p ?/ 'divides)) |
| 656 | ((delphi-char-token-at p ?: 'colon)) | 612 | ((opascal-char-token-at p ?: 'colon)) |
| 657 | 613 | ||
| 658 | ((delphi-explicit-token-at p "<>" 'not-equals)) | 614 | ((opascal-explicit-token-at p "<>" 'not-equals)) |
| 659 | 615 | ||
| 660 | ((delphi-point-token-at p 'punctuation))))) | 616 | ((opascal-point-token-at p 'punctuation))))) |
| 661 | 617 | ||
| 662 | (defun delphi-current-token () | 618 | (defun opascal-current-token () |
| 663 | ;; Returns the delphi source token under the current point. | 619 | ;; Returns the opascal source token under the current point. |
| 664 | (delphi-token-at (point))) | 620 | (opascal-token-at (point))) |
| 665 | 621 | ||
| 666 | (defun delphi-next-token (token) | 622 | (defun opascal-next-token (token) |
| 667 | ;; Returns the token after the specified token. | 623 | ;; Returns the token after the specified token. |
| 668 | (when token | 624 | (when token |
| 669 | (let ((next (delphi-token-at (delphi-token-end token)))) | 625 | (let ((next (opascal-token-at (opascal-token-end token)))) |
| 670 | (if next | 626 | (if next |
| 671 | (delphi-step-progress (delphi-token-start next) "Scanning" | 627 | (opascal-step-progress (opascal-token-start next) "Scanning" |
| 672 | delphi-scanning-progress-step)) | 628 | opascal-scanning-progress-step)) |
| 673 | next))) | 629 | next))) |
| 674 | 630 | ||
| 675 | (defun delphi-previous-token (token) | 631 | (defun opascal-previous-token (token) |
| 676 | ;; Returns the token before the specified token. | 632 | ;; Returns the token before the specified token. |
| 677 | (when token | 633 | (when token |
| 678 | (let ((previous (delphi-token-at (1- (delphi-token-start token))))) | 634 | (let ((previous (opascal-token-at (1- (opascal-token-start token))))) |
| 679 | (if previous | 635 | (if previous |
| 680 | (delphi-step-progress (delphi-token-start previous) "Scanning" | 636 | (opascal-step-progress (opascal-token-start previous) "Scanning" |
| 681 | delphi-scanning-progress-step)) | 637 | opascal-scanning-progress-step)) |
| 682 | previous))) | 638 | previous))) |
| 683 | 639 | ||
| 684 | (defun delphi-next-visible-token (token) | 640 | (defun opascal-next-visible-token (token) |
| 685 | ;; Returns the first non-space token after the specified token. | 641 | ;; Returns the first non-space token after the specified token. |
| 686 | (let (next-token) | 642 | (let (next-token) |
| 687 | (while (progn | 643 | (while (progn |
| 688 | (setq next-token (delphi-next-token token)) | 644 | (setq next-token (opascal-next-token token)) |
| 689 | (delphi-is (delphi-token-kind next-token) '(space newline)))) | 645 | (opascal-is (opascal-token-kind next-token) '(space newline)))) |
| 690 | next-token)) | 646 | next-token)) |
| 691 | 647 | ||
| 692 | (defun delphi-parse-region (from to) | 648 | (defun opascal-parse-region (from to) |
| 693 | ;; Parses the literal tokens in the region. The point is set to "to". | 649 | ;; Parses the literal tokens in the region. The point is set to "to". |
| 694 | (save-restriction | 650 | (save-restriction |
| 695 | (widen) | 651 | (widen) |
| 696 | (goto-char from) | 652 | (goto-char from) |
| 697 | (while (< (point) to) | 653 | (while (< (point) to) |
| 698 | (delphi-parse-next-literal to)))) | 654 | (opascal-parse-next-literal to)))) |
| 699 | 655 | ||
| 700 | (defun delphi-parse-region-until-stable (from to) | 656 | (defun opascal-parse-region-until-stable (from to) |
| 701 | ;; Parses at least the literal tokens in the region. After that, parsing | 657 | ;; Parses at least the literal tokens in the region. After that, parsing |
| 702 | ;; continues as long as obsolete literal regions are encountered. The point | 658 | ;; continues as long as obsolete literal regions are encountered. The point |
| 703 | ;; is set to the encountered stable point. | 659 | ;; is set to the encountered stable point. |
| 704 | (save-restriction | 660 | (save-restriction |
| 705 | (widen) | 661 | (widen) |
| 706 | (delphi-parse-region from to) | 662 | (opascal-parse-region from to) |
| 707 | (while (not (delphi-is-stable-literal (point))) | 663 | (while (not (opascal-is-stable-literal (point))) |
| 708 | (delphi-parse-next-literal (point-max))))) | 664 | (opascal-parse-next-literal (point-max))))) |
| 709 | 665 | ||
| 710 | (defun delphi-fontify-region (from to &optional verbose) | 666 | (defun opascal-fontify-region (from to &optional verbose) |
| 711 | ;; Colors the text in the region according to Delphi rules. | 667 | ;; Colors the text in the region according to OPascal rules. |
| 712 | (delphi-save-excursion | 668 | (opascal-save-excursion |
| 713 | (delphi-save-state | 669 | (opascal-save-state |
| 714 | (let ((p from) | 670 | (let ((p from) |
| 715 | (delphi-verbose verbose) | 671 | (opascal-verbose verbose) |
| 716 | (token nil)) | 672 | (token nil)) |
| 717 | (delphi-progress-start) | 673 | (opascal-progress-start) |
| 718 | (while (< p to) | 674 | (while (< p to) |
| 719 | ;; Color the token and move past it. | 675 | ;; Color the token and move past it. |
| 720 | (setq token (delphi-token-at p)) | 676 | (setq token (opascal-token-at p)) |
| 721 | (add-text-properties | 677 | (add-text-properties |
| 722 | (delphi-token-start token) (delphi-token-end token) | 678 | (opascal-token-start token) (opascal-token-end token) |
| 723 | (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t)) | 679 | (list 'face (opascal-face-of (opascal-token-kind token)) 'lazy-lock t)) |
| 724 | (setq p (delphi-token-end token)) | 680 | (setq p (opascal-token-end token)) |
| 725 | (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step)) | 681 | (opascal-step-progress p "Fontifying" opascal-fontifying-progress-step)) |
| 726 | (delphi-progress-done))))) | 682 | (opascal-progress-done))))) |
| 727 | 683 | ||
| 728 | (defun delphi-after-change (change-start change-end _old-length) | 684 | (defun opascal-after-change (change-start change-end _old-length) |
| 729 | ;; Called when the buffer has changed. Reparses the changed region. | 685 | ;; Called when the buffer has changed. Reparses the changed region. |
| 730 | (unless delphi-ignore-changes | 686 | (unless opascal--ignore-changes |
| 731 | (let ((delphi-ignore-changes t)) ; Prevent recursive calls. | 687 | (let ((opascal--ignore-changes t)) ; Prevent recursive calls. |
| 732 | (delphi-save-excursion | 688 | (opascal-save-excursion |
| 733 | (delphi-progress-start) | 689 | (opascal-progress-start) |
| 734 | ;; Reparse at least from the token previous to the change to the end of | 690 | ;; Reparse at least from the token previous to the change to the end of |
| 735 | ;; line after the change. | 691 | ;; line after the change. |
| 736 | (delphi-parse-region-until-stable | 692 | (opascal-parse-region-until-stable |
| 737 | (delphi-token-start (delphi-token-at (1- change-start))) | 693 | (opascal-token-start (opascal-token-at (1- change-start))) |
| 738 | (progn (goto-char change-end) (end-of-line) (point))) | 694 | (progn (goto-char change-end) (end-of-line) (point))) |
| 739 | (delphi-progress-done))))) | 695 | (opascal-progress-done))))) |
| 740 | 696 | ||
| 741 | (defun delphi-group-start (from-token) | 697 | (defun opascal-group-start (from-token) |
| 742 | ;; Returns the token that denotes the start of the ()/[] group. | 698 | ;; Returns the token that denotes the start of the ()/[] group. |
| 743 | (let ((token (delphi-previous-token from-token)) | 699 | (let ((token (opascal-previous-token from-token)) |
| 744 | (token-kind nil)) | 700 | (token-kind nil)) |
| 745 | (catch 'done | 701 | (catch 'done |
| 746 | (while token | 702 | (while token |
| 747 | (setq token-kind (delphi-token-kind token)) | 703 | (setq token-kind (opascal-token-kind token)) |
| 748 | (cond | 704 | (cond |
| 749 | ;; Skip over nested groups. | 705 | ;; Skip over nested groups. |
| 750 | ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | 706 | ((eq 'close-group token-kind) (setq token (opascal-group-start token))) |
| 751 | ((eq 'open-group token-kind) (throw 'done token))) | 707 | ((eq 'open-group token-kind) (throw 'done token))) |
| 752 | (setq token (delphi-previous-token token))) | 708 | (setq token (opascal-previous-token token))) |
| 753 | ;; Start not found. | 709 | ;; Start not found. |
| 754 | nil))) | 710 | nil))) |
| 755 | 711 | ||
| 756 | (defun delphi-group-end (from-token) | 712 | (defun opascal-group-end (from-token) |
| 757 | ;; Returns the token that denotes the end of the ()/[] group. | 713 | ;; Returns the token that denotes the end of the ()/[] group. |
| 758 | (let ((token (delphi-next-token from-token)) | 714 | (let ((token (opascal-next-token from-token)) |
| 759 | (token-kind nil)) | 715 | (token-kind nil)) |
| 760 | (catch 'done | 716 | (catch 'done |
| 761 | (while token | 717 | (while token |
| 762 | (setq token-kind (delphi-token-kind token)) | 718 | (setq token-kind (opascal-token-kind token)) |
| 763 | (cond | 719 | (cond |
| 764 | ;; Skip over nested groups. | 720 | ;; Skip over nested groups. |
| 765 | ((eq 'open-group token-kind) (setq token (delphi-group-end token))) | 721 | ((eq 'open-group token-kind) (setq token (opascal-group-end token))) |
| 766 | ((eq 'close-group token-kind) (throw 'done token))) | 722 | ((eq 'close-group token-kind) (throw 'done token))) |
| 767 | (setq token (delphi-next-token token))) | 723 | (setq token (opascal-next-token token))) |
| 768 | ;; end not found. | 724 | ;; end not found. |
| 769 | nil))) | 725 | nil))) |
| 770 | 726 | ||
| 771 | (defun delphi-indent-of (token &optional offset) | 727 | (defun opascal-indent-of (token &optional offset) |
| 772 | ;; Returns the start column of the token, plus any offset. | 728 | ;; Returns the start column of the token, plus any offset. |
| 773 | (let ((indent (+ (delphi-column-of (delphi-token-start token)) | 729 | (let ((indent (+ (opascal-column-of (opascal-token-start token)) |
| 774 | (if offset offset 0)))) | 730 | (if offset offset 0)))) |
| 775 | (when delphi-debug | 731 | (when opascal-debug |
| 776 | (delphi-debug-log | 732 | (opascal-debug-log |
| 777 | (concat "\n Indent of: %S %S" | 733 | (concat "\n Indent of: %S %S" |
| 778 | "\n column: %d indent: %d offset: %d") | 734 | "\n column: %d indent: %d offset: %d") |
| 779 | token (delphi-token-string token) | 735 | token (opascal-token-string token) |
| 780 | (delphi-column-of (delphi-token-start token)) | 736 | (opascal-column-of (opascal-token-start token)) |
| 781 | indent (if offset offset 0))) | 737 | indent (if offset offset 0))) |
| 782 | indent)) | 738 | indent)) |
| 783 | 739 | ||
| 784 | (defun delphi-line-indent-of (from-token &optional offset &rest terminators) | 740 | (defun opascal-line-indent-of (from-token &optional offset &rest terminators) |
| 785 | ;; Returns the column of first non-space character on the token's line, plus | 741 | ;; Returns the column of first non-space character on the token's line, plus |
| 786 | ;; any offset. We also stop if one of the terminators or an open ( or [ is | 742 | ;; any offset. We also stop if one of the terminators or an open ( or [ is |
| 787 | ;; encountered. | 743 | ;; encountered. |
| 788 | (let ((token (delphi-previous-token from-token)) | 744 | (let ((token (opascal-previous-token from-token)) |
| 789 | (last-token from-token) | 745 | (last-token from-token) |
| 790 | (kind nil)) | 746 | (kind nil)) |
| 791 | (catch 'done | 747 | (catch 'done |
| 792 | (while token | 748 | (while token |
| 793 | (setq kind (delphi-token-kind token)) | 749 | (setq kind (opascal-token-kind token)) |
| 794 | (cond | 750 | (cond |
| 795 | ;; Skip over ()/[] groups. | 751 | ;; Skip over ()/[] groups. |
| 796 | ((eq 'close-group kind) (setq token (delphi-group-start token))) | 752 | ((eq 'close-group kind) (setq token (opascal-group-start token))) |
| 797 | 753 | ||
| 798 | ;; Stop at the beginning of the line or an open group. | 754 | ;; Stop at the beginning of the line or an open group. |
| 799 | ((delphi-is kind '(newline open-group)) (throw 'done nil)) | 755 | ((opascal-is kind '(newline open-group)) (throw 'done nil)) |
| 800 | 756 | ||
| 801 | ;; Stop at one of the specified terminators. | 757 | ;; Stop at one of the specified terminators. |
| 802 | ((delphi-is kind terminators) (throw 'done nil))) | 758 | ((opascal-is kind terminators) (throw 'done nil))) |
| 803 | (unless (delphi-is kind delphi-whitespace) (setq last-token token)) | 759 | (unless (opascal-is kind opascal-whitespace) (setq last-token token)) |
| 804 | (setq token (delphi-previous-token token)))) | 760 | (setq token (opascal-previous-token token)))) |
| 805 | (delphi-indent-of last-token offset))) | 761 | (opascal-indent-of last-token offset))) |
| 806 | 762 | ||
| 807 | (defun delphi-stmt-line-indent-of (from-token &optional offset) | 763 | (defun opascal-stmt-line-indent-of (from-token &optional offset) |
| 808 | ;; Like `delphi-line-indent-of' except is also stops on a use clause, and | 764 | ;; Like `opascal-line-indent-of' except is also stops on a use clause, and |
| 809 | ;; colons that precede statements (i.e. case labels). | 765 | ;; colons that precede statements (i.e. case labels). |
| 810 | (let ((token (delphi-previous-token from-token)) | 766 | (let ((token (opascal-previous-token from-token)) |
| 811 | (last-token from-token) | 767 | (last-token from-token) |
| 812 | (kind nil)) | 768 | (kind nil)) |
| 813 | (catch 'done | 769 | (catch 'done |
| 814 | (while token | 770 | (while token |
| 815 | (setq kind (delphi-token-kind token)) | 771 | (setq kind (opascal-token-kind token)) |
| 816 | (cond | 772 | (cond |
| 817 | ((and (eq 'colon kind) | 773 | ((and (eq 'colon kind) |
| 818 | (delphi-is (delphi-token-kind last-token) | 774 | (opascal-is (opascal-token-kind last-token) |
| 819 | `(,@delphi-block-statements | 775 | `(,@opascal-block-statements |
| 820 | ,@delphi-expr-statements))) | 776 | ,@opascal-expr-statements))) |
| 821 | ;; We hit a label followed by a statement. Indent to the statement. | 777 | ;; We hit a label followed by a statement. Indent to the statement. |
| 822 | (throw 'done nil)) | 778 | (throw 'done nil)) |
| 823 | 779 | ||
| 824 | ;; Skip over ()/[] groups. | 780 | ;; Skip over ()/[] groups. |
| 825 | ((eq 'close-group kind) (setq token (delphi-group-start token))) | 781 | ((eq 'close-group kind) (setq token (opascal-group-start token))) |
| 826 | 782 | ||
| 827 | ((delphi-is kind `(newline open-group ,@delphi-use-clauses)) | 783 | ((opascal-is kind `(newline open-group ,@opascal-use-clauses)) |
| 828 | ;; Stop at the beginning of the line, an open group, or a use clause | 784 | ;; Stop at the beginning of the line, an open group, or a use clause |
| 829 | (throw 'done nil))) | 785 | (throw 'done nil))) |
| 830 | (unless (delphi-is kind delphi-whitespace) (setq last-token token)) | 786 | (unless (opascal-is kind opascal-whitespace) (setq last-token token)) |
| 831 | (setq token (delphi-previous-token token)))) | 787 | (setq token (opascal-previous-token token)))) |
| 832 | (delphi-indent-of last-token offset))) | 788 | (opascal-indent-of last-token offset))) |
| 833 | 789 | ||
| 834 | (defun delphi-open-group-indent (token last-token &optional offset) | 790 | (defun opascal-open-group-indent (token last-token &optional offset) |
| 835 | ;; Returns the indent relative to an unmatched ( or [. | 791 | ;; Returns the indent relative to an unmatched ( or [. |
| 836 | (when (eq 'open-group (delphi-token-kind token)) | 792 | (when (eq 'open-group (opascal-token-kind token)) |
| 837 | (if last-token | 793 | (if last-token |
| 838 | (delphi-indent-of last-token offset) | 794 | (opascal-indent-of last-token offset) |
| 839 | ;; There is nothing following the ( or [. Indent from its line. | 795 | ;; There is nothing following the ( or [. Indent from its line. |
| 840 | (delphi-stmt-line-indent-of token delphi-indent-level)))) | 796 | (opascal-stmt-line-indent-of token opascal-indent-level)))) |
| 841 | 797 | ||
| 842 | (defun delphi-composite-type-start (token last-token) | 798 | (defun opascal-composite-type-start (token last-token) |
| 843 | ;; Returns true (actually the last-token) if the pair equals (= class), (= | 799 | ;; Returns true (actually the last-token) if the pair equals (= class), (= |
| 844 | ;; dispinterface), (= interface), (= object), or (= record), and nil | 800 | ;; dispinterface), (= interface), (= object), or (= record), and nil |
| 845 | ;; otherwise. | 801 | ;; otherwise. |
| 846 | (if (and (eq 'equals (delphi-token-kind token)) | 802 | (if (and (eq 'equals (opascal-token-kind token)) |
| 847 | (delphi-is (delphi-token-kind last-token) delphi-composite-types)) | 803 | (opascal-is (opascal-token-kind last-token) opascal-composite-types)) |
| 848 | last-token)) | 804 | last-token)) |
| 849 | 805 | ||
| 850 | (defun delphi-is-simple-class-type (at-token limit-token) | 806 | (defun opascal-is-simple-class-type (at-token limit-token) |
| 851 | ;; True if at-token is the start of a simple class type. E.g. | 807 | ;; True if at-token is the start of a simple class type. E.g. |
| 852 | ;; class of TClass; | 808 | ;; class of TClass; |
| 853 | ;; class (TBaseClass); | 809 | ;; class (TBaseClass); |
| 854 | ;; class; | 810 | ;; class; |
| 855 | (when (delphi-is (delphi-token-kind at-token) delphi-class-types) | 811 | (when (opascal-is (opascal-token-kind at-token) opascal-class-types) |
| 856 | (catch 'done | 812 | (catch 'done |
| 857 | ;; Scan until the semi colon. | 813 | ;; Scan until the semi colon. |
| 858 | (let ((token (delphi-next-token at-token)) | 814 | (let ((token (opascal-next-token at-token)) |
| 859 | (token-kind nil) | 815 | (token-kind nil) |
| 860 | (limit (delphi-token-start limit-token))) | 816 | (limit (opascal-token-start limit-token))) |
| 861 | (while (and token (<= (delphi-token-start token) limit)) | 817 | (while (and token (<= (opascal-token-start token) limit)) |
| 862 | (setq token-kind (delphi-token-kind token)) | 818 | (setq token-kind (opascal-token-kind token)) |
| 863 | (cond | 819 | (cond |
| 864 | ;; A semicolon delimits the search. | 820 | ;; A semicolon delimits the search. |
| 865 | ((eq 'semicolon token-kind) (throw 'done token)) | 821 | ((eq 'semicolon token-kind) (throw 'done token)) |
| 866 | 822 | ||
| 867 | ;; Skip over the inheritance list. | 823 | ;; Skip over the inheritance list. |
| 868 | ((eq 'open-group token-kind) (setq token (delphi-group-end token))) | 824 | ((eq 'open-group token-kind) (setq token (opascal-group-end token))) |
| 869 | 825 | ||
| 870 | ;; Only allow "of" and whitespace, and an identifier | 826 | ;; Only allow "of" and whitespace, and an identifier |
| 871 | ((delphi-is token-kind `(of word ,@delphi-whitespace))) | 827 | ((opascal-is token-kind `(of word ,@opascal-whitespace))) |
| 872 | 828 | ||
| 873 | ;; Otherwise we are not in a simple class declaration. | 829 | ;; Otherwise we are not in a simple class declaration. |
| 874 | ((throw 'done nil))) | 830 | ((throw 'done nil))) |
| 875 | (setq token (delphi-next-token token))))))) | 831 | (setq token (opascal-next-token token))))))) |
| 876 | 832 | ||
| 877 | (defun delphi-block-start (from-token &optional stop-on-class) | 833 | (defun opascal-block-start (from-token &optional stop-on-class) |
| 878 | ;; Returns the token that denotes the start of the block. | 834 | ;; Returns the token that denotes the start of the block. |
| 879 | (let ((token (delphi-previous-token from-token)) | 835 | (let ((token (opascal-previous-token from-token)) |
| 880 | (last-token nil) | 836 | (last-token nil) |
| 881 | (token-kind nil)) | 837 | (token-kind nil)) |
| 882 | (catch 'done | 838 | (catch 'done |
| 883 | (while token | 839 | (while token |
| 884 | (setq token-kind (delphi-token-kind token)) | 840 | (setq token-kind (opascal-token-kind token)) |
| 885 | (cond | 841 | (cond |
| 886 | ;; Skip over nested blocks. | 842 | ;; Skip over nested blocks. |
| 887 | ((delphi-is token-kind delphi-end-block-statements) | 843 | ((opascal-is token-kind opascal-end-block-statements) |
| 888 | (setq token (delphi-block-start token))) | 844 | (setq token (opascal-block-start token))) |
| 889 | 845 | ||
| 890 | ;; Regular block start found. | 846 | ;; Regular block start found. |
| 891 | ((delphi-is token-kind delphi-block-statements) | 847 | ((opascal-is token-kind opascal-block-statements) |
| 892 | (throw 'done | 848 | (throw 'done |
| 893 | ;; As a special case, when a "case" block appears | 849 | ;; As a special case, when a "case" block appears |
| 894 | ;; within a record declaration (to denote a variant | 850 | ;; within a record declaration (to denote a variant |
| @@ -896,42 +852,42 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 896 | ;; the enclosing block. | 852 | ;; the enclosing block. |
| 897 | (if (eq 'case token-kind) | 853 | (if (eq 'case token-kind) |
| 898 | (let ((enclosing-token | 854 | (let ((enclosing-token |
| 899 | (delphi-block-start token | 855 | (opascal-block-start token |
| 900 | 'stop-on-class))) | 856 | 'stop-on-class))) |
| 901 | (if | 857 | (if |
| 902 | (eq 'record | 858 | (eq 'record |
| 903 | (delphi-token-kind enclosing-token)) | 859 | (opascal-token-kind enclosing-token)) |
| 904 | (if stop-on-class | 860 | (if stop-on-class |
| 905 | enclosing-token | 861 | enclosing-token |
| 906 | (delphi-previous-token enclosing-token)) | 862 | (opascal-previous-token enclosing-token)) |
| 907 | token)) | 863 | token)) |
| 908 | token))) | 864 | token))) |
| 909 | 865 | ||
| 910 | ;; A class/record start also begins a block. | 866 | ;; A class/record start also begins a block. |
| 911 | ((delphi-composite-type-start token last-token) | 867 | ((opascal-composite-type-start token last-token) |
| 912 | (throw 'done (if stop-on-class last-token token))) | 868 | (throw 'done (if stop-on-class last-token token))) |
| 913 | ) | 869 | ) |
| 914 | (unless (delphi-is token-kind delphi-whitespace) | 870 | (unless (opascal-is token-kind opascal-whitespace) |
| 915 | (setq last-token token)) | 871 | (setq last-token token)) |
| 916 | (setq token (delphi-previous-token token))) | 872 | (setq token (opascal-previous-token token))) |
| 917 | ;; Start not found. | 873 | ;; Start not found. |
| 918 | nil))) | 874 | nil))) |
| 919 | 875 | ||
| 920 | (defun delphi-else-start (from-else) | 876 | (defun opascal-else-start (from-else) |
| 921 | ;; Returns the token of the if or case statement. | 877 | ;; Returns the token of the if or case statement. |
| 922 | (let ((token (delphi-previous-token from-else)) | 878 | (let ((token (opascal-previous-token from-else)) |
| 923 | (token-kind nil) | 879 | (token-kind nil) |
| 924 | (semicolon-count 0)) | 880 | (semicolon-count 0)) |
| 925 | (catch 'done | 881 | (catch 'done |
| 926 | (while token | 882 | (while token |
| 927 | (setq token-kind (delphi-token-kind token)) | 883 | (setq token-kind (opascal-token-kind token)) |
| 928 | (cond | 884 | (cond |
| 929 | ;; Skip over nested groups. | 885 | ;; Skip over nested groups. |
| 930 | ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | 886 | ((eq 'close-group token-kind) (setq token (opascal-group-start token))) |
| 931 | 887 | ||
| 932 | ;; Skip over any nested blocks. | 888 | ;; Skip over any nested blocks. |
| 933 | ((delphi-is token-kind delphi-end-block-statements) | 889 | ((opascal-is token-kind opascal-end-block-statements) |
| 934 | (setq token (delphi-block-start token))) | 890 | (setq token (opascal-block-start token))) |
| 935 | 891 | ||
| 936 | ((eq 'semicolon token-kind) | 892 | ((eq 'semicolon token-kind) |
| 937 | ;; Semicolon means we are looking for an enclosing if, unless we | 893 | ;; Semicolon means we are looking for an enclosing if, unless we |
| @@ -947,151 +903,151 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 947 | ((eq 'case token-kind) | 903 | ((eq 'case token-kind) |
| 948 | ;; We have hit a case statement start. | 904 | ;; We have hit a case statement start. |
| 949 | (throw 'done token))) | 905 | (throw 'done token))) |
| 950 | (setq token (delphi-previous-token token))) | 906 | (setq token (opascal-previous-token token))) |
| 951 | ;; No if or case statement found. | 907 | ;; No if or case statement found. |
| 952 | nil))) | 908 | nil))) |
| 953 | 909 | ||
| 954 | (defun delphi-comment-content-start (comment) | 910 | (defun opascal-comment-content-start (comment) |
| 955 | ;; Returns the point of the first non-space character in the comment. | 911 | ;; Returns the point of the first non-space character in the comment. |
| 956 | (let ((kind (delphi-token-kind comment))) | 912 | (let ((kind (opascal-token-kind comment))) |
| 957 | (when (delphi-is kind delphi-comments) | 913 | (when (opascal-is kind opascal-comments) |
| 958 | (delphi-save-excursion | 914 | (opascal-save-excursion |
| 959 | (goto-char (+ (delphi-token-start comment) | 915 | (goto-char (+ (opascal-token-start comment) |
| 960 | (length (delphi-literal-start-pattern kind)))) | 916 | (length (opascal-literal-start-pattern kind)))) |
| 961 | (skip-chars-forward delphi-space-chars) | 917 | (skip-chars-forward opascal-space-chars) |
| 962 | (point))))) | 918 | (point))))) |
| 963 | 919 | ||
| 964 | (defun delphi-comment-block-start (comment) | 920 | (defun opascal-comment-block-start (comment) |
| 965 | ;; Returns the starting comment token of a contiguous // comment block. If | 921 | ;; Returns the starting comment token of a contiguous // comment block. If |
| 966 | ;; the comment is multiline (i.e. {...} or (*...*)), the original comment is | 922 | ;; the comment is multiline (i.e. {...} or (*...*)), the original comment is |
| 967 | ;; returned. | 923 | ;; returned. |
| 968 | (if (not (eq 'comment-single-line (delphi-token-kind comment))) | 924 | (if (not (eq 'comment-single-line (opascal-token-kind comment))) |
| 969 | comment | 925 | comment |
| 970 | ;; Scan until we run out of // comments. | 926 | ;; Scan until we run out of // comments. |
| 971 | (let ((prev-comment comment) | 927 | (let ((prev-comment comment) |
| 972 | (start-comment comment)) | 928 | (start-comment comment)) |
| 973 | (while (let ((kind (delphi-token-kind prev-comment))) | 929 | (while (let ((kind (opascal-token-kind prev-comment))) |
| 974 | (cond ((eq kind 'space)) | 930 | (cond ((eq kind 'space)) |
| 975 | ((eq kind 'comment-single-line) | 931 | ((eq kind 'comment-single-line) |
| 976 | (setq start-comment prev-comment)) | 932 | (setq start-comment prev-comment)) |
| 977 | (t nil))) | 933 | (t nil))) |
| 978 | (setq prev-comment (delphi-previous-token prev-comment))) | 934 | (setq prev-comment (opascal-previous-token prev-comment))) |
| 979 | start-comment))) | 935 | start-comment))) |
| 980 | 936 | ||
| 981 | (defun delphi-comment-block-end (comment) | 937 | (defun opascal-comment-block-end (comment) |
| 982 | ;; Returns the end comment token of a contiguous // comment block. If the | 938 | ;; Returns the end comment token of a contiguous // comment block. If the |
| 983 | ;; comment is multiline (i.e. {...} or (*...*)), the original comment is | 939 | ;; comment is multiline (i.e. {...} or (*...*)), the original comment is |
| 984 | ;; returned. | 940 | ;; returned. |
| 985 | (if (not (eq 'comment-single-line (delphi-token-kind comment))) | 941 | (if (not (eq 'comment-single-line (opascal-token-kind comment))) |
| 986 | comment | 942 | comment |
| 987 | ;; Scan until we run out of // comments. | 943 | ;; Scan until we run out of // comments. |
| 988 | (let ((next-comment comment) | 944 | (let ((next-comment comment) |
| 989 | (end-comment comment)) | 945 | (end-comment comment)) |
| 990 | (while (let ((kind (delphi-token-kind next-comment))) | 946 | (while (let ((kind (opascal-token-kind next-comment))) |
| 991 | (cond ((eq kind 'space)) | 947 | (cond ((eq kind 'space)) |
| 992 | ((eq kind 'comment-single-line) | 948 | ((eq kind 'comment-single-line) |
| 993 | (setq end-comment next-comment)) | 949 | (setq end-comment next-comment)) |
| 994 | (t nil))) | 950 | (t nil))) |
| 995 | (setq next-comment (delphi-next-token next-comment))) | 951 | (setq next-comment (opascal-next-token next-comment))) |
| 996 | end-comment))) | 952 | end-comment))) |
| 997 | 953 | ||
| 998 | (defun delphi-on-first-comment-line (comment) | 954 | (defun opascal-on-first-comment-line (comment) |
| 999 | ;; Returns true if the current point is on the first line of the comment. | 955 | ;; Returns true if the current point is on the first line of the comment. |
| 1000 | (save-excursion | 956 | (save-excursion |
| 1001 | (let ((comment-start (delphi-token-start comment)) | 957 | (let ((comment-start (opascal-token-start comment)) |
| 1002 | (current-point (point))) | 958 | (current-point (point))) |
| 1003 | (goto-char comment-start) | 959 | (goto-char comment-start) |
| 1004 | (end-of-line) | 960 | (end-of-line) |
| 1005 | (and (<= comment-start current-point) (<= current-point (point)))))) | 961 | (and (<= comment-start current-point) (<= current-point (point)))))) |
| 1006 | 962 | ||
| 1007 | (defun delphi-comment-indent-of (comment) | 963 | (defun opascal-comment-indent-of (comment) |
| 1008 | ;; Returns the correct indentation for the comment. | 964 | ;; Returns the correct indentation for the comment. |
| 1009 | (let ((start-comment (delphi-comment-block-start comment))) | 965 | (let ((start-comment (opascal-comment-block-start comment))) |
| 1010 | (if (and (eq start-comment comment) | 966 | (if (and (eq start-comment comment) |
| 1011 | (delphi-on-first-comment-line comment)) | 967 | (opascal-on-first-comment-line comment)) |
| 1012 | ;; Indent as a statement. | 968 | ;; Indent as a statement. |
| 1013 | (delphi-enclosing-indent-of comment) | 969 | (opascal-enclosing-indent-of comment) |
| 1014 | (save-excursion | 970 | (save-excursion |
| 1015 | (let ((kind (delphi-token-kind comment))) | 971 | (let ((kind (opascal-token-kind comment))) |
| 1016 | (beginning-of-line) | 972 | (beginning-of-line) |
| 1017 | (cond ((eq 'comment-single-line kind) | 973 | (cond ((eq 'comment-single-line kind) |
| 1018 | ;; Indent to the first comment in the // block. | 974 | ;; Indent to the first comment in the // block. |
| 1019 | (delphi-indent-of start-comment)) | 975 | (opascal-indent-of start-comment)) |
| 1020 | 976 | ||
| 1021 | ((looking-at (concat delphi-leading-spaces-re | 977 | ((looking-at (concat opascal-leading-spaces-re |
| 1022 | (delphi-literal-stop-pattern kind))) | 978 | (opascal-literal-stop-pattern kind))) |
| 1023 | ;; Indent multi-line comment terminators to the comment start. | 979 | ;; Indent multi-line comment terminators to the comment start. |
| 1024 | (delphi-indent-of comment)) | 980 | (opascal-indent-of comment)) |
| 1025 | 981 | ||
| 1026 | ;; Indent according to the comment's content start. | 982 | ;; Indent according to the comment's content start. |
| 1027 | ((delphi-column-of (delphi-comment-content-start comment))))))) | 983 | ((opascal-column-of (opascal-comment-content-start comment))))))) |
| 1028 | )) | 984 | )) |
| 1029 | 985 | ||
| 1030 | (defun delphi-is-use-clause-end (at-token last-token last-colon from-kind) | 986 | (defun opascal-is-use-clause-end (at-token last-token last-colon from-kind) |
| 1031 | ;; True if we are after the end of a uses type clause. | 987 | ;; True if we are after the end of a uses type clause. |
| 1032 | (when (and last-token | 988 | (when (and last-token |
| 1033 | (not last-colon) | 989 | (not last-colon) |
| 1034 | (eq 'comma (delphi-token-kind at-token)) | 990 | (eq 'comma (opascal-token-kind at-token)) |
| 1035 | (eq 'semicolon from-kind)) | 991 | (eq 'semicolon from-kind)) |
| 1036 | ;; Scan for the uses statement, just to be sure. | 992 | ;; Scan for the uses statement, just to be sure. |
| 1037 | (let ((token (delphi-previous-token at-token)) | 993 | (let ((token (opascal-previous-token at-token)) |
| 1038 | (token-kind nil)) | 994 | (token-kind nil)) |
| 1039 | (catch 'done | 995 | (catch 'done |
| 1040 | (while token | 996 | (while token |
| 1041 | (setq token-kind (delphi-token-kind token)) | 997 | (setq token-kind (opascal-token-kind token)) |
| 1042 | (cond ((delphi-is token-kind delphi-use-clauses) | 998 | (cond ((opascal-is token-kind opascal-use-clauses) |
| 1043 | (throw 'done t)) | 999 | (throw 'done t)) |
| 1044 | 1000 | ||
| 1045 | ;; Whitespace, identifiers, strings, "in" keyword, and commas | 1001 | ;; Whitespace, identifiers, strings, "in" keyword, and commas |
| 1046 | ;; are allowed in use clauses. | 1002 | ;; are allowed in use clauses. |
| 1047 | ((or (delphi-is token-kind '(word comma in newline)) | 1003 | ((or (opascal-is token-kind '(word comma in newline)) |
| 1048 | (delphi-is token-kind delphi-whitespace) | 1004 | (opascal-is token-kind opascal-whitespace) |
| 1049 | (delphi-is token-kind delphi-strings))) | 1005 | (opascal-is token-kind opascal-strings))) |
| 1050 | 1006 | ||
| 1051 | ;; Nothing else is. | 1007 | ;; Nothing else is. |
| 1052 | ((throw 'done nil))) | 1008 | ((throw 'done nil))) |
| 1053 | (setq token (delphi-previous-token token))) | 1009 | (setq token (opascal-previous-token token))) |
| 1054 | nil)))) | 1010 | nil)))) |
| 1055 | 1011 | ||
| 1056 | (defun delphi-is-block-after-expr-statement (token) | 1012 | (defun opascal-is-block-after-expr-statement (token) |
| 1057 | ;; Returns true if we have a block token trailing an expression delimiter (of | 1013 | ;; Returns true if we have a block token trailing an expression delimiter (of |
| 1058 | ;; presumably an expression statement). | 1014 | ;; presumably an expression statement). |
| 1059 | (when (delphi-is (delphi-token-kind token) delphi-block-statements) | 1015 | (when (opascal-is (opascal-token-kind token) opascal-block-statements) |
| 1060 | (let ((previous (delphi-previous-token token)) | 1016 | (let ((previous (opascal-previous-token token)) |
| 1061 | (previous-kind nil)) | 1017 | (previous-kind nil)) |
| 1062 | (while (progn | 1018 | (while (progn |
| 1063 | (setq previous-kind (delphi-token-kind previous)) | 1019 | (setq previous-kind (opascal-token-kind previous)) |
| 1064 | (eq previous-kind 'space)) | 1020 | (eq previous-kind 'space)) |
| 1065 | (setq previous (delphi-previous-token previous))) | 1021 | (setq previous (opascal-previous-token previous))) |
| 1066 | (or (delphi-is previous-kind delphi-expr-delimiters) | 1022 | (or (opascal-is previous-kind opascal-expr-delimiters) |
| 1067 | (eq previous-kind 'else))))) | 1023 | (eq previous-kind 'else))))) |
| 1068 | 1024 | ||
| 1069 | (defun delphi-previous-indent-of (from-token) | 1025 | (defun opascal-previous-indent-of (from-token) |
| 1070 | ;; Returns the indentation of the previous statement of the token. | 1026 | ;; Returns the indentation of the previous statement of the token. |
| 1071 | (let ((token (delphi-previous-token from-token)) | 1027 | (let ((token (opascal-previous-token from-token)) |
| 1072 | (token-kind nil) | 1028 | (token-kind nil) |
| 1073 | (from-kind (delphi-token-kind from-token)) | 1029 | (from-kind (opascal-token-kind from-token)) |
| 1074 | (last-colon nil) | 1030 | (last-colon nil) |
| 1075 | (last-of nil) | 1031 | (last-of nil) |
| 1076 | (last-token nil)) | 1032 | (last-token nil)) |
| 1077 | (catch 'done | 1033 | (catch 'done |
| 1078 | (while token | 1034 | (while token |
| 1079 | (setq token-kind (delphi-token-kind token)) | 1035 | (setq token-kind (opascal-token-kind token)) |
| 1080 | (cond | 1036 | (cond |
| 1081 | ;; An open ( or [ always is an indent point. | 1037 | ;; An open ( or [ always is an indent point. |
| 1082 | ((eq 'open-group token-kind) | 1038 | ((eq 'open-group token-kind) |
| 1083 | (throw 'done (delphi-open-group-indent token last-token))) | 1039 | (throw 'done (opascal-open-group-indent token last-token))) |
| 1084 | 1040 | ||
| 1085 | ;; Skip over any ()/[] groups. | 1041 | ;; Skip over any ()/[] groups. |
| 1086 | ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | 1042 | ((eq 'close-group token-kind) (setq token (opascal-group-start token))) |
| 1087 | 1043 | ||
| 1088 | ((delphi-is token-kind delphi-end-block-statements) | 1044 | ((opascal-is token-kind opascal-end-block-statements) |
| 1089 | (if (eq 'newline (delphi-token-kind (delphi-previous-token token))) | 1045 | (if (eq 'newline (opascal-token-kind (opascal-previous-token token))) |
| 1090 | ;; We can stop at an end token that is right up against the | 1046 | ;; We can stop at an end token that is right up against the |
| 1091 | ;; margin. | 1047 | ;; margin. |
| 1092 | (throw 'done 0) | 1048 | (throw 'done 0) |
| 1093 | ;; Otherwise, skip over any nested blocks. | 1049 | ;; Otherwise, skip over any nested blocks. |
| 1094 | (setq token (delphi-block-start token)))) | 1050 | (setq token (opascal-block-start token)))) |
| 1095 | 1051 | ||
| 1096 | ;; Special case: if we encounter a ", word;" then we assume that we | 1052 | ;; Special case: if we encounter a ", word;" then we assume that we |
| 1097 | ;; are in some kind of uses clause, and thus indent to column 0. This | 1053 | ;; are in some kind of uses clause, and thus indent to column 0. This |
| @@ -1102,19 +1058,19 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1102 | ;; someUnit, | 1058 | ;; someUnit, |
| 1103 | ;; someOtherUnit; | 1059 | ;; someOtherUnit; |
| 1104 | ;; // this should be at column 0! | 1060 | ;; // this should be at column 0! |
| 1105 | ((delphi-is-use-clause-end token last-token last-colon from-kind) | 1061 | ((opascal-is-use-clause-end token last-token last-colon from-kind) |
| 1106 | (throw 'done 0)) | 1062 | (throw 'done 0)) |
| 1107 | 1063 | ||
| 1108 | ;; A previous terminator means we can stop. If we are on a directive, | 1064 | ;; A previous terminator means we can stop. If we are on a directive, |
| 1109 | ;; however, then we are not actually encountering a new statement. | 1065 | ;; however, then we are not actually encountering a new statement. |
| 1110 | ((and last-token | 1066 | ((and last-token |
| 1111 | (delphi-is token-kind delphi-previous-terminators) | 1067 | (opascal-is token-kind opascal-previous-terminators) |
| 1112 | (not (delphi-is (delphi-token-kind last-token) | 1068 | (not (opascal-is (opascal-token-kind last-token) |
| 1113 | delphi-directives))) | 1069 | opascal-directives))) |
| 1114 | (throw 'done (delphi-stmt-line-indent-of last-token 0))) | 1070 | (throw 'done (opascal-stmt-line-indent-of last-token 0))) |
| 1115 | 1071 | ||
| 1116 | ;; Ignore whitespace. | 1072 | ;; Ignore whitespace. |
| 1117 | ((delphi-is token-kind delphi-whitespace)) | 1073 | ((opascal-is token-kind opascal-whitespace)) |
| 1118 | 1074 | ||
| 1119 | ;; Remember any "of" we encounter, since that affects how we | 1075 | ;; Remember any "of" we encounter, since that affects how we |
| 1120 | ;; indent to a case statement within a record declaration | 1076 | ;; indent to a case statement within a record declaration |
| @@ -1132,61 +1088,61 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1132 | ;; specially. | 1088 | ;; specially. |
| 1133 | ((eq 'case token-kind) | 1089 | ((eq 'case token-kind) |
| 1134 | (throw 'done | 1090 | (throw 'done |
| 1135 | (if last-colon (delphi-line-indent-of last-colon) | 1091 | (if last-colon (opascal-line-indent-of last-colon) |
| 1136 | (delphi-line-indent-of token delphi-case-label-indent)))) | 1092 | (opascal-line-indent-of token opascal-case-label-indent)))) |
| 1137 | 1093 | ||
| 1138 | ;; If we are in a use clause then commas mark an enclosing rather than | 1094 | ;; If we are in a use clause then commas mark an enclosing rather than |
| 1139 | ;; a previous statement. | 1095 | ;; a previous statement. |
| 1140 | ((delphi-is token-kind delphi-use-clauses) | 1096 | ((opascal-is token-kind opascal-use-clauses) |
| 1141 | (throw 'done | 1097 | (throw 'done |
| 1142 | (if (eq 'comma from-kind) | 1098 | (if (eq 'comma from-kind) |
| 1143 | (if last-token | 1099 | (if last-token |
| 1144 | ;; Indent to first unit in use clause. | 1100 | ;; Indent to first unit in use clause. |
| 1145 | (delphi-indent-of last-token) | 1101 | (opascal-indent-of last-token) |
| 1146 | ;; Indent from use clause keyword. | 1102 | ;; Indent from use clause keyword. |
| 1147 | (delphi-line-indent-of token delphi-indent-level)) | 1103 | (opascal-line-indent-of token opascal-indent-level)) |
| 1148 | ;; Indent to use clause keyword. | 1104 | ;; Indent to use clause keyword. |
| 1149 | (delphi-line-indent-of token)))) | 1105 | (opascal-line-indent-of token)))) |
| 1150 | 1106 | ||
| 1151 | ;; Assembly sections always indent in from the asm keyword. | 1107 | ;; Assembly sections always indent in from the asm keyword. |
| 1152 | ((eq token-kind 'asm) | 1108 | ((eq token-kind 'asm) |
| 1153 | (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) | 1109 | (throw 'done (opascal-stmt-line-indent-of token opascal-indent-level))) |
| 1154 | 1110 | ||
| 1155 | ;; An enclosing statement delimits a previous statement. | 1111 | ;; An enclosing statement delimits a previous statement. |
| 1156 | ;; We try to use the existing indent of the previous statement, | 1112 | ;; We try to use the existing indent of the previous statement, |
| 1157 | ;; otherwise we calculate from the enclosing statement. | 1113 | ;; otherwise we calculate from the enclosing statement. |
| 1158 | ((delphi-is token-kind delphi-previous-enclosing-statements) | 1114 | ((opascal-is token-kind opascal-previous-enclosing-statements) |
| 1159 | (throw 'done (if last-token | 1115 | (throw 'done (if last-token |
| 1160 | ;; Otherwise indent to the last token | 1116 | ;; Otherwise indent to the last token |
| 1161 | (delphi-line-indent-of last-token) | 1117 | (opascal-line-indent-of last-token) |
| 1162 | ;; Just indent from the enclosing keyword | 1118 | ;; Just indent from the enclosing keyword |
| 1163 | (delphi-line-indent-of token delphi-indent-level)))) | 1119 | (opascal-line-indent-of token opascal-indent-level)))) |
| 1164 | 1120 | ||
| 1165 | ;; A class or record declaration also delimits a previous statement. | 1121 | ;; A class or record declaration also delimits a previous statement. |
| 1166 | ((delphi-composite-type-start token last-token) | 1122 | ((opascal-composite-type-start token last-token) |
| 1167 | (throw | 1123 | (throw |
| 1168 | 'done | 1124 | 'done |
| 1169 | (if (delphi-is-simple-class-type last-token from-token) | 1125 | (if (opascal-is-simple-class-type last-token from-token) |
| 1170 | ;; c = class; or c = class of T; are previous statements. | 1126 | ;; c = class; or c = class of T; are previous statements. |
| 1171 | (delphi-line-indent-of token) | 1127 | (opascal-line-indent-of token) |
| 1172 | ;; Otherwise c = class ... or r = record ... are enclosing | 1128 | ;; Otherwise c = class ... or r = record ... are enclosing |
| 1173 | ;; statements. | 1129 | ;; statements. |
| 1174 | (delphi-line-indent-of last-token delphi-indent-level)))) | 1130 | (opascal-line-indent-of last-token opascal-indent-level)))) |
| 1175 | 1131 | ||
| 1176 | ;; We have a definite previous statement delimiter. | 1132 | ;; We have a definite previous statement delimiter. |
| 1177 | ((delphi-is token-kind delphi-previous-statements) | 1133 | ((opascal-is token-kind opascal-previous-statements) |
| 1178 | (throw 'done (delphi-stmt-line-indent-of token 0))) | 1134 | (throw 'done (opascal-stmt-line-indent-of token 0))) |
| 1179 | ) | 1135 | ) |
| 1180 | (unless (delphi-is token-kind delphi-whitespace) | 1136 | (unless (opascal-is token-kind opascal-whitespace) |
| 1181 | (setq last-token token)) | 1137 | (setq last-token token)) |
| 1182 | (setq token (delphi-previous-token token))) | 1138 | (setq token (opascal-previous-token token))) |
| 1183 | ;; We ran out of tokens. Indent to column 0. | 1139 | ;; We ran out of tokens. Indent to column 0. |
| 1184 | 0))) | 1140 | 0))) |
| 1185 | 1141 | ||
| 1186 | (defun delphi-section-indent-of (section-token) | 1142 | (defun opascal-section-indent-of (section-token) |
| 1187 | ;; Returns the indentation appropriate for begin/var/const/type/label | 1143 | ;; Returns the indentation appropriate for begin/var/const/type/label |
| 1188 | ;; tokens. | 1144 | ;; tokens. |
| 1189 | (let* ((token (delphi-previous-token section-token)) | 1145 | (let* ((token (opascal-previous-token section-token)) |
| 1190 | (token-kind nil) | 1146 | (token-kind nil) |
| 1191 | (last-token nil) | 1147 | (last-token nil) |
| 1192 | (nested-block-count 0) | 1148 | (nested-block-count 0) |
| @@ -1194,22 +1150,22 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1194 | (last-terminator nil)) | 1150 | (last-terminator nil)) |
| 1195 | (catch 'done | 1151 | (catch 'done |
| 1196 | (while token | 1152 | (while token |
| 1197 | (setq token-kind (delphi-token-kind token)) | 1153 | (setq token-kind (opascal-token-kind token)) |
| 1198 | (cond | 1154 | (cond |
| 1199 | ;; Always stop at unmatched ( or [. | 1155 | ;; Always stop at unmatched ( or [. |
| 1200 | ((eq token-kind 'open-group) | 1156 | ((eq token-kind 'open-group) |
| 1201 | (throw 'done (delphi-open-group-indent token last-token))) | 1157 | (throw 'done (opascal-open-group-indent token last-token))) |
| 1202 | 1158 | ||
| 1203 | ;; Skip over any ()/[] groups. | 1159 | ;; Skip over any ()/[] groups. |
| 1204 | ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | 1160 | ((eq 'close-group token-kind) (setq token (opascal-group-start token))) |
| 1205 | 1161 | ||
| 1206 | ((delphi-is token-kind delphi-end-block-statements) | 1162 | ((opascal-is token-kind opascal-end-block-statements) |
| 1207 | (if (eq 'newline (delphi-token-kind (delphi-previous-token token))) | 1163 | (if (eq 'newline (opascal-token-kind (opascal-previous-token token))) |
| 1208 | ;; We can stop at an end token that is right up against the | 1164 | ;; We can stop at an end token that is right up against the |
| 1209 | ;; margin. | 1165 | ;; margin. |
| 1210 | (throw 'done 0) | 1166 | (throw 'done 0) |
| 1211 | ;; Otherwise, skip over any nested blocks. | 1167 | ;; Otherwise, skip over any nested blocks. |
| 1212 | (setq token (delphi-block-start token) | 1168 | (setq token (opascal-block-start token) |
| 1213 | nested-block-count (1+ nested-block-count)))) | 1169 | nested-block-count (1+ nested-block-count)))) |
| 1214 | 1170 | ||
| 1215 | ;; Remember if we have encountered any forward routine declarations. | 1171 | ;; Remember if we have encountered any forward routine declarations. |
| @@ -1217,7 +1173,7 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1217 | (setq nested-block-count (1+ nested-block-count))) | 1173 | (setq nested-block-count (1+ nested-block-count))) |
| 1218 | 1174 | ||
| 1219 | ;; Mark the completion of a nested routine traversal. | 1175 | ;; Mark the completion of a nested routine traversal. |
| 1220 | ((and (delphi-is token-kind delphi-routine-statements) | 1176 | ((and (opascal-is token-kind opascal-routine-statements) |
| 1221 | (> nested-block-count 0)) | 1177 | (> nested-block-count 0)) |
| 1222 | (setq nested-block-count (1- nested-block-count))) | 1178 | (setq nested-block-count (1- nested-block-count))) |
| 1223 | 1179 | ||
| @@ -1225,50 +1181,50 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1225 | ((eq 'semicolon token-kind) (setq last-terminator token)) | 1181 | ((eq 'semicolon token-kind) (setq last-terminator token)) |
| 1226 | 1182 | ||
| 1227 | ;; Remember if we have encountered any expression delimiters. | 1183 | ;; Remember if we have encountered any expression delimiters. |
| 1228 | ((delphi-is token-kind delphi-expr-delimiters) | 1184 | ((opascal-is token-kind opascal-expr-delimiters) |
| 1229 | (setq expr-delimited token)) | 1185 | (setq expr-delimited token)) |
| 1230 | 1186 | ||
| 1231 | ;; Enclosing body statements are delimiting. We indent the compound | 1187 | ;; Enclosing body statements are delimiting. We indent the compound |
| 1232 | ;; bodies specially. | 1188 | ;; bodies specially. |
| 1233 | ((and (not last-terminator) | 1189 | ((and (not last-terminator) |
| 1234 | (delphi-is token-kind delphi-body-statements)) | 1190 | (opascal-is token-kind opascal-body-statements)) |
| 1235 | (throw 'done | 1191 | (throw 'done |
| 1236 | (delphi-stmt-line-indent-of token delphi-compound-block-indent))) | 1192 | (opascal-stmt-line-indent-of token opascal-compound-block-indent))) |
| 1237 | 1193 | ||
| 1238 | ;; An enclosing ":" means a label. | 1194 | ;; An enclosing ":" means a label. |
| 1239 | ((and (eq 'colon token-kind) | 1195 | ((and (eq 'colon token-kind) |
| 1240 | (delphi-is (delphi-token-kind section-token) | 1196 | (opascal-is (opascal-token-kind section-token) |
| 1241 | delphi-block-statements) | 1197 | opascal-block-statements) |
| 1242 | (not last-terminator) | 1198 | (not last-terminator) |
| 1243 | (not expr-delimited) | 1199 | (not expr-delimited) |
| 1244 | (not (eq 'equals (delphi-token-kind last-token)))) | 1200 | (not (eq 'equals (opascal-token-kind last-token)))) |
| 1245 | (throw 'done | 1201 | (throw 'done |
| 1246 | (delphi-stmt-line-indent-of token delphi-indent-level))) | 1202 | (opascal-stmt-line-indent-of token opascal-indent-level))) |
| 1247 | 1203 | ||
| 1248 | ;; Block and mid block tokens are always enclosing | 1204 | ;; Block and mid block tokens are always enclosing |
| 1249 | ((delphi-is token-kind delphi-begin-enclosing-tokens) | 1205 | ((opascal-is token-kind opascal-begin-enclosing-tokens) |
| 1250 | (throw 'done | 1206 | (throw 'done |
| 1251 | (delphi-stmt-line-indent-of token delphi-indent-level))) | 1207 | (opascal-stmt-line-indent-of token opascal-indent-level))) |
| 1252 | 1208 | ||
| 1253 | ;; Declaration sections and routines are delimiters, unless they | 1209 | ;; Declaration sections and routines are delimiters, unless they |
| 1254 | ;; are part of a nested routine. | 1210 | ;; are part of a nested routine. |
| 1255 | ((and (delphi-is token-kind delphi-decl-delimiters) | 1211 | ((and (opascal-is token-kind opascal-decl-delimiters) |
| 1256 | (= 0 nested-block-count)) | 1212 | (= 0 nested-block-count)) |
| 1257 | (throw 'done (delphi-line-indent-of token 0))) | 1213 | (throw 'done (opascal-line-indent-of token 0))) |
| 1258 | 1214 | ||
| 1259 | ;; Unit statements mean we indent right to the left. | 1215 | ;; Unit statements mean we indent right to the left. |
| 1260 | ((delphi-is token-kind delphi-unit-statements) (throw 'done 0)) | 1216 | ((opascal-is token-kind opascal-unit-statements) (throw 'done 0)) |
| 1261 | ) | 1217 | ) |
| 1262 | (unless (delphi-is token-kind delphi-whitespace) | 1218 | (unless (opascal-is token-kind opascal-whitespace) |
| 1263 | (setq last-token token)) | 1219 | (setq last-token token)) |
| 1264 | (setq token (delphi-previous-token token))) | 1220 | (setq token (opascal-previous-token token))) |
| 1265 | ;; We ran out of tokens. Indent to column 0. | 1221 | ;; We ran out of tokens. Indent to column 0. |
| 1266 | 0))) | 1222 | 0))) |
| 1267 | 1223 | ||
| 1268 | (defun delphi-enclosing-indent-of (from-token) | 1224 | (defun opascal-enclosing-indent-of (from-token) |
| 1269 | ;; Returns the indentation offset from the enclosing statement of the token. | 1225 | ;; Returns the indentation offset from the enclosing statement of the token. |
| 1270 | (let ((token (delphi-previous-token from-token)) | 1226 | (let ((token (opascal-previous-token from-token)) |
| 1271 | (from-kind (delphi-token-kind from-token)) | 1227 | (from-kind (opascal-token-kind from-token)) |
| 1272 | (token-kind nil) | 1228 | (token-kind nil) |
| 1273 | (stmt-start nil) | 1229 | (stmt-start nil) |
| 1274 | (last-token nil) | 1230 | (last-token nil) |
| @@ -1277,51 +1233,51 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1277 | (expr-delimited nil)) | 1233 | (expr-delimited nil)) |
| 1278 | (catch 'done | 1234 | (catch 'done |
| 1279 | (while token | 1235 | (while token |
| 1280 | (setq token-kind (delphi-token-kind token)) | 1236 | (setq token-kind (opascal-token-kind token)) |
| 1281 | (cond | 1237 | (cond |
| 1282 | ;; An open ( or [ always is an indent point. | 1238 | ;; An open ( or [ always is an indent point. |
| 1283 | ((eq 'open-group token-kind) | 1239 | ((eq 'open-group token-kind) |
| 1284 | (throw 'done | 1240 | (throw 'done |
| 1285 | (delphi-open-group-indent | 1241 | (opascal-open-group-indent |
| 1286 | token last-token | 1242 | token last-token |
| 1287 | (if (delphi-is from-kind delphi-binary-ops) | 1243 | (if (opascal-is from-kind opascal-binary-ops) |
| 1288 | ;; Keep binary operations aligned with the open group. | 1244 | ;; Keep binary operations aligned with the open group. |
| 1289 | 0 | 1245 | 0 |
| 1290 | delphi-indent-level)))) | 1246 | opascal-indent-level)))) |
| 1291 | 1247 | ||
| 1292 | ;; Skip over any ()/[] groups. | 1248 | ;; Skip over any ()/[] groups. |
| 1293 | ((eq 'close-group token-kind) (setq token (delphi-group-start token))) | 1249 | ((eq 'close-group token-kind) (setq token (opascal-group-start token))) |
| 1294 | 1250 | ||
| 1295 | ;; Skip over any nested blocks. | 1251 | ;; Skip over any nested blocks. |
| 1296 | ((delphi-is token-kind delphi-end-block-statements) | 1252 | ((opascal-is token-kind opascal-end-block-statements) |
| 1297 | (setq token (delphi-block-start token))) | 1253 | (setq token (opascal-block-start token))) |
| 1298 | 1254 | ||
| 1299 | ;; An expression delimiter affects indentation depending on whether | 1255 | ;; An expression delimiter affects indentation depending on whether |
| 1300 | ;; the point is before or after it. Remember that we encountered one. | 1256 | ;; the point is before or after it. Remember that we encountered one. |
| 1301 | ;; Also remember the last encountered token, since if it exists it | 1257 | ;; Also remember the last encountered token, since if it exists it |
| 1302 | ;; should be the actual indent point. | 1258 | ;; should be the actual indent point. |
| 1303 | ((delphi-is token-kind delphi-expr-delimiters) | 1259 | ((opascal-is token-kind opascal-expr-delimiters) |
| 1304 | (setq expr-delimited token stmt-start last-token)) | 1260 | (setq expr-delimited token stmt-start last-token)) |
| 1305 | 1261 | ||
| 1306 | ;; With a non-delimited expression statement we indent after the | 1262 | ;; With a non-delimited expression statement we indent after the |
| 1307 | ;; statement's keyword, unless we are on the delimiter itself. | 1263 | ;; statement's keyword, unless we are on the delimiter itself. |
| 1308 | ((and (not expr-delimited) | 1264 | ((and (not expr-delimited) |
| 1309 | (delphi-is token-kind delphi-expr-statements)) | 1265 | (opascal-is token-kind opascal-expr-statements)) |
| 1310 | (throw 'done | 1266 | (throw 'done |
| 1311 | (cond ((delphi-is from-kind delphi-expr-delimiters) | 1267 | (cond ((opascal-is from-kind opascal-expr-delimiters) |
| 1312 | ;; We are indenting a delimiter. Indent to the statement. | 1268 | ;; We are indenting a delimiter. Indent to the statement. |
| 1313 | (delphi-stmt-line-indent-of token 0)) | 1269 | (opascal-stmt-line-indent-of token 0)) |
| 1314 | 1270 | ||
| 1315 | ((and last-token (delphi-is from-kind delphi-binary-ops)) | 1271 | ((and last-token (opascal-is from-kind opascal-binary-ops)) |
| 1316 | ;; Align binary ops with the expression. | 1272 | ;; Align binary ops with the expression. |
| 1317 | (delphi-indent-of last-token)) | 1273 | (opascal-indent-of last-token)) |
| 1318 | 1274 | ||
| 1319 | (last-token | 1275 | (last-token |
| 1320 | ;; Indent in from the expression. | 1276 | ;; Indent in from the expression. |
| 1321 | (delphi-indent-of last-token delphi-indent-level)) | 1277 | (opascal-indent-of last-token opascal-indent-level)) |
| 1322 | 1278 | ||
| 1323 | ;; Indent in from the statement's keyword. | 1279 | ;; Indent in from the statement's keyword. |
| 1324 | ((delphi-indent-of token delphi-indent-level))))) | 1280 | ((opascal-indent-of token opascal-indent-level))))) |
| 1325 | 1281 | ||
| 1326 | ;; A delimited case statement indents the label according to | 1282 | ;; A delimited case statement indents the label according to |
| 1327 | ;; a special rule. | 1283 | ;; a special rule. |
| @@ -1330,72 +1286,72 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1330 | (if stmt-start | 1286 | (if stmt-start |
| 1331 | ;; We are not actually indenting to the case statement, | 1287 | ;; We are not actually indenting to the case statement, |
| 1332 | ;; but are within a label expression. | 1288 | ;; but are within a label expression. |
| 1333 | (delphi-stmt-line-indent-of | 1289 | (opascal-stmt-line-indent-of |
| 1334 | stmt-start delphi-indent-level) | 1290 | stmt-start opascal-indent-level) |
| 1335 | ;; Indent from the case keyword. | 1291 | ;; Indent from the case keyword. |
| 1336 | (delphi-stmt-line-indent-of | 1292 | (opascal-stmt-line-indent-of |
| 1337 | token delphi-case-label-indent)))) | 1293 | token opascal-case-label-indent)))) |
| 1338 | 1294 | ||
| 1339 | ;; Body expression statements are enclosing. Indent from the | 1295 | ;; Body expression statements are enclosing. Indent from the |
| 1340 | ;; statement's keyword, unless we have a non-block statement following | 1296 | ;; statement's keyword, unless we have a non-block statement following |
| 1341 | ;; it. | 1297 | ;; it. |
| 1342 | ((delphi-is token-kind delphi-body-expr-statements) | 1298 | ((opascal-is token-kind opascal-body-expr-statements) |
| 1343 | (throw 'done | 1299 | (throw 'done |
| 1344 | (delphi-stmt-line-indent-of | 1300 | (opascal-stmt-line-indent-of |
| 1345 | (or stmt-start token) delphi-indent-level))) | 1301 | (or stmt-start token) opascal-indent-level))) |
| 1346 | 1302 | ||
| 1347 | ;; An else statement is enclosing, but it doesn't have an expression. | 1303 | ;; An else statement is enclosing, but it doesn't have an expression. |
| 1348 | ;; Thus we take into account last-token instead of stmt-start. | 1304 | ;; Thus we take into account last-token instead of stmt-start. |
| 1349 | ((eq 'else token-kind) | 1305 | ((eq 'else token-kind) |
| 1350 | (throw 'done (delphi-stmt-line-indent-of | 1306 | (throw 'done (opascal-stmt-line-indent-of |
| 1351 | (or last-token token) delphi-indent-level))) | 1307 | (or last-token token) opascal-indent-level))) |
| 1352 | 1308 | ||
| 1353 | ;; We indent relative to an enclosing declaration section. | 1309 | ;; We indent relative to an enclosing declaration section. |
| 1354 | ((delphi-is token-kind delphi-decl-sections) | 1310 | ((opascal-is token-kind opascal-decl-sections) |
| 1355 | (throw 'done (delphi-indent-of (if last-token last-token token) | 1311 | (throw 'done (opascal-indent-of (if last-token last-token token) |
| 1356 | delphi-indent-level))) | 1312 | opascal-indent-level))) |
| 1357 | 1313 | ||
| 1358 | ;; In unit sections we indent right to the left. | 1314 | ;; In unit sections we indent right to the left. |
| 1359 | ((delphi-is token-kind delphi-unit-sections) | 1315 | ((opascal-is token-kind opascal-unit-sections) |
| 1360 | (throw 'done | 1316 | (throw 'done |
| 1361 | ;; Handle specially the case of "interface", which can be used | 1317 | ;; Handle specially the case of "interface", which can be used |
| 1362 | ;; to start either a unit section or an interface definition. | 1318 | ;; to start either a unit section or an interface definition. |
| 1363 | (if (delphi-is token-kind delphi-interface-types) | 1319 | (if (opascal-is token-kind opascal-interface-types) |
| 1364 | (progn | 1320 | (progn |
| 1365 | ;; Find the previous non-whitespace token. | 1321 | ;; Find the previous non-whitespace token. |
| 1366 | (while (progn | 1322 | (while (progn |
| 1367 | (setq last-token token | 1323 | (setq last-token token |
| 1368 | token (delphi-previous-token token) | 1324 | token (opascal-previous-token token) |
| 1369 | token-kind (delphi-token-kind token)) | 1325 | token-kind (opascal-token-kind token)) |
| 1370 | (and token | 1326 | (and token |
| 1371 | (delphi-is token-kind | 1327 | (opascal-is token-kind |
| 1372 | delphi-whitespace)))) | 1328 | opascal-whitespace)))) |
| 1373 | ;; If this token is an equals sign, "interface" is being | 1329 | ;; If this token is an equals sign, "interface" is being |
| 1374 | ;; used to start an interface definition and we should | 1330 | ;; used to start an interface definition and we should |
| 1375 | ;; treat it as a composite type; otherwise, we should | 1331 | ;; treat it as a composite type; otherwise, we should |
| 1376 | ;; consider it the start of a unit section. | 1332 | ;; consider it the start of a unit section. |
| 1377 | (if (and token (eq token-kind 'equals)) | 1333 | (if (and token (eq token-kind 'equals)) |
| 1378 | (delphi-line-indent-of last-token | 1334 | (opascal-line-indent-of last-token |
| 1379 | delphi-indent-level) | 1335 | opascal-indent-level) |
| 1380 | 0)) | 1336 | 0)) |
| 1381 | 0))) | 1337 | 0))) |
| 1382 | 1338 | ||
| 1383 | ;; A previous terminator means we can stop. | 1339 | ;; A previous terminator means we can stop. |
| 1384 | ((delphi-is token-kind delphi-previous-terminators) | 1340 | ((opascal-is token-kind opascal-previous-terminators) |
| 1385 | (throw 'done | 1341 | (throw 'done |
| 1386 | (cond ((and last-token | 1342 | (cond ((and last-token |
| 1387 | (eq 'comma token-kind) | 1343 | (eq 'comma token-kind) |
| 1388 | (delphi-is from-kind delphi-binary-ops)) | 1344 | (opascal-is from-kind opascal-binary-ops)) |
| 1389 | ;; Align binary ops with the expression. | 1345 | ;; Align binary ops with the expression. |
| 1390 | (delphi-indent-of last-token)) | 1346 | (opascal-indent-of last-token)) |
| 1391 | 1347 | ||
| 1392 | (last-token | 1348 | (last-token |
| 1393 | ;; Indent in from the expression. | 1349 | ;; Indent in from the expression. |
| 1394 | (delphi-indent-of last-token delphi-indent-level)) | 1350 | (opascal-indent-of last-token opascal-indent-level)) |
| 1395 | 1351 | ||
| 1396 | ;; No enclosing expression; use the previous statement's | 1352 | ;; No enclosing expression; use the previous statement's |
| 1397 | ;; indent. | 1353 | ;; indent. |
| 1398 | ((delphi-previous-indent-of token))))) | 1354 | ((opascal-previous-indent-of token))))) |
| 1399 | 1355 | ||
| 1400 | ;; A block statement after an expression delimiter has its start | 1356 | ;; A block statement after an expression delimiter has its start |
| 1401 | ;; column as the expression statement. E.g. | 1357 | ;; column as the expression statement. E.g. |
| @@ -1404,37 +1360,37 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1404 | ;; //... | 1360 | ;; //... |
| 1405 | ;; end; | 1361 | ;; end; |
| 1406 | ;; Remember it for when we encounter the expression statement start. | 1362 | ;; Remember it for when we encounter the expression statement start. |
| 1407 | ((delphi-is-block-after-expr-statement token) | 1363 | ((opascal-is-block-after-expr-statement token) |
| 1408 | (throw 'done | 1364 | (throw 'done |
| 1409 | (cond (last-token (delphi-indent-of last-token delphi-indent-level)) | 1365 | (cond (last-token (opascal-indent-of last-token opascal-indent-level)) |
| 1410 | 1366 | ||
| 1411 | ((+ (delphi-section-indent-of token) delphi-indent-level))))) | 1367 | ((+ (opascal-section-indent-of token) opascal-indent-level))))) |
| 1412 | 1368 | ||
| 1413 | ;; Assembly sections always indent in from the asm keyword. | 1369 | ;; Assembly sections always indent in from the asm keyword. |
| 1414 | ((eq token-kind 'asm) | 1370 | ((eq token-kind 'asm) |
| 1415 | (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) | 1371 | (throw 'done (opascal-stmt-line-indent-of token opascal-indent-level))) |
| 1416 | 1372 | ||
| 1417 | ;; Stop at an enclosing statement and indent from it. | 1373 | ;; Stop at an enclosing statement and indent from it. |
| 1418 | ((delphi-is token-kind delphi-enclosing-statements) | 1374 | ((opascal-is token-kind opascal-enclosing-statements) |
| 1419 | (throw 'done (delphi-stmt-line-indent-of | 1375 | (throw 'done (opascal-stmt-line-indent-of |
| 1420 | (or last-token token) delphi-indent-level))) | 1376 | (or last-token token) opascal-indent-level))) |
| 1421 | 1377 | ||
| 1422 | ;; A class/record declaration is also enclosing. | 1378 | ;; A class/record declaration is also enclosing. |
| 1423 | ((delphi-composite-type-start token last-token) | 1379 | ((opascal-composite-type-start token last-token) |
| 1424 | (throw 'done | 1380 | (throw 'done |
| 1425 | (delphi-line-indent-of last-token delphi-indent-level))) | 1381 | (opascal-line-indent-of last-token opascal-indent-level))) |
| 1426 | 1382 | ||
| 1427 | ;; A ":" we indent relative to its line beginning. If we are in a | 1383 | ;; A ":" we indent relative to its line beginning. If we are in a |
| 1428 | ;; parameter list, then stop also if we hit a ";". | 1384 | ;; parameter list, then stop also if we hit a ";". |
| 1429 | ((and (eq token-kind 'colon) | 1385 | ((and (eq token-kind 'colon) |
| 1430 | (not expr-delimited) | 1386 | (not expr-delimited) |
| 1431 | (not (delphi-is from-kind delphi-expr-delimiters)) | 1387 | (not (opascal-is from-kind opascal-expr-delimiters)) |
| 1432 | (not equals-encountered) | 1388 | (not equals-encountered) |
| 1433 | (not (eq from-kind 'equals))) | 1389 | (not (eq from-kind 'equals))) |
| 1434 | (throw 'done | 1390 | (throw 'done |
| 1435 | (if last-token | 1391 | (if last-token |
| 1436 | (delphi-indent-of last-token delphi-indent-level) | 1392 | (opascal-indent-of last-token opascal-indent-level) |
| 1437 | (delphi-line-indent-of token delphi-indent-level 'semicolon)))) | 1393 | (opascal-line-indent-of token opascal-indent-level 'semicolon)))) |
| 1438 | 1394 | ||
| 1439 | ;; If the ":" was not processed above and we have token after the "=", | 1395 | ;; If the ":" was not processed above and we have token after the "=", |
| 1440 | ;; then indent from the "=". Ignore :=, however. | 1396 | ;; then indent from the "=". Ignore :=, however. |
| @@ -1449,88 +1405,88 @@ non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: | |||
| 1449 | ;; + 2; | 1405 | ;; + 2; |
| 1450 | ;; which doesn't look right. | 1406 | ;; which doesn't look right. |
| 1451 | ;;;; Align binary ops with the before token. | 1407 | ;;;; Align binary ops with the before token. |
| 1452 | ;;((delphi-is from-kind delphi-binary-ops) | 1408 | ;;((opascal-is from-kind opascal-binary-ops) |
| 1453 | ;;(throw 'done (delphi-indent-of before-equals 0))) | 1409 | ;;(throw 'done (opascal-indent-of before-equals 0))) |
| 1454 | 1410 | ||
| 1455 | ;; Assignments (:=) we skip over to get a normal indent. | 1411 | ;; Assignments (:=) we skip over to get a normal indent. |
| 1456 | ((eq (delphi-token-kind last-token) 'equals)) | 1412 | ((eq (opascal-token-kind last-token) 'equals)) |
| 1457 | 1413 | ||
| 1458 | ;; Otherwise indent in from the equals. | 1414 | ;; Otherwise indent in from the equals. |
| 1459 | ((throw 'done | 1415 | ((throw 'done |
| 1460 | (delphi-indent-of before-equals delphi-indent-level))))) | 1416 | (opascal-indent-of before-equals opascal-indent-level))))) |
| 1461 | 1417 | ||
| 1462 | ;; Remember any "=" we encounter if it has not already been processed. | 1418 | ;; Remember any "=" we encounter if it has not already been processed. |
| 1463 | ((eq token-kind 'equals) | 1419 | ((eq token-kind 'equals) |
| 1464 | (setq equals-encountered token | 1420 | (setq equals-encountered token |
| 1465 | before-equals last-token)) | 1421 | before-equals last-token)) |
| 1466 | ) | 1422 | ) |
| 1467 | (unless (delphi-is token-kind delphi-whitespace) | 1423 | (unless (opascal-is token-kind opascal-whitespace) |
| 1468 | (setq last-token token)) | 1424 | (setq last-token token)) |
| 1469 | (setq token (delphi-previous-token token))) | 1425 | (setq token (opascal-previous-token token))) |
| 1470 | ;; We ran out of tokens. Indent to column 0. | 1426 | ;; We ran out of tokens. Indent to column 0. |
| 1471 | 0))) | 1427 | 0))) |
| 1472 | 1428 | ||
| 1473 | (defun delphi-corrected-indentation () | 1429 | (defun opascal-corrected-indentation () |
| 1474 | ;; Returns the corrected indentation for the current line. | 1430 | ;; Returns the corrected indentation for the current line. |
| 1475 | (delphi-save-excursion | 1431 | (opascal-save-excursion |
| 1476 | (delphi-progress-start) | 1432 | (opascal-progress-start) |
| 1477 | ;; Move to the first token on the line. | 1433 | ;; Move to the first token on the line. |
| 1478 | (beginning-of-line) | 1434 | (beginning-of-line) |
| 1479 | (skip-chars-forward delphi-space-chars) | 1435 | (skip-chars-forward opascal-space-chars) |
| 1480 | (let* ((token (delphi-current-token)) | 1436 | (let* ((token (opascal-current-token)) |
| 1481 | (token-kind (delphi-token-kind token)) | 1437 | (token-kind (opascal-token-kind token)) |
| 1482 | (indent | 1438 | (indent |
| 1483 | (cond ((eq 'close-group token-kind) | 1439 | (cond ((eq 'close-group token-kind) |
| 1484 | ;; Indent to the matching start ( or [. | 1440 | ;; Indent to the matching start ( or [. |
| 1485 | (delphi-indent-of (delphi-group-start token))) | 1441 | (opascal-indent-of (opascal-group-start token))) |
| 1486 | 1442 | ||
| 1487 | ((delphi-is token-kind delphi-unit-statements) 0) | 1443 | ((opascal-is token-kind opascal-unit-statements) 0) |
| 1488 | 1444 | ||
| 1489 | ((delphi-is token-kind delphi-comments) | 1445 | ((opascal-is token-kind opascal-comments) |
| 1490 | ;; In a comment. | 1446 | ;; In a comment. |
| 1491 | (delphi-comment-indent-of token)) | 1447 | (opascal-comment-indent-of token)) |
| 1492 | 1448 | ||
| 1493 | ((delphi-is token-kind delphi-decl-matchers) | 1449 | ((opascal-is token-kind opascal-decl-matchers) |
| 1494 | ;; Use a previous section/routine's indent. | 1450 | ;; Use a previous section/routine's indent. |
| 1495 | (delphi-section-indent-of token)) | 1451 | (opascal-section-indent-of token)) |
| 1496 | 1452 | ||
| 1497 | ((delphi-is token-kind delphi-match-block-statements) | 1453 | ((opascal-is token-kind opascal-match-block-statements) |
| 1498 | ;; Use the block's indentation. | 1454 | ;; Use the block's indentation. |
| 1499 | (let ((block-start | 1455 | (let ((block-start |
| 1500 | (delphi-block-start token 'stop-on-class))) | 1456 | (opascal-block-start token 'stop-on-class))) |
| 1501 | (cond | 1457 | (cond |
| 1502 | ;; When trailing a body statement, indent to | 1458 | ;; When trailing a body statement, indent to |
| 1503 | ;; the statement's keyword. | 1459 | ;; the statement's keyword. |
| 1504 | ((delphi-is-block-after-expr-statement block-start) | 1460 | ((opascal-is-block-after-expr-statement block-start) |
| 1505 | (delphi-section-indent-of block-start)) | 1461 | (opascal-section-indent-of block-start)) |
| 1506 | 1462 | ||
| 1507 | ;; Otherwise just indent to the block start. | 1463 | ;; Otherwise just indent to the block start. |
| 1508 | ((delphi-stmt-line-indent-of block-start 0))))) | 1464 | ((opascal-stmt-line-indent-of block-start 0))))) |
| 1509 | 1465 | ||
| 1510 | ((eq 'else token-kind) | 1466 | ((eq 'else token-kind) |
| 1511 | ;; Find the start of the if or case statement. | 1467 | ;; Find the start of the if or case statement. |
| 1512 | (delphi-stmt-line-indent-of (delphi-else-start token) 0)) | 1468 | (opascal-stmt-line-indent-of (opascal-else-start token) 0)) |
| 1513 | 1469 | ||
| 1514 | ;; Otherwise indent in from enclosing statement. | 1470 | ;; Otherwise indent in from enclosing statement. |
| 1515 | ((delphi-enclosing-indent-of | 1471 | ((opascal-enclosing-indent-of |
| 1516 | (if token token (delphi-token-at (1- (point))))))))) | 1472 | (if token token (opascal-token-at (1- (point))))))))) |
| 1517 | (delphi-progress-done) | 1473 | (opascal-progress-done) |
| 1518 | indent))) | 1474 | indent))) |
| 1519 | 1475 | ||
| 1520 | (defun delphi-indent-line () | 1476 | (defun opascal-indent-line () |
| 1521 | "Indent the current line according to the current language construct. | 1477 | "Indent the current line according to the current language construct. |
| 1522 | If before the indent, the point is moved to the indent." | 1478 | If before the indent, the point is moved to the indent." |
| 1523 | (interactive) | 1479 | (interactive) |
| 1524 | (delphi-save-match-data | 1480 | (save-match-data |
| 1525 | (let ((marked-point (point-marker)) ; Maintain our position reliably. | 1481 | (let ((marked-point (point-marker)) ; Maintain our position reliably. |
| 1526 | (line-start nil) | 1482 | (line-start nil) |
| 1527 | (old-indent 0) | 1483 | (old-indent 0) |
| 1528 | (new-indent 0)) | 1484 | (new-indent 0)) |
| 1529 | (beginning-of-line) | 1485 | (beginning-of-line) |
| 1530 | (setq line-start (point)) | 1486 | (setq line-start (point)) |
| 1531 | (skip-chars-forward delphi-space-chars) | 1487 | (skip-chars-forward opascal-space-chars) |
| 1532 | (setq old-indent (current-column)) | 1488 | (setq old-indent (current-column)) |
| 1533 | (setq new-indent (delphi-corrected-indentation)) | 1489 | (setq new-indent (opascal-corrected-indentation)) |
| 1534 | (if (< marked-point (point)) | 1490 | (if (< marked-point (point)) |
| 1535 | ;; If before the indent column, then move to it. | 1491 | ;; If before the indent column, then move to it. |
| 1536 | (set-marker marked-point (point))) | 1492 | (set-marker marked-point (point))) |
| @@ -1542,17 +1498,17 @@ If before the indent, the point is moved to the indent." | |||
| 1542 | (goto-char marked-point) | 1498 | (goto-char marked-point) |
| 1543 | (set-marker marked-point nil)))) | 1499 | (set-marker marked-point nil)))) |
| 1544 | 1500 | ||
| 1545 | (defvar delphi-mode-abbrev-table nil | 1501 | (defvar opascal-mode-abbrev-table nil |
| 1546 | "Abbrev table in use in Delphi mode buffers.") | 1502 | "Abbrev table in use in OPascal mode buffers.") |
| 1547 | (define-abbrev-table 'delphi-mode-abbrev-table ()) | 1503 | (define-abbrev-table 'opascal-mode-abbrev-table ()) |
| 1548 | 1504 | ||
| 1549 | (defmacro delphi-ensure-buffer (buffer-var buffer-name) | 1505 | (defmacro opascal-ensure-buffer (buffer-var buffer-name) |
| 1550 | ;; Ensures there exists a buffer of the specified name in the specified | 1506 | ;; Ensures there exists a buffer of the specified name in the specified |
| 1551 | ;; variable. | 1507 | ;; variable. |
| 1552 | `(when (not (buffer-live-p ,buffer-var)) | 1508 | `(when (not (buffer-live-p ,buffer-var)) |
| 1553 | (setq ,buffer-var (get-buffer-create ,buffer-name)))) | 1509 | (setq ,buffer-var (get-buffer-create ,buffer-name)))) |
| 1554 | 1510 | ||
| 1555 | (defun delphi-log-msg (to-buffer the-msg) | 1511 | (defun opascal-log-msg (to-buffer the-msg) |
| 1556 | ;; Writes a message to the end of the specified buffer. | 1512 | ;; Writes a message to the end of the specified buffer. |
| 1557 | (with-current-buffer to-buffer | 1513 | (with-current-buffer to-buffer |
| 1558 | (save-selected-window | 1514 | (save-selected-window |
| @@ -1563,176 +1519,160 @@ If before the indent, the point is moved to the indent." | |||
| 1563 | 1519 | ||
| 1564 | ;; Debugging helpers: | 1520 | ;; Debugging helpers: |
| 1565 | 1521 | ||
| 1566 | (defvar delphi-debug-buffer nil | 1522 | (defvar opascal-debug-buffer nil |
| 1567 | "Buffer to write Delphi mode debug messages to. Created on demand.") | 1523 | "Buffer to write OPascal mode debug messages to. Created on demand.") |
| 1568 | 1524 | ||
| 1569 | (defun delphi-debug-log (format-string &rest args) | 1525 | (defun opascal-debug-log (format-string &rest args) |
| 1570 | ;; Writes a message to the log buffer. | 1526 | ;; Writes a message to the log buffer. |
| 1571 | (when delphi-debug | 1527 | (when opascal-debug |
| 1572 | (delphi-ensure-buffer delphi-debug-buffer "*Delphi Debug Log*") | 1528 | (opascal-ensure-buffer opascal-debug-buffer "*OPascal Debug Log*") |
| 1573 | (delphi-log-msg delphi-debug-buffer | 1529 | (opascal-log-msg opascal-debug-buffer |
| 1574 | (concat (format-time-string "%H:%M:%S " (current-time)) | 1530 | (concat (format-time-string "%H:%M:%S " (current-time)) |
| 1575 | (apply #'format (cons format-string args)) | 1531 | (apply #'format (cons format-string args)) |
| 1576 | "\n")))) | 1532 | "\n")))) |
| 1577 | 1533 | ||
| 1578 | (defun delphi-debug-token-string (token) | 1534 | (defun opascal-debug-token-string (token) |
| 1579 | (let* ((image (delphi-token-string token)) | 1535 | (let* ((image (opascal-token-string token)) |
| 1580 | (has-newline (string-match "^\\([^\n]*\\)\n\\(.+\\)?$" image))) | 1536 | (has-newline (string-match "^\\([^\n]*\\)\n\\(.+\\)?$" image))) |
| 1581 | (when has-newline | 1537 | (when has-newline |
| 1582 | (setq image (concat (match-string 1 image) | 1538 | (setq image (concat (match-string 1 image) |
| 1583 | (if (match-beginning 2) "...")))) | 1539 | (if (match-beginning 2) "...")))) |
| 1584 | image)) | 1540 | image)) |
| 1585 | 1541 | ||
| 1586 | (defun delphi-debug-show-current-token () | 1542 | (defun opascal-debug-show-current-token () |
| 1587 | (interactive) | 1543 | (interactive) |
| 1588 | (let ((token (delphi-current-token))) | 1544 | (let ((token (opascal-current-token))) |
| 1589 | (delphi-debug-log "Token: %S %S" token (delphi-debug-token-string token)))) | 1545 | (opascal-debug-log "Token: %S %S" token (opascal-debug-token-string token)))) |
| 1590 | 1546 | ||
| 1591 | (defun delphi-debug-goto-point (p) | 1547 | (defun opascal-debug-goto-point (p) |
| 1592 | (interactive "NGoto char: ") | 1548 | (interactive "NGoto char: ") |
| 1593 | (goto-char p)) | 1549 | (goto-char p)) |
| 1594 | 1550 | ||
| 1595 | (defun delphi-debug-goto-next-token () | 1551 | (defun opascal-debug-goto-next-token () |
| 1596 | (interactive) | 1552 | (interactive) |
| 1597 | (goto-char (delphi-token-start (delphi-next-token (delphi-current-token))))) | 1553 | (goto-char (opascal-token-start (opascal-next-token (opascal-current-token))))) |
| 1598 | 1554 | ||
| 1599 | (defun delphi-debug-goto-previous-token () | 1555 | (defun opascal-debug-goto-previous-token () |
| 1600 | (interactive) | 1556 | (interactive) |
| 1601 | (goto-char | 1557 | (goto-char |
| 1602 | (delphi-token-start (delphi-previous-token (delphi-current-token))))) | 1558 | (opascal-token-start (opascal-previous-token (opascal-current-token))))) |
| 1603 | 1559 | ||
| 1604 | (defun delphi-debug-show-current-string (from to) | 1560 | (defun opascal-debug-show-current-string (from to) |
| 1605 | (interactive "r") | 1561 | (interactive "r") |
| 1606 | (delphi-debug-log "String: %S" (buffer-substring from to))) | 1562 | (opascal-debug-log "String: %S" (buffer-substring from to))) |
| 1607 | 1563 | ||
| 1608 | (defun delphi-debug-show-is-stable () | 1564 | (defun opascal-debug-show-is-stable () |
| 1609 | (interactive) | 1565 | (interactive) |
| 1610 | (delphi-debug-log "stable: %S prev: %S next: %S" | 1566 | (opascal-debug-log "stable: %S prev: %S next: %S" |
| 1611 | (delphi-is-stable-literal (point)) | 1567 | (opascal-is-stable-literal (point)) |
| 1612 | (delphi-literal-kind (1- (point))) | 1568 | (opascal-literal-kind (1- (point))) |
| 1613 | (delphi-literal-kind (point)))) | 1569 | (opascal-literal-kind (point)))) |
| 1614 | 1570 | ||
| 1615 | (defun delphi-debug-unparse-buffer () | 1571 | (defun opascal-debug-unparse-buffer () |
| 1616 | (interactive) | 1572 | (interactive) |
| 1617 | (delphi-set-text-properties (point-min) (point-max) nil)) | 1573 | (opascal-set-text-properties (point-min) (point-max) nil)) |
| 1618 | 1574 | ||
| 1619 | (defun delphi-debug-parse-region (from to) | 1575 | (defun opascal-debug-parse-region (from to) |
| 1620 | (interactive "r") | 1576 | (interactive "r") |
| 1621 | (let ((delphi-verbose t)) | 1577 | (let ((opascal-verbose t)) |
| 1622 | (delphi-save-excursion | 1578 | (opascal-save-excursion |
| 1623 | (delphi-progress-start) | 1579 | (opascal-progress-start) |
| 1624 | (delphi-parse-region from to) | 1580 | (opascal-parse-region from to) |
| 1625 | (delphi-progress-done "Parsing done")))) | 1581 | (opascal-progress-done "Parsing done")))) |
| 1626 | 1582 | ||
| 1627 | (defun delphi-debug-parse-window () | 1583 | (defun opascal-debug-parse-window () |
| 1628 | (interactive) | 1584 | (interactive) |
| 1629 | (delphi-debug-parse-region (window-start) (window-end))) | 1585 | (opascal-debug-parse-region (window-start) (window-end))) |
| 1630 | 1586 | ||
| 1631 | (defun delphi-debug-parse-buffer () | 1587 | (defun opascal-debug-parse-buffer () |
| 1632 | (interactive) | 1588 | (interactive) |
| 1633 | (delphi-debug-parse-region (point-min) (point-max))) | 1589 | (opascal-debug-parse-region (point-min) (point-max))) |
| 1634 | 1590 | ||
| 1635 | (defun delphi-debug-fontify-window () | 1591 | (defun opascal-debug-fontify-window () |
| 1636 | (interactive) | 1592 | (interactive) |
| 1637 | (delphi-fontify-region (window-start) (window-end) t)) | 1593 | (opascal-fontify-region (window-start) (window-end) t)) |
| 1638 | 1594 | ||
| 1639 | (defun delphi-debug-fontify-buffer () | 1595 | (defun opascal-debug-fontify-buffer () |
| 1640 | (interactive) | 1596 | (interactive) |
| 1641 | (delphi-fontify-region (point-min) (point-max) t)) | 1597 | (opascal-fontify-region (point-min) (point-max) t)) |
| 1642 | 1598 | ||
| 1643 | (defun delphi-debug-tokenize-region (from to) | 1599 | (defun opascal-debug-tokenize-region (from to) |
| 1644 | (interactive) | 1600 | (interactive) |
| 1645 | (delphi-save-excursion | 1601 | (opascal-save-excursion |
| 1646 | (delphi-progress-start) | 1602 | (opascal-progress-start) |
| 1647 | (goto-char from) | 1603 | (goto-char from) |
| 1648 | (while (< (point) to) | 1604 | (while (< (point) to) |
| 1649 | (goto-char (delphi-token-end (delphi-current-token))) | 1605 | (goto-char (opascal-token-end (opascal-current-token))) |
| 1650 | (delphi-step-progress (point) "Tokenizing" delphi-scanning-progress-step)) | 1606 | (opascal-step-progress (point) "Tokenizing" opascal-scanning-progress-step)) |
| 1651 | (delphi-progress-done "Tokenizing done"))) | 1607 | (opascal-progress-done "Tokenizing done"))) |
| 1652 | 1608 | ||
| 1653 | (defun delphi-debug-tokenize-buffer () | 1609 | (defun opascal-debug-tokenize-buffer () |
| 1654 | (interactive) | 1610 | (interactive) |
| 1655 | (delphi-debug-tokenize-region (point-min) (point-max))) | 1611 | (opascal-debug-tokenize-region (point-min) (point-max))) |
| 1656 | 1612 | ||
| 1657 | (defun delphi-debug-tokenize-window () | 1613 | (defun opascal-debug-tokenize-window () |
| 1658 | (interactive) | 1614 | (interactive) |
| 1659 | (delphi-debug-tokenize-region (window-start) (window-end))) | 1615 | (opascal-debug-tokenize-region (window-start) (window-end))) |
| 1660 | 1616 | ||
| 1661 | (defun delphi-newline () | 1617 | |
| 1662 | "Terminate the current line with a newline and indent the next, unless | 1618 | (defun opascal-tab () |
| 1663 | `delphi-newline-always-indents' is nil, in which case no reindenting occurs." | ||
| 1664 | (interactive) | ||
| 1665 | ;; Remove trailing spaces | ||
| 1666 | (delete-horizontal-space) | ||
| 1667 | (newline) | ||
| 1668 | (when delphi-newline-always-indents | ||
| 1669 | ;; Indent both the (now) previous and current line first. | ||
| 1670 | (save-excursion | ||
| 1671 | (forward-line -1) | ||
| 1672 | (delphi-indent-line)) | ||
| 1673 | (delphi-indent-line))) | ||
| 1674 | |||
| 1675 | |||
| 1676 | (defun delphi-tab () | ||
| 1677 | "Indent the region, when Transient Mark mode is enabled and the region is | 1619 | "Indent the region, when Transient Mark mode is enabled and the region is |
| 1678 | active. Otherwise, indent the current line or insert a TAB, depending on the | 1620 | active. Otherwise, indent the current line or insert a TAB, depending on the |
| 1679 | value of `delphi-tab-always-indents' and the current line position." | 1621 | value of `opascal-tab-always-indents' and the current line position." |
| 1680 | (interactive) | 1622 | (interactive) |
| 1681 | (cond ((use-region-p) | 1623 | (cond ((use-region-p) |
| 1682 | ;; If Transient Mark mode is enabled and the region is active, indent | 1624 | ;; If Transient Mark mode is enabled and the region is active, indent |
| 1683 | ;; the entire region. | 1625 | ;; the entire region. |
| 1684 | (indent-region (region-beginning) (region-end))) | 1626 | (indent-region (region-beginning) (region-end))) |
| 1685 | ((or delphi-tab-always-indents | 1627 | ((or opascal-tab-always-indents |
| 1686 | (save-excursion (skip-chars-backward delphi-space-chars) (bolp))) | 1628 | (save-excursion (skip-chars-backward opascal-space-chars) (bolp))) |
| 1687 | ;; Otherwise, if we are configured always to indent (regardless of the | 1629 | ;; Otherwise, if we are configured always to indent (regardless of the |
| 1688 | ;; point's position in the line) or we are before the first non-space | 1630 | ;; point's position in the line) or we are before the first non-space |
| 1689 | ;; character on the line, indent the line. | 1631 | ;; character on the line, indent the line. |
| 1690 | (delphi-indent-line)) | 1632 | (opascal-indent-line)) |
| 1691 | (t | 1633 | (t |
| 1692 | ;; Otherwise, insert a tab character. | 1634 | ;; Otherwise, insert a tab character. |
| 1693 | (insert "\t")))) | 1635 | (insert "\t")))) |
| 1694 | 1636 | ||
| 1695 | 1637 | ||
| 1696 | (defun delphi-is-directory (path) | 1638 | (defun opascal-is-directory (path) |
| 1697 | ;; True if the specified path is an existing directory. | 1639 | ;; True if the specified path is an existing directory. |
| 1698 | (let ((attributes (file-attributes path))) | 1640 | (let ((attributes (file-attributes path))) |
| 1699 | (and attributes (car attributes)))) | 1641 | (and attributes (car attributes)))) |
| 1700 | 1642 | ||
| 1701 | (defun delphi-is-file (path) | 1643 | (defun opascal-is-file (path) |
| 1702 | ;; True if the specified file exists as a file. | 1644 | ;; True if the specified file exists as a file. |
| 1703 | (let ((attributes (file-attributes path))) | 1645 | (let ((attributes (file-attributes path))) |
| 1704 | (and attributes (null (car attributes))))) | 1646 | (and attributes (null (car attributes))))) |
| 1705 | 1647 | ||
| 1706 | (defun delphi-search-directory (unit dir &optional recurse) | 1648 | (defun opascal-search-directory (unit dir &optional recurse) |
| 1707 | ;; Searches for the unit in the specified directory. If recurse is true, then | 1649 | ;; Searches for the unit in the specified directory. If recurse is true, then |
| 1708 | ;; the directory is recursively searched. File name comparison is done in a | 1650 | ;; the directory is recursively searched. File name comparison is done in a |
| 1709 | ;; case insensitive manner. | 1651 | ;; case insensitive manner. |
| 1710 | (when (delphi-is-directory dir) | 1652 | (when (opascal-is-directory dir) |
| 1711 | (let ((files (directory-files dir)) | 1653 | (let ((files (directory-files dir)) |
| 1712 | (unit-file (downcase unit))) | 1654 | (unit-file (downcase unit))) |
| 1713 | (catch 'done | 1655 | (catch 'done |
| 1714 | ;; Search for the file. | 1656 | ;; Search for the file. |
| 1715 | (mapc #'(lambda (file) | 1657 | (dolist (file files) |
| 1716 | (let ((path (concat dir "/" file))) | 1658 | (let ((path (concat dir "/" file))) |
| 1717 | (if (and (string= unit-file (downcase file)) | 1659 | (if (and (string= unit-file (downcase file)) |
| 1718 | (delphi-is-file path)) | 1660 | (opascal-is-file path)) |
| 1719 | (throw 'done path)))) | 1661 | (throw 'done path)))) |
| 1720 | files) | ||
| 1721 | 1662 | ||
| 1722 | ;; Not found. Search subdirectories. | 1663 | ;; Not found. Search subdirectories. |
| 1723 | (when recurse | 1664 | (when recurse |
| 1724 | (mapc #'(lambda (subdir) | 1665 | (dolist (subdir files) |
| 1725 | (unless (member subdir '("." "..")) | 1666 | (unless (member subdir '("." "..")) |
| 1726 | (let ((path (delphi-search-directory | 1667 | (let ((path (opascal-search-directory |
| 1727 | unit (concat dir "/" subdir) recurse))) | 1668 | unit (concat dir "/" subdir) recurse))) |
| 1728 | (if path (throw 'done path))))) | 1669 | (if path (throw 'done path)))))) |
| 1729 | files)) | ||
| 1730 | 1670 | ||
| 1731 | ;; Not found. | 1671 | ;; Not found. |
| 1732 | nil)))) | 1672 | nil)))) |
| 1733 | 1673 | ||
| 1734 | 1674 | ||
| 1735 | (defun delphi-find-unit-in-directory (unit dir) | 1675 | (defun opascal-find-unit-in-directory (unit dir) |
| 1736 | ;; Searches for the unit in the specified directory. If the directory ends | 1676 | ;; Searches for the unit in the specified directory. If the directory ends |
| 1737 | ;; in \"...\", then it is recursively searched. | 1677 | ;; in \"...\", then it is recursively searched. |
| 1738 | (let ((dir-name dir) | 1678 | (let ((dir-name dir) |
| @@ -1744,90 +1684,88 @@ value of `delphi-tab-always-indents' and the current line position." | |||
| 1744 | ;; Ensure the trailing slash is removed. | 1684 | ;; Ensure the trailing slash is removed. |
| 1745 | (if (string-match "^\\(.+\\)[\\\\/]$" dir-name) | 1685 | (if (string-match "^\\(.+\\)[\\\\/]$" dir-name) |
| 1746 | (setq dir-name (match-string 1 dir-name))) | 1686 | (setq dir-name (match-string 1 dir-name))) |
| 1747 | (delphi-search-directory unit dir-name recurse))) | 1687 | (opascal-search-directory unit dir-name recurse))) |
| 1748 | 1688 | ||
| 1749 | (defun delphi-find-unit-file (unit) | 1689 | (defun opascal-find-unit-file (unit) |
| 1750 | ;; Finds the specified delphi source file according to `delphi-search-path'. | 1690 | ;; Finds the specified opascal source file according to `opascal-search-path'. |
| 1751 | ;; If found, the full path is returned, otherwise nil is returned. | 1691 | ;; If found, the full path is returned, otherwise nil is returned. |
| 1752 | (catch 'done | 1692 | (catch 'done |
| 1753 | (cond ((null delphi-search-path) | 1693 | (cond ((null opascal-search-path) |
| 1754 | (delphi-find-unit-in-directory unit ".")) | 1694 | (opascal-find-unit-in-directory unit ".")) |
| 1755 | 1695 | ||
| 1756 | ((stringp delphi-search-path) | 1696 | ((stringp opascal-search-path) |
| 1757 | (delphi-find-unit-in-directory unit delphi-search-path)) | 1697 | (opascal-find-unit-in-directory unit opascal-search-path)) |
| 1758 | 1698 | ||
| 1759 | ((mapc | 1699 | ((dolist (dir opascal-search-path) |
| 1760 | #'(lambda (dir) | 1700 | (let ((file (opascal-find-unit-in-directory unit dir))) |
| 1761 | (let ((file (delphi-find-unit-in-directory unit dir))) | 1701 | (if file (throw 'done file)))))) |
| 1762 | (if file (throw 'done file)))) | ||
| 1763 | delphi-search-path))) | ||
| 1764 | nil)) | 1702 | nil)) |
| 1765 | 1703 | ||
| 1766 | (defun delphi-find-unit (unit) | 1704 | (defun opascal-find-unit (unit) |
| 1767 | "Find the specified Delphi source file according to `delphi-search-path'. | 1705 | "Find the specified OPascal source file according to `opascal-search-path'. |
| 1768 | If no extension is specified, .pas is assumed. Creates a buffer for the unit." | 1706 | If no extension is specified, .pas is assumed. Creates a buffer for the unit." |
| 1769 | (interactive "sDelphi unit name: ") | 1707 | (interactive "sOPascal unit name: ") |
| 1770 | (let* ((unit-file (if (string-match "^\\(.*\\)\\.[a-z]+$" unit) | 1708 | (let* ((unit-file (if (string-match "^\\(.*\\)\\.[a-z]+$" unit) |
| 1771 | unit | 1709 | unit |
| 1772 | (concat unit ".pas"))) | 1710 | (concat unit ".pas"))) |
| 1773 | (file (delphi-find-unit-file unit-file))) | 1711 | (file (opascal-find-unit-file unit-file))) |
| 1774 | (if (null file) | 1712 | (if (null file) |
| 1775 | (error "unit not found: %s" unit-file) | 1713 | (error "unit not found: %s" unit-file) |
| 1776 | (find-file file) | 1714 | (find-file file) |
| 1777 | (if (not (derived-mode-p 'delphi-mode)) | 1715 | (if (not (derived-mode-p 'opascal-mode)) |
| 1778 | (delphi-mode))) | 1716 | (opascal-mode))) |
| 1779 | file)) | 1717 | file)) |
| 1780 | 1718 | ||
| 1781 | (defun delphi-find-current-def () | 1719 | (defun opascal-find-current-def () |
| 1782 | "Find the definition of the identifier under the current point." | 1720 | "Find the definition of the identifier under the current point." |
| 1783 | (interactive) | 1721 | (interactive) |
| 1784 | (error "delphi-find-current-def: not implemented yet")) | 1722 | (error "opascal-find-current-def: not implemented yet")) |
| 1785 | 1723 | ||
| 1786 | (defun delphi-find-current-xdef () | 1724 | (defun opascal-find-current-xdef () |
| 1787 | "Find the definition of the identifier under the current point, searching | 1725 | "Find the definition of the identifier under the current point, searching |
| 1788 | in external units if necessary (as listed in the current unit's use clause). | 1726 | in external units if necessary (as listed in the current unit's use clause). |
| 1789 | The set of directories to search for a unit is specified by the global variable | 1727 | The set of directories to search for a unit is specified by the global variable |
| 1790 | `delphi-search-path'." | 1728 | `opascal-search-path'." |
| 1791 | (interactive) | 1729 | (interactive) |
| 1792 | (error "delphi-find-current-xdef: not implemented yet")) | 1730 | (error "opascal-find-current-xdef: not implemented yet")) |
| 1793 | 1731 | ||
| 1794 | (defun delphi-find-current-body () | 1732 | (defun opascal-find-current-body () |
| 1795 | "Find the body of the identifier under the current point, assuming | 1733 | "Find the body of the identifier under the current point, assuming |
| 1796 | it is a routine." | 1734 | it is a routine." |
| 1797 | (interactive) | 1735 | (interactive) |
| 1798 | (error "delphi-find-current-body: not implemented yet")) | 1736 | (error "opascal-find-current-body: not implemented yet")) |
| 1799 | 1737 | ||
| 1800 | (defun delphi-fill-comment () | 1738 | (defun opascal-fill-comment () |
| 1801 | "Fill the text of the current comment, according to `fill-column'. | 1739 | "Fill the text of the current comment, according to `fill-column'. |
| 1802 | An error is raised if not in a comment." | 1740 | An error is raised if not in a comment." |
| 1803 | (interactive) | 1741 | (interactive) |
| 1804 | (save-excursion | 1742 | (save-excursion |
| 1805 | (save-restriction | 1743 | (save-restriction |
| 1806 | (let* ((comment (delphi-current-token)) | 1744 | (let* ((comment (opascal-current-token)) |
| 1807 | (comment-kind (delphi-token-kind comment))) | 1745 | (comment-kind (opascal-token-kind comment))) |
| 1808 | (if (not (delphi-is comment-kind delphi-comments)) | 1746 | (if (not (opascal-is comment-kind opascal-comments)) |
| 1809 | (error "Not in a comment") | 1747 | (error "Not in a comment") |
| 1810 | (let* ((start-comment (delphi-comment-block-start comment)) | 1748 | (let* ((start-comment (opascal-comment-block-start comment)) |
| 1811 | (end-comment (delphi-comment-block-end comment)) | 1749 | (end-comment (opascal-comment-block-end comment)) |
| 1812 | (comment-start (delphi-token-start start-comment)) | 1750 | (comment-start (opascal-token-start start-comment)) |
| 1813 | (comment-end (delphi-token-end end-comment)) | 1751 | (comment-end (opascal-token-end end-comment)) |
| 1814 | (content-start (delphi-comment-content-start start-comment)) | 1752 | (content-start (opascal-comment-content-start start-comment)) |
| 1815 | (content-indent (delphi-column-of content-start)) | 1753 | (content-indent (opascal-column-of content-start)) |
| 1816 | (content-prefix (make-string content-indent ?\s)) | 1754 | (content-prefix (make-string content-indent ?\s)) |
| 1817 | (content-prefix-re delphi-leading-spaces-re) | 1755 | (content-prefix-re opascal-leading-spaces-re) |
| 1818 | (p nil) | 1756 | (p nil) |
| 1819 | (marked-point (point-marker))) ; Maintain our position reliably. | 1757 | (marked-point (point-marker))) ; Maintain our position reliably. |
| 1820 | (when (eq 'comment-single-line comment-kind) | 1758 | (when (eq 'comment-single-line comment-kind) |
| 1821 | ;; // style comments need more work. | 1759 | ;; // style comments need more work. |
| 1822 | (setq content-prefix | 1760 | (setq content-prefix |
| 1823 | (let ((comment-indent (delphi-column-of comment-start))) | 1761 | (let ((comment-indent (opascal-column-of comment-start))) |
| 1824 | (concat (make-string comment-indent ?\s) "//" | 1762 | (concat (make-string comment-indent ?\s) "//" |
| 1825 | (make-string (- content-indent comment-indent 2) | 1763 | (make-string (- content-indent comment-indent 2) |
| 1826 | ?\s))) | 1764 | ?\s))) |
| 1827 | content-prefix-re (concat delphi-leading-spaces-re | 1765 | content-prefix-re (concat opascal-leading-spaces-re |
| 1828 | "//" | 1766 | "//" |
| 1829 | delphi-spaces-re) | 1767 | opascal-spaces-re) |
| 1830 | comment-end (if (delphi-is-literal-end comment-end) | 1768 | comment-end (if (opascal-is-literal-end comment-end) |
| 1831 | ;; Don't include the trailing newline. | 1769 | ;; Don't include the trailing newline. |
| 1832 | (1- comment-end) | 1770 | (1- comment-end) |
| 1833 | comment-end))) | 1771 | comment-end))) |
| @@ -1879,155 +1817,144 @@ An error is raised if not in a comment." | |||
| 1879 | (set-marker marked-point nil) | 1817 | (set-marker marked-point nil) |
| 1880 | 1818 | ||
| 1881 | ;; React to the entire fill change as a whole. | 1819 | ;; React to the entire fill change as a whole. |
| 1882 | (delphi-progress-start) | 1820 | (opascal-progress-start) |
| 1883 | (delphi-parse-region comment-start comment-end) | 1821 | (opascal-parse-region comment-start comment-end) |
| 1884 | (delphi-progress-done))))))) | 1822 | (opascal-progress-done))))))) |
| 1885 | 1823 | ||
| 1886 | (defun delphi-new-comment-line () | 1824 | (defun opascal-new-comment-line () |
| 1887 | "If in a // comment, do a newline, indented such that one is still in the | 1825 | "If in a // comment, do a newline, indented such that one is still in the |
| 1888 | comment block. If not in a // comment, just does a normal newline." | 1826 | comment block. If not in a // comment, just does a normal newline." |
| 1889 | (interactive) | 1827 | (interactive) |
| 1890 | (let ((comment (delphi-current-token))) | 1828 | (let ((comment (opascal-current-token))) |
| 1891 | (if (not (eq 'comment-single-line (delphi-token-kind comment))) | 1829 | (if (not (eq 'comment-single-line (opascal-token-kind comment))) |
| 1892 | ;; Not in a // comment. Just do the normal newline. | 1830 | ;; Not in a // comment. Just do the normal newline. |
| 1893 | (delphi-newline) | 1831 | (newline) |
| 1894 | (let* ((start-comment (delphi-comment-block-start comment)) | 1832 | (let* ((start-comment (opascal-comment-block-start comment)) |
| 1895 | (comment-start (delphi-token-start start-comment)) | 1833 | (comment-start (opascal-token-start start-comment)) |
| 1896 | (content-start (delphi-comment-content-start start-comment)) | 1834 | (content-start (opascal-comment-content-start start-comment)) |
| 1897 | (prefix | 1835 | (prefix |
| 1898 | (concat (make-string (delphi-column-of comment-start) ?\s) "//" | 1836 | (concat (make-string (opascal-column-of comment-start) ?\s) "//" |
| 1899 | (make-string (- content-start comment-start 2) ?\s)))) | 1837 | (make-string (- content-start comment-start 2) ?\s)))) |
| 1900 | (delete-horizontal-space) | 1838 | (delete-horizontal-space) |
| 1901 | (newline) | 1839 | (insert "\n" prefix))))) |
| 1902 | (insert prefix))))) | ||
| 1903 | 1840 | ||
| 1904 | (defun delphi-match-token (token limit) | 1841 | (defun opascal-match-token (token limit) |
| 1905 | ;; Sets the match region used by (match-string 0) and friends to the token's | 1842 | ;; Sets the match region used by (match-string 0) and friends to the token's |
| 1906 | ;; region. Sets the current point to the end of the token (or limit). | 1843 | ;; region. Sets the current point to the end of the token (or limit). |
| 1907 | (set-match-data nil) | 1844 | (set-match-data nil) |
| 1908 | (if token | 1845 | (if token |
| 1909 | (let ((end (min (delphi-token-end token) limit))) | 1846 | (let ((end (min (opascal-token-end token) limit))) |
| 1910 | (set-match-data (list (delphi-token-start token) end)) | 1847 | (set-match-data (list (opascal-token-start token) end)) |
| 1911 | (goto-char end) | 1848 | (goto-char end) |
| 1912 | token))) | 1849 | token))) |
| 1913 | 1850 | ||
| 1914 | (defconst delphi-font-lock-defaults | 1851 | (defconst opascal-font-lock-defaults |
| 1915 | '(nil ; We have our own fontify routine, so keywords don't apply. | 1852 | '(nil ; We have our own fontify routine, so keywords don't apply. |
| 1916 | t ; Syntactic fontification doesn't apply. | 1853 | t ; Syntactic fontification doesn't apply. |
| 1917 | nil ; Don't care about case since we don't use regexps to find tokens. | 1854 | nil ; Don't care about case since we don't use regexps to find tokens. |
| 1918 | nil ; Syntax alists don't apply. | 1855 | nil ; Syntax alists don't apply. |
| 1919 | nil ; Syntax begin movement doesn't apply | 1856 | nil ; Syntax begin movement doesn't apply |
| 1920 | (font-lock-fontify-region-function . delphi-fontify-region) | 1857 | (font-lock-fontify-region-function . opascal-fontify-region) |
| 1921 | (font-lock-verbose . delphi-fontifying-progress-step)) | 1858 | (font-lock-verbose . opascal-fontifying-progress-step)) |
| 1922 | "Delphi mode font-lock defaults. Syntactic fontification is ignored.") | 1859 | "OPascal mode font-lock defaults. Syntactic fontification is ignored.") |
| 1923 | 1860 | ||
| 1924 | (defvar delphi-debug-mode-map | 1861 | (defvar opascal-debug-mode-map |
| 1925 | (let ((kmap (make-sparse-keymap))) | 1862 | (let ((kmap (make-sparse-keymap))) |
| 1926 | (mapc #'(lambda (binding) (define-key kmap (car binding) (cadr binding))) | 1863 | (dolist (binding '(("n" opascal-debug-goto-next-token) |
| 1927 | '(("n" delphi-debug-goto-next-token) | 1864 | ("p" opascal-debug-goto-previous-token) |
| 1928 | ("p" delphi-debug-goto-previous-token) | 1865 | ("t" opascal-debug-show-current-token) |
| 1929 | ("t" delphi-debug-show-current-token) | 1866 | ("T" opascal-debug-tokenize-buffer) |
| 1930 | ("T" delphi-debug-tokenize-buffer) | 1867 | ("W" opascal-debug-tokenize-window) |
| 1931 | ("W" delphi-debug-tokenize-window) | 1868 | ("g" opascal-debug-goto-point) |
| 1932 | ("g" delphi-debug-goto-point) | 1869 | ("s" opascal-debug-show-current-string) |
| 1933 | ("s" delphi-debug-show-current-string) | 1870 | ("a" opascal-debug-parse-buffer) |
| 1934 | ("a" delphi-debug-parse-buffer) | 1871 | ("w" opascal-debug-parse-window) |
| 1935 | ("w" delphi-debug-parse-window) | 1872 | ("f" opascal-debug-fontify-window) |
| 1936 | ("f" delphi-debug-fontify-window) | 1873 | ("F" opascal-debug-fontify-buffer) |
| 1937 | ("F" delphi-debug-fontify-buffer) | 1874 | ("r" opascal-debug-parse-region) |
| 1938 | ("r" delphi-debug-parse-region) | 1875 | ("c" opascal-debug-unparse-buffer) |
| 1939 | ("c" delphi-debug-unparse-buffer) | 1876 | ("x" opascal-debug-show-is-stable))) |
| 1940 | ("x" delphi-debug-show-is-stable) | 1877 | (define-key kmap (car binding) (cadr binding))) |
| 1941 | )) | ||
| 1942 | kmap) | 1878 | kmap) |
| 1943 | "Keystrokes for Delphi mode debug commands.") | 1879 | "Keystrokes for OPascal mode debug commands.") |
| 1944 | 1880 | ||
| 1945 | (defvar delphi-mode-map | 1881 | (defvar opascal-mode-map |
| 1946 | (let ((kmap (make-sparse-keymap))) | 1882 | (let ((kmap (make-sparse-keymap))) |
| 1947 | (mapc #'(lambda (binding) (define-key kmap (car binding) (cadr binding))) | 1883 | (dolist (binding |
| 1948 | (list '("\r" delphi-newline) | 1884 | (list ;; '("\C-cd" opascal-find-current-def) |
| 1949 | '("\t" delphi-tab) | 1885 | ;; '("\C-cx" opascal-find-current-xdef) |
| 1950 | '("\177" backward-delete-char-untabify) | 1886 | ;; '("\C-cb" opascal-find-current-body) |
| 1951 | ;; '("\C-cd" delphi-find-current-def) | 1887 | '("\C-cu" opascal-find-unit) |
| 1952 | ;; '("\C-cx" delphi-find-current-xdef) | 1888 | '("\M-q" opascal-fill-comment) |
| 1953 | ;; '("\C-cb" delphi-find-current-body) | 1889 | '("\M-j" opascal-new-comment-line) |
| 1954 | '("\C-cu" delphi-find-unit) | 1890 | ;; Debug bindings: |
| 1955 | '("\M-q" delphi-fill-comment) | 1891 | (list "\C-c\C-d" opascal-debug-mode-map))) |
| 1956 | '("\M-j" delphi-new-comment-line) | 1892 | (define-key kmap (car binding) (cadr binding))) |
| 1957 | ;; Debug bindings: | ||
| 1958 | (list "\C-c\C-d" delphi-debug-mode-map))) | ||
| 1959 | kmap) | 1893 | kmap) |
| 1960 | "Keymap used in Delphi mode.") | 1894 | "Keymap used in OPascal mode.") |
| 1961 | 1895 | ||
| 1896 | (define-obsolete-variable-alias 'delphi-mode-hook 'opascal-mode-hook "24.4") | ||
| 1962 | ;;;###autoload | 1897 | ;;;###autoload |
| 1963 | (define-derived-mode delphi-mode prog-mode "Delphi" | 1898 | (define-obsolete-function-alias 'delphi-mode 'opascal-mode "24.4") |
| 1964 | "Major mode for editing Delphi code. \\<delphi-mode-map> | 1899 | ;;;###autoload |
| 1965 | \\[delphi-tab]\t- Indents the current line (or region, if Transient Mark mode | 1900 | (define-derived-mode opascal-mode prog-mode "OPascal" |
| 1966 | \t is enabled and the region is active) of Delphi code. | 1901 | "Major mode for editing OPascal code. \\<opascal-mode-map> |
| 1967 | \\[delphi-find-unit]\t- Search for a Delphi source file. | 1902 | \\[opascal-find-unit]\t- Search for a OPascal source file. |
| 1968 | \\[delphi-fill-comment]\t- Fill the current comment. | 1903 | \\[opascal-fill-comment]\t- Fill the current comment. |
| 1969 | \\[delphi-new-comment-line]\t- If in a // comment, do a new comment line. | 1904 | \\[opascal-new-comment-line]\t- If in a // comment, do a new comment line. |
| 1970 | 1905 | ||
| 1971 | \\[indent-region] also works for indenting a whole region. | 1906 | \\[indent-region] also works for indenting a whole region. |
| 1972 | 1907 | ||
| 1973 | Customization: | 1908 | Customization: |
| 1974 | 1909 | ||
| 1975 | `delphi-indent-level' (default 3) | 1910 | `opascal-indent-level' (default 3) |
| 1976 | Indentation of Delphi statements with respect to containing block. | 1911 | Indentation of OPascal statements with respect to containing block. |
| 1977 | `delphi-compound-block-indent' (default 0) | 1912 | `opascal-compound-block-indent' (default 0) |
| 1978 | Extra indentation for blocks in compound statements. | 1913 | Extra indentation for blocks in compound statements. |
| 1979 | `delphi-case-label-indent' (default 0) | 1914 | `opascal-case-label-indent' (default 0) |
| 1980 | Extra indentation for case statement labels. | 1915 | Extra indentation for case statement labels. |
| 1981 | `delphi-tab-always-indents' (default t) | 1916 | `opascal-tab-always-indents' (default `tab-always-indents') |
| 1982 | Non-nil means TAB in Delphi mode should always reindent the current line, | 1917 | Non-nil means TAB in OPascal mode should always reindent the current line, |
| 1983 | regardless of where in the line point is when the TAB command is used. | 1918 | regardless of where in the line point is when the TAB command is used. |
| 1984 | `delphi-newline-always-indents' (default t) | 1919 | `opascal-search-path' (default .) |
| 1985 | Non-nil means NEWLINE in Delphi mode should always reindent the current | ||
| 1986 | line, insert a blank line and move to the default indent column of the | ||
| 1987 | blank line. | ||
| 1988 | `delphi-search-path' (default .) | ||
| 1989 | Directories to search when finding external units. | 1920 | Directories to search when finding external units. |
| 1990 | `delphi-verbose' (default nil) | 1921 | `opascal-verbose' (default nil) |
| 1991 | If true then Delphi token processing progress is reported to the user. | 1922 | If true then OPascal token processing progress is reported to the user. |
| 1992 | 1923 | ||
| 1993 | Coloring: | 1924 | Coloring: |
| 1994 | 1925 | ||
| 1995 | `delphi-comment-face' (default font-lock-comment-face) | 1926 | `opascal-comment-face' (default font-lock-comment-face) |
| 1996 | Face used to color Delphi comments. | 1927 | Face used to color OPascal comments. |
| 1997 | `delphi-string-face' (default font-lock-string-face) | 1928 | `opascal-string-face' (default font-lock-string-face) |
| 1998 | Face used to color Delphi strings. | 1929 | Face used to color OPascal strings. |
| 1999 | `delphi-keyword-face' (default font-lock-keyword-face) | 1930 | `opascal-keyword-face' (default font-lock-keyword-face) |
| 2000 | Face used to color Delphi keywords. | 1931 | Face used to color OPascal keywords. |
| 2001 | `delphi-other-face' (default nil) | 1932 | `opascal-other-face' (default nil) |
| 2002 | Face used to color everything else. | 1933 | Face used to color everything else. |
| 2003 | 1934 | ||
| 2004 | Turning on Delphi mode calls the value of the variable `delphi-mode-hook' | 1935 | Turning on OPascal mode calls the value of the variable `opascal-mode-hook' |
| 2005 | with no args, if that value is non-nil." | 1936 | with no args, if that value is non-nil." |
| 2006 | 1937 | ||
| 2007 | ;; Buffer locals: | 1938 | ;; Buffer locals: |
| 2008 | (mapc #'(lambda (var) | 1939 | (setq-local indent-line-function #'opascal-indent-line) |
| 2009 | (let ((var-symb (car var)) | 1940 | (setq-local comment-indent-function #'opascal-indent-line) |
| 2010 | (var-val (cadr var))) | 1941 | (setq-local case-fold-search t) |
| 2011 | (set (make-local-variable var-symb) var-val))) | 1942 | (setq-local opascal-progress-last-reported-point nil) |
| 2012 | (list '(indent-line-function delphi-indent-line) | 1943 | (setq-local opascal--ignore-changes nil) |
| 2013 | '(comment-indent-function delphi-indent-line) | 1944 | (setq-local font-lock-defaults opascal-font-lock-defaults) |
| 2014 | '(case-fold-search t) | 1945 | (setq-local tab-always-indent opascal-tab-always-indents) |
| 2015 | '(delphi-progress-last-reported-point nil) | 1946 | |
| 2016 | '(delphi-ignore-changes nil) | 1947 | ;; FIXME: Use syntax-propertize-function to tokenize, maybe? |
| 2017 | (list 'font-lock-defaults delphi-font-lock-defaults))) | 1948 | |
| 2018 | |||
| 2019 | ;; We need to keep track of changes to the buffer to determine if we need | 1949 | ;; We need to keep track of changes to the buffer to determine if we need |
| 2020 | ;; to retokenize changed text. | 1950 | ;; to retokenize changed text. |
| 2021 | (add-hook 'after-change-functions 'delphi-after-change nil t) | 1951 | (add-hook 'after-change-functions #'opascal-after-change nil t) |
| 2022 | |||
| 2023 | (widen) | ||
| 2024 | |||
| 2025 | (delphi-save-excursion | ||
| 2026 | (let ((delphi-verbose t)) | ||
| 2027 | (delphi-progress-start) | ||
| 2028 | (delphi-parse-region (point-min) (point-max)) | ||
| 2029 | (delphi-progress-done))) | ||
| 2030 | 1952 | ||
| 2031 | (run-mode-hooks 'delphi-mode-hook)) | 1953 | (opascal-save-excursion |
| 1954 | (let ((opascal-verbose t)) | ||
| 1955 | (opascal-progress-start) | ||
| 1956 | (opascal-parse-region (point-min) (point-max)) | ||
| 1957 | (opascal-progress-done)))) | ||
| 2032 | 1958 | ||
| 2033 | ;;; delphi.el ends here | 1959 | (provide 'opascal) |
| 1960 | ;;; opascal.el ends here | ||
diff --git a/test/indent/pascal.pas b/test/indent/pascal.pas index 4dc8f795dfc..0dda0c47fef 100644 --- a/test/indent/pascal.pas +++ b/test/indent/pascal.pas | |||
| @@ -25,6 +25,8 @@ by the GNU General Public License. } | |||
| 25 | 25 | ||
| 26 | {$gnu-pascal,I+} | 26 | {$gnu-pascal,I+} |
| 27 | 27 | ||
| 28 | // Free-pascal style comment. | ||
| 29 | |||
| 28 | program CRTDemo; | 30 | program CRTDemo; |
| 29 | 31 | ||
| 30 | uses GPC, CRT; | 32 | uses GPC, CRT; |