ps-mode.el 36 KB

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