diff options
| author | Stefan Monnier | 2014-04-28 00:40:41 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-04-28 00:40:41 -0400 |
| commit | 9b7b020ddefd619ffecc5010ae335baa5bae0856 (patch) | |
| tree | 6e2728b59514044815f9e883cd5cb6c3a3e1d7e2 | |
| parent | 6ab1b16c54b63d1c4217b6fcea026400029fcc72 (diff) | |
| download | emacs-9b7b020ddefd619ffecc5010ae335baa5bae0856.tar.gz emacs-9b7b020ddefd619ffecc5010ae335baa5bae0856.zip | |
* lisp/progmodes/ps-mode.el: Use SMIE. Move string and comment recognition
to syntax-propertize.
(ps-mode-auto-indent): Mark as obsolete.
(ps-mode-font-lock-keywords-1): Remove string-or-comment handling.
(ps-mode-font-lock-keywords-3): Use symbol regexp operators instead of
word regexp operators.
(ps-mode-map): Move initialization into declaration. Remove binding
for TAB, RET, >, ], and }.
(ps-mode-syntax-table): Move initialization into declaration.
Don't give word syntax to non-word chars.
(ps-run-mode-map): Move initialization into declaration.
(ps-mode-menu-main): Remove auto-indent entry.
(ps-mode-smie-rules): New function.
(ps-mode): Setup smie, syntax-propertize, and electric-indent-mode.
(ps-mode-looking-at-nested, ps-mode-match-string-or-comment): Remove.
(ps-mode--string-syntax-table): New const.
(ps-mode--syntax-propertize-special, ps-mode-syntax-propertize):
New functions.
(ps-mode-newline, ps-mode-tabkey, ps-mode-r-brace, ps-mode-r-angle)
(ps-mode-r-gt, ps-mode-r-balance): Remove functions.
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/progmodes/ps-mode.el | 340 | ||||
| -rw-r--r-- | lisp/simple.el | 1 |
3 files changed, 161 insertions, 203 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3bbd2a8dc66..d58fd9cdc08 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2014-04-28 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * progmodes/ps-mode.el: Use SMIE. Move string and comment recognition | ||
| 4 | to syntax-propertize. | ||
| 5 | (ps-mode-auto-indent): Mark as obsolete. | ||
| 6 | (ps-mode-font-lock-keywords-1): Remove string-or-comment handling. | ||
| 7 | (ps-mode-font-lock-keywords-3): Use symbol regexp operators instead of | ||
| 8 | word regexp operators. | ||
| 9 | (ps-mode-map): Move initialization into declaration. Remove binding | ||
| 10 | for TAB, RET, >, ], and }. | ||
| 11 | (ps-mode-syntax-table): Move initialization into declaration. | ||
| 12 | Don't give word syntax to non-word chars. | ||
| 13 | (ps-run-mode-map): Move initialization into declaration. | ||
| 14 | (ps-mode-menu-main): Remove auto-indent entry. | ||
| 15 | (ps-mode-smie-rules): New function. | ||
| 16 | (ps-mode): Setup smie, syntax-propertize, and electric-indent-mode. | ||
| 17 | (ps-mode-looking-at-nested, ps-mode-match-string-or-comment): Remove. | ||
| 18 | (ps-mode--string-syntax-table): New const. | ||
| 19 | (ps-mode--syntax-propertize-special, ps-mode-syntax-propertize): | ||
| 20 | New functions. | ||
| 21 | (ps-mode-newline, ps-mode-tabkey, ps-mode-r-brace, ps-mode-r-angle) | ||
| 22 | (ps-mode-r-gt, ps-mode-r-balance): Remove functions. | ||
| 23 | |||
| 1 | 2014-04-27 Daniel Colascione <dancol@dancol.org> | 24 | 2014-04-27 Daniel Colascione <dancol@dancol.org> |
| 2 | 25 | ||
| 3 | * term/xterm.el (xterm-paste): Use large finite timeout when | 26 | * term/xterm.el (xterm-paste): Use large finite timeout when |
diff --git a/lisp/progmodes/ps-mode.el b/lisp/progmodes/ps-mode.el index f7de331f73b..7cf53cbe45c 100644 --- a/lisp/progmodes/ps-mode.el +++ b/lisp/progmodes/ps-mode.el | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | 41 | ||
| 42 | (require 'comint) | 42 | (require 'comint) |
| 43 | (require 'easymenu) | 43 | (require 'easymenu) |
| 44 | (require 'smie) | ||
| 44 | 45 | ||
| 45 | ;; Define core `PostScript' group. | 46 | ;; Define core `PostScript' group. |
| 46 | (defgroup PostScript nil | 47 | (defgroup PostScript nil |
| @@ -60,10 +61,7 @@ | |||
| 60 | 61 | ||
| 61 | ;; User variables. | 62 | ;; User variables. |
| 62 | 63 | ||
| 63 | (defcustom ps-mode-auto-indent t | 64 | (make-obsolete-variable 'ps-mode-auto-indent 'electric-indent-mode "24.5") |
| 64 | "Should we use autoindent?" | ||
| 65 | :group 'PostScript-edit | ||
| 66 | :type 'boolean) | ||
| 67 | 65 | ||
| 68 | (defcustom ps-mode-tab 4 | 66 | (defcustom ps-mode-tab 4 |
| 69 | "Number of spaces to use when indenting." | 67 | "Number of spaces to use when indenting." |
| @@ -204,7 +202,7 @@ If nil, use `temporary-file-directory'." | |||
| 204 | "bind" "null" | 202 | "bind" "null" |
| 205 | "gsave" "grestore" "grestoreall" | 203 | "gsave" "grestore" "grestoreall" |
| 206 | "showpage"))) | 204 | "showpage"))) |
| 207 | (concat "\\<" (regexp-opt ops t) "\\>")) | 205 | (concat "\\_<" (regexp-opt ops t) "\\_>")) |
| 208 | "Regexp of PostScript operators that will be fontified.") | 206 | "Regexp of PostScript operators that will be fontified.") |
| 209 | 207 | ||
| 210 | ;; Level 1 font-lock: | 208 | ;; Level 1 font-lock: |
| @@ -214,13 +212,9 @@ If nil, use `temporary-file-directory'." | |||
| 214 | ;; - 8bit characters (warning face) | 212 | ;; - 8bit characters (warning face) |
| 215 | ;; Multiline strings are not supported. Strings with nested brackets are. | 213 | ;; Multiline strings are not supported. Strings with nested brackets are. |
| 216 | (defconst ps-mode-font-lock-keywords-1 | 214 | (defconst ps-mode-font-lock-keywords-1 |
| 217 | '(("\\`%!PS.*" . font-lock-constant-face) | 215 | '(("\\`%!PS.*" (0 font-lock-constant-face t)) |
| 218 | ("^%%BoundingBox:[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]*$" | 216 | ("^%%BoundingBox:[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]*$" |
| 219 | . font-lock-constant-face) | 217 | (0 font-lock-constant-face t)) |
| 220 | (ps-mode-match-string-or-comment | ||
| 221 | (1 font-lock-comment-face nil t) | ||
| 222 | (2 font-lock-string-face nil t)) | ||
| 223 | ("([^()\n%]*\\|[^()\n]*)" . font-lock-warning-face) | ||
| 224 | ("[\200-\377]+" (0 font-lock-warning-face prepend nil))) | 218 | ("[\200-\377]+" (0 font-lock-warning-face prepend nil))) |
| 225 | "Subdued level highlighting for PostScript mode.") | 219 | "Subdued level highlighting for PostScript mode.") |
| 226 | 220 | ||
| @@ -255,19 +249,17 @@ If nil, use `temporary-file-directory'." | |||
| 255 | ;; Names are fontified before PostScript operators, allowing the use of | 249 | ;; Names are fontified before PostScript operators, allowing the use of |
| 256 | ;; a more simple (efficient) regexp than the one used in level 2. | 250 | ;; a more simple (efficient) regexp than the one used in level 2. |
| 257 | (defconst ps-mode-font-lock-keywords-3 | 251 | (defconst ps-mode-font-lock-keywords-3 |
| 258 | (append | 252 | `(,@ps-mode-font-lock-keywords-1 |
| 259 | ps-mode-font-lock-keywords-1 | 253 | ("//\\(?:\\sw\\|\\s_\\)+" . font-lock-type-face) |
| 260 | (list | 254 | (,(concat |
| 261 | '("//\\w+" . font-lock-type-face) | 255 | "^\\(/\\(?:\\sw\\|\\s_\\)+\\)\\_>" |
| 262 | `(,(concat | 256 | "\\([[ \t]*\\(%.*\\)?\r?$" ; Nothing but `[' or comment after the name. |
| 263 | "^\\(/\\w+\\)\\>" | 257 | "\\|[ \t]*\\({\\|<<\\)" ; `{' or `<<' following the name. |
| 264 | "\\([[ \t]*\\(%.*\\)?\r?$" ; Nothing but `[' or comment after the name. | 258 | "\\|[ \t]+[0-9]+[ \t]+dict\\_>" ; `[0-9]+ dict' following the name. |
| 265 | "\\|[ \t]*\\({\\|<<\\)" ; `{' or `<<' following the name. | 259 | "\\|.*\\_<def\\_>\\)") ; `def' somewhere on the same line. |
| 266 | "\\|[ \t]+[0-9]+[ \t]+dict\\>" ; `[0-9]+ dict' following the name. | 260 | . (1 font-lock-function-name-face)) |
| 267 | "\\|.*\\<def\\>\\)") ; `def' somewhere on the same line. | 261 | ("/\\(?:\\sw\\|\\s_\\)+" . font-lock-variable-name-face) |
| 268 | . (1 font-lock-function-name-face)) | 262 | (,ps-mode-operators . font-lock-keyword-face)) |
| 269 | '("/\\w+" . font-lock-variable-name-face) | ||
| 270 | (cons ps-mode-operators 'font-lock-keyword-face))) | ||
| 271 | "High level highlighting for PostScript mode.") | 263 | "High level highlighting for PostScript mode.") |
| 272 | 264 | ||
| 273 | (defconst ps-mode-font-lock-keywords ps-mode-font-lock-keywords-1 | 265 | (defconst ps-mode-font-lock-keywords ps-mode-font-lock-keywords-1 |
| @@ -289,13 +281,68 @@ If nil, use `temporary-file-directory'." | |||
| 289 | 281 | ||
| 290 | ;; Variables. | 282 | ;; Variables. |
| 291 | 283 | ||
| 292 | (defvar ps-mode-map nil | 284 | (defvar ps-mode-map |
| 285 | (let ((map (make-sparse-keymap))) | ||
| 286 | (define-key map "\C-c\C-v" 'ps-run-boundingbox) | ||
| 287 | (define-key map "\C-c\C-u" 'ps-mode-uncomment-region) | ||
| 288 | (define-key map "\C-c\C-t" 'ps-mode-epsf-rich) | ||
| 289 | (define-key map "\C-c\C-s" 'ps-run-start) | ||
| 290 | (define-key map "\C-c\C-r" 'ps-run-region) | ||
| 291 | (define-key map "\C-c\C-q" 'ps-run-quit) | ||
| 292 | (define-key map "\C-c\C-p" 'ps-mode-print-buffer) | ||
| 293 | (define-key map "\C-c\C-o" 'ps-mode-comment-out-region) | ||
| 294 | (define-key map "\C-c\C-k" 'ps-run-kill) | ||
| 295 | (define-key map "\C-c\C-j" 'ps-mode-other-newline) | ||
| 296 | (define-key map "\C-c\C-l" 'ps-run-clear) | ||
| 297 | (define-key map "\C-c\C-b" 'ps-run-buffer) | ||
| 298 | ;; FIXME: Add `indent' to backward-delete-char-untabify-method instead? | ||
| 299 | (define-key map "\177" 'ps-mode-backward-delete-char) | ||
| 300 | map) | ||
| 293 | "Local keymap to use in PostScript mode.") | 301 | "Local keymap to use in PostScript mode.") |
| 294 | 302 | ||
| 295 | (defvar ps-mode-syntax-table nil | 303 | (defvar ps-mode-syntax-table |
| 304 | (let ((st (make-syntax-table))) | ||
| 305 | |||
| 306 | (modify-syntax-entry ?\% "< " st) | ||
| 307 | (modify-syntax-entry ?\n "> " st) | ||
| 308 | (modify-syntax-entry ?\r "> " st) | ||
| 309 | (modify-syntax-entry ?\f "> " st) | ||
| 310 | (modify-syntax-entry ?\< "(>" st) | ||
| 311 | (modify-syntax-entry ?\> ")<" st) | ||
| 312 | |||
| 313 | (modify-syntax-entry ?\! "_ " st) | ||
| 314 | (modify-syntax-entry ?\" "_ " st) | ||
| 315 | (modify-syntax-entry ?\# "_ " st) | ||
| 316 | (modify-syntax-entry ?\$ "_ " st) | ||
| 317 | (modify-syntax-entry ?\& "_ " st) | ||
| 318 | (modify-syntax-entry ?\' "_ " st) | ||
| 319 | (modify-syntax-entry ?\* "_ " st) | ||
| 320 | (modify-syntax-entry ?\+ "_ " st) | ||
| 321 | (modify-syntax-entry ?\, "_ " st) | ||
| 322 | (modify-syntax-entry ?\- "_ " st) | ||
| 323 | (modify-syntax-entry ?\. "_ " st) | ||
| 324 | (modify-syntax-entry ?\: "_ " st) | ||
| 325 | (modify-syntax-entry ?\; "_ " st) | ||
| 326 | (modify-syntax-entry ?\= "_ " st) | ||
| 327 | (modify-syntax-entry ?\? "_ " st) | ||
| 328 | (modify-syntax-entry ?\@ "_ " st) | ||
| 329 | (modify-syntax-entry ?\\ "\\" st) | ||
| 330 | (modify-syntax-entry ?^ "_ " st) ; NOT: ?\^ | ||
| 331 | (modify-syntax-entry ?\_ "_ " st) | ||
| 332 | (modify-syntax-entry ?\` "_ " st) | ||
| 333 | (modify-syntax-entry ?\| "_ " st) | ||
| 334 | (modify-syntax-entry ?\~ "_ " st) | ||
| 335 | st) | ||
| 296 | "Syntax table used while in PostScript mode.") | 336 | "Syntax table used while in PostScript mode.") |
| 297 | 337 | ||
| 298 | (defvar ps-run-mode-map nil | 338 | (defvar ps-run-mode-map |
| 339 | (let ((map (make-sparse-keymap))) | ||
| 340 | (set-keymap-parent map comint-mode-map) | ||
| 341 | (define-key map "\C-c\C-q" 'ps-run-quit) | ||
| 342 | (define-key map "\C-c\C-k" 'ps-run-kill) | ||
| 343 | (define-key map "\C-c\C-e" 'ps-run-goto-error) | ||
| 344 | (define-key map [mouse-2] 'ps-run-mouse-goto-error) | ||
| 345 | map) | ||
| 299 | "Local keymap to use in PostScript run mode.") | 346 | "Local keymap to use in PostScript run mode.") |
| 300 | 347 | ||
| 301 | (defvar ps-mode-tmp-file nil | 348 | (defvar ps-mode-tmp-file nil |
| @@ -365,9 +412,6 @@ If nil, use `temporary-file-directory'." | |||
| 365 | ["8-bit to Octal Buffer" ps-mode-octal-buffer t] | 412 | ["8-bit to Octal Buffer" ps-mode-octal-buffer t] |
| 366 | ["8-bit to Octal Region" ps-mode-octal-region (mark t)] | 413 | ["8-bit to Octal Region" ps-mode-octal-region (mark t)] |
| 367 | "---" | 414 | "---" |
| 368 | ["Auto Indent" (setq ps-mode-auto-indent (not ps-mode-auto-indent)) | ||
| 369 | :style toggle :selected ps-mode-auto-indent] | ||
| 370 | "---" | ||
| 371 | ["Start PostScript" | 415 | ["Start PostScript" |
| 372 | ps-run-start | 416 | ps-run-start |
| 373 | t] | 417 | t] |
| @@ -404,79 +448,7 @@ If nil, use `temporary-file-directory'." | |||
| 404 | ps-mode-submit-bug-report | 448 | ps-mode-submit-bug-report |
| 405 | t])) | 449 | t])) |
| 406 | 450 | ||
| 407 | 451 | (easy-menu-define ps-mode-main ps-mode-map "PostScript" ps-mode-menu-main) | |
| 408 | ;; Mode maps for PostScript edit mode and PostScript interaction mode. | ||
| 409 | |||
| 410 | (unless ps-mode-map | ||
| 411 | (setq ps-mode-map (make-sparse-keymap)) | ||
| 412 | (define-key ps-mode-map "\C-c\C-v" 'ps-run-boundingbox) | ||
| 413 | (define-key ps-mode-map "\C-c\C-u" 'ps-mode-uncomment-region) | ||
| 414 | (define-key ps-mode-map "\C-c\C-t" 'ps-mode-epsf-rich) | ||
| 415 | (define-key ps-mode-map "\C-c\C-s" 'ps-run-start) | ||
| 416 | (define-key ps-mode-map "\C-c\C-r" 'ps-run-region) | ||
| 417 | (define-key ps-mode-map "\C-c\C-q" 'ps-run-quit) | ||
| 418 | (define-key ps-mode-map "\C-c\C-p" 'ps-mode-print-buffer) | ||
| 419 | (define-key ps-mode-map "\C-c\C-o" 'ps-mode-comment-out-region) | ||
| 420 | (define-key ps-mode-map "\C-c\C-k" 'ps-run-kill) | ||
| 421 | (define-key ps-mode-map "\C-c\C-j" 'ps-mode-other-newline) | ||
| 422 | (define-key ps-mode-map "\C-c\C-l" 'ps-run-clear) | ||
| 423 | (define-key ps-mode-map "\C-c\C-b" 'ps-run-buffer) | ||
| 424 | (define-key ps-mode-map ">" 'ps-mode-r-gt) | ||
| 425 | (define-key ps-mode-map "]" 'ps-mode-r-angle) | ||
| 426 | (define-key ps-mode-map "}" 'ps-mode-r-brace) | ||
| 427 | (define-key ps-mode-map "\177" 'ps-mode-backward-delete-char) | ||
| 428 | (define-key ps-mode-map "\t" 'ps-mode-tabkey) | ||
| 429 | (define-key ps-mode-map "\r" 'ps-mode-newline) | ||
| 430 | (easy-menu-define ps-mode-main ps-mode-map "PostScript" ps-mode-menu-main)) | ||
| 431 | |||
| 432 | (unless ps-run-mode-map | ||
| 433 | (setq ps-run-mode-map (make-sparse-keymap)) | ||
| 434 | (set-keymap-parent ps-run-mode-map comint-mode-map) | ||
| 435 | (define-key ps-run-mode-map "\C-c\C-q" 'ps-run-quit) | ||
| 436 | (define-key ps-run-mode-map "\C-c\C-k" 'ps-run-kill) | ||
| 437 | (define-key ps-run-mode-map "\C-c\C-e" 'ps-run-goto-error) | ||
| 438 | (define-key ps-run-mode-map [mouse-2] 'ps-run-mouse-goto-error)) | ||
| 439 | |||
| 440 | |||
| 441 | ;; Syntax table. | ||
| 442 | |||
| 443 | (unless ps-mode-syntax-table | ||
| 444 | (setq ps-mode-syntax-table (make-syntax-table)) | ||
| 445 | |||
| 446 | (modify-syntax-entry ?\% "< " ps-mode-syntax-table) | ||
| 447 | (modify-syntax-entry ?\n "> " ps-mode-syntax-table) | ||
| 448 | (modify-syntax-entry ?\r "> " ps-mode-syntax-table) | ||
| 449 | (modify-syntax-entry ?\f "> " ps-mode-syntax-table) | ||
| 450 | (modify-syntax-entry ?\< "(>" ps-mode-syntax-table) | ||
| 451 | (modify-syntax-entry ?\> ")<" ps-mode-syntax-table) | ||
| 452 | |||
| 453 | (modify-syntax-entry ?\! "w " ps-mode-syntax-table) | ||
| 454 | (modify-syntax-entry ?\" "w " ps-mode-syntax-table) | ||
| 455 | (modify-syntax-entry ?\# "w " ps-mode-syntax-table) | ||
| 456 | (modify-syntax-entry ?\$ "w " ps-mode-syntax-table) | ||
| 457 | (modify-syntax-entry ?\& "w " ps-mode-syntax-table) | ||
| 458 | (modify-syntax-entry ?\' "w " ps-mode-syntax-table) | ||
| 459 | (modify-syntax-entry ?\* "w " ps-mode-syntax-table) | ||
| 460 | (modify-syntax-entry ?\+ "w " ps-mode-syntax-table) | ||
| 461 | (modify-syntax-entry ?\, "w " ps-mode-syntax-table) | ||
| 462 | (modify-syntax-entry ?\- "w " ps-mode-syntax-table) | ||
| 463 | (modify-syntax-entry ?\. "w " ps-mode-syntax-table) | ||
| 464 | (modify-syntax-entry ?\: "w " ps-mode-syntax-table) | ||
| 465 | (modify-syntax-entry ?\; "w " ps-mode-syntax-table) | ||
| 466 | (modify-syntax-entry ?\= "w " ps-mode-syntax-table) | ||
| 467 | (modify-syntax-entry ?\? "w " ps-mode-syntax-table) | ||
| 468 | (modify-syntax-entry ?\@ "w " ps-mode-syntax-table) | ||
| 469 | (modify-syntax-entry ?\\ "w " ps-mode-syntax-table) | ||
| 470 | (modify-syntax-entry ?^ "w " ps-mode-syntax-table) ; NOT: ?\^ | ||
| 471 | (modify-syntax-entry ?\_ "w " ps-mode-syntax-table) | ||
| 472 | (modify-syntax-entry ?\` "w " ps-mode-syntax-table) | ||
| 473 | (modify-syntax-entry ?\| "w " ps-mode-syntax-table) | ||
| 474 | (modify-syntax-entry ?\~ "w " ps-mode-syntax-table) | ||
| 475 | |||
| 476 | (let ((i 128)) | ||
| 477 | (while (< i 256) | ||
| 478 | (modify-syntax-entry i "w " ps-mode-syntax-table) | ||
| 479 | (setq i (1+ i))))) | ||
| 480 | 452 | ||
| 481 | 453 | ||
| 482 | 454 | ||
| @@ -484,6 +456,13 @@ If nil, use `temporary-file-directory'." | |||
| 484 | 456 | ||
| 485 | ;; PostScript mode. | 457 | ;; PostScript mode. |
| 486 | 458 | ||
| 459 | (defun ps-mode-smie-rules (kind token) | ||
| 460 | (pcase (cons kind token) | ||
| 461 | (`(:after . "<") (when (smie-rule-next-p "<") 0)) | ||
| 462 | (`(:elem . basic) ps-mode-tab) | ||
| 463 | (`(:close-all . ">") t) | ||
| 464 | (`(:list-intro . ,_) t))) | ||
| 465 | |||
| 487 | ;;;###autoload | 466 | ;;;###autoload |
| 488 | (define-derived-mode ps-mode prog-mode "PostScript" | 467 | (define-derived-mode ps-mode prog-mode "PostScript" |
| 489 | "Major mode for editing PostScript with GNU Emacs. | 468 | "Major mode for editing PostScript with GNU Emacs. |
| @@ -493,7 +472,6 @@ Entry to this mode calls `ps-mode-hook'. | |||
| 493 | The following variables hold user options, and can | 472 | The following variables hold user options, and can |
| 494 | be set through the `customize' command: | 473 | be set through the `customize' command: |
| 495 | 474 | ||
| 496 | `ps-mode-auto-indent' | ||
| 497 | `ps-mode-tab' | 475 | `ps-mode-tab' |
| 498 | `ps-mode-paper-size' | 476 | `ps-mode-paper-size' |
| 499 | `ps-mode-print-function' | 477 | `ps-mode-print-function' |
| @@ -523,12 +501,16 @@ with a file position. Clicking mouse-2 on this number will bring | |||
| 523 | point to the corresponding spot in the PostScript window, if input | 501 | point to the corresponding spot in the PostScript window, if input |
| 524 | to the interpreter was sent from that window. | 502 | to the interpreter was sent from that window. |
| 525 | Typing \\<ps-run-mode-map>\\[ps-run-goto-error] when the cursor is at the number has the same effect." | 503 | Typing \\<ps-run-mode-map>\\[ps-run-goto-error] when the cursor is at the number has the same effect." |
| 504 | (setq-local syntax-propertize-function #'ps-mode-syntax-propertize) | ||
| 526 | (set (make-local-variable 'font-lock-defaults) | 505 | (set (make-local-variable 'font-lock-defaults) |
| 527 | '((ps-mode-font-lock-keywords | 506 | '((ps-mode-font-lock-keywords |
| 528 | ps-mode-font-lock-keywords-1 | 507 | ps-mode-font-lock-keywords-1 |
| 529 | ps-mode-font-lock-keywords-2 | 508 | ps-mode-font-lock-keywords-2 |
| 530 | ps-mode-font-lock-keywords-3) | 509 | ps-mode-font-lock-keywords-3) |
| 531 | t)) | 510 | nil)) |
| 511 | (smie-setup nil #'ps-mode-smie-rules) | ||
| 512 | (setq-local electric-indent-chars | ||
| 513 | (append '(?> ?\] ?\}) electric-indent-chars)) | ||
| 532 | (set (make-local-variable 'comment-start) "%") | 514 | (set (make-local-variable 'comment-start) "%") |
| 533 | ;; NOTE: `\' has a special meaning in strings only | 515 | ;; NOTE: `\' has a special meaning in strings only |
| 534 | (set (make-local-variable 'comment-start-skip) "%+[ \t]*") | 516 | (set (make-local-variable 'comment-start-skip) "%+[ \t]*") |
| @@ -555,8 +537,7 @@ Typing \\<ps-run-mode-map>\\[ps-run-goto-error] when the cursor is at the number | |||
| 555 | (reporter-submit-bug-report | 537 | (reporter-submit-bug-report |
| 556 | ps-mode-maintainer-address | 538 | ps-mode-maintainer-address |
| 557 | (format "ps-mode.el %s [%s]" ps-mode-version system-type) | 539 | (format "ps-mode.el %s [%s]" ps-mode-version system-type) |
| 558 | '(ps-mode-auto-indent | 540 | '(ps-mode-tab |
| 559 | ps-mode-tab | ||
| 560 | ps-mode-paper-size | 541 | ps-mode-paper-size |
| 561 | ps-mode-print-function | 542 | ps-mode-print-function |
| 562 | ps-run-prompt | 543 | ps-run-prompt |
| @@ -570,53 +551,54 @@ Typing \\<ps-run-mode-map>\\[ps-run-goto-error] when the cursor is at the number | |||
| 570 | 551 | ||
| 571 | ;; Helper functions for font-lock. | 552 | ;; Helper functions for font-lock. |
| 572 | 553 | ||
| 573 | ;; When this function is called, point is at an opening bracket. | 554 | (defconst ps-mode--string-syntax-table |
| 574 | ;; This function should test if point is at the start of a string | 555 | (let ((st (make-syntax-table ps-mode-syntax-table))) |
| 575 | ;; with nested brackets. | 556 | (modify-syntax-entry ?% "." st) |
| 576 | ;; If true: move point to end of string | 557 | (modify-syntax-entry ?< "." st) |
| 577 | ;; set string to match data nr 2 | 558 | (modify-syntax-entry ?> "." st) |
| 578 | ;; return new point | 559 | (modify-syntax-entry ?\{ "." st) |
| 579 | ;; If false: return nil | 560 | (modify-syntax-entry ?\} "." st) |
| 580 | (defun ps-mode-looking-at-nested (limit) | 561 | (modify-syntax-entry ?\[ "." st) |
| 581 | (let ((first (point)) | 562 | (modify-syntax-entry ?\] "." st) |
| 582 | (level 1) | 563 | st)) |
| 583 | pos) | 564 | |
| 584 | ;; Move past opening bracket. | 565 | (defun ps-mode--syntax-propertize-special (end) |
| 585 | (forward-char 1) | 566 | (let ((ppss (syntax-ppss)) |
| 586 | (setq pos (point)) | 567 | char) |
| 587 | (while (and (> level 0) (< pos limit)) | 568 | (cond |
| 588 | ;; Search next bracket, stepping over escaped brackets. | 569 | ((not (nth 3 ppss))) ;Not in (...), <~..base85..~>, or <..hex..>. |
| 589 | (if (not (looking-at "\\([^()\\\n]\\|\\\\.\\)*\\([()]\\)")) | 570 | ((eq ?\( (setq char (char-after (nth 8 ppss)))) |
| 590 | (setq level -1) | 571 | (save-restriction |
| 591 | (setq level (+ level (if (string= "(" (match-string 2)) 1 -1))) | 572 | (narrow-to-region (point-min) end) |
| 592 | (goto-char (setq pos (match-end 0))))) | 573 | (goto-char (nth 8 ppss)) |
| 593 | (if (not (= level 0)) | 574 | (condition-case nil |
| 594 | nil | 575 | (with-syntax-table ps-mode--string-syntax-table |
| 595 | ;; Found string with nested brackets, now set match data nr 2. | 576 | (let ((parse-sexp-lookup-properties nil)) |
| 596 | (set-match-data (list first pos nil nil first pos)) | 577 | (forward-sexp 1)) |
| 597 | pos))) | 578 | (put-text-property (1- (point)) (point) |
| 598 | 579 | 'syntax-table (string-to-syntax "|"))) | |
| 599 | ;; This function should search for a string or comment | 580 | (scan-error (goto-char end))))) |
| 600 | ;; If comment, return as match data nr 1 | 581 | ((eq char ?<) |
| 601 | ;; If string, return as match data nr 2 | 582 | (when (re-search-forward (if (eq ?~ (char-after (1+ (nth 8 ppss)))) |
| 602 | (defun ps-mode-match-string-or-comment (limit) | 583 | "~>" ">") |
| 603 | ;; Find the first potential match. | 584 | end 'move) |
| 604 | (if (not (re-search-forward "[%(]" limit t)) | 585 | (put-text-property (1- (point)) (point) |
| 605 | ;; Nothing found: return failure. | 586 | 'syntax-table (string-to-syntax "|"))))))) |
| 606 | nil | 587 | |
| 607 | (let ((end (match-end 0))) | 588 | (defun ps-mode-syntax-propertize (start end) |
| 608 | (goto-char (match-beginning 0)) | 589 | (goto-char start) |
| 609 | (cond ((looking-at "\\(%.*\\)\\|\\((\\([^()\\\n]\\|\\\\.\\)*)\\)") | 590 | (ps-mode--syntax-propertize-special end) |
| 610 | ;; It's a comment or string without nested, unescaped brackets. | 591 | (funcall |
| 611 | (goto-char (match-end 0)) | 592 | (syntax-propertize-rules |
| 612 | (point)) | 593 | ("\\(<\\)\\(?:~\\|[ \n\t]*[[:xdigit:]]\\)\\|\\(?1:(\\)" |
| 613 | ((ps-mode-looking-at-nested limit) | 594 | (1 (unless (or (eq (char-after (match-beginning 0)) |
| 614 | ;; It's a string with nested brackets. | 595 | (char-before (match-beginning 0))) ;Avoid "<<". |
| 615 | (point)) | 596 | (nth 8 (save-excursion (syntax-ppss (match-beginning 1))))) |
| 616 | (t | 597 | (put-text-property (match-beginning 1) (match-end 1) |
| 617 | ;; Try next match. | 598 | 'syntax-table (string-to-syntax "|")) |
| 618 | (goto-char end) | 599 | (ps-mode--syntax-propertize-special end) |
| 619 | (ps-mode-match-string-or-comment limit)))))) | 600 | nil)))) |
| 601 | (point) end)) | ||
| 620 | 602 | ||
| 621 | 603 | ||
| 622 | ;; Key-handlers. | 604 | ;; Key-handlers. |
| @@ -654,34 +636,12 @@ defines the beginning of a group. These tokens are: { [ <<" | |||
| 654 | (setq target (+ target ps-mode-tab))) | 636 | (setq target (+ target ps-mode-tab))) |
| 655 | target))))) | 637 | target))))) |
| 656 | 638 | ||
| 657 | (defun ps-mode-newline () | ||
| 658 | "Insert newline with proper indentation." | ||
| 659 | (interactive) | ||
| 660 | (delete-horizontal-space) | ||
| 661 | (insert "\n") | ||
| 662 | (if ps-mode-auto-indent | ||
| 663 | (indent-to (ps-mode-target-column)))) | ||
| 664 | |||
| 665 | (defun ps-mode-tabkey () | ||
| 666 | "Indent/reindent current line, or insert tab." | ||
| 667 | (interactive) | ||
| 668 | (let ((column (current-column)) | ||
| 669 | target) | ||
| 670 | (if (or (not ps-mode-auto-indent) | ||
| 671 | (< ps-mode-tab 1) | ||
| 672 | (not (re-search-backward "^[ \t]*\\=" nil t))) | ||
| 673 | (insert "\t") | ||
| 674 | (setq target (ps-mode-target-column)) | ||
| 675 | (while (<= target column) | ||
| 676 | (setq target (+ target ps-mode-tab))) | ||
| 677 | (indent-line-to target)))) | ||
| 678 | |||
| 679 | (defun ps-mode-backward-delete-char () | 639 | (defun ps-mode-backward-delete-char () |
| 680 | "Delete backward indentation, or delete backward character." | 640 | "Delete backward indentation, or delete backward character." |
| 681 | (interactive) | 641 | (interactive) |
| 682 | (let ((column (current-column)) | 642 | (let ((column (current-column)) |
| 683 | target) | 643 | target) |
| 684 | (if (or (not ps-mode-auto-indent) | 644 | (if (or (not electric-indent-mode) |
| 685 | (< ps-mode-tab 1) | 645 | (< ps-mode-tab 1) |
| 686 | (not (re-search-backward "^[ \t]+\\=" nil t))) | 646 | (not (re-search-backward "^[ \t]+\\=" nil t))) |
| 687 | (call-interactively 'delete-backward-char) | 647 | (call-interactively 'delete-backward-char) |
| @@ -694,32 +654,6 @@ defines the beginning of a group. These tokens are: { [ <<" | |||
| 694 | (setq target 0)) | 654 | (setq target 0)) |
| 695 | (indent-line-to target)))) | 655 | (indent-line-to target)))) |
| 696 | 656 | ||
| 697 | (defun ps-mode-r-brace () | ||
| 698 | "Insert `}' and perform balance." | ||
| 699 | (interactive) | ||
| 700 | (insert "}") | ||
| 701 | (ps-mode-r-balance "}")) | ||
| 702 | |||
| 703 | (defun ps-mode-r-angle () | ||
| 704 | "Insert `]' and perform balance." | ||
| 705 | (interactive) | ||
| 706 | (insert "]") | ||
| 707 | (ps-mode-r-balance "]")) | ||
| 708 | |||
| 709 | (defun ps-mode-r-gt () | ||
| 710 | "Insert `>' and perform balance." | ||
| 711 | (interactive) | ||
| 712 | (insert ">") | ||
| 713 | (ps-mode-r-balance ">>")) | ||
| 714 | |||
| 715 | (defun ps-mode-r-balance (right) | ||
| 716 | "Adjust indenting if point after RIGHT." | ||
| 717 | (if ps-mode-auto-indent | ||
| 718 | (save-excursion | ||
| 719 | (when (re-search-backward (concat "^[ \t]*" (regexp-quote right) "\\=") nil t) | ||
| 720 | (indent-line-to (ps-mode-target-column))))) | ||
| 721 | (blink-matching-open)) | ||
| 722 | |||
| 723 | (defun ps-mode-other-newline () | 657 | (defun ps-mode-other-newline () |
| 724 | "Perform newline in `*ps-run*' buffer." | 658 | "Perform newline in `*ps-run*' buffer." |
| 725 | (interactive) | 659 | (interactive) |
diff --git a/lisp/simple.el b/lisp/simple.el index e3bae58a380..3273d86879c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -6476,6 +6476,7 @@ The function should return non-nil if the two tokens do not match.") | |||
| 6476 | (not blink-matching-paren-dont-ignore-comments)))) | 6476 | (not blink-matching-paren-dont-ignore-comments)))) |
| 6477 | (condition-case () | 6477 | (condition-case () |
| 6478 | (progn | 6478 | (progn |
| 6479 | (syntax-propertize (point)) | ||
| 6479 | (forward-sexp -1) | 6480 | (forward-sexp -1) |
| 6480 | ;; backward-sexp skips backward over prefix chars, | 6481 | ;; backward-sexp skips backward over prefix chars, |
| 6481 | ;; so move back to the matching paren. | 6482 | ;; so move back to the matching paren. |