Merge from emacs--rel--22
[bpt/emacs.git] / lisp / progmodes / ps-mode.el
1 ;;; ps-mode.el --- PostScript mode for GNU Emacs
2
3 ;; Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: Peter Kleiweg <p.c.j.kleiweg@rug.nl>
7 ;; Maintainer: Peter Kleiweg <p.c.j.kleiweg@rug.nl>
8 ;; Created: 20 Aug 1997
9 ;; Version: 1.1h, 16 Jun 2005
10 ;; Keywords: PostScript, languages
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;;; Commentary:
30
31 \f
32 ;;; Code:
33
34 (defconst ps-mode-version "1.1h, 16 Jun 2005")
35 (defconst ps-mode-maintainer-address "Peter Kleiweg <p.c.j.kleiweg@rug.nl>")
36
37 (require 'easymenu)
38
39 ;; Define core `PostScript' group.
40 (defgroup PostScript nil
41 "PostScript mode for Emacs."
42 :group 'languages)
43
44 (defgroup PostScript-edit nil
45 "PostScript editing."
46 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
47 :prefix "ps-mode-"
48 :group 'PostScript)
49
50 (defgroup PostScript-interaction nil
51 "PostScript interaction."
52 :prefix "ps-run-"
53 :group 'PostScript)
54
55 ;; User variables.
56
57 (defcustom ps-mode-auto-indent t
58 "*Should we use autoindent?"
59 :group 'PostScript-edit
60 :type 'boolean)
61
62 (defcustom ps-mode-tab 4
63 "*Number of spaces to use when indenting."
64 :group 'PostScript-edit
65 :type 'integer)
66
67 (defcustom ps-mode-paper-size '(595 842)
68 "*Default paper size.
69
70 When inserting an EPSF template these values are used
71 to set the boundingbox to include the whole page.
72 When the figure is finished these values should be replaced."
73 :group 'PostScript-edit
74 :type '(choice
75 (const :tag "letter" (612 792))
76 (const :tag "legal" (612 1008))
77 (const :tag "a0" (2380 3368))
78 (const :tag "a1" (1684 2380))
79 (const :tag "a2" (1190 1684))
80 (const :tag "a3" (842 1190))
81 (const :tag "a4" (595 842))
82 (const :tag "a5" (421 595))
83 (const :tag "a6" (297 421))
84 (const :tag "a7" (210 297))
85 (const :tag "a8" (148 210))
86 (const :tag "a9" (105 148))
87 (const :tag "a10" (74 105))
88 (const :tag "b0" (2836 4008))
89 (const :tag "b1" (2004 2836))
90 (const :tag "b2" (1418 2004))
91 (const :tag "b3" (1002 1418))
92 (const :tag "b4" (709 1002))
93 (const :tag "b5" (501 709))
94 (const :tag "archE" (2592 3456))
95 (const :tag "archD" (1728 2592))
96 (const :tag "archC" (1296 1728))
97 (const :tag "archB" (864 1296))
98 (const :tag "archA" (648 864))
99 (const :tag "flsa" (612 936))
100 (const :tag "flse" (612 936))
101 (const :tag "halfletter" (396 612))
102 (const :tag "11x17" (792 1224))
103 (const :tag "tabloid" (792 1224))
104 (const :tag "ledger" (1224 792))
105 (const :tag "csheet" (1224 1584))
106 (const :tag "dsheet" (1584 2448))
107 (const :tag "esheet" (2448 3168))))
108
109 (defcustom ps-mode-print-function
110 (lambda ()
111 (let ((lpr-switches nil)
112 (lpr-command (if (memq system-type '(usg-unix-v dgux hpux irix))
113 "lp" "lpr")))
114 (lpr-buffer)))
115 "*Lisp function to print current buffer as PostScript."
116 :group 'PostScript-edit
117 :type 'function)
118
119 (defcustom ps-run-prompt "\\(GS\\(<[0-9]+\\)?>\\)+"
120 "*Regexp to match prompt in interactive PostScript."
121 :group 'PostScript-interaction
122 :type 'regexp)
123
124 (defcustom ps-run-font-lock-keywords-2
125 (append (unless (string= ps-run-prompt "")
126 (list (list (if (= ?^ (string-to-char ps-run-prompt))
127 ps-run-prompt
128 (concat "^" ps-run-prompt))
129 '(0 font-lock-function-name-face nil nil))))
130 '((">>showpage, press <return> to continue<<"
131 (0 font-lock-keyword-face nil nil))
132 ("^\\(Error\\|Can't\\).*"
133 (0 font-lock-warning-face nil nil))
134 ("^\\(Current file position is\\) \\([0-9]+\\)"
135 (1 font-lock-comment-face nil nil)
136 (2 font-lock-warning-face nil nil))))
137 "*Medium level highlighting of messages from the PostScript interpreter.
138
139 See documentation on font-lock for details."
140 :group 'PostScript-interaction
141 :type '(repeat (list :tag "Expression with one or more highlighters"
142 :value ("" (0 default nil t))
143 (regexp :tag "Expression")
144 (repeat :tag "Highlighters"
145 :inline regexp
146 (list :tag "Highlighter"
147 (integer :tag "Subexp")
148 face
149 (boolean :tag "Override")
150 (boolean :tag "Laxmatch" :value t))))))
151
152 (defcustom ps-run-x '("gs" "-r72" "-sPAPERSIZE=a4")
153 "*Command as list to run PostScript with graphic display."
154 :group 'PostScript-interaction
155 :type '(repeat string))
156
157 (defcustom ps-run-dumb '("gs" "-dNODISPLAY")
158 "*Command as list to run PostScript without graphic display."
159 :group 'PostScript-interaction
160 :type '(repeat string))
161
162 (defcustom ps-run-init nil
163 "*String of commands to send to PostScript to start interactive.
164
165 Example: \"executive\"
166
167 You won't need to set this option for Ghostscript."
168 :group 'PostScript-interaction
169 :type '(choice (const nil) string))
170
171 (defcustom ps-run-error-line-numbers nil
172 "*What values are used by the PostScript interpreter in error messages?"
173 :group 'PostScript-interaction
174 :type '(choice (const :tag "line numbers" t)
175 (const :tag "byte counts" nil)))
176
177 (defcustom ps-run-tmp-dir nil
178 "*Name of directory to place temporary file.
179
180 If nil, the following are tried in turn, until success:
181 1. \"$TEMP\"
182 2. \"$TMP\"
183 3. \"$HOME/tmp\"
184 4. \"/tmp\""
185 :group 'PostScript-interaction
186 :type '(choice (const nil) directory))
187
188 \f
189 ;; Constants used for font-lock.
190
191 ;; Only a small set of the PostScript operators is selected for fontification.
192 ;; Fontification is meant to clarify the document structure and process flow,
193 ;; fontifying all known PostScript operators would hinder that objective.
194 (defconst ps-mode-operators
195 (let ((ops '("clear" "mark" "cleartomark" "counttomark"
196 "forall"
197 "dict" "begin" "end" "def"
198 "true" "false"
199 "exec" "if" "ifelse" "for" "repeat" "loop" "exit"
200 "stop" "stopped" "countexecstack" "execstack"
201 "quit" "start"
202 "save" "restore"
203 "bind" "null"
204 "gsave" "grestore" "grestoreall"
205 "showpage")))
206 (concat "\\<" (regexp-opt ops t) "\\>"))
207 "Regexp of PostScript operators that will be fontified.")
208
209 ;; Level 1 font-lock:
210 ;; - Special comments (reference face)
211 ;; - Strings and other comments
212 ;; - Partial strings (warning face)
213 ;; - 8bit characters (warning face)
214 ;; Multiline strings are not supported. Strings with nested brackets are.
215 (defconst ps-mode-font-lock-keywords-1
216 '(("\\`%!PS.*" . font-lock-reference-face)
217 ("^%%BoundingBox:[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]+-?[0-9]+[ \t]*$"
218 . font-lock-reference-face)
219 (ps-mode-match-string-or-comment
220 (1 font-lock-comment-face nil t)
221 (2 font-lock-string-face nil t))
222 ("([^()\n%]*\\|[^()\n]*)" . font-lock-warning-face)
223 ("[\200-\377]+" (0 font-lock-warning-face prepend nil)))
224 "Subdued level highlighting for PostScript mode.")
225
226 ;; Level 2 font-lock:
227 ;; - All from level 1
228 ;; - PostScript operators (keyword face)
229 (defconst ps-mode-font-lock-keywords-2
230 (append
231 ps-mode-font-lock-keywords-1
232 (list
233 (cons
234 ;; exclude names prepended by `/'
235 (concat "\\(^\\|[^/\n]\\)" ps-mode-operators)
236 '(2 font-lock-keyword-face))))
237 "Medium level highlighting for PostScript mode.")
238
239 ;; Level 3 font-lock:
240 ;; - All from level 2
241 ;; - Immediately evaluated names: those starting with `//' (type face)
242 ;; - Names that look like they are used for the definition of:
243 ;; * a function
244 ;; * an array
245 ;; * a dictionary
246 ;; * a "global" variable
247 ;; (function name face)
248 ;; - Other names (variable name face)
249 ;; The rules used to determine what names fit in the first category are:
250 ;; - Only names that are at the left margin, and one of these on the same line:
251 ;; * Nothing after the name except possibly one or more `[' or a comment
252 ;; * A `{' or `<<' or `[0-9]+ dict' following the name
253 ;; * A `def' somewhere in the same line
254 ;; Names are fontified before PostScript operators, allowing the use of
255 ;; a more simple (efficient) regexp than the one used in level 2.
256 (defconst ps-mode-font-lock-keywords-3
257 (append
258 ps-mode-font-lock-keywords-1
259 (list
260 '("//\\w+" . font-lock-type-face)
261 `(,(concat
262 "^\\(/\\w+\\)\\>"
263 "\\([[ \t]*\\(%.*\\)?\r?$" ; Nothing but `[' or comment after the name.
264 "\\|[ \t]*\\({\\|<<\\)" ; `{' or `<<' following the name.
265 "\\|[ \t]+[0-9]+[ \t]+dict\\>" ; `[0-9]+ dict' following the name.
266 "\\|.*\\<def\\>\\)") ; `def' somewhere on the same line.
267 . (1 font-lock-function-name-face))
268 '("/\\w+" . font-lock-variable-name-face)
269 (cons ps-mode-operators 'font-lock-keyword-face)))
270 "High level highliting for PostScript mode.")
271
272 (defconst ps-mode-font-lock-keywords ps-mode-font-lock-keywords-1
273 "Default expressions to highlight in PostScript mode.")
274
275 ;; Level 1 font-lock for ps-run-mode
276 ;; - prompt (function name face)
277 (defconst ps-run-font-lock-keywords-1
278 (unless (string= "" ps-run-prompt)
279 (list (cons (if (= ?^ (string-to-char ps-run-prompt))
280 ps-run-prompt
281 (concat "^" ps-run-prompt))
282 'font-lock-function-name-face)))
283 "Subdued level highlighting for PostScript run mode.")
284
285 (defconst ps-run-font-lock-keywords ps-run-font-lock-keywords-1
286 "Default expressions to highlight in PostScript run mode.")
287
288 \f
289 ;; Variables.
290
291 (defvar ps-mode-map nil
292 "Local keymap to use in PostScript mode.")
293
294 (defvar ps-mode-syntax-table nil
295 "Syntax table used while in PostScript mode.")
296
297 (defvar ps-run-mode-map nil
298 "Local keymap to use in PostScript run mode.")
299
300 (defvar ps-mode-tmp-file nil
301 "Name of temporary file, set by `ps-run'.")
302
303 (defvar ps-run-mark nil
304 "Mark to start of region that was sent to PostScript interpreter.")
305
306 (defvar ps-run-parent nil
307 "Parent window of interactive PostScript.")
308
309 \f
310 ;; Menu
311
312 (defconst ps-mode-menu-main
313 '("PostScript"
314 ["EPSF Template, Sparse" ps-mode-epsf-sparse t]
315 ["EPSF Template, Rich" ps-mode-epsf-rich t]
316 "---"
317 ("Cookbook"
318 ["RE" ps-mode-RE t]
319 ["ISOLatin1Extended" ps-mode-latin-extended t]
320 ["center" ps-mode-center t]
321 ["right" ps-mode-right t]
322 ["Heapsort" ps-mode-heapsort t])
323 ("Fonts (1)"
324 ["Times-Roman" (insert "/Times-Roman ") t]
325 ["Times-Bold" (insert "/Times-Bold ") t]
326 ["Times-Italic" (insert "/Times-Italic ") t]
327 ["Times-BoldItalic" (insert "/Times-BoldItalic ") t]
328 ["Helvetica" (insert "/Helvetica ") t]
329 ["Helvetica-Bold" (insert "/Helvetica-Bold ") t]
330 ["Helvetica-Oblique" (insert "/Helvetica-Oblique ") t]
331 ["Helvetica-BoldOblique" (insert "/Helvetica-BoldOblique ") t]
332 ["Courier" (insert "/Courier ") t]
333 ["Courier-Bold" (insert "/Courier-Bold ") t]
334 ["Courier-Oblique" (insert "/Courier-Oblique ") t]
335 ["Courier-BoldOblique" (insert "/Courier-BoldOblique ") t]
336 ["Symbol" (insert "/Symbol") t ])
337 ("Fonts (2)"
338 ["AvantGarde-Book" (insert "/AvantGarde-Book ") t]
339 ["AvantGarde-Demi" (insert "/AvantGarde-Demi ") t]
340 ["AvantGarde-BookOblique" (insert "/AvantGarde-BookOblique ") t]
341 ["AvantGarde-DemiOblique" (insert "/AvantGarde-DemiOblique ") t]
342 ["Bookman-Light" (insert "/Bookman-Light ") t]
343 ["Bookman-Demi" (insert "/Bookman-Demi ") t]
344 ["Bookman-LightItalic" (insert "/Bookman-LightItalic ") t]
345 ["Bookman-DemiItalic" (insert "/Bookman-DemiItalic ") t]
346 ["Helvetica-Narrow" (insert "/Helvetica-Narrow ") t]
347 ["Helvetica-Narrow-Bold" (insert "/Helvetica-Narrow-Bold ") t]
348 ["Helvetica-Narrow-Oblique" (insert "/Helvetica-Narrow-Oblique ") t]
349 ["Helvetica-Narrow-BoldOblique" (insert "/Helvetica-Narrow-BoldOblique ") t]
350 ["NewCenturySchlbk-Roman" (insert "/NewCenturySchlbk-Roman ") t]
351 ["NewCenturySchlbk-Bold" (insert "/NewCenturySchlbk-Bold ") t]
352 ["NewCenturySchlbk-Italic" (insert "/NewCenturySchlbk-Italic ") t]
353 ["NewCenturySchlbk-BoldItalic" (insert "/NewCenturySchlbk-BoldItalic ") t]
354 ["Palatino-Roman" (insert "/Palatino-Roman ") t]
355 ["Palatino-Bold" (insert "/Palatino-Bold ") t]
356 ["Palatino-Italic" (insert "/Palatino-Italic ") t]
357 ["Palatino-BoldItalic" (insert "/Palatino-BoldItalic ") t]
358 ["ZapfChancery-MediumItalic" (insert "/ZapfChancery-MediumItalic ") t]
359 ["ZapfDingbats" (insert "/ZapfDingbats ") t])
360 "---"
361 ["Comment Out Region" ps-mode-comment-out-region (mark t)]
362 ["Uncomment Region" ps-mode-uncomment-region (mark t)]
363 "---"
364 ["8-bit to Octal Buffer" ps-mode-octal-buffer t]
365 ["8-bit to Octal Region" ps-mode-octal-region (mark t)]
366 "---"
367 ["Auto Indent" (setq ps-mode-auto-indent (not ps-mode-auto-indent))
368 :style toggle :selected ps-mode-auto-indent]
369 "---"
370 ["Start PostScript"
371 ps-run-start
372 t]
373 ["Quit PostScript" ps-run-quit (process-status "ps-run")]
374 ["Kill PostScript" ps-run-kill (process-status "ps-run")]
375 ["Send Buffer to Interpreter"
376 ps-run-buffer
377 (process-status "ps-run")]
378 ["Send Region to Interpreter"
379 ps-run-region
380 (and (mark t) (process-status "ps-run"))]
381 ["Send Newline to Interpreter"
382 ps-mode-other-newline
383 (process-status "ps-run")]
384 ["View BoundingBox"
385 ps-run-boundingbox
386 (process-status "ps-run")]
387 ["Clear/Reset PostScript Graphics"
388 ps-run-clear
389 (process-status "ps-run")]
390 "---"
391 ["Print Buffer as PostScript"
392 ps-mode-print-buffer
393 t]
394 ["Print Region as PostScript"
395 ps-mode-print-region
396 (mark t)]
397 "---"
398 ["Customize for PostScript"
399 (customize-group "PostScript")
400 t]
401 "---"
402 ["Submit Bug Report"
403 ps-mode-submit-bug-report
404 t]))
405
406 \f
407 ;; Mode maps for PostScript edit mode and PostScript interaction mode.
408
409 (unless ps-mode-map
410 (setq ps-mode-map (make-sparse-keymap))
411 (define-key ps-mode-map "\C-c\C-v" 'ps-run-boundingbox)
412 (define-key ps-mode-map "\C-c\C-u" 'ps-mode-uncomment-region)
413 (define-key ps-mode-map "\C-c\C-t" 'ps-mode-epsf-rich)
414 (define-key ps-mode-map "\C-c\C-s" 'ps-run-start)
415 (define-key ps-mode-map "\C-c\C-r" 'ps-run-region)
416 (define-key ps-mode-map "\C-c\C-q" 'ps-run-quit)
417 (define-key ps-mode-map "\C-c\C-p" 'ps-mode-print-buffer)
418 (define-key ps-mode-map "\C-c\C-o" 'ps-mode-comment-out-region)
419 (define-key ps-mode-map "\C-c\C-k" 'ps-run-kill)
420 (define-key ps-mode-map "\C-c\C-j" 'ps-mode-other-newline)
421 (define-key ps-mode-map "\C-c\C-l" 'ps-run-clear)
422 (define-key ps-mode-map "\C-c\C-b" 'ps-run-buffer)
423 (define-key ps-mode-map ">" 'ps-mode-r-gt)
424 (define-key ps-mode-map "]" 'ps-mode-r-angle)
425 (define-key ps-mode-map "}" 'ps-mode-r-brace)
426 (define-key ps-mode-map "\177" 'ps-mode-backward-delete-char)
427 (define-key ps-mode-map "\t" 'ps-mode-tabkey)
428 (define-key ps-mode-map "\r" 'ps-mode-newline)
429 (define-key ps-mode-map [return] '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 (define-key ps-run-mode-map "\C-c\C-q" 'ps-run-quit)
435 (define-key ps-run-mode-map "\C-c\C-k" 'ps-run-kill)
436 (define-key ps-run-mode-map "\C-c\C-e" 'ps-run-goto-error)
437 (define-key ps-run-mode-map [mouse-2] 'ps-run-mouse-goto-error)
438 (define-key ps-run-mode-map "\r" 'ps-run-newline)
439 (define-key ps-run-mode-map [return] 'ps-run-newline))
440
441 \f
442 ;; Syntax table.
443
444 (unless ps-mode-syntax-table
445 (setq ps-mode-syntax-table (make-syntax-table))
446
447 (modify-syntax-entry ?\% "< " ps-mode-syntax-table)
448 (modify-syntax-entry ?\n "> " ps-mode-syntax-table)
449 (modify-syntax-entry ?\r "> " ps-mode-syntax-table)
450 (modify-syntax-entry ?\f "> " ps-mode-syntax-table)
451 (modify-syntax-entry ?\< "(>" ps-mode-syntax-table)
452 (modify-syntax-entry ?\> ")<" ps-mode-syntax-table)
453
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)
471 (modify-syntax-entry ?^ "w " ps-mode-syntax-table) ; NOT: ?\^
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 (modify-syntax-entry ?\~ "w " ps-mode-syntax-table)
476
477 (let ((i 128))
478 (while (< i 256)
479 (modify-syntax-entry i "w " ps-mode-syntax-table)
480 (setq i (1+ i)))))
481
482 \f
483 ;; PostScript mode.
484
485 ;;;###autoload
486 (define-derived-mode ps-mode fundamental-mode "PostScript"
487 "Major mode for editing PostScript with GNU Emacs.
488
489 Entry to this mode calls `ps-mode-hook'.
490
491 The following variables hold user options, and can
492 be set through the `customize' command:
493
494 `ps-mode-auto-indent'
495 `ps-mode-tab'
496 `ps-mode-paper-size'
497 `ps-mode-print-function'
498 `ps-run-prompt'
499 `ps-run-font-lock-keywords-2'
500 `ps-run-x'
501 `ps-run-dumb'
502 `ps-run-init'
503 `ps-run-error-line-numbers'
504 `ps-run-tmp-dir'
505
506 Type \\[describe-variable] for documentation on these options.
507
508
509 \\{ps-mode-map}
510
511
512 When starting an interactive PostScript process with \\[ps-run-start],
513 a second window will be displayed, and `ps-run-mode-hook' will be called.
514 The keymap for this second window is:
515
516 \\{ps-run-mode-map}
517
518
519 When Ghostscript encounters an error it displays an error message
520 with a file position. Clicking mouse-2 on this number will bring
521 point to the corresponding spot in the PostScript window, if input
522 to the interpreter was sent from that window.
523 Typing \\<ps-run-mode-map>\\[ps-run-goto-error] when the cursor is at the number has the same effect."
524 (set (make-local-variable 'font-lock-defaults)
525 '((ps-mode-font-lock-keywords
526 ps-mode-font-lock-keywords-1
527 ps-mode-font-lock-keywords-2
528 ps-mode-font-lock-keywords-3)
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]*")
533 ;; enable doc-view-minor-mode => C-c C-c starts viewing the current ps file
534 ;; with doc-view-mode.
535 (doc-view-minor-mode 1))
536
537 (defun ps-mode-show-version ()
538 "Show current version of PostScript mode."
539 (interactive)
540 (message " *** PostScript Mode (ps-mode) Version %s *** " ps-mode-version))
541
542 (defun ps-mode-submit-bug-report ()
543 "Submit via mail a bug report on PostScript mode."
544 (interactive)
545 (when (y-or-n-p "Submit bug report on PostScript mode? ")
546 (let ((reporter-prompt-for-summary-p nil)
547 (reporter-dont-compact-list '(ps-mode-print-function
548 ps-run-font-lock-keywords-2)))
549 (reporter-submit-bug-report
550 ps-mode-maintainer-address
551 (format "ps-mode.el %s [%s]" ps-mode-version system-type)
552 '(ps-mode-auto-indent
553 ps-mode-tab
554 ps-mode-paper-size
555 ps-mode-print-function
556 ps-run-prompt
557 ps-run-font-lock-keywords-2
558 ps-run-x
559 ps-run-dumb
560 ps-run-init
561 ps-run-error-line-numbers
562 ps-run-tmp-dir)))))
563
564 \f
565 ;; Helper functions for font-lock.
566
567 ;; When this function is called, point is at an opening bracket.
568 ;; This function should test if point is at the start of a string
569 ;; with nested brackets.
570 ;; If true: move point to end of string
571 ;; set string to match data nr 2
572 ;; return new point
573 ;; If false: return nil
574 (defun ps-mode-looking-at-nested (limit)
575 (let ((first (point))
576 (level 1)
577 pos)
578 ;; Move past opening bracket.
579 (forward-char 1)
580 (setq pos (point))
581 (while (and (> level 0) (< pos limit))
582 ;; Search next bracket, stepping over escaped brackets.
583 (if (not (looking-at "\\([^()\\\n]\\|\\\\.\\)*\\([()]\\)"))
584 (setq level -1)
585 (setq level (+ level (if (string= "(" (match-string 2)) 1 -1)))
586 (goto-char (setq pos (match-end 0)))))
587 (if (not (= level 0))
588 nil
589 ;; Found string with nested brackets, now set match data nr 2.
590 (set-match-data (list first pos nil nil first pos))
591 pos)))
592
593 ;; This function should search for a string or comment
594 ;; If comment, return as match data nr 1
595 ;; If string, return as match data nr 2
596 (defun ps-mode-match-string-or-comment (limit)
597 ;; Find the first potential match.
598 (if (not (re-search-forward "[%(]" limit t))
599 ;; Nothing found: return failure.
600 nil
601 (let ((end (match-end 0)))
602 (goto-char (match-beginning 0))
603 (cond ((looking-at "\\(%.*\\)\\|\\((\\([^()\\\n]\\|\\\\.\\)*)\\)")
604 ;; It's a comment or string without nested, unescaped brackets.
605 (goto-char (match-end 0))
606 (point))
607 ((ps-mode-looking-at-nested limit)
608 ;; It's a string with nested brackets.
609 (point))
610 (t
611 ;; Try next match.
612 (goto-char end)
613 (ps-mode-match-string-or-comment limit))))))
614
615 \f
616 ;; Key-handlers.
617
618 (defun ps-mode-target-column ()
619 "To what column should text on current line be indented?
620
621 Identation is increased if the last token on the current line
622 defines the beginning of a group. These tokens are: { [ <<"
623 (save-excursion
624 (beginning-of-line)
625 (if (looking-at "[ \t]*\\(}\\|\\]\\|>>\\)")
626 (condition-case err
627 (progn
628 (goto-char (match-end 0))
629 (backward-sexp 1)
630 (beginning-of-line)
631 (if (looking-at "[ \t]+")
632 (goto-char (match-end 0)))
633 (current-column))
634 (error
635 (ding)
636 (message "%s" (error-message-string err))
637 0))
638 (let (target)
639 (if (not (re-search-backward "[^ \t\n\r\f][ \t\n\r\f]*\\=" nil t))
640 0
641 (goto-char (match-beginning 0))
642 (beginning-of-line)
643 (if (looking-at "[ \t]+")
644 (goto-char (match-end 0)))
645 (setq target (current-column))
646 (end-of-line)
647 (if (re-search-backward "\\({\\|\\[\\|<<\\)[ \t]*\\(%[^\n]*\\)?\\=" nil t)
648 (setq target (+ target ps-mode-tab)))
649 target)))))
650
651 (defun ps-mode-newline ()
652 "Insert newline with proper indentation."
653 (interactive)
654 (delete-horizontal-space)
655 (insert "\n")
656 (if ps-mode-auto-indent
657 (indent-to (ps-mode-target-column))))
658
659 (defun ps-mode-tabkey ()
660 "Indent/reindent current line, or insert tab."
661 (interactive)
662 (let ((column (current-column))
663 target)
664 (if (or (not ps-mode-auto-indent)
665 (< ps-mode-tab 1)
666 (not (re-search-backward "^[ \t]*\\=" nil t)))
667 (insert "\t")
668 (setq target (ps-mode-target-column))
669 (while (<= target column)
670 (setq target (+ target ps-mode-tab)))
671 (indent-line-to target))))
672
673 (defun ps-mode-backward-delete-char ()
674 "Delete backward indentation, or delete backward character."
675 (interactive)
676 (let ((column (current-column))
677 target)
678 (if (or (not ps-mode-auto-indent)
679 (< ps-mode-tab 1)
680 (not (re-search-backward "^[ \t]+\\=" nil t)))
681 (delete-backward-char 1)
682 (setq target (ps-mode-target-column))
683 (while (> column target)
684 (setq target (+ target ps-mode-tab)))
685 (while (>= target column)
686 (setq target (- target ps-mode-tab)))
687 (if (< target 0)
688 (setq target 0))
689 (indent-line-to target))))
690
691 (defun ps-mode-r-brace ()
692 "Insert `}' and perform balance."
693 (interactive)
694 (insert "}")
695 (ps-mode-r-balance "}"))
696
697 (defun ps-mode-r-angle ()
698 "Insert `]' and perform balance."
699 (interactive)
700 (insert "]")
701 (ps-mode-r-balance "]"))
702
703 (defun ps-mode-r-gt ()
704 "Insert `>' and perform balance."
705 (interactive)
706 (insert ">")
707 (ps-mode-r-balance ">>"))
708
709 (defun ps-mode-r-balance (right)
710 "Adjust indentification if point after RIGHT."
711 (if ps-mode-auto-indent
712 (save-excursion
713 (when (re-search-backward (concat "^[ \t]*" (regexp-quote right) "\\=") nil t)
714 (indent-line-to (ps-mode-target-column)))))
715 (blink-matching-open))
716
717 (defun ps-mode-other-newline ()
718 "Perform newline in `*ps run*' buffer."
719 (interactive)
720 (let ((buf (current-buffer)))
721 (set-buffer "*ps run*")
722 (ps-run-newline)
723 (set-buffer buf)))
724
725 \f
726 ;; Print PostScript.
727
728 (defun ps-mode-print-buffer ()
729 "Print buffer as PostScript."
730 (interactive)
731 (funcall ps-mode-print-function))
732
733 (defun ps-mode-print-region (begin end)
734 "Print region as PostScript, adding minimal header and footer lines:
735
736 %!PS
737 <region>
738 showpage"
739 (interactive "r")
740 (let ((buf (current-buffer)))
741 (with-temp-buffer
742 (insert "%!PS\n")
743 (insert-buffer-substring buf begin end)
744 (insert "\nshowpage\n")
745 (funcall ps-mode-print-function))))
746
747 \f
748 ;; Comment Out / Uncomment.
749
750 (defun ps-mode-comment-out-region (begin end)
751 "Comment out region."
752 (interactive "r")
753 (let ((endm (make-marker)))
754 (set-marker endm end)
755 (save-excursion
756 (goto-char begin)
757 (if (= (current-column) 0)
758 (insert "%"))
759 (while (and (= (forward-line) 0)
760 (< (point) (marker-position endm)))
761 (insert "%")))
762 (set-marker endm nil)))
763
764 (defun ps-mode-uncomment-region (begin end)
765 "Uncomment region.
766
767 Only one `%' is removed, and it has to be in the first column."
768 (interactive "r")
769 (let ((endm (make-marker)))
770 (set-marker endm end)
771 (save-excursion
772 (goto-char begin)
773 (if (looking-at "^%")
774 (delete-char 1))
775 (while (and (= (forward-line) 0)
776 (< (point) (marker-position endm)))
777 (if (looking-at "%")
778 (delete-char 1))))
779 (set-marker endm nil)))
780
781 \f
782 ;; Convert 8-bit to octal codes.
783
784 (defun ps-mode-octal-buffer ()
785 "Change 8-bit characters to octal codes in buffer."
786 (interactive)
787 (ps-mode-octal-region (point-min) (point-max)))
788
789 (defun ps-mode-octal-region (begin end)
790 "Change 8-bit characters to octal codes in region."
791 (interactive "r")
792 (if buffer-read-only
793 (progn
794 (ding)
795 (message "Buffer is read only"))
796 (save-excursion
797 (let (endm i)
798 (setq endm (make-marker))
799 (set-marker endm end)
800 (goto-char begin)
801 (setq i 0)
802 (while (re-search-forward "[\200-\377]" (marker-position endm) t)
803 (setq i (1+ i))
804 (backward-char)
805 (insert (format "\\%03o" (string-to-char (buffer-substring (point) (1+ (point))))))
806 (delete-char 1))
807 (message "%d change%s made" i (if (= i 1) "" "s"))
808 (set-marker endm nil)))))
809
810 \f
811 ;; Cookbook.
812
813 (defun ps-mode-center ()
814 "Insert function /center."
815 (interactive)
816 (insert "
817 /center {
818 dup stringwidth
819 exch 2 div neg
820 exch 2 div neg
821 rmoveto
822 } bind def
823 "))
824
825 (defun ps-mode-right ()
826 "Insert function /right."
827 (interactive)
828 (insert "
829 /right {
830 dup stringwidth
831 exch neg
832 exch neg
833 rmoveto
834 } bind def
835 "))
836
837 (defun ps-mode-RE ()
838 "Insert function /RE."
839 (interactive)
840 (insert "
841 % `new-font-name' `encoding-vector' `old-font-name' RE -
842 /RE {
843 findfont
844 dup maxlength dict begin {
845 1 index /FID ne { def } { pop pop } ifelse
846 } forall
847 /Encoding exch def
848 dup /FontName exch def
849 currentdict end definefont pop
850 } bind def
851 "))
852
853 (defun ps-mode-latin-extended ()
854 "Insert array /ISOLatin1Extended.
855
856 This encoding vector contains all the entries from ISOLatin1Encoding
857 plus the usually uncoded characters inserted on positions 1 through 28."
858 (interactive)
859 (insert "
860 % ISOLatin1Encoding, extended with remaining uncoded glyphs
861 /ISOLatin1Extended [
862 /.notdef /Lslash /lslash /OE /oe /Scaron /scaron /Zcaron /zcaron
863 /Ydieresis /trademark /bullet /dagger /daggerdbl /ellipsis /emdash
864 /endash /fi /fl /florin /fraction /guilsinglleft /guilsinglright
865 /perthousand /quotedblbase /quotedblleft /quotedblright
866 /quotesinglbase /quotesingle /.notdef /.notdef /.notdef /space
867 /exclam /quotedbl /numbersign /dollar /percent /ampersand
868 /quoteright /parenleft /parenright /asterisk /plus /comma /minus
869 /period /slash /zero /one /two /three /four /five /six /seven /eight
870 /nine /colon /semicolon /less /equal /greater /question /at /A /B /C
871 /D /E /F /G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z
872 /bracketleft /backslash /bracketright /asciicircum /underscore
873 /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s
874 /t /u /v /w /x /y /z /braceleft /bar /braceright /asciitilde
875 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
876 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
877 /.notdef /.notdef /.notdef /dotlessi /grave /acute /circumflex
878 /tilde /macron /breve /dotaccent /dieresis /.notdef /ring /cedilla
879 /.notdef /hungarumlaut /ogonek /caron /space /exclamdown /cent
880 /sterling /currency /yen /brokenbar /section /dieresis /copyright
881 /ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron
882 /degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph
883 /periodcentered /cedilla /onesuperior /ordmasculine /guillemotright
884 /onequarter /onehalf /threequarters /questiondown /Agrave /Aacute
885 /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute
886 /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth
887 /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply
888 /Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn
889 /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring
890 /ae /ccedilla /egrave /eacute /ecircumflex /edieresis /igrave
891 /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute
892 /ocircumflex /otilde /odieresis /divide /oslash /ugrave /uacute
893 /ucircumflex /udieresis /yacute /thorn /ydieresis
894 ] def
895 "))
896
897 (defun ps-mode-heapsort ()
898 "Insert function /Heapsort."
899 (interactive)
900 (insert "
901 % `array-element' Heapsort-cvi-or-cvr-or-cvs `number-or-string'
902 /Heapsort-cvi-or-cvr-or-cvs {
903 % 0 get
904 } bind def
905 % `array' Heapsort `sorted-array'
906 /Heapsort {
907 dup length /hsR exch def
908 /hsL hsR 2 idiv 1 add def
909 {
910 hsR 2 lt { exit } if
911 hsL 1 gt {
912 /hsL hsL 1 sub def
913 } {
914 /hsR hsR 1 sub def
915 dup dup dup 0 get exch dup hsR get
916 0 exch put
917 hsR exch put
918 } ifelse
919 dup hsL 1 sub get /hsT exch def
920 /hsJ hsL def
921 {
922 /hsS hsJ def
923 /hsJ hsJ dup add def
924 hsJ hsR gt { exit } if
925 hsJ hsR lt {
926 dup dup hsJ 1 sub get Heapsort-cvi-or-cvr-or-cvs
927 exch hsJ get Heapsort-cvi-or-cvr-or-cvs
928 lt { /hsJ hsJ 1 add def } if
929 } if
930 dup hsJ 1 sub get Heapsort-cvi-or-cvr-or-cvs
931 hsT Heapsort-cvi-or-cvr-or-cvs
932 le { exit } if
933 dup dup hsS 1 sub exch hsJ 1 sub get put
934 } loop
935 dup hsS 1 sub hsT put
936 } loop
937 } bind def
938 "))
939
940 \f
941 ;; EPSF document lay-out.
942
943 (defun ps-mode-epsf-sparse ()
944 "Insert sparse EPSF template."
945 (interactive)
946 (goto-char (point-max))
947 (unless (re-search-backward "%%EOF[ \t\n]*\\'" nil t)
948 (goto-char (point-max))
949 (insert "\n%%EOF\n"))
950 (goto-char (point-max))
951 (unless (re-search-backward "\\bshowpage[ \t\n]+%%EOF[ \t\n]*\\'" nil t)
952 (re-search-backward "%%EOF")
953 (insert "showpage\n"))
954 (goto-char (point-max))
955 (unless (re-search-backward "\\bend[ \t\n]+\\bshowpage[ \t\n]+%%EOF[ \t\n]*\\'" nil t)
956 (re-search-backward "showpage")
957 (insert "\nend\n"))
958 (goto-char (point-min))
959 (insert "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 ")
960 (insert (format "%d %d\n\n"
961 (car ps-mode-paper-size)
962 (car (cdr ps-mode-paper-size))))
963 (insert "64 dict begin\n\n"))
964
965 (defun ps-mode-epsf-rich ()
966 "Insert rich EPSF template."
967 (interactive)
968 (ps-mode-epsf-sparse)
969 (forward-line -3)
970 (when buffer-file-name
971 (insert "%%Title: " (file-name-nondirectory buffer-file-name) "\n"))
972 (insert "%%Creator: " (user-full-name) "\n")
973 (insert "%%CreationDate: " (current-time-string) "\n")
974 (insert "%%EndComments\n")
975 (forward-line 3))
976
977 \f
978 ;; Interactive PostScript interpreter.
979
980 (define-derived-mode ps-run-mode fundamental-mode "Interactive PS"
981 "Major mode in interactive PostScript window.
982 This mode is invoked from `ps-mode' and should not be called directly.
983
984 \\{ps-run-mode-map}"
985 (set (make-local-variable 'font-lock-defaults)
986 '((ps-run-font-lock-keywords
987 ps-run-font-lock-keywords-1
988 ps-run-font-lock-keywords-2)
989 t))
990 (setq mode-line-process '(":%s")))
991
992 (defun ps-run-running ()
993 "Error if not in `ps-mode' or not running PostScript."
994 (unless (equal major-mode 'ps-mode)
995 (error "This function can only be called from PostScript mode"))
996 (unless (equal (process-status "ps-run") 'run)
997 (error "No PostScript process running")))
998
999 (defun ps-run-start ()
1000 "Start interactive PostScript."
1001 (interactive)
1002 (let ((command (or (and window-system ps-run-x) ps-run-dumb))
1003 (init-file nil)
1004 (process-connection-type nil)
1005 (oldwin (selected-window)))
1006 (unless command
1007 (error "No command specified to run interactive PostScript"))
1008 (unless (and ps-run-mark (markerp ps-run-mark))
1009 (setq ps-run-mark (make-marker)))
1010 (when ps-run-init
1011 (setq init-file (ps-run-make-tmp-filename))
1012 (write-region (concat ps-run-init "\n") 0 init-file)
1013 (setq init-file (list init-file)))
1014 (pop-to-buffer "*ps run*")
1015 (ps-run-mode)
1016 (when (process-status "ps-run")
1017 (delete-process "ps-run"))
1018 (erase-buffer)
1019 (setq command (append command init-file))
1020 (insert (mapconcat 'identity command " ") "\n")
1021 (apply 'start-process "ps-run" "*ps run*" command)
1022 (select-window oldwin)))
1023
1024 (defun ps-run-quit ()
1025 "Quit interactive PostScript."
1026 (interactive)
1027 (ps-run-send-string "quit" t)
1028 (ps-run-cleanup))
1029
1030 (defun ps-run-kill ()
1031 "Kill interactive PostScript."
1032 (interactive)
1033 (delete-process "ps-run")
1034 (ps-run-cleanup))
1035
1036 (defun ps-run-clear ()
1037 "Clear/reset PostScript graphics."
1038 (interactive)
1039 (ps-run-send-string "showpage" t)
1040 (sit-for 1)
1041 (ps-run-send-string "" t))
1042
1043 (defun ps-run-buffer ()
1044 "Send buffer to PostScript interpreter."
1045 (interactive)
1046 (ps-run-region (point-min) (point-max)))
1047
1048 (defun ps-run-region (begin end)
1049 "Send region to PostScript interpreter."
1050 (interactive "r")
1051 (ps-run-running)
1052 (setq ps-run-parent (buffer-name))
1053 (let ((f (ps-run-make-tmp-filename)))
1054 (set-marker ps-run-mark begin)
1055 (write-region begin end f)
1056 (ps-run-send-string (format "(%s) run" f) t)))
1057
1058 (defun ps-run-boundingbox ()
1059 "View BoundingBox."
1060 (interactive)
1061 (ps-run-running)
1062 (let (x1 y1 x2 y2 f
1063 (buf (current-buffer)))
1064 (save-excursion
1065 (goto-char 1)
1066 (re-search-forward
1067 "^%%BoundingBox:[ \t]+\\(-?[0-9]+\\)[ \t]+\\(-?[0-9]+\\)[ \t]+\\(-?[0-9]+\\)[ \t]+\\(-?[0-9]+\\)")
1068 (setq x1 (match-string 1)
1069 y1 (match-string 2)
1070 x2 (match-string 3)
1071 y2 (match-string 4)))
1072 (unless (< (string-to-number x1) (string-to-number x2))
1073 (error "x1 (%s) should be less than x2 (%s)" x1 x2))
1074 (unless (< (string-to-number y1) (string-to-number y2))
1075 (error "y1 (%s) should be less than y2 (%s)" y1 y2))
1076 (setq f (ps-run-make-tmp-filename))
1077 (write-region
1078 (format
1079 "gsave
1080 initgraphics
1081 2 setlinewidth
1082 %s %s moveto
1083 %s %s lineto
1084 %s %s lineto
1085 %s %s lineto
1086 closepath
1087 gsave
1088 [ 4 20 ] 0 setdash
1089 1 0 0 setrgbcolor
1090 stroke
1091 grestore
1092 gsave
1093 [ 4 20 ] 8 setdash
1094 0 1 0 setrgbcolor
1095 stroke
1096 grestore
1097 [ 4 20 ] 16 setdash
1098 0 0 1 setrgbcolor
1099 stroke
1100 grestore
1101 " x1 y1 x2 y1 x2 y2 x1 y2)
1102 0
1103 f)
1104 (ps-run-send-string (format "(%s) run" f) t)
1105 (set-buffer buf)))
1106
1107 (defun ps-run-send-string (string &optional echo)
1108 (let ((oldwin (selected-window)))
1109 (pop-to-buffer "*ps run*")
1110 (goto-char (point-max))
1111 (when echo
1112 (insert string "\n"))
1113 (set-marker (process-mark (get-process "ps-run")) (point))
1114 (process-send-string "ps-run" (concat string "\n"))
1115 (select-window oldwin)))
1116
1117 (defun ps-run-make-tmp-filename ()
1118 (unless ps-mode-tmp-file
1119 (cond (ps-run-tmp-dir)
1120 ((setq ps-run-tmp-dir (getenv "TEMP")))
1121 ((setq ps-run-tmp-dir (getenv "TMP")))
1122 ((setq ps-run-tmp-dir (getenv "HOME"))
1123 (setq
1124 ps-run-tmp-dir
1125 (concat (file-name-as-directory ps-run-tmp-dir) "tmp"))
1126 (unless (file-directory-p ps-run-tmp-dir)
1127 (setq ps-run-tmp-dir nil))))
1128 (unless ps-run-tmp-dir
1129 (setq ps-run-tmp-dir "/tmp"))
1130 (setq ps-mode-tmp-file
1131 (make-temp-file
1132 (concat
1133 (if ps-run-tmp-dir
1134 (file-name-as-directory ps-run-tmp-dir)
1135 "")
1136 "ps-run-"))))
1137 ps-mode-tmp-file)
1138
1139 ;; Remove temporary file
1140 ;; This shouldn't fail twice, because it is called at kill-emacs
1141 (defun ps-run-cleanup ()
1142 (when ps-mode-tmp-file
1143 (let ((i ps-mode-tmp-file))
1144 (setq ps-mode-tmp-file nil)
1145 (when (file-exists-p i)
1146 (delete-file i)))))
1147
1148 (defun ps-run-mouse-goto-error (event)
1149 "Set point at mouse click, then call `ps-run-goto-error'."
1150 (interactive "e")
1151 (mouse-set-point event)
1152 (ps-run-goto-error))
1153
1154 (defun ps-run-newline ()
1155 "Process newline in PostScript interpreter window."
1156 (interactive)
1157 (end-of-line)
1158 (insert "\n")
1159 (forward-line -1)
1160 (when (looking-at ps-run-prompt)
1161 (goto-char (match-end 0)))
1162 (looking-at ".*")
1163 (goto-char (1+ (match-end 0)))
1164 (ps-run-send-string (buffer-substring (match-beginning 0) (match-end 0))))
1165
1166 (defun ps-run-goto-error ()
1167 "Jump to buffer position read as integer at point.
1168 Use line numbers if `ps-run-error-line-numbers' is not nil"
1169 (interactive)
1170 (let ((p (point)))
1171 (unless (looking-at "[0-9]")
1172 (goto-char (max 1 (1- (point)))))
1173 (when (looking-at "[0-9]")
1174 (forward-char 1)
1175 (forward-word -1)
1176 (when (looking-at "[0-9]+")
1177 (let (i)
1178 (setq
1179 i
1180 (string-to-number
1181 (buffer-substring (match-beginning 0) (match-end 0))))
1182 (goto-char p)
1183 (pop-to-buffer ps-run-parent)
1184 (if ps-run-error-line-numbers
1185 (progn
1186 (goto-char (marker-position ps-run-mark))
1187 (forward-line (1- i))
1188 (end-of-line))
1189 (goto-char (+ i (marker-position ps-run-mark)))))))))
1190
1191 \f
1192 ;;
1193 (add-hook 'kill-emacs-hook 'ps-run-cleanup)
1194
1195 (provide 'ps-mode)
1196
1197 ;;; arch-tag: dce13d2d-69fb-4ec4-9d5d-6dd29c3f0e6e
1198 ;;; ps-mode.el ends here