comparison lisp/progmodes/ps-mode.el @ 40901:f2a856e8a39c

(ps-mode-font-lock-keywords-1): Merge two regular expressions into one. (ps-mode): Make local bindings for `comment-start' and `comment-start-skip'. (ps-mode-looking-at-nested): Simplify an if-else construct; use `set-match-data' to set the result.
author Richard M. Stallman <rms@gnu.org>
date Sat, 10 Nov 2001 19:36:51 +0000
parents bdb409454d22
children 4111d9e8065d
comparison
equal deleted inserted replaced
40900:733a4e58f062 40901:f2a856e8a39c
3 ;; Copyright (C) 1999, 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
4 4
5 ;; Author: Peter Kleiweg <kleiweg@let.rug.nl> 5 ;; Author: Peter Kleiweg <kleiweg@let.rug.nl>
6 ;; Maintainer: Peter Kleiweg <kleiweg@let.rug.nl> 6 ;; Maintainer: Peter Kleiweg <kleiweg@let.rug.nl>
7 ;; Created: 20 Aug 1997 7 ;; Created: 20 Aug 1997
8 ;; Version: 1.1f, 25 Oct 2001 8 ;; Version: 1.1g, 9 Nov 2001
9 ;; Keywords: PostScript, languages 9 ;; Keywords: PostScript, languages
10 10
11 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
12 12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;; GNU Emacs is free software; you can redistribute it and/or modify
28 ;;; Commentary: 28 ;;; Commentary:
29 29
30 30
31 ;;; Code: 31 ;;; Code:
32 32
33 (defconst ps-mode-version "1.1f, 25 Oct 2001") 33 (defconst ps-mode-version "1.1g, 9 Nov 2001")
34 (defconst ps-mode-maintainer-address "Peter Kleiweg <kleiweg@let.rug.nl>") 34 (defconst ps-mode-maintainer-address "Peter Kleiweg <kleiweg@let.rug.nl>")
35 35
36 (require 'easymenu) 36 (require 'easymenu)
37 37
38 ;; Define core `PostScript' group. 38 ;; Define core `PostScript' group.
254 (defconst ps-mode-font-lock-keywords-3 254 (defconst ps-mode-font-lock-keywords-3
255 (append 255 (append
256 ps-mode-font-lock-keywords-1 256 ps-mode-font-lock-keywords-1
257 (list 257 (list
258 '("//\\w+" . font-lock-type-face) 258 '("//\\w+" . font-lock-type-face)
259 '("^\\(/\\w+\\)\\>[[ \t]*\\(%.*\\)?\r?$" 259 `(,(concat
260 . (1 font-lock-function-name-face)) 260 "^\\(/\\w+\\)\\>"
261 '("^\\(/\\w+\\)\\>\\([ \t]*{\\|[ \t]*<<\\|.*\\<def\\>\\|[ \t]+[0-9]+[ \t]+dict\\>\\)" 261 "\\([[ \t]*\\(%.*\\)?\r?$" ; Nothing but `[' or comment after the name.
262 "\\|[ \t]*\\({\\|<<\\)" ; `{' or `<<' following the name.
263 "\\|[ \t]+[0-9]+[ \t]+dict\\>" ; `[0-9]+ dict' following the name.
264 "\\|.*\\<def\\>\\)") ; `def' somewhere on the same line.
262 . (1 font-lock-function-name-face)) 265 . (1 font-lock-function-name-face))
263 '("/\\w+" . font-lock-variable-name-face) 266 '("/\\w+" . font-lock-variable-name-face)
264 (cons ps-mode-operators 'font-lock-keyword-face))) 267 (cons ps-mode-operators 'font-lock-keyword-face)))
265 "High level highliting for PostScript mode.") 268 "High level highliting for PostScript mode.")
266 269
521 (set (make-local-variable 'font-lock-defaults) 524 (set (make-local-variable 'font-lock-defaults)
522 '((ps-mode-font-lock-keywords 525 '((ps-mode-font-lock-keywords
523 ps-mode-font-lock-keywords-1 526 ps-mode-font-lock-keywords-1
524 ps-mode-font-lock-keywords-2 527 ps-mode-font-lock-keywords-2
525 ps-mode-font-lock-keywords-3) 528 ps-mode-font-lock-keywords-3)
526 t))) 529 t))
530 (set (make-local-variable 'comment-start) "%")
531 ;; NOTE: `\' has a special meaning in strings only
532 (set (make-local-variable 'comment-start-skip) "%+[ \t]*"))
527 533
528 (defun ps-mode-show-version () 534 (defun ps-mode-show-version ()
529 "Show current version of PostScript mode." 535 "Show current version of PostScript mode."
530 (interactive) 536 (interactive)
531 (message " *** PostScript Mode (ps-mode) Version %s *** " ps-mode-version)) 537 (message " *** PostScript Mode (ps-mode) Version %s *** " ps-mode-version))
571 (setq pos (point)) 577 (setq pos (point))
572 (while (and (> level 0) (< pos limit)) 578 (while (and (> level 0) (< pos limit))
573 ;; Search next bracket, stepping over escaped brackets. 579 ;; Search next bracket, stepping over escaped brackets.
574 (if (not (looking-at "\\([^()\\\n]\\|\\\\.\\)*\\([()]\\)")) 580 (if (not (looking-at "\\([^()\\\n]\\|\\\\.\\)*\\([()]\\)"))
575 (setq level -1) 581 (setq level -1)
576 (if (string= "(" (match-string 2)) 582 (setq level (+ level (if (string= "(" (match-string 2)) 1 -1)))
577 (setq level (1+ level)) 583 (goto-char (setq pos (match-end 0)))))
578 (setq level (1- level)))
579 (goto-char (setq pos (match-end 0)))))
580 (if (not (= level 0)) 584 (if (not (= level 0))
581 nil 585 nil
582 ;; Found string with nested brackets, now set match data nr 2. 586 ;; Found string with nested brackets, now set match data nr 2.
583 (goto-char first) 587 (set-match-data (list first pos nil nil first pos))
584 (re-search-forward "\\(%\\)\\|\\((.*\\)" pos)))) 588 pos)))
585 589
586 ;; This function should search for a string or comment 590 ;; This function should search for a string or comment
587 ;; If comment, return as match data nr 1 591 ;; If comment, return as match data nr 1
588 ;; If string, return as match data nr 2 592 ;; If string, return as match data nr 2
589 (defun ps-mode-match-string-or-comment (limit) 593 (defun ps-mode-match-string-or-comment (limit)