annotate lisp/modes/postscript.el @ 187:b405438285a2 r20-3b20

Import from CVS: tag r20-3b20
author cvs
date Mon, 13 Aug 2007 09:56:28 +0200
parents 0293115a14e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; postscript.el --- major mode for editing PostScript programs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Keywords: langauges
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
20 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Author: Chris Maio
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; Last edit: 4 Sep 1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Includes patches from relph@presto.ig.com (John M. Relph) posted to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; gnu.emacs.sources on 22 Nov 90 04:53:43 GMT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; The following two statements, placed in your .emacs file or site-init.el,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; will cause this file to be autoloaded, and postscript-mode invoked, when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; visiting .ps or .cps files:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; (autoload 'postscript-mode "postscript.el" "" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; (setq auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; (cons '("\\.c?ps$".postscript-mode) auto-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (provide 'postscript)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defconst ps-indent-level 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "*Indentation to be used inside of PostScript blocks or arrays")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defconst ps-tab-width 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "*Tab stop width for PostScript mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defun ps-make-tabs (stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (and (< stop 132) (cons stop (ps-make-tabs (+ stop ps-tab-width)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defconst ps-tab-stop-list (ps-make-tabs ps-tab-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "*Tab stop list for PostScript mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (defconst ps-postscript-command '("gs" "-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 "*Command used to invoke with a printer spooler or NeWS server.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar ps-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "Keymap used in PostScript mode buffers")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defvar ps-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "PostScript mode syntax table")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar ps-balanced-string-syntax-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (let ((b (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (loser (generate-new-buffer "x")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (set-buffer loser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (set-syntax-table (copy-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (modify-syntax-entry ?\( "\"\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (insert "((")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (let ((v (parse-partial-sexp (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (if (elt v 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; New syntax code think's we're still inside a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (set-buffer b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (kill-buffer loser))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defconst postscript-font-lock-keywords (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; Proper rule for Postscript strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 '("(\\([^)]\\|\\\\.\\|\\\\\n\\)*)" . font-lock-string-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; Make any line beginning with a / be a ``keyword''
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 '("^/[^\n%]*" . font-lock-keyword-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; Make brackets of all forms be keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 '("[][<>{}]+" . font-lock-keyword-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; Keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (list (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "[][ \t\f\n\r()<>{}/%]" ;delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (mapconcat 'identity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 '("begin" "end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "save" "restore" "gsave" "grestore"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; Any delimited name ending in 'def'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "[a-zA-Z0-9-._]*def"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "[Dd]efine[a-zA-Z0-9-._]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "\\|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 "\\([][ \t\f\n\r()<>{}/%]\\|$\\)" ;delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 1 'font-lock-keyword-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Expressions to highlight in Postscript buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (put 'postscript-mode 'font-lock-defaults '(postscript-font-lock-keywords))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (if ps-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (let ((i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq ps-mode-syntax-table (copy-syntax-table nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (while (< i 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (or (= (char-syntax i ps-mode-syntax-table) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (modify-syntax-entry i "_" ps-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (modify-syntax-entry ?\ " " ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (modify-syntax-entry ?\t " " ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (modify-syntax-entry ?\f " " ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (modify-syntax-entry ?\r " " ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (modify-syntax-entry ?\% "<" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (modify-syntax-entry ?\n ">" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (modify-syntax-entry ?\\ "\\" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (modify-syntax-entry ?? "_" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (modify-syntax-entry ?_ "_" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (modify-syntax-entry ?. "_" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (modify-syntax-entry ?/ "'" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if ps-balanced-string-syntax-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (modify-syntax-entry ?\( "\"\)" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (modify-syntax-entry ?\) "\"\(" ps-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; This isn't correct, but Emacs syntax stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; has no way to deal with string syntax which uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; different open and close characters. Sigh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (modify-syntax-entry ?\( "(" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (modify-syntax-entry ?\) ")" ps-mode-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (modify-syntax-entry ?\[ "(\]" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (modify-syntax-entry ?\] ")\[" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (modify-syntax-entry ?\{ "\(\}" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (modify-syntax-entry ?\} "\)\}" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (modify-syntax-entry ?/ "' p" ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defun postscript-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "Major mode for editing PostScript files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 \\[ps-execute-buffer] will send the contents of the buffer to the NeWS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 server using psh(1). \\[ps-execute-region] sends the current region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 \\[ps-shell] starts an interactive psh(1) window which will be used for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 subsequent \\[ps-execute-buffer] or \\[ps-execute-region] commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 In this mode, TAB and \\[indent-region] attempt to indent code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 based on the position of {}, [], and begin/end pairs. The variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ps-indent-level controls the amount of indentation used inside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 arrays and begin/end pairs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 \\{ps-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 \\[postscript-mode] calls the value of the variable postscript-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 with no args, if that value is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (use-local-map ps-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (set-syntax-table ps-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq comment-start "% ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq comment-start-skip "%+ *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (setq comment-column 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq indent-line-function 'ps-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (make-local-variable 'tab-stop-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (setq tab-stop-list ps-tab-stop-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (make-local-variable 'page-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (setq page-delimiter "^showpage")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (make-local-variable 'parse-sexp-ignore-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (setq parse-sexp-ignore-comments t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq mode-name "PostScript")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (setq major-mode 'postscript-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (run-hooks 'ps-mode-hook) ; bad name! Kept for compatibility.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (run-hooks 'postscript-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (defun ps-tab ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "Command assigned to the TAB key in PostScript mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (save-excursion (skip-chars-backward " \t") (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (ps-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (ps-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (defun ps-indent-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 "Indents a line of PostScript code."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if (not (or (looking-at "%%") ; "%%" comments stay at left margin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (ps-top-level-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (if (and (< (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (eq ?\) (char-syntax (char-after (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (ps-indent-close) ; indent close-delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (if (looking-at "\\(dict\\|class\\)?end\\|cdef\\|grestore\\|>>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (ps-indent-end) ; indent end token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (ps-indent-in-block))))) ; indent line after open delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;(defun ps-open ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ; (insert last-command-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun ps-insert-d-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 "Awful hack to make \"end\" and \"cdef\" keywords indent themselves."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (insert-char last-command-char arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if (looking-at "^[ \t]*\\(\\(dict\\|class\\)?end\\|cdef\\|grestore\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (ps-indent-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (defun ps-close ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 "Inserts and indents a close delimiter."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (insert last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (ps-indent-close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (blink-matching-open))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (defun ps-indent-close ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 "Internal function to indent a line containing a an array close delimiter."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (save-excursion (skip-chars-backward " \t") (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (let (x (oldpoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (forward-char) (backward-sexp) ;XXX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (if (and (eq 1 (count-lines (point) oldpoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (> 1 (- oldpoint (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (goto-char oldpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq x (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (goto-char oldpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (indent-to x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defun ps-indent-end ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 "Indent an \"end\" token or array close delimiter."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (let ((goal (ps-block-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (if (not goal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (indent-relative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq goal (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (goto-char goal) (back-to-indentation) (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (indent-to goal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (defun ps-indent-in-block ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 "Indent a line which does not open or close a block."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (let ((goal (ps-block-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq goal (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (goto-char goal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ps-indent-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (+ (current-column) ps-indent-level))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (indent-to goal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;;; returns nil if at top-level, or char pos of beginning of current block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (defun ps-block-start ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 "Returns the character position of the character following the nearest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 enclosing `[' `{' or `begin' keyword."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (let ((open (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (backward-up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (ps-begin-end-hack open))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (defun ps-begin-end-hack (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 "Search backwards from point to START for enclosing `begin' and returns the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 character number of the character following `begin' or START if not found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (let ((depth 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (while (and (> depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (or (re-search-backward "^[ \t]*\\(dict\\|class\\)?\\(end\\|grestore\\|>>\\)\\|\\(begin\\|gsave\\|<<\\)[ \t]*\\(%.*\\)*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 start t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (re-search-backward "^[ \t]*cdef.*$" start t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq depth (if (looking-at "[ \t]*\\(dict\\|class\\)?\\(end\\|grestore\\|>>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (1+ depth) (1- depth))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (if (not (eq 0 depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (defun ps-top-level-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 "Awful test to see whether we are inside some sort of PostScript block."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (and (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (not (scan-lists (point) -1 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (error t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (not (ps-begin-end-hack nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;;; initialize the keymap if it doesn't already exist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (if (null ps-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (setq ps-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (set-keymap-name ps-mode-map 'ps-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;;(define-key ps-mode-map "d" 'ps-insert-d-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;;(define-key ps-mode-map "f" 'ps-insert-d-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;;(define-key ps-mode-map "{" 'ps-open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;;(define-key ps-mode-map "}" 'ps-close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ;;(define-key ps-mode-map "[" 'ps-open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;;(define-key ps-mode-map "]" 'ps-close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (define-key ps-mode-map "\t" 'ps-tab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (define-key ps-mode-map "\C-c\C-c" 'ps-execute-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (define-key ps-mode-map "\C-c|" 'ps-execute-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;; make up yout mind! -- the below or the above?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (define-key ps-mode-map "\C-c!" 'ps-shell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (defun ps-execute-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 "Send the contents of the buffer to a printer or NeWS server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (mark-whole-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (ps-execute-region (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (defun ps-execute-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 "Send the region between START and END to a printer or NeWS server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 You should kill any existing *PostScript* buffer unless you want the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 PostScript text to be executed in that process."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let ((start (min (point) (mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (end (max (point) (mark))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (process-send-string "PostScript" (buffer-substring start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (error (shell-command-on-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 start end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (mapconcat 'identity ps-postscript-command " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (defun ps-shell ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 "Start a shell communicating with a PostScript printer or NeWS server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (require 'shell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (switch-to-buffer-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (apply 'make-comint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 "PostScript"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (car ps-postscript-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (cdr ps-postscript-command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (make-local-variable 'shell-prompt-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ; (setq shell-prompt-pattern "PS>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (setq shell-prompt-pattern "GS>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ; (process-send-string "PostScript" "executive\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 )