Recent Posts
None | 24 sec ago
None | 2 min ago
HTML | 3 min ago
None | 3 min ago
None | 4 min ago
None | 6 min ago
ASM (NASM) | 7 min ago
ASM (NASM) | 8 min ago
PHP | 8 min ago
Bash | 10 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Marco Pessotto on the 7th of Feb 2008 06:49:57 PM Download | Raw | Embed | Report
  1. ;;; pov-mode.el --- major mode for Povray scene files
  2. ;;
  3. ;; Author: Peter Boettcher <pwb@andrew.cmu.edu>
  4. ;; Maintainer: Peter Toneby <woormie@acc.umu.se>
  5. ;; Created: 04 March 1994
  6. ;; Modified: 05 Feb 2008
  7. ;; Version: 2.10-pl1
  8. ;; Keywords: pov, povray
  9. ;;
  10. ;; Modified by: Marco Pessotto <marco.erika@gmail.com>
  11. ;; 1/5/2008
  12. ;; Workaround for Emacs 22
  13. ;; Peter Toneby no more maintains pov-mode :-(
  14. ;;
  15. ;; LCD Archive Entry:
  16. ;; povray|Peter Toneby|woormie@acc.umu.se|
  17. ;; Major mode for Povray scene files|
  18. ;; 08-Sep-2003|2.10|~/lib/emacs/pov-mode.el|
  19. ;;
  20. ;; Copyright (C) 1997 Peter W. Boettcher
  21. ;;
  22. ;; This program is free software; you can redistribute it and/or modify
  23. ;; it under the terms of the GNU General Public License as published by
  24. ;; the Free Software Foundation; either version 2, or (at your option)
  25. ;; any later version.
  26. ;; This program is distributed in the hope that it will be useful,
  27. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29. ;; GNU General Public License for more details.
  30. ;;
  31. ;; You should have received a copy of the GNU General Public License
  32. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  33. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  34. ;;
  35. ;;; Commentary:
  36. ;;
  37. ;; This major mode for GNU Emacs provides support for editing Povray
  38. ;; scene files, rendering and viewing them.  It automatically indents
  39. ;; blocks, both {} and #if #end.  It also provides context-sensitive
  40. ;; keyword completion and font-lock highlighting, as well as the
  41. ;; ability to look up those keywords in the povray docu.
  42. ;;
  43. ;; It should work for either Xemacs or FSF Emacs, versions >= 20;
  44. ;; however, only Xemacs can display pictures.
  45. ;;
  46. ;; To automatically load pov-mode every time Emacs starts up, put the
  47. ;; following line into your .emacs file:
  48. ;;
  49. ;;      (require 'pov-mode)
  50. ;;
  51. ;; Of course pov-mode has to be somewhere in your load-path for emacs
  52. ;; to find it (Use C-h v load-path to see which directories are in the
  53. ;; load-path).
  54. ;;
  55. ;; NOTE: To achieve any sort of reasonable performance, YOU MUST
  56. ;;   byte-compile this package.  In emacs, type M-x byte-compile
  57. ;;   and then enter the name of this file.
  58. ;;
  59. ;; You can customize the behaviour of pov-mode and via the
  60. ;; customization menu or by simply entering M-x customize-group pov.
  61. ;; In many or even most cases, however, it should be completely
  62. ;; sufficient to to rely on the default settings.
  63. ;;
  64. ;; To learn about the basics, just load a pov-file and press C-h m.
  65. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  66.  
  67. ;;
  68. ;;Modified by: Peter Boettcher <pwb@andrew.cmu.edu>
  69. ;;  5/8/97:
  70. ;;    Added font-lock support for Emacs/XEmacs 19
  71. ;;    Indent under `#declare Object=' lines
  72. ;;    Corrected comment syntax
  73. ;;    Got rid of more remnants from postscript mode
  74. ;;    General cleanup
  75. ;;    Arbitrarily chose version 1.2
  76. ;; 5/8/97:  Version 1.21
  77. ;;    fontify-insanely was ignored.  fixed.
  78. ;;
  79. ;; 9/24/97: Version 1.3
  80. ;;    Added indentation for Pov 3 syntax (#if #else, etc)
  81. ;;    Preliminary context-sensitive keyword completion
  82. ;;
  83. ;; 1/13/98 by Peter Boettcher <pwb@andrew.cmu.edu>
  84. ;;    Explicitly placed package under GPL
  85. ;;    Reorganized comment sections and change log to follow GNU standards
  86. ;;    Added simple code for jumping to pov documentation (Thanks to
  87. ;;         Benjamin Strautin <bis@acpub.duke.edu> for this code)
  88. ;;
  89. ;; Modified by: Peter Toneby <woormie@acc.umu.se>
  90. ;;  22/3/99: Version 1.99beata1
  91. ;;    Added support for Pov3.1s new keywords. (not all, I think...)
  92. ;;    Removed atmosphere (and atmosphere_*) (stupid me...)
  93. ;;
  94. ;; Modified by: Peter Toneby <woormie@acc.umu.se>
  95. ;;  23/4/99: Version 1.99beata2
  96. ;;    Added support for all new keyword, BUT
  97. ;;    Added atmosphere (and atmosphere_*) again
  98. ;;    Got Pete Boettchers blessing to continue (but with a note
  99. ;;      that said that I should have talked to him first, I'm sorry
  100. ;;      for not doing that). Pete also said he was willing to let
  101. ;;      me continue the maintainance of this file.
  102. ;;    I can't get the pov-keyword-help to work, anyone with knowledge
  103. ;;      about elisp can send me a fix for it.
  104. ;;    The keyword expansion doesn't work for all keywords,
  105. ;;      I need to add lots of stuff and read through the docs
  106. ;;      to get everything correct.
  107. ;;
  108. ;; Modified by: Alexander Schmolck <aschmolck@gmx.de>
  109. ;; 2000-01-31: Version 2beataXXX
  110. ;;    Added working keyword lookup in povuser.txt
  111. ;;    Added rendering and viewing from within Emacs and with an external viewer
  112. ;;    Added customization and made installation simpler
  113. ;;    Added a few other minor details
  114. ;;
  115. ;; Modified by: Peter Toneby <woormie@acc.umu.se>
  116. ;; 2000-05-24: Version 2
  117. ;;    Changed the keyword lookup a little, povuser.txt didn't open as
  118. ;;       expected when having set the pov-home-dir and pov-help-file
  119. ;;       manually.
  120. ;;
  121. ;; Modified by: Peter Toneby <woormie@acc.umu.se>
  122. ;; 2000-08-10: Version 2.5b1
  123. ;;    Added povray-font-lock-faces.
  124. ;;    Made sure font-lock works properly on:
  125. ;;        XEmacs 19.15p7
  126. ;;        XEmacs 20.0
  127. ;;        XEmacs 21.1p10
  128. ;;        Emacs 19.29.1
  129. ;;        Emacs 20.7.2
  130. ;;    Added all 3.1 keywords except track, since I don't know what it
  131. ;;        is, I have also dropped the 3.0 specific keywords that
  132. ;;        shouldn't be used anymore.
  133. ;;    Fixed some completion stuff, I think I have added all keywords to
  134. ;;        the completions.
  135. ;;    Added configureation for all faces. To bad I can't get the defaults
  136. ;;        to work properly on dark backgrounds, I don't know why that is.
  137. ;;    Added a toolbar, it replaces to standard XEmacs toolbar, I think
  138. ;;        that is the best thing to do, but I retain the standard useful
  139. ;;        functionality.
  140. ;;    Fixed an error in the external viewer, it used variables that were
  141. ;;        not available in the same scope as the sentinel.
  142. ;;    Added basic imenu support, currently only #local and #declare,
  143. ;;        but I will try to add objects, cameras and lightsources later.
  144. ;; 2000-09-12 Version 2.5.b2
  145. ;;    Added basic support for megapov
  146. ;;    Bob Pepin fixed a bug in test to select external/internal viewer.
  147. ;;    fortsätt på kapitel 5.6
  148. ;; 2001-04-05 Version 2.6
  149. ;;    Added the capability to open standard include files by pressing
  150. ;;        C-c i. It opens the file entered ro.
  151. ;;    Fixed leeking color in emacs (Robert Kleemann)
  152. ;;    Changed the rendertoolbarbutton to show a popup dialog with buttons
  153. ;;        for the different qualities.
  154. ;; 2001-12-07 Version 2.7
  155. ;;    Fixed font-locks for Emacs 21
  156. ;; 2002-06-19 Version 2.8
  157. ;;    Fixed loading for Emacs 21-2, missed a test for customizations
  158. ;;    Added most parts of a patch from  Christoph Hormann that cleaned
  159. ;;        up the Regexp mess, and added all (or at least most) of the
  160. ;;        keywords for 3.5 Parts of that patch are still missing, I'll
  161. ;;        get around to those sometime...
  162. ;; 2002-08-07 Version 2.9
  163. ;;    Added Insert menu, it uses the directory structure of the winpov
  164. ;;        insert menu.
  165. ;;    Moved the toolbar icons out to separate xpm-files.
  166. ;;    Added some missing keyword expansions
  167. ;;    Fixed so that box, cylinder... has their own face, object-face,
  168. ;;        removed unused faces
  169. ;;    Cleaned up the code, removed unused stuff.
  170. ;;    It works in versions 21, can't test in 20, font-lock is borked for me.
  171. ;; 2002-08-10 Version 2.9.1
  172. ;;    Fixed so that tollbar icons are searched for, not hard coded.
  173. ;; 2003-08-29 Version 2.10
  174. ;;    Fixed references to povray.el.
  175. ;;    Fixed cut-n-pasted comment for font-pov-operator-face.
  176. ;;    Fixed the insert menus, they missed the last items, thanks to Hartwig
  177. ;;        Bosse for the heads up, and a fix.
  178. ;; 2003-08-29 Version 2.11 (This is a future version)
  179. ;;    Fix a bug with rendering so that the active buffer is changed to the
  180. ;;        correct buffer, found by Hartwig Bosse.
  181. ;;
  182. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  183. ;;
  184. ;; Original Author:     Kevin O. Grover <grover@isri.unlv.edu>
  185. ;;        Cre Date:     04 March 1994
  186. ;; This file derived from postscript mode by Chris Maio
  187. ;;
  188. ;;  Please send bug reports/comments/suggestions to Peter Toneby
  189. ;;        woormie@acc.umu.se
  190. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  191. ;;
  192. ;; TODO list:
  193. ;; * Vector operations (add <0, .5, 1> to every vector in region)
  194. ;; * Clean up completion code
  195. ;; * TAGS, to jump to #declared objects elsewhere in the code
  196. ;; * c-mode like electric parens (?)
  197. ;; * clean up viewing and rendering code
  198. ;; * should render or view be decided on filedates? If so, what
  199. ;;     image file-name extensions should be checked?
  200. ;;     I think PNG is default for UNIX, not sure.
  201. ;;     I could make this a customizeation option.
  202. ;; * imenu support
  203. ;;     started, but needs to be fixed so it handles nested menus.
  204. ;; * Make sure the scopes are correct
  205. ;; * Make hooks for menus, so they are userselectable
  206. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  207.  
  208. ;; Better safe than sorry, lets fail if you are using a (very?) old
  209. ;; version of (X)Emacs.
  210. (if (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version)))
  211.         (and (= emacs-major-version 19) (< emacs-minor-version 14))
  212.       (and (= emacs-major-version 19) (< emacs-minor-version 29)))
  213.     (error "`font-pov' was written for Emacs 19.29/XEmacs 19.14 or later"))
  214.  
  215. (defvar font-pov-is-XEmacs19
  216.   (and (not (null (save-match-data
  217.                     (string-match "XEmacs\\|Lucid" emacs-version))))
  218.        (= 19 emacs-major-version)))
  219. (defvar font-pov-is-XEmacs20
  220.   (and (not (null (save-match-data
  221.                     (string-match "XEmacs\\|Lucid" emacs-version))))
  222.        (<= 20 emacs-major-version)))
  223. (defvar font-pov-is-XEmacs21
  224.   (and (not (null (save-match-data
  225.                     (string-match "XEmacs\\|Lucid" emacs-version))))
  226.        (<= 21 emacs-major-version)))
  227.  
  228. (defvar font-pov-is-XEmacs20-2
  229.   (or (and font-pov-is-XEmacs20 (<= 2 emacs-minor-version))
  230.       font-pov-is-XEmacs21))
  231.  
  232. (defvar font-pov-is-Emacs19
  233.   (and (not font-pov-is-XEmacs19)
  234.        (not font-pov-is-XEmacs20)
  235.        (= 19 emacs-major-version)))
  236. (defvar font-pov-is-Emacs20
  237.   (and (not font-pov-is-XEmacs19)
  238.        (not font-pov-is-XEmacs20)
  239.        (= 20 emacs-major-version)))
  240. (defvar font-pov-is-Emacs21
  241.   (and (not font-pov-is-XEmacs19)
  242.        (not font-pov-is-XEmacs20)
  243.        (not font-pov-is-XEmacs21)
  244.        (= 21 emacs-major-version)))
  245. (defvar font-pov-is-Emacs22
  246.   (and (not font-pov-is-XEmacs19)
  247.        (not font-pov-is-XEmacs20)
  248.        (not font-pov-is-XEmacs21)
  249.        (= 22 emacs-major-version)))
  250.  
  251. (defvar font-pov-is-Emacs
  252.   (or font-pov-is-Emacs19
  253.       font-pov-is-Emacs20
  254.       font-pov-is-Emacs21
  255.       font-pov-is-Emacs22))
  256.  
  257.  
  258. (require 'cl)
  259. (require 'font-lock) ;;[TODO] Not nice to reqire it, the user should
  260.                      ;;       have a choise...
  261.  
  262. (defconst pov-mode-version '2.10
  263.   "The povray mode version.")
  264.  
  265. (defvar pov-tab-width 8)
  266. (defvar pov-autoindent-endblocks t)
  267.  
  268. ;;Create fontfaces
  269. (defvar font-pov-number-face 'font-pov-number-face
  270.   "Face to use for PoV numbers.")
  271.  
  272. (defvar font-pov-variable-face 'font-pov-variable-face
  273.   "Face to use for PoV variables.")
  274.  
  275. (defvar font-pov-directive-face 'font-pov-directive-face
  276.   "Face to use for PoV directives.")
  277.  
  278. (defvar font-pov-object-face 'font-pov-object-face
  279.   "Face to use for PoV objects.")
  280.  
  281. ;(defvar font-pov-object-modifier-face 'font-pov-object-modifier-face
  282. ;  "Face to use for PoV objects.")
  283.  
  284. ;(defvar font-pov-texture-face 'font-pov-texture-face
  285. ;  "Face to use for PoV objects.")
  286.  
  287. (defvar font-pov-operator-face 'font-pov-operator-face
  288.   "Face to use for PoV operators.")
  289.  
  290. (defvar font-pov-csg-face 'font-pov-csg-face
  291.   "Face to use for PoV csg keywords.")
  292.  
  293. ;(defvar font-pov-string-face nil
  294. ;  "Face to use for strings.  This is set by font-PoV.")
  295.  
  296. (defvar font-pov-macro-name-face nil
  297.   "Face to use for strings.  This is set by font-PoV.")
  298.  
  299. (defvar font-pov-keyword-face nil
  300.   "Face to use for misc keywords.  This is set by font-PoV.")
  301.  
  302. (defvar pov-insertmenu-location nil
  303.   "Location of the InsertMenu directory structure.")
  304.  
  305. (defvar pov-icons-location nil
  306.   "Location of the menubaricons.")
  307.  
  308. ; Seems like Emacs lacks these functions (locate-data-[directory|file])...
  309. (unless (fboundp 'locate-data-directory)
  310.   (defun locate-data-directory (name &optional dirs)
  311.     (if dirs
  312.         (if (file-directory-p (expand-file-name name (car dirs)))
  313.             (expand-file-name name (car dirs))
  314.           (locate-data-directory name (cdr dirs)))
  315.       (expand-file-name name data-directory))))
  316.  
  317. (unless (fboundp 'locate-data-file)
  318.   (defun locate-data-file (name &optional dirs)
  319.     (print dirs)
  320.     (if dirs
  321.         (if (file-regular-p (expand-file-name name (car dirs)))
  322.             (expand-file-name name (car dirs))
  323.           (locate-data-file name (cdr dirs)))
  324.       (expand-file-name name data-directory))))
  325.  
  326. ;; This is because FSFEmacs has a ridiculusly low max-lisp-eval-depth
  327. (when (> 1000 max-lisp-eval-depth)
  328.   (customize-set-value 'max-lisp-eval-depth 1000))
  329.  
  330. ;; Yup XEmacs didn't get cutomizations until 20.2.
  331. (cond ((or font-pov-is-XEmacs20-2 (or font-pov-is-Emacs20 font-pov-is-Emacs21 font-pov-is-Emacs22))
  332.       (defgroup  pov nil
  333.         "*Major mode for editing povray 3.X scence files <http://www.povray.org>."
  334.         :group 'languages)
  335.  
  336.       (defcustom povray-command "povray"
  337.         "*Command used to invoke the povray."
  338.         :type 'string
  339.         :group 'pov)
  340.  
  341.       (defcustom pov-external-viewer-command "xv"
  342.         "*The external viewer to call."
  343.         :type 'string
  344.         :group 'pov)
  345.  
  346.       (defcustom pov-external-view-options "%s"
  347.         "*The options for the viewer; %s is replaced with the name of the rendered image."
  348.         :type 'string
  349.         :group 'pov)
  350.  
  351.       ;;allow user to customize external or internal viewer as defaults if she
  352.       ;;is using Xemacs; for FSF Emacs assume external, since it can't
  353.       ;;handle pictures anyway
  354.       ;(if  (and (boundp 'running-xemacs) running-xemacs)
  355.       (defcustom pov-default-view-internal t
  356.         "*Should the pictures be displayed internally by default?"
  357.         :type 'boolean
  358.         :group 'pov)
  359.       ;(defvar pov-default-view-internal nil))
  360.  
  361.       (defcustom pov-run-default "+i%s"
  362.         "*The default options for the Render command (%s is replaced by the filename)."
  363.         :type 'string
  364.         :group 'pov
  365.         )
  366.       (defcustom pov-run-test "res120 -Q3 +i%s"
  367.         "*The default options for the Test Render command (%s is replaced by the filename)."
  368.         :type 'string
  369.         :group 'pov
  370.         )
  371.       (defcustom pov-run-low "res320 +i%s"
  372.         "*The default options for the Test Render command (%s is replaced by the filename)."
  373.         :type 'string
  374.         :group 'pov
  375.         )
  376.       (defcustom pov-run-mid "res640 +i%s"
  377.         "*The default options for the Medium Res Render command (%s is replaced by the filename)."
  378.         :type 'string
  379.         :group 'pov
  380.         )
  381.       (defcustom pov-run-high "res800 +i%s"
  382.         "*The default options for the High Res Render command (%s is replaced by the filename)."
  383.         :type 'string
  384.         :group 'pov
  385.         )
  386.       (defcustom pov-run-highest "res1k +i%s"
  387.         "*The default options for the Higest Res Render command (%s is replaced by the filename)."
  388.         :type 'string
  389.         :group 'pov
  390.         )
  391.       (defvar pov-external-view
  392.         "External view")
  393.       (defvar pov-internal-view
  394.         "Internal view")
  395.       (defvar pov-command-alist (list (list "Render"
  396.                                             povray-command pov-run-default
  397.                                             '()) ;history for the command
  398.                                       (list "Test quality render"
  399.                                             povray-command pov-run-test
  400.                                             '())
  401.                                       (list "Low quality render"
  402.                                             povray-command pov-run-low
  403.                                             '())
  404.                                       (list "Medium quality render"
  405.                                             povray-command pov-run-highest
  406.                                             '())
  407.                                       (list "High quality render"
  408.                                             povray-command pov-run-high
  409.                                             '())
  410.                                       (list pov-external-view
  411.                                             pov-external-viewer-command
  412.                                             pov-external-view-options
  413.                                             '())
  414.                                       (list pov-internal-view
  415.                                             (list pov-internal-view)
  416.                                             '()))
  417.         "the commands to run")
  418.  
  419.       (defcustom pov-home-dir "SHARELIBSPOVRAY"
  420.         "*The directory in which the povray files reside."
  421.         :type 'directory
  422.         :group 'pov)
  423.  
  424.       (defcustom pov-include-dir "SHARELIBSPOVRAY/include"
  425.         "*The directory in which the povray includefiles reside."
  426.         :type 'directory
  427.         :group 'pov)
  428.  
  429.       (defcustom pov-help-file "povuser.txt"
  430.         "*The name of the helpfile."
  431.         :type  'file
  432.         :group 'pov)
  433.  
  434.       (defcustom pov-associate-pov-and-inc-with-pov-mode-flag t
  435.         "*If t then files ending with .pov and .inc will automatically start
  436. pov-mode when loaded, unless those file-endings are already in use."
  437.         :type 'boolean
  438.         :group 'pov)
  439.  
  440.       (defcustom pov-fontify-insanely t
  441.         "*Non-nil means colorize every povray keyword.  This may take a while on large files.  Maybe disable this on slow systems."
  442.         :type 'boolean
  443.         :group 'pov)
  444.  
  445.       (defcustom pov-imenu-in-menu t
  446.         "*Non-nil means have #locals and #declares in a menu called PoV in the menubar. This may take a while on large files.  Maybe disable this on slow systems."
  447.         :type 'boolean
  448.         :group 'pov)
  449. ;; CH
  450.       (defcustom pov-imenu-only-macros t
  451.         "*Non-nil means to restrict imenu to macro declarations."
  452.         :type 'boolean
  453.         :group 'pov)
  454. ;; /end CH
  455.       (defcustom pov-indent-level 2
  456.         "*Indentation to be used inside of PoVray blocks or arrays."
  457.         :type 'integer
  458.         :group 'pov)
  459.  
  460.       (defcustom pov-autoindent-endblocks t
  461.         "*When non-nil, automatically reindents when you type break, end, or else."
  462.         :type 'boolean
  463.         :group 'pov
  464.         )
  465.  
  466.       (defcustom pov-indent-under-declare 2
  467.         "*Indentation under a `#declare Object=' line."
  468.         :type 'integer
  469.         :group 'pov)
  470.  
  471.       (defcustom pov-tab-width 8
  472.         "*Tab stop width for PoV mode."
  473.         :type 'integer
  474.         :group 'pov)
  475.  
  476.       (defcustom pov-turn-on-font-lock t
  477.         "*Turn on syntax highlighting automatically"
  478.         :type 'boolean
  479.         :group 'pov)
  480.  
  481.       (defcustom font-pov-csg-face t
  482.         "*What color does CSG-object have"
  483.         :type 'face
  484.         :group 'pov)
  485.  
  486.       (defcustom font-pov-object-face t
  487.         "*What color does objects have"
  488.         :type 'face
  489.         :group 'pov)
  490.  
  491.       (defcustom font-pov-variable-face t
  492.         "*What color does variables (in declarations) have"
  493.         :type 'face
  494.         :group 'pov)
  495.  
  496. ;      (defcustom font-pov-string-face t
  497. ;       "*What color does strings have"
  498. ;       :type 'face
  499. ;       :group 'pov)
  500.  
  501. ;      (defcustom font-pov-texture-face t
  502. ;       "*What color does textures have"
  503. ;       :type 'face
  504. ;       :group 'pov)
  505.  
  506. ;      (defcustom font-pov-object-modifier-face t
  507. ;       "*What color does object modifiers have"
  508. ;       :type 'face
  509. ;       :group 'pov)
  510.  
  511.       (defcustom font-pov-directive-face t
  512.         "*What color does (#)-directives have"
  513.         :type 'face
  514.         :group 'pov)
  515.  
  516.       (defcustom font-pov-number-face t
  517.         "*What color does numbers have"
  518.         :type 'face
  519.         :group 'pov)
  520.  
  521.       (defcustom font-pov-keyword-face t
  522.         "*What color does keywords have"
  523.         :type 'face
  524.         :group 'pov)
  525.       )
  526. )
  527.  
  528. ; Find where the menubar icons are placed, should be where pov-mode is...
  529. ;; (setq pov-icons-location
  530. ;;       (file-name-directory (locate-data-file "povrender.xpm"
  531. ;;                                           (cons (file-name-directory (locate-library "pov-mode"))
  532. ;;                                                 (if font-pov-is-Emacs data-directory data-directory-list)))))
  533.  
  534. ;;FIX ME
  535.  
  536. (setq pov-icons-location "EMACSLISPLIBRARY/povrender.xpm")
  537.  
  538.  
  539. ;; Lets play with the Toolbar, we want to add buttons for
  540. ;; rendering and showing images, lets place them on the rightmost
  541. ;; position of the toolbar.
  542. (cond ((or font-pov-is-XEmacs20 font-pov-is-XEmacs21)
  543.        (defvar toolbar-render-icon
  544.          (if (featurep 'xpm)
  545.              (let ((rendericon (concat pov-icons-location "povrender.xpm")))
  546.                (toolbar-make-button-list (make-image-instance (vector 'xpm :file rendericon))))
  547.          ))
  548.        (defvar toolbar-look-icon
  549.          (if (featurep 'xpm)
  550.              (let ((viewicon (concat pov-icons-location "povview.xpm")))
  551.                (toolbar-make-button-list (make-image-instance (vector 'xpm :file viewicon))))
  552.            ))
  553.        (defvar pov-toolbar
  554.          '(
  555.            [toolbar-file-icon    toolbar-open    t "Open a file"]
  556.            [toolbar-folder-icon  toolbar-dired   t "Edit a directory"]
  557.            [toolbar-disk-icon    toolbar-save    t "Save buffer"]
  558.            [toolbar-printer-icon toolbar-print   t "Print buffer"]
  559.            [toolbar-cut-icon     toolbar-cut     t "Kill region"]
  560.            [toolbar-copy-icon    toolbar-copy    t "Copy region"]
  561.            [toolbar-paste-icon   toolbar-paste   t "Paste from clipboard"]
  562.            [toolbar-undo-icon    toolbar-undo    t "Undo edit"]
  563.            [toolbar-spell-icon   toolbar-ispell  t "Check spelling"]
  564.            [toolbar-replace-icon toolbar-replace t "Search & Replace"]
  565.            nil
  566.            [toolbar-render-icon  (pov-render-dialog) t "Configured Render the file"]
  567. ;          [toolbar-render-icon
  568. ;           (pov-render-file "Render" (buffer-file-name) nil)
  569. ;           t "Quick Render the file"]
  570.            [toolbar-look-icon
  571.             (if pov-default-view-internal
  572.                 (pov-display-image-xemacs pov-image-file)
  573.               (pov-display-image-externally pov-image-file nil))
  574.             t "Show the rendered file"]
  575.            ))
  576.        (defvar pov-render-dialog-desc
  577.          '("Render Image"
  578.            ["Test render"   (pov-render-file "Test quality render"   (buffer-file-name) nil) t]
  579.            ["Low render"    (pov-render-file "Low quality render"    (buffer-file-name) nil) t]
  580.            ["Medium render" (pov-render-file "Medium quality render" (buffer-file-name) nil) t]
  581.            ["High render"   (pov-render-file "High quality render"   (buffer-file-name) nil) t]
  582.            ["Render"        (pov-render-file "Render"                (buffer-file-name) nil) t]
  583.            ["Cancel"        (pov-render-file "Render"                (buffer-file-name) nil) t]
  584.            ))
  585.        ))
  586.  
  587. (defun pov-toolbar ()
  588.   (interactive)
  589.   (set-specifier default-toolbar (cons (current-buffer) pov-toolbar)))
  590.  
  591. ;; Menubar stuff, buttonmenu will be nice to have too.
  592.  
  593.  
  594. ;; Abbrev support
  595. (defvar pov-mode-abbrev-table nil
  596.   "Abbrev table in use in pov-mode buffers.")
  597. (define-abbrev-table 'pov-mode-abbrev-table ())
  598.  
  599. (cond ((or font-pov-is-XEmacs20-2 font-pov-is-Emacs20)
  600.        (when pov-turn-on-font-lock
  601.          (turn-on-font-lock))
  602.        ;; associate *.pov and *.inc with pov if flag is set and no other
  603.        ;; modes already have
  604.        (cond (pov-associate-pov-and-inc-with-pov-mode-flag
  605.               (when (not (assoc "\\.pov\\'" auto-mode-alist))
  606.                 (setq auto-mode-alist
  607.                       (append '(("\\.pov\\'" . pov-mode)) auto-mode-alist)))
  608.               (when (not (assoc "\\.inc\\'" auto-mode-alist))
  609.                 (setq auto-mode-alist
  610.                       (append '(("\\.inc\\'" . pov-mode)) auto-mode-alist)))))
  611.        ))
  612.  
  613. ;;END AS
  614.  
  615. (defvar font-pov-do-multi-line t
  616.   "*Set this to nil to disable the multi-line fontification prone to infinite loop bugs.")
  617.  
  618. (defun font-pov-setup ()
  619.   "Setup this buffer for PoV font-lock."
  620.   (cond
  621.    ((or font-pov-is-Emacs20 font-pov-is-Emacs21 font-pov-is-Emacs22)
  622.     ;; Tell Font Lock about the support.
  623.     (make-local-variable 'font-lock-defaults))
  624.    ((or font-pov-is-XEmacs19 font-pov-is-XEmacs20)
  625.     ;; Cool patch from Christoph Wedler...
  626.     (let (instance)
  627.       (mapcar (function
  628.                (lambda (property)
  629.                  (setq instance
  630.                        (face-property-instance 'font-pov-number-face property nil 0 t))
  631.                  (if (numberp instance)
  632.                      (setq instance
  633.                            (face-property-instance 'default property nil 0)))
  634.                  ;(or (numberp instance)
  635.                  ;    (set-face-property 'font-lock-string-face property
  636.                 ;                       instance (current-buffer)))))
  637.                  ))
  638.               (built-in-face-specifiers))))
  639.    (font-pov-is-Emacs19
  640.     (make-local-variable 'font-lock-defaults))))
  641.  
  642. (cond
  643.  ((or font-pov-is-Emacs20 font-pov-is-XEmacs20-2 font-pov-is-Emacs21 font-pov-is-Emacs22)
  644.   (defface font-pov-object-face
  645.     '((((class grayscale) (background light)) (:foreground "DimGray" :bold t))
  646.       (((class grayscale) (background dark))  (:foreground "LightGray" :bold t))
  647.       (((class color) (background light))    (:foreground "DarkOliveGreen" :bold t))
  648.       (((class color) (background dark))     (:foreground "White" :bold t ))
  649.       (t (:bold t)))
  650.     "Font Lock mode face used for objects."
  651.     :group 'font-pov-faces)
  652.  
  653.   (defface font-pov-directive-face
  654.     '((((class grayscale) (background light)) (:foreground "DimGray"))
  655.       (((class grayscale) (background dark))  (:foreground "LightGray"))
  656.       (((class color) (background light))     (:foreground "DarkRed"))
  657.       (((class color) (background dark))      (:foreground "lightgreen"))
  658.       (t (:italic t)))
  659.     "Font Lock mode face used to highlight PoV directives."
  660.     :group 'font-pov-faces)
  661.  
  662.   (defface font-pov-number-face
  663.     '((((class grayscale) (background light))(:foreground "DimGray" :underline t))
  664.       (((class grayscale) (background dark)) (:foreground "LightGray" :underline t))
  665.       (((class color) (background light))    (:foreground "SaddleBrown"))
  666.       (((class color) (background dark))     (:foreground "wheat"))
  667.       (t (:underline t)))
  668.     "Font Lock mode face used to highlight numbers in PoV."
  669.     :group 'font-pov-faces)
  670.  
  671.   (defface font-pov-variable-face
  672.     '((((class grayscale) (background light)) (:foreground "DimGray"))
  673.       (((class grayscale) (background dark))  (:foreground "LightGray"))
  674.       (((class color) (background light))     (:foreground "ForestGreen"))
  675.       (((class color) (background dark))      (:foreground "gray80"))
  676.       )
  677.     "Font Lock mode face used to highlight variabledeclarations in PoV."
  678.     :group 'font-pov-faces)
  679.  
  680.   (defface font-pov-csg-face
  681.     '((((class grayscale) (background light)) (:foreground "DimGray"))
  682.       (((class grayscale) (background dark))  (:foreground "LightGray"))
  683.       (((class color) (background light))     (:foreground "Blue"))
  684.       (((class color) (background dark))      (:foreground "red"))
  685.       )
  686.     "Font Lock mode face used to highlight CSGs in PoV."
  687.     :group 'font-pov-faces)
  688.  
  689. ;; -- C.H. --
  690.  
  691.   (defface font-pov-macro-name-face
  692.     '((((class grayscale) (background light)) (:foreground "DimGray" :bold t))
  693.       (((class grayscale) (background dark))  (:foreground "LightGray" :bold t))
  694.       (((class color) (background light))     (:foreground "Blue2" :bold t))
  695.       (((class color) (background dark))      (:foreground "gray80" :bold t))
  696.       )
  697.     "Font Lock mode face used to highlight macro declarations in PoV."
  698.     :group 'font-pov-faces)
  699.  
  700.   (defface font-pov-keyword-face
  701.     '((((class grayscale) (background light)) (:foreground "DimGray"))
  702.       (((class grayscale) (background dark))  (:foreground "LightGray"))
  703.       (((class color) (background light))     (:foreground "Blue4"))
  704.       (((class color) (background dark))      (:foreground "Blue"))
  705.       )
  706.     "Font Lock mode face used to highlight general keywords in PoV."
  707.     :group 'font-pov-faces)
  708.  
  709. ;; -- end C.H. --
  710.  
  711.  
  712.   (defface font-pov-operator-face
  713.     '((((class grayscale)(background light)) (:foreground "DimGray" :bold t))
  714.       (((class grayscale)(background dark))  (:foreground "LightGray" :bold t))
  715.       (((class color)(background light))     (:foreground "Limegreen" :bold t ))
  716.       (((class color)(background dark))      (:foreground "Limegreen" :bold t ))
  717.       (t (:bold t)))
  718.     "Font Lock mode face used to highlight operators in PoV."
  719.     :group 'font-pov-faces))
  720.  
  721.  (font-pov-is-Emacs19
  722.   (unless (assq 'font-pov-variable-face font-lock-face-attributes)
  723.     (cond
  724.      ;; FIXME: Add better conditions for grayscale.
  725.      ((memq font-lock-display-type '(mono monochrome grayscale greyscale
  726.                                           grayshade greyshade))
  727.       (setq font-lock-face-attributes
  728.             (append
  729.              font-lock-face-attributes
  730.              (list '(font-pov-variable-face nil nil t nil nil)
  731.                    '(font-pov-macro-name-face nil nil t nil nil)  ;; C.H.
  732.                    '(font-pov-keyword-face nil nil nil t nil)     ;; C.H.
  733.                    '(font-pov-object-face nil nil nil t nil)
  734.                    '(font-pov-number-face nil nil nil nil t)
  735.                    (list
  736.                     'font-pov-operator-face
  737.                     (cdr (assq 'background-color (frame-parameters)))
  738.                     (cdr (assq 'foreground-color (frame-parameters)))
  739.                     nil nil nil)))))
  740.      ((eq font-lock-background-mode 'light) ; light color background
  741.       (setq font-lock-face-attributes
  742.             (append
  743.              font-lock-face-attributes
  744.              ;;;FIXME: These won't follow font-lock-type-face's changes.
  745.              ;;;       Should I change to a (copy-face) scheme?
  746.              '((font-pov-variable-face "DarkOliveGreen" nil t nil nil)
  747.                (font-pov-macro-name-face "DarkOliveGreen" nil t nil nil)  ;; C.H.
  748.                (font-pov-keyword-face "grey50")                           ;; C.H.
  749.                (font-pov-number-face "DarkOliveGreen" nil nil t nil)
  750.                (font-pov-object-face "grey50")
  751.                (font-pov-directive-face "red" nil t nil nil)))))
  752.      (t                 ; dark color background
  753.       (setq font-lock-face-attributes
  754.             (append
  755.              font-lock-face-attributes
  756.              '((font-pov-varible-face "OliveDrab" nil t nil nil)
  757.                (font-pov-macro-name-face "OliveDrab" nil t nil nil)   ;; C.H.
  758.                (font-pov-keyword-face "grey60")                       ;; C.H.
  759.                (font-pov-number-face "OliveDrab" nil nil t nil)
  760.                ;; good are > LightSeaGreen, LightCoral, coral, orchid, orange
  761.                (font-pov-object-face "grey60")
  762.                (font-pov-directive-face "red" nil t nil nil))))))))
  763.  (t
  764.   ;;; XEmacs < version 20.2
  765.   (make-face 'font-pov-variable-face "Face to use for PoV variables.")
  766.   (make-face 'font-pov-macro-name-face "Face to use for PoV macros.")      ;; C.H.
  767.   (make-face 'font-pov-keyword-face "Face to use for PoV keywords.")       ;; C.H.
  768.   (make-face 'font-pov-directive-face "Face to use for PoV directives.")
  769.   (make-face 'font-pov-number-face "Face to use for PoV numbers.")
  770.   (make-face 'font-pov-operator-face "Face to use for PoV operators.")
  771.   (make-face 'font-pov-csg-face "Face to use for PoV csg.")
  772.   (make-face 'font-pov-object-face "Face to use for PoV objects.")
  773.  
  774.   (make-face-bold 'font-pov-object-face)
  775.  
  776.   ;; XEmacs uses a tag-list thingy to determine if we are using color
  777.   ;;  or mono (and I assume a dark background).
  778.   (set-face-foreground 'font-pov-object-face "green4" 'global nil 'append)
  779.   (set-face-foreground 'font-pov-number-face "green" 'global nil 'append)
  780.   (set-face-foreground 'font-pov-variable-face "red" 'global nil 'append)
  781.   (set-face-foreground 'font-pov-macro-name-face "blue2" 'global nil 'append)   ;; C.H.
  782.   (set-face-foreground 'font-pov-keyword-face "blue4" 'global nil 'append)      ;; C.H.
  783.   ))
  784.  
  785.  
  786. (font-pov-setup) ;; Setup and register the fonts...
  787.  
  788. (defun pov-make-tabs (stop)
  789.   (and (< stop 132) (cons stop (pov-make-tabs (+ stop pov-tab-width)))))
  790.  
  791. (defconst pov-tab-stop-list (pov-make-tabs pov-tab-width)
  792.   "Tab stop list for PoV mode")
  793.  
  794. (defvar pov-mode-map nil
  795.   "Keymap used in PoV mode buffers")
  796.  
  797. (defvar pov-mode-syntax-table nil
  798.   "PoV mode syntax table")
  799.  
  800. (defconst pov-comment-start-regexp "//\\|/\\*"
  801.   "Dual comment value for `comment-start-regexp'.")
  802.  
  803. (defvar pov-comment-syntax-string ". 124b"
  804.   "PoV hack to handle Emacs/XEmacs foo")
  805.  
  806. (defvar pov-begin-re "\\<#\\(if\\(n?def\\)?\\|case\\|range\\|switch\\|while\\)\\>")
  807. (defvar pov-end-re  "\\<#break\\|#end\\>")
  808.  
  809. (defvar pov-else-re "\\<#else\\>")
  810.  
  811. (defvar pov-begin-end-re (concat
  812.                           pov-begin-re
  813.                           "\\|"
  814.                           pov-end-re
  815.                           "\\|"
  816.                           pov-else-re))
  817.  
  818. (defun pov-setup-syntax-table nil
  819.   (if (or (string-match "Lucid" emacs-version)
  820.           (string-match "XEmacs" emacs-version))
  821.       (setq pov-comment-syntax-string ". 1456"))
  822.   (if pov-mode-syntax-table
  823.       ()
  824.     (setq pov-mode-syntax-table (make-syntax-table))
  825.     (modify-syntax-entry ?_ "w" pov-mode-syntax-table)
  826.     (modify-syntax-entry ?# "w" pov-mode-syntax-table)
  827.     (modify-syntax-entry ?/ pov-comment-syntax-string pov-mode-syntax-table)
  828.     (modify-syntax-entry ?* ". 23" pov-mode-syntax-table)
  829.     (modify-syntax-entry ?\n "> b" pov-mode-syntax-table)
  830.     (set-syntax-table pov-mode-syntax-table)))
  831.  
  832. ;; -- C.H. --
  833.  
  834. (defvar pov-all-keyword-matcher
  835.   (eval-when-compile
  836.     (concat "\\<\\("
  837.             (regexp-opt '("aa_level" "aa_threshold" "abs" "absorption" "accuracy" "acos" "acosh" "adaptive"
  838.                           "adc_bailout" "agate" "agate_turb" "all" "all_intersections" "alpha" "altitude"
  839.                           "always_sample" "ambient" "ambient_light" "angle" "aperture" "append" "arc_angle"
  840.                           "area_light" "array" "asc" "ascii" "asin" "asinh" "assumed_gamma" "atan" "atan2"
  841.                           "atanh" "autostop" "average"
  842.                           "b_spline" "background" "bezier_spline" "bicubic_patch" "black_hole" "blob" "blue"
  843.                           "blur_samples" "bounded_by" "box" "boxed" "bozo" "break" "brick" "brick_size"
  844.                           "brightness" "brilliance" "bump_map" "bump_size" "bumps"
  845.                           "camera" "case" "caustics" "ceil" "cells" "charset" "checker" "chr" "circular"
  846.                           "clipped_by" "clock" "clock_delta" "clock_on" "collect" "color" "color_map"
  847.                           "colour" "colour_map" "component" "composite" "concat" "cone" "confidence"
  848.                           "conic_sweep" "conserve_energy" "contained_by" "control0" "control1" "coords"
  849.                           "cos" "cosh" "count" "crackle" "crand" "cube" "cubic" "cubic_spline" "cubic_wave"
  850.                           "cutaway_textures" "cylinder" "cylindrical" "debug" "declare" "default" "defined"
  851.                           "degrees" "density" "density_file" "density_map" "dents" "df3" "difference"
  852.                           "diffuse" "dimension_size" "dimensions" "direction" "disc" "dispersion"
  853.                           "dispersion_samples" "dist_exp" "distance" "div" "double_illuminate" "eccentricity"
  854.                           "else" "emission" "end" "error" "error_bound" "evaluate" "exp" "expand_thresholds"
  855.                           "exponent" "exterior" "extinction"
  856.                           "face_indices" "facets" "fade_color" "fade_colour" "fade_distance" "fade_power"
  857.                           "falloff" "falloff_angle" "false" "fclose" "file_exists" "filter" "final_clock"
  858.                           "final_frame" "finish" "fisheye" "flatness" "flip" "floor" "focal_point" "fog"
  859.                           "fog_alt" "fog_offset" "fog_type" "fopen" "form" "frame_number" "frequency"
  860.                           "fresnel" "function" "gather" "gif" "global_lights" "global_settings" "gradient"
  861.                           "granite" "gray" "gray_threshold" "green"
  862.                           "height_field" "hexagon" "hf_gray_16" "hierarchy" "hypercomplex" "hollow"
  863.                           "if" "ifdef" "iff" "ifndef" "image_height" "image_map" "image_pattern" "image_width"
  864.                           "include" "initial_clock" "initial_frame" "inside" "int" "interior" "interior_texture"
  865.                           "internal" "interpolate" "intersection" "intervals" "inverse" "ior" "irid"
  866.                           "irid_wavelength" "isosurface"
  867.                           "jitter" "jpeg" "julia" "julia_fractal"
  868.                           "lambda" "lathe" "leopard" "light_group" "light_source" "linear_spline" "linear_sweep"
  869.                           "ln" "load_file" "local" "location" "log" "look_at" "looks_like" "low_error_factor"
  870.                           "macro" "magnet" "major_radius" "mandel" "map_type" "marble" "material" "material_map"
  871.                           "matrix" "max" "max_extent" "max_gradient" "max_intersections" "max_iteration"
  872.                           "max_sample" "max_trace" "max_trace_level" "media" "media_attenuation"
  873.                           "media_interaction" "merge" "mesh" "mesh2" "metallic" "method" "metric" "min"
  874.                           "min_extent" "minimum_reuse" "mod" "mortar"
  875.                           "natural_spline" "nearest_count" "no" "no_bump_scale" "no_image" "no_reflection"
  876.                           "no_shadow" "noise_generator" "normal" "normal_indices" "normal_map" "normal_vectors"
  877.                           "number_of_waves"
  878.                           "object" "octaves" "off" "offset" "omega" "omnimax" "on" "once" "onion" "open"
  879.                           "orient" "orientation" "orthographic"
  880.                           "panoramic" "parallel" "parametric" "pass_through" "pattern" "perspective" "pgm"
  881.                           "phase" "phong" "phong_size" "photons" "pi" "pigment" "pigment_map" "pigment_pattern"
  882.                           "planar" "plane" "png" "point_at" "poly" "poly_wave" "polygon" "pot" "pow" "ppm"
  883.                           "precision" "precompute" "pretrace_end" "pretrace_start" "prism" "projected_through"
  884.                           "pwr"
  885.                           "quadratic_spline" "quadric" "quartic" "quaternion" "quick_color" "quick_colour"
  886.                           "quilted"
  887.                           "radial" "radians" "radiosity" "radius" "rainbow" "ramp_wave" "rand" "range"
  888.                           "range_divider" "ratio" "read" "reciprocal" "recursion_limit" "red" "reflection"
  889.                           "reflection_exponent" "refraction" "render" "repeat" "rgb" "rgbf" "rgbft" "rgbt"
  890.                           "right" "ripples" "rotate" "roughness"
  891.                           "samples" "save_file" "scale" "scallop_wave" "scattering" "seed" "select" "shadowless"
  892.                           "sin" "sine_wave" "sinh" "size" "sky" "sky_sphere" "slice" "slope" "slope_map"
  893.                           "smooth" "smooth_triangle" "solid" "sor" "spacing" "specular" "sphere" "sphere_sweep"
  894.                           "spherical" "spiral1" "spiral2" "spline" "split_union" "spotlight" "spotted" "sqr"
  895.                           "sqrt" "statistics" "str" "strcmp" "strength" "strlen" "strlwr" "strupr" "sturm"
  896.                           "substr" "superellipsoid" "switch" "sys"
  897.                           "t" "tan" "tanh" "target" "text" "texture" "texture_list" "texture_map" "tga"
  898.                           "thickness" "threshold" "tiff" "tightness" "tile2" "tiles" "tolerance" "toroidal"
  899.                           "torus" "trace" "transform" "translate" "transmit" "triangle" "triangle_wave" "true"
  900.                           "ttf" "turb_depth" "turbulence" "type"
  901.                           "u" "u_steps" "ultra_wide_angle" "undef" "union" "up" "use_alpha" "use_color"
  902.                           "use_colour" "use_index" "utf8" "uv_indices" "uv_mapping" "uv_vectors"
  903.                           "v" "v_steps" "val" "variance" "vaxis_rotate" "vcross" "vdot" "version"
  904.                           "vertex_vectors" "vlength" "vnormalize" "vrotate" "vstr" "vturbulence" "warning"
  905.                           "warp" "water_level" "waves" "while" "width" "wood" "wrinkles" "write"
  906.                           "x"
  907.                           "y" "yes"
  908.                           "z") t)
  909.             "\\)\\>")))
  910.  
  911. (defvar pov-all-directives-matcher
  912.   (eval-when-compile
  913.     (concat "\\<\\("
  914.             (regexp-opt '("#break" "#case" "#debug" "#declare" "#default" "#else" "#end" "#error" "#fclose"
  915.                           "#fopen" "#if" "#ifdef" "#ifndef" "#include" "#local" "#macro" "#range" "#read"
  916.                           "#render" "#statistics" "#switch" "#undef" "#version" "#warning" "#while" "#write") t)
  917.             "\\)\\>")))
  918.  
  919. (defvar pov-all-objects-matcher
  920.   (eval-when-compile
  921.     (concat "\\<\\("
  922.             (regexp-opt '("background" "bicubic_patch" "blob" "box" "camera" "cone" "cubic" "cylinder" "disc"
  923.                           "fog" "height_field" "isosurface" "julia_fractal" "lathe" "light_group" "light_source"
  924.                           "mesh" "mesh2" "object" "parametric" "plane" "poly" "polygon" "prism" "rainbow"
  925.                           "sky_sphere" "smooth_triangle" "sor" "sphere" "sphere_sweep" "superellipsoid" "text" "torus"
  926.                           "triangle" "quadric" "quartic") t)
  927.             "\\)\\>")))
  928.  
  929. (defvar pov-font-lock-keywords
  930.   (list
  931.    ;; highlight variable names after '#declare/#local'
  932.    (list "\\<\\(#declare\\|#local\\)\\>[ \t\n]*\\(\\sw+\\)" '(2 font-pov-variable-face nil t))
  933.    ;; highlight csg-keywords
  934.    (list "\\<\\(difference\\|intersection\\|merge\\|union\\)\\>" '(1 font-pov-csg-face))
  935.    ;; highlight variable names after '#macro'
  936.    (list "\\<\\(#macro\\)\\>[ \t\n]*\\(\\sw+\\)" '(2 font-pov-macro-name-face nil t))
  937.    ;; highlight numbers with type-face
  938.    (list "\\(\\<\\([0-9]*\\.[0-9]+\\|[0-9]+\\)\\|\\.[0-9]+\\)\\([eE][+\\-]?[0-9]+\\)?\\>"
  939.          '(1 font-pov-number-face))
  940.    ;; highlight operators keywords
  941.    (list "\\([\\-\\+\\|\\^=&!?:/\\>\\<\\*]+\\)" '(1 font-pov-operator-face))
  942.    ;; highlight directives
  943.    (list pov-all-directives-matcher '(1 font-pov-directive-face))
  944.    ;; highlight objects
  945.    (list pov-all-objects-matcher '(1 font-pov-object-face))
  946.    ;; highlight general keywords
  947.    (list pov-all-keyword-matcher '(1 font-pov-keyword-face))
  948.    )
  949.   "Expressions to highlight in PoV mode."
  950. )
  951. ;; -- end C.H --
  952.  
  953. (defun pov-mode nil
  954.   "Major mode for editing PoV files. (Version 2.11)
  955.  
  956.   In this mode, TAB and \\[indent-region] attempt to indent code
  957. based on the position of {} pairs and #-type directives.  The variable
  958. pov-indent-level controls the amount of indentation used inside
  959. arrays and begin/end pairs.  The variable pov-indent-under-declare
  960. determines indent level when you have something like this:
  961. #declare foo =
  962.   some_object {
  963.  
  964. This mode also provides PoVray keyword fontification using font-lock.
  965. Set pov-fontify-insanely to nil to disable (recommended for large
  966. files!).
  967.  
  968. \\[pov-complete-word] runs pov-complete-word, which attempts to complete the
  969. current word based on point location.
  970. \\[pov-keyword-help] looks up a povray keyword in the povray documentation.
  971. \\[pov-command-query] will render or display the current file.
  972.  
  973. \\{pov-mode-map}
  974.  
  975. \\[pov-mode] calls the value of the variable pov-mode-hook  with no args, if that value is non-nil.
  976. "
  977.   (interactive)
  978.   (kill-all-local-variables)
  979.   (use-local-map pov-mode-map)
  980.   (pov-setup-syntax-table)
  981.   (make-local-variable 'font-lock-keywords)
  982.   (make-local-variable 'comment-start)
  983.   (make-local-variable 'comment-start-skip)
  984.   (make-local-variable 'comment-end)
  985.   (make-local-variable 'comment-multi-line)
  986.   (make-local-variable 'comment-column)
  987.   (make-local-variable 'indent-line-function)
  988.   (make-local-variable 'tab-stop-list)
  989.   (make-local-variable 'font-lock-defaults)
  990.  
  991.   (setq font-lock-keywords pov-font-lock-keywords)
  992.   (setq font-lock-defaults '(pov-font-lock-keywords))
  993.   (if (and (boundp 'running-xemacs) running-xemacs)
  994.       (pov-toolbar))
  995.   (if pov-imenu-in-menu
  996.       (pov-helper-imenu-setup))
  997.  
  998.   ;; Create and show the insert menu
  999.   (pov-im-make-menu)
  1000.   (easy-menu-add pov-im-menu)
  1001.  
  1002.   (set-syntax-table pov-mode-syntax-table)
  1003.   (setq comment-start "// "
  1004.         comment-start-skip "/\\*+ *\\|// *"
  1005.         comment-end ""
  1006.         comment-multi-line nil
  1007.         comment-column 60
  1008.         indent-line-function 'pov-indent-line
  1009.         tab-stop-list pov-tab-stop-list)
  1010.   (setq mode-name "PoV")
  1011.   (setq major-mode 'pov-mode)
  1012.   (run-hooks 'pov-mode-hook)
  1013. )
  1014.  
  1015. (defun pov-tab ()
  1016.   "Command assigned to the TAB key in PoV mode."
  1017.   (interactive)
  1018.   (if (save-excursion (skip-chars-backward " \t") (bolp))
  1019.       (pov-indent-line)
  1020.     (save-excursion
  1021.       (pov-indent-line))))
  1022.  
  1023. (defun pov-indent-line nil
  1024.   "Indents a line of PoV code."
  1025.   (interactive)
  1026.   (beginning-of-line)
  1027.   (delete-horizontal-space)
  1028.   (if (pov-top-level-p)
  1029.       (pov-indent-top-level)
  1030.     (if (not (pov-top-level-p))
  1031.         (if (pov-in-star-comment-p)
  1032.             (indent-to '2)
  1033.           (if (and (< (point) (point-max))
  1034.                    (or
  1035.                     (eq ?\) (char-syntax (char-after (point))))
  1036.                     (or
  1037.                      (looking-at "\\<#\\(end\\|break\\)\\>")
  1038.                      (and (looking-at "\\<#else\\>")
  1039.                           (not (pov-in-switch-p 0))))))
  1040.               (pov-indent-close)                ; indent close-delimiter
  1041.             (pov-indent-in-block))))))  ; indent line after open delimiter
  1042.  
  1043. (defun pov-newline nil
  1044.   "Terminate line and indent next line."
  1045.   (interactive)
  1046.   (newline)
  1047.   (pov-indent-line))
  1048.  
  1049. (defun pov-in-star-comment-p nil
  1050.   "Return true if in a star comment"
  1051.   (let ((state
  1052.          (save-excursion
  1053.            (parse-partial-sexp (point-min) (point)))))
  1054.     (nth 4 state)))
  1055.  
  1056. (defun pov-open nil
  1057.   (interactive)
  1058.   (insert last-command-char))
  1059.  
  1060. (defun pov-close nil
  1061.   "Inserts and indents a close delimiter."
  1062.   (interactive)
  1063.   (insert last-command-char)
  1064.   (backward-char 1)
  1065.   (pov-indent-close)
  1066.   (forward-char 1)
  1067.   (blink-matching-open))
  1068.  
  1069. (defun pov-indent-close nil
  1070.   "Internal function to indent a line containing a close delimiter."
  1071.   (if (save-excursion (skip-chars-backward " \t") (bolp))
  1072.       (let (x (oldpoint (point)))
  1073.         (if (looking-at "#end\\|#else\\|#break")
  1074.             (progn
  1075.               (goto-char (pov-find-begin 0))
  1076.               (if (and (looking-at "#else")
  1077.                        (pov-in-switch-p 0))
  1078.                   (goto-char (pov-find-begin 0))))
  1079.           (forward-char) (backward-sexp))       ;XXX
  1080.         (if (and (eq 1 (count-lines (point) oldpoint))
  1081.                  (> 1 (- oldpoint (point))))
  1082.             (goto-char oldpoint)
  1083.           (beginning-of-line)
  1084.           (skip-chars-forward " \t")
  1085.           (setq x (current-column))
  1086.           (goto-char oldpoint)
  1087.           (delete-horizontal-space)
  1088.           (indent-to x)))))
  1089.  
  1090. (defun pov-indent-in-block nil
  1091.   "Indent a line which does not open or close a block."
  1092.   (let ((goal (pov-block-start)))
  1093.     (setq goal (save-excursion
  1094.                  (goto-char goal)
  1095.                  (back-to-indentation)
  1096.                  (if (bolp)
  1097.                      pov-indent-level
  1098.                    (back-to-indentation)
  1099.                    (+ (current-column) pov-indent-level))))
  1100.     (indent-to goal)))
  1101.  
  1102. (defun pov-indent-top-level nil
  1103.   (if (save-excursion
  1104.         (forward-line -1)
  1105.         (looking-at "\\<#declare[ \t]+[0-9a-zA-Z_]+[ \t]*=[ \t]*$"))
  1106.       (indent-to pov-indent-under-declare)))
  1107.  
  1108. ;;; returns nil if at top-level, or char pos of beginning of current block
  1109.  
  1110. (defun pov-block-start nil
  1111.   "Returns the character position of the character following the nearest
  1112. enclosing `{' or `begin' keyword."
  1113.   (save-excursion
  1114.     (let (open (skip 0))
  1115.       (setq open (condition-case nil
  1116.                      (save-excursion
  1117.                        (backward-up-list 1)
  1118.                        (1+ (point)))
  1119.                    (error nil)))
  1120.       (pov-find-begin open))))
  1121.  
  1122. (defun pov-find-begin (start)
  1123.   "Search backwards from point to START for enclosing `begin' and returns the
  1124. character number of the character following `begin' or START if not found."
  1125.   (save-excursion
  1126.     (let ((depth 1) match)
  1127.       (while (and (> depth 0)
  1128.                   (pov-re-search-backward pov-begin-end-re start t))
  1129.         (setq depth (if (looking-at pov-end-re)
  1130.                         (if (and (looking-at "#end")
  1131.                                  (pov-in-switch-p start))
  1132.                             (progn
  1133.                               (pov-re-search-backward "\\<#switch\\>" start t)
  1134.                               depth)
  1135.                           (+ 1 depth))
  1136.                       (if (looking-at "\\<#else\\>")
  1137.                           (if (pov-in-switch-p start)
  1138.                               (1- depth)
  1139.                             depth)
  1140.                         (1- depth)))))
  1141.       (if (not (eq 0 depth))
  1142.           start
  1143.         (point)))))
  1144.  
  1145. (defun pov-in-switch-p (start)
  1146.   "Return t if one level under a switch."
  1147.   (save-excursion
  1148.     (if (looking-at "\\<#end\\>")
  1149.         (pov-re-search-backward pov-begin-end-re start t))
  1150.     (beginning-of-line)
  1151.     (pov-re-search-backward pov-begin-end-re start t)
  1152.     (if (looking-at "\\<#else\\>>") (forward-word -1))
  1153.     (while (looking-at "\\<#break\\>")
  1154.       (progn
  1155.         (pov-re-search-backward "\\<#case\\|#range\\>" start t)
  1156.         (pov-re-search-backward pov-begin-end-re start t)))
  1157.     (pov-re-search-backward pov-begin-end-re start t)
  1158.     (looking-at "\\<#switch\\>")))
  1159.  
  1160. (defun pov-top-level-p nil
  1161.   "Awful test to see whether we are inside some sort of PoVray block."
  1162.   (and (condition-case nil
  1163.            (not (scan-lists (point) -1 1))
  1164.          (error t))
  1165.        (not (pov-find-begin nil))))
  1166.  
  1167. (defsubst pov-re-search-backward (REGEXP BOUND NOERROR)
  1168.   "Like re-search-backward, but skips over matches in comments or strings"
  1169.   (set-match-data '(nil nil))
  1170.   (while (and
  1171.           (re-search-backward REGEXP BOUND NOERROR)
  1172.           (pov-skip-backward-comment-or-string)
  1173.           (not (set-match-data '(nil nil))))
  1174.     ())
  1175.   (match-end 0))
  1176.  
  1177. (defun pov-autoindent-endblock nil
  1178.   "Hack to automatically reindent end, break, and else."
  1179.   (interactive)
  1180.   (self-insert-command 1)
  1181.   (save-excursion
  1182.     (forward-word -1)
  1183.     (if (looking-at "\\<#else\\|#end\\|#break\\>")
  1184.         (pov-indent-line))))
  1185.  
  1186. ; Taken from verilog-mode.el
  1187. (defun pov-skip-backward-comment-or-string ()
  1188.   "Return true if in a string or comment"
  1189.   (let ((state
  1190.          (save-excursion
  1191.            (parse-partial-sexp (point-min) (point)))))
  1192.     (cond
  1193.      ((nth 3 state)                      ;Inside string
  1194.       (search-backward "\"")
  1195.       t)
  1196.      ((nth 7 state)                      ;Inside // comment
  1197.       (search-backward "//")
  1198.       t)
  1199.      ((nth 4 state)                      ;Inside /* */ comment
  1200.       (search-backward "/*")
  1201.       t)
  1202.      (t
  1203.       nil))))
  1204.  
  1205. ; *******************
  1206. ; *** Completions ***
  1207. ; *******************
  1208. ;; -------------------------------------------------------------------
  1209. ;; C.H.: adapted completion to POV-Ray 3.5 syntax to some extent
  1210. ;; -------------------------------------------------------------------
  1211. (defvar pov-completion-str nil)
  1212. (defvar pov-completion-all nil)
  1213. (defvar pov-completion-pred nil)
  1214. ;(defvar pov-completion-buffer-to-use nil)
  1215. (defvar pov-completion-flag nil)
  1216.  
  1217. (defvar pov-global-keywords
  1218.   '("#break" "#case" "#debug" "#declare" "#default" "#else" "#end" "#fclose" "#fopen" "#include" "#local"
  1219.     "#macro" "#read" "#render" "#statistics" "#switch" "#undef" "#version" "#warning" "#write"))
  1220.  
  1221. (defvar pov-top-level-keywords
  1222.   '("global_settings" "camera" "light_source" "light_group" "media" "background" "sky_sphere" "photons" "rainbow"))
  1223.  
  1224. (defvar pov-csg-scope-re
  1225.   "\\<inverse\\|union\\|intersection\\|difference\\|merge\\>")
  1226.  
  1227. (defvar pov-solid-primitive-keywords
  1228.   '("blob" "box" "cone" "cylinder" "height_field" "julia_fractal" "lathe" "object" "prism" "sphere"
  1229.     "sphere_sweep" "superellipsoid" "sor" "text" "torus" "isosurface" "parametric"))
  1230.  
  1231. (defvar pov-blob-keywords
  1232.   '("threshold" "cylinder" "sphere" "component" "hierarchy" "sturm"))
  1233.  
  1234. (defvar pov-heightfield-keywords
  1235.   '("hierarchy" "smooth" "water_level"))
  1236.  
  1237. (defvar pob-isosurface-keywords
  1238.   '("accuracy" "all_intersections" "contained_by" "evaluate" "function" "max_gradient" "max_trace" "method"
  1239.     "open" "threshold"))
  1240.  
  1241. (defvar pov-juliafractal-keywords
  1242.   '("max_iteration" "precision" "slice" "quaternion" "hypercomplex" "slice"))
  1243.  
  1244. (defvar pov-prism-keywords
  1245.   '("linear_sweep" "conic_sweep" "linear_spline" "quadratic_spline" "cubic_spline" "bezier_spline" "sturm"))
  1246.  
  1247. (defvar pov-patch-primitive-keywords
  1248.   '("bicubic_patch" "disc" "smooth_triangle" "triangle" "polygon" "mesh" "mesh2"))
  1249.  
  1250. (defvar pov-bicubic-keywords
  1251.   '("type" "flatness" "u_steps" "v_steps"))
  1252.  
  1253. ;defvar pov-bezier-keywords
  1254. ; '("accuracy" "rational" "trimmed_by"))
  1255.  
  1256. (defvar pov-infinite-solid-keywords
  1257.   '("plane" "cubic" "poly" "quadric" "quartic"))
  1258.  
  1259. (defvar pov-csg-keywords
  1260.   '("inverse" "union" "intersection" "difference" "merge" "split_union"))
  1261.  
  1262. (defvar pov-light-source-keywords
  1263.   '("color" "spotlight" "point_at" "radius" "falloff" "tightness" "area_light" "adaptive" "jitter" "looks_like"
  1264.     "shadowless" "cylinder" "fade_distance" "fade_power" "media_attenuation" "media_interaction" "rgb"
  1265.     "circular" "orient" "groups" "parallel"))
  1266.  
  1267. (defvar pov-object-modifier-keywords
  1268.   '("clipped_by" "bounded_by" "hollow" "no_shadow" "no_reflection" "no_image" "interior_texture"))
  1269.  
  1270. (defvar pov-transformation-keywords
  1271.   '("rotate" "scale" "translate" "matrix" "transform"))
  1272.  
  1273. (defvar pov-camera-keywords
  1274.   '("perspective" "orthographic" "fisheye" "ultra_wide_angle" "omnimax" "panoramic" "cylinder" "spherical"
  1275.     "location" "look_at" "right" "up" "direction" "sky" "sphere" "spherical_camera" "h_angle" "v_angle" "angle"
  1276.     "blur_samples" "aperture" "focal_point" "normal" "rotate" "translate"))
  1277.  
  1278. (defvar pov-texture-keywords
  1279.   '("pigment" "normal" "finish" "halo" "texture_map" "material_map" "boxed" "planar" "cylindrical" "spherical"))
  1280.  
  1281. ;(defvar pov-pigment-keywords
  1282. ;  '("colour" "boxed" "brick" "checker" "cylindrical" "hexagon" "color_map" "gradient" "pigment_map" "pigment" "planar" "spherical" "image_map" "quick_color" "rgb"))
  1283. (defvar pov-pigment-keywords
  1284.   '("color" "colour" "colour_map" "color_map" "pigment_map" "pigment" "image_map" "quick_color"))
  1285.  
  1286. (defvar pov-normal-keywords
  1287.   '("slope_map" "normal_map" "bump_map" "bump_size" "boxed" "cylindrical" "planar" "spherical"))
  1288.  
  1289. (defvar pov-finish-keywords
  1290.   '("ambient" "diffuse" "brilliance" "phong" "phong_size" "specular" "roughness" "metallic" "reflection" "irid"
  1291.     "crand"))
  1292. ;; "refraction" "ior" "caustics" "fade_distance" "fade_power" ;;povray3.0
  1293.  
  1294. (defvar pov-reflection-keywords
  1295.   '("fresnel" "falloff" "exponent" "metallic" ))
  1296.  
  1297. (defvar pov-irid-keywords
  1298.   '("thickness" "turbulence"))
  1299.  
  1300. ;(defvar pov-pattern-keywords
  1301. ;  '("agate" "average" "boxed" "bozo" "brick" "bumps" "checker" "color" "crackle" "cylindrical" "density_file" "dents" "gradient" "granite" "hexagon" "leopard" "mandel" "marble" "onion" "planar" "pattern1" "pattern2" "pattern3" "quilted" "radial" "ripples" "spherical" "spiral1" "spiral2" "spotted" "waves" "wood" "wrinkles" "image_map" "bump_map" ))
  1302. (defvar pov-pattern-keywords
  1303.   '("agate" "average" "boxed" "bozo" "brick" "bumps" "cells" "checker" "crackle" "cylindrical" "density_file"
  1304.     "dents" "julia" "mandel" "magnet" "function" "gradient" "granite" "hexagon" "image_pattern" "leopard"
  1305.     "marble" "object" "onion" "pigment_pattern" "planar" "quilted" "radial" "ripples" "slope" "spherical"
  1306.     "spiral1" "spiral2" "spotted" "wood" "waves" "wrinkles" "frequency" "phase" "ramp_wave" "triangle_wave"
  1307.     "sine_wave" "scallop_wave" "cubic_wave" "poly_wave" "noise_generator" "turbulence" "octaves" "omega"
  1308.     "lambda" "warp"))
  1309.  
  1310. (defvar pov-media-keywords
  1311.   '("intervals" "samples" "confidence" "variance" "ratio" "absorption" "emission" "scattering" "density"
  1312.     "color_map" "density_map" "light_group" "sample_method" "aa_level" "aa_threshold" "jitter" "method"))
  1313.  
  1314. (defvar pov-interior-keywords
  1315.   '("ior" "caustics" "fade_distance" "fade_power" "media" "dispersion" "dispersion_samples"  "fade_color"))
  1316.  
  1317. (defvar pov-texture-keywords
  1318.   '("pigment" "normal" "finish" "texture_map" "material_map"))
  1319.  
  1320. (defvar pov-material-keywords
  1321.   '("texture" "interior"))
  1322.  
  1323. (defvar pov-warp-keywords
  1324.   '("repeat" "black_hole" "turbulence" "cylindrical" "spherical" "toroidal" "planar" "orientation" "dist_exp"
  1325.     "major_radius" "offset" "flip" "strength" "falloff" "inverse"))
  1326.  
  1327. (defvar pov-density-keyword
  1328.   '("colour" "colour_map" "boxed" "planar" "cylindrical" "spherical"))
  1329.  
  1330. (defvar pov-fog-keywords
  1331.  '("fog_type" "distance" "color" "turbulence" "turb_depth" "omega" "lambda" "octaves" "fog_offset" "fog_alt"
  1332.    "up"))
  1333.  
  1334. (defvar pov-rainbow-keywords
  1335.  '("direction" "angle" "width" "distance" "jitter" "up" "arc_angle" "falloff_angle"))
  1336.  
  1337. (defvar pov-global-settings-keywords
  1338.   '("adc_bailout" "ambient_light" "assumed_gamma" "charset" "hf_gray_16" "irid_wavelength" "max_intersections"
  1339.     "max_trace_level" "number_of_waves" "radiosity" "reflection_samples" "photons" "noise_generator"))
  1340.  
  1341. (defvar pov-radiosity-keywords
  1342.   '("adc_bailout" "always_sample" "brightness" "count" "distance_maximum" "error_bound" "gray_threshold"
  1343.     "low_error_factor" "minimum_reuse" "nearest_count" "recursion_limit" "max_sample" "media" "normal"
  1344.     "pretrace_end" "pretrace_start" "recursion_limit" "save_file"))
  1345.  
  1346. (defvar pov-object-keywords
  1347.  '("texture" "pigment" "finish" "interior" "normal" "no_shadow"))
  1348.  
  1349. ;; Povray3.0
  1350. ;;(defvar pov-atmosphere-keywords
  1351. ;;  '("type" "distance" "scattering" "eccentricity" "samples" "jitter" "aa_threshold" "aa_level" "colour" "color"))
  1352.  
  1353. ;AS: halo is no longer existent in pov 3.1 so we won't need that
  1354. ;(defvar pov-halo-keywords
  1355. ;  '("attenuating" "emitting" "glowing" "dust" "constant" "linear" "cubic" "poly" "planar_mapping" "spherical_mapping" "cylindrical_mapping" "box_mapping" "dust_type" "eccentricity" "max_value" "exponent" "samples" "aa_level" "aa_threshold" "jitter" "turbulence" "octaves" "omega" "lambda" "colour_map" "frequency" "phase" "scale" "rotate" "translate"))
  1356.  
  1357.  
  1358. ;;AS
  1359. (defvar pov-keyword-completion-alist
  1360.   (mapcar (function
  1361.            (lambda (item) (list item item)))
  1362.            (append
  1363.             pov-global-keywords
  1364.             pov-top-level-keywords
  1365.             pov-solid-primitive-keywords
  1366.             pov-blob-keywords
  1367.             pov-heightfield-keywords
  1368.             pov-juliafractal-keywords
  1369.             pov-prism-keywords
  1370.             pov-patch-primitive-keywords
  1371.             pov-bicubic-keywords
  1372.             pov-infinite-solid-keywords
  1373.             pov-csg-keywords
  1374.             pov-light-source-keywords
  1375.             pov-object-modifier-keywords
  1376.             pov-transformation-keywords
  1377.             pov-camera-keywords
  1378.             pov-texture-keywords
  1379.             pov-pigment-keywords
  1380.             pov-normal-keywords
  1381.             pov-finish-keywords
  1382.             pov-reflection-keywords
  1383.             pov-irid-keywords
  1384.             pov-pattern-keywords
  1385.             pov-pattern-keywords
  1386.             pov-media-keywords
  1387.             pov-interior-keywords
  1388.             pov-texture-keywords
  1389.             pov-material-keywords
  1390.             pov-warp-keywords
  1391.             pov-fog-keywords
  1392.             pov-rainbow-keywords
  1393.             pov-global-settings-keywords
  1394.             pov-radiosity-keywords
  1395.             pov-object-keywords
  1396.             )))
  1397.  
  1398. ;pov-media-keywords
  1399. ;          pov-bicubic-keywords
  1400. ;                  pov-normal-keywords
  1401. ;                  pov-blob-keywords
  1402. ;                  pov-object-keywords
  1403. ;                  pov-camera-keywords
  1404. ;                  pov-pattern-keywords
  1405. ;                  pov-csg-keywords
  1406. ;                  pov-pigment-keywords
  1407. ;                  pov-density-keyword
  1408. ;                  pov-prism-keywords
  1409. ;                  pov-finish-keywords
  1410. ;                  pov-radiosity-keywords
  1411. ;                  pov-fog-keywords
  1412. ;                  pov-texture-keywords
  1413. ;                  pov-heightfield-keywords
  1414. ;                  pov-global-keywords)))
  1415. ;        pov-atmosphere-keywords
  1416. ;pov-halo-keywords
  1417.  
  1418. (defun pov-string-diff (str1 str2)
  1419.   "Return index of first letter where STR1 and STR2 differs."
  1420.   (catch 'done
  1421.     (let ((diff 0))
  1422.       (while t
  1423.         (if (or (> (1+ diff) (length str1))
  1424.                 (> (1+ diff) (length str2)))
  1425.             (throw 'done diff))
  1426.         (or (equal (aref str1 diff) (aref str2 diff))
  1427.             (throw 'done diff))
  1428.         (setq diff (1+ diff))))))
  1429.  
  1430. (defun pov-get-scope nil
  1431.   "Return the scope of the POV source at point"
  1432.   (interactive)
  1433.   (save-excursion
  1434.     (if (not (pov-top-level-p))
  1435.         (progn
  1436.           (backward-up-list 1)
  1437.           (forward-word -1)
  1438.           (cond
  1439.            ((looking-at "camera")
  1440.             (setq pov-completion-list pov-camera-keywords))
  1441.            ((looking-at "texture")
  1442.             (setq pov-completion-list (append pov-texture-keywords pov-pattern-keywords)))
  1443.            ((looking-at "material")
  1444.             (setq pov-completion-list (append pov-material-keywords pov-pattern-keywords)))
  1445.            ((looking-at "pigment")
  1446.             (setq pov-completion-list (append pov-pigment-keywords pov-pattern-keywords)))
  1447.            ((looking-at "normal")
  1448.             (setq pov-completion-list (append pov-normal-keywords pov-pattern-keywords)))
  1449.            ((looking-at "density")
  1450.             (setq pov-completion-list (append pov-density-keywords pov-pattern-keywords)))
  1451.            ((looking-at "finish")
  1452.             (setq pov-completion-list pov-finish-keywords))
  1453.            ((looking-at "warp")
  1454.             (setq pov-completion-list pov-warp-keywords))
  1455.            ((looking-at "finish")
  1456.             (setq pov-completion-list pov-finish-keywords))
  1457.            ((looking-at "reflection")
  1458.             (setq pov-completion-list pov-reflection-keywords))
  1459.            ((looking-at "irid")
  1460.             (setq pov-completion-list pov-irid-keywords))
  1461.            ((looking-at "blob")
  1462.             (setq pov-completion-list pov-blob-keywords))
  1463.            ((looking-at "isosurface")
  1464.             (setq pov-completion-list pov-isosurface-keywords))
  1465.            ((looking-at "heightfield")
  1466.             (setq pov-completion-list pov-heightfield-keywords))
  1467.            ((looking-at "prism")
  1468.             (setq pov-completion-list pov-prism-keywords))
  1469.            ((looking-at "julia_fractal")
  1470.             (setq pov-completion-list pov-juliafractal-keywords))
  1471.            ((looking-at "bicubic")
  1472.             (setq pov-completion-list pov-bicubic-keywords))
  1473.            ((looking-at "bezier")
  1474.             (setq pov-completion-list pov-bezier-keywords))
  1475.            ((looking-at "trimmed_by")
  1476.             (setq pov-completion-list pov-bezier-keywords))
  1477.            ((looking-at "light_source")
  1478.             (setq pov-completion-list pov-light-source-keywords))
  1479.            ((looking-at "interior")
  1480.             (setq pov-completion-list pov-interior-keywords))
  1481.            ((looking-at "media")
  1482.             (setq pov-completion-list pov-media-keywords))
  1483.            ((looking-at "fog")
  1484.             (setq pov-completion-list pov-fog-keywords))
  1485.            ((looking-at "global_settings")
  1486.             (setq pov-completion-list pov-global-settings-keywords ))
  1487.            ((looking-at "radiosity")
  1488.             (setq pov-completion-list pov-radiosity-keywords))
  1489.            ((looking-at "photons")
  1490.             (setq pov-completion-list pov-photons-keywords))
  1491.            ((looking-at pov-csg-scope-re)
  1492.             (setq pov-completion-list (append pov-solid-primitive-keywords pov-infinite-solid-keywords pov-object-modifier-keywords pov-csg-keywords)))
  1493.            (t
  1494.             (setq pov-completion-list (append pov-object-modifier-keywords pov-object-keywords))))
  1495.           (setq pov-completion-list (append pov-completion-list pov-transformation-keywords)))
  1496.       (setq pov-completion-list (append pov-top-level-keywords pov-solid-primitive-keywords pov-infinite-solid-keywords pov-patch-primitive-keywords pov-csg-keywords)))
  1497.     ;Append the language directives so that they are available at all places.
  1498.     (setq pov-completion-list (append pov-completion-list pov-global-keywords))))
  1499.  
  1500. (defun pov-completion (pov-completion-str pov-completion-pred pov-completion-flag)
  1501.   (save-excursion
  1502.     (let ((pov-completion-all nil))
  1503.       (pov-get-scope)
  1504.       (mapcar '(lambda (s)
  1505.                  (if (string-match (concat "\\<" pov-completion-str) s)
  1506.                      (setq pov-completion-all (cons s pov-completion-all))))
  1507.               pov-completion-list)
  1508.       ;; Now we have built a list of all matches. Give response to caller
  1509.       (pov-completion-response))))
  1510.  
  1511. (defun pov-completion-response ()
  1512.   (cond ((or (equal pov-completion-flag 'lambda) (null pov-completion-flag))
  1513.          ;; This was not called by all-completions
  1514.          (if (null pov-completion-all)
  1515.              ;; Return nil if there was no matching label
  1516.              nil
  1517.            ;; Get longest string common in the labels
  1518.            (let* ((elm (cdr pov-completion-all))
  1519.                   (match (car pov-completion-all))
  1520.                   (min (length match))
  1521.                   tmp)
  1522.              (if (string= match pov-completion-str)
  1523.                  ;; Return t if first match was an exact match
  1524.                  (setq match t)
  1525.                (while (not (null elm))
  1526.                  ;; Find longest common string
  1527.                  (if (< (setq tmp (pov-string-diff match (car elm))) min)
  1528.                      (progn
  1529.                        (setq min tmp)
  1530.                        (setq match (substring match 0 min))))
  1531.                  ;; Terminate with match=t if this is an exact match
  1532.                  (if (string= (car elm) pov-completion-str)
  1533.                      (progn
  1534.                        (setq match t)
  1535.                        (setq elm nil))
  1536.                    (setq elm (cdr elm)))))
  1537.              ;; If this is a test just for exact match, return nil ot t
  1538.              (if (and (equal pov-completion-flag 'lambda) (not (equal match 't)))
  1539.                  nil
  1540.                match))))
  1541.         ;; If flag is t, this was called by all-completions. Return
  1542.         ;; list of all possible completions
  1543.         (pov-completion-flag
  1544.          pov-completion-all)))
  1545.  
  1546. (defun pov-complete-word ()
  1547.   "Complete word at current point based on POV syntax."
  1548.   (interactive)
  1549.   (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9#_") (point)))
  1550.          (e (save-excursion (skip-chars-forward "a-zA-Z0-9#_") (point)))
  1551.          (pov-completion-str (buffer-substring b e))
  1552.          ;; The following variable is used in pov-completion
  1553.          ;(pov-buffer-to-use (current-buffer))
  1554.          (allcomp (all-completions pov-completion-str 'pov-completion))
  1555.          (match (try-completion
  1556.                  pov-completion-str (mapcar '(lambda (elm)
  1557.                                                (cons elm 0)) allcomp))))
  1558.     ;; Delete old string
  1559.     (delete-region b e)
  1560.     ;; Insert match if found, or the original string if no match
  1561.     (if (or (null match) (equal match 't))
  1562.         (progn (insert "" pov-completion-str)
  1563.                (message "(No match)"))
  1564.       (insert "" match))
  1565.     ;; Give message about current status of completion
  1566.     (cond ((equal match 't)
  1567.            (if (not (null (cdr allcomp)))
  1568.                (message "(Complete but not unique)")
  1569.              (message "(Sole completion)")))
  1570.           ;; Display buffer if the current completion didn't help
  1571.           ;; on completing the label.
  1572.           ((and (not (null (cdr allcomp))) (= (length pov-completion-str)
  1573.                                               (length match)))
  1574.            (with-output-to-temp-buffer "*Completions*"
  1575.              (display-completion-list allcomp))
  1576.            ;; Wait for a keypress. Then delete *Completion*  window
  1577.            (momentary-string-display "" (point))
  1578.            (delete-window (get-buffer-window (get-buffer "*Completions*")))))))
  1579.  
  1580.  
  1581. ;;; initialize the keymap if it doesn't already exist
  1582. (if (null pov-mode-map)
  1583.     (progn
  1584.       (setq pov-mode-map (make-sparse-keymap))
  1585.       (define-key pov-mode-map "{" 'pov-open)
  1586.       (define-key pov-mode-map "}" 'pov-close)
  1587.       (define-key pov-mode-map "\t" 'pov-tab)
  1588.       (define-key pov-mode-map "\r" 'pov-newline)
  1589.       (define-key pov-mode-map "\C-c\C-c" 'pov-command-query) ;AS
  1590.       (define-key pov-mode-map [(shift f1)] 'pov-keyword-help) ;AS
  1591.       (define-key pov-mode-map "\C-c\C-l" 'pov-show-render-output) ;AS
  1592.       (define-key pov-mode-map "\C-ci" 'pov-open-include-file)
  1593.       (define-key pov-mode-map "\M-\t" 'pov-complete-word)))
  1594.  
  1595. ;; Hack to redindent end/else/break
  1596. (if pov-autoindent-endblocks
  1597.     (progn
  1598.       (define-key pov-mode-map "e" 'pov-autoindent-endblock)
  1599.       (define-key pov-mode-map "k" 'pov-autoindent-endblock)
  1600.       (define-key pov-mode-map "d" 'pov-autoindent-endblock)))
  1601.  
  1602. ; ***********************
  1603. ; *** povkeyword help ***
  1604. ; ***********************
  1605. (defun pov-keyword-help nil
  1606.   (interactive)
  1607.   "look up the appropriate place for keyword in the POV documentation"
  1608.   "keyword can be entered and autocompleteted, default is word at point /AS"
  1609.   (let* ((default (current-word))
  1610.          (input (completing-read
  1611.                  (format "lookup keyword (default %s): " default)
  1612.                  pov-keyword-completion-alist))
  1613.          (kw (if (equal input "")
  1614.                  default
  1615.                input)))
  1616.     (get-buffer-create pov-doc-buffer-name)
  1617.     (switch-to-buffer-other-window pov-doc-buffer-name)
  1618.     (find-file-read-only (concat pov-home-dir pov-help-file))
  1619.     ;;Try to look up a keyword in the povray-documentation:
  1620.     ;;uses a heuristic to find the appropriate entry
  1621.     ;;since the povray-docu is formatted rather arbitrarily
  1622.     ;;try:
  1623.     (cond
  1624.      ((progn
  1625.        (goto-char (point-min))
  1626.        (search-forward-regexp
  1627.         ;;first: the language description is in section four, so look for:
  1628.         (concat
  1629.          "^4\\.[0-9]+\\(\\.[0-9]+\\)?\\(\\.[0-9]+\\)?\\(\\.[0-9]+\\)?[  ]+"
  1630.          ;;change light_source -> light_source OR light source (that's
  1631.          ;;the usual spelling in the headings)
  1632.          ;;(wouldn't a working replace-in-string be nice, even for
  1633.          ;;FSF-emacs ???)
  1634.          (if (string-match "\\(.*\\)_\\(.*\\)" kw)
  1635.              (concat (match-string 1 kw)
  1636.                      "[_        ]"
  1637.                      (match-string 2 kw)
  1638.                      ".*\\>$")
  1639.            kw))
  1640.         nil t))                 ;return nil if not found
  1641.        ;; make the line of the match the top line of screen XXX
  1642.        (recenter 0))
  1643.  
  1644.      ;;second: if that didn't work:
  1645.      ;;same again with a relaxed regexp that allows more matches:
  1646.      ((progn
  1647.         (goto-char (point-min))
  1648.         (search-forward-regexp
  1649.          (concat
  1650.           "^4\\.[0-9]+\\(\\.[0-9]+\\)?\\(\\.[0-9]+\\)?\\(\\.[0-9]+\\)?[         ]+.*"
  1651.           (if (string-match "\\(.*\\)_\\(.*\\)" kw)
  1652.               (concat
  1653.                (match-string 1 kw)
  1654.                "[_      ]"
  1655.                (match-string 2 kw))
  1656.             kw))
  1657.          nil t))
  1658.       (recenter 0))
  1659.      ;;third try:
  1660.      ;;syntactic definitions appear like this: "KEYWORD:"
  1661.      ((progn
  1662.         (goto-char (point-min))
  1663.         (search-forward-regexp
  1664.          (concat "\\<" (upcase kw) ":")
  1665.          nil t)))
  1666.       ;;last try: simply search keyword from beginning of buffer
  1667.      ((progn
  1668.        (goto-char (point-min))
  1669.        (while (y-or-n-p (concat "Continue to look for " kw))
  1670.          (search-forward-regexp
  1671.           (concat  "\\<" kw  "\\>")
  1672.           nil t))))
  1673.      ;;OK, that's it: we failed
  1674.      (t (error (concat "Couldn't find keyword: " kw
  1675.                       ", maybe you misspelled it?"))))
  1676.     ))
  1677.  
  1678. ; **********************************
  1679. ; *** Open standard include file ***
  1680. ; **********************************
  1681. (defun pov-open-include-file nil
  1682.   (interactive)
  1683.   "Open one of the standard include files"
  1684.   (let* ((default (current-word))
  1685.          (input (completing-read
  1686.                  (format "File to open (default %s): " default)
  1687.                  pov-keyword-completion-alist))
  1688.          (kw (if (equal input "")
  1689.                  default
  1690.                input)))
  1691.     ;(get-buffer-create kw)
  1692.     ;(switch-to-buffer-other-window kw)
  1693.     ;(message (concat pov-include-dir (concat kw ".inc")))
  1694.     (find-file-read-only (concat pov-include-dir (concat kw ".inc")))
  1695. ))
  1696.  
  1697. ; ***************************
  1698. ; *** Commands for povray ***
  1699. ; ***************************
  1700.  
  1701. ;;; Execution of Povray and View processes
  1702. (defvar pov-next-default-command "Render" ;XXX
  1703.   "The default command to run next time pov-command-query is run")
  1704. (defvar pov-last-render-command "Render" ;XXX
  1705.   "The last command used to render a scene")
  1706. (defvar pov-rendered-succesfully nil
  1707.   "Whether the last rendering completed without errors")
  1708. (defvar pov-doc-buffer-name "*Povray Doc*"
  1709.   "The name of the buffer in which the documentation will be displayed")
  1710. ;; will be set to *Pov Render <buffer-name>*
  1711. (defvar pov-render-buffer-name ""
  1712.   "The name of the buffer that contains the rendering output")
  1713. (defvar pov-current-render-process nil
  1714.   "The process rendering at the moment or nil")
  1715. (defvar pov-current-view-processes (make-hash-table)
  1716.   "The processes that display pictures at the moment")
  1717. (defvar pov-buffer-modified-tick-at-last-render 0
  1718.   "The number of modifications at time of last render")
  1719.  
  1720. ;;make all the render variables buffer-local that are pov-file
  1721. ;;dependent, so that users can render more than one file at the same
  1722. ;;time etc.  Note: for the *view processes* a hash is used (rather
  1723. ;;then making the variables local, because somebody might want to view
  1724. ;;a file from a different render buffer.
  1725.  
  1726. (mapc 'make-variable-buffer-local
  1727.       '(pov-command-alist ;because of history XXX
  1728.         pov-next-default-command
  1729.         pov-last-render-command
  1730.         pov-image-file
  1731.         pov-render-buffer-name
  1732.         pov-buffer-modified-tick-at-last-render
  1733.         pov-current-render-process))
  1734.  
  1735. (defvar pov-image-file ""
  1736.   "The name of the rendered image that should be displayed"
  1737.   )
  1738.  
  1739. (defun pov-default-view-command ()
  1740.   "Return the default view command (internal or external)"
  1741.   (if pov-default-view-internal
  1742.       pov-internal-view
  1743.     pov-external-view))
  1744.  
  1745. (defun pov-command-query () ;XXX
  1746.   "Query the user which command to execute"
  1747.   ;;XXX this one is still a mess
  1748.   (interactive)
  1749.   ;;Check whether the buffer has been modified since last call,
  1750.   ;;and the last rendering was succesful. If so he probably
  1751.   ;;wants to render, otherwise he wants to view.
  1752.   (let* ((default
  1753.            (if (and (= (buffer-modified-tick)
  1754.                        pov-buffer-modified-tick-at-last-render)
  1755.                     pov-rendered-succesfully)
  1756.                (pov-default-view-command)
  1757.              pov-last-render-command))
  1758.          (completion-ignore-case t)
  1759.          (pov-command (completing-read
  1760.                        (format "Which command (default: %s)? " default)
  1761.                        pov-command-alist nil t nil t)))
  1762.     (setq pov-command
  1763.           (if (not (string-equal pov-command ""))
  1764.               pov-command
  1765.             default))
  1766.     (setq pov-next-default-command pov-command)
  1767.   ;;XXX argl: all this information should be in pov-command-alist
  1768.   (cond ((string-match pov-command pov-internal-view)
  1769.          (pov-display-image-xemacs pov-image-file)) ;XXX
  1770.         ((string-match pov-command pov-external-view)
  1771.          (pov-display-image-externally pov-image-file t))
  1772.         (t
  1773.            (setq pov-buffer-modified-tick-at-last-render
  1774.                  (buffer-modified-tick))
  1775.         ;   (message (format
  1776.         ;            "DEBUG: buffer %s modified tick%d "
  1777.         ;            (buffer-name)
  1778.         ;            (buffer-modified-tick)))
  1779.            (pov-render-file pov-command (buffer-file-name) t)
  1780.            ))))
  1781.  
  1782. (defun pov-render-file (pov-command file verify-render)
  1783.   "Render a file using pov-command."
  1784.   ;;XXX Check that there isn't already a render running
  1785.   (when
  1786.       (or
  1787.        (not pov-current-render-process)
  1788.        (and pov-current-render-process
  1789.             (cond ((y-or-n-p
  1790.                     ;;XXX could theoretically be also running in other buffer...
  1791.                     "There is a render process already running: abort it?")
  1792.                    (kill-process pov-current-render-process)
  1793.                    (message "Process killed")
  1794.                    t)
  1795.                   )))
  1796.     (let ((render-command nil)
  1797.           (render-command-options nil)
  1798.           (render-command-history nil)
  1799.           (old-buffer (current-buffer))
  1800.           (process nil))
  1801.  
  1802.       ;; if the user hasn't saved his pov-file, ask him
  1803.     (if (buffer-modified-p)
  1804.         (and (y-or-n-p
  1805.               (concat (buffer-name (current-buffer)) " modified; save ? "))
  1806.              (save-buffer)))
  1807.     ;; assign the buffer local value of the render buffer name
  1808.     (setq pov-render-buffer-name (format "*Povray Render %s*" file))
  1809.     (set-buffer (get-buffer-create pov-render-buffer-name))
  1810.     ;(switch-to-buffer (buffer-name))   % XXX use this for 2.11, and fix it
  1811.     (erase-buffer)
  1812.     (setq render-command (second (assoc pov-command pov-command-alist)))
  1813.     (setq render-command-options (format
  1814.                                   (third (assoc pov-command pov-command-alist))
  1815.                                   file))
  1816.     (setq render-command-history
  1817.           (fourth (assoc pov-command pov-command-alist)))
  1818.     ;(message (format "DEBUG FUCK %s %s"render-command-options (or
  1819.     ;           render-command-history "NIL")))
  1820.     (if verify-render
  1821.          (setq render-command-options
  1822.                (read-string "Render with the following options: "
  1823.                             render-command-options
  1824.                             'render-command-history)))
  1825.     (message (format "Running %s on %s" pov-command file))
  1826.     (insert (format "Running %s on %s with: %s %s..." pov-command file
  1827.                     render-command  render-command-options))
  1828.  
  1829.     (setq process (apply 'start-process pov-command (current-buffer)
  1830.                          render-command
  1831.                          (split-string render-command-options)))
  1832.     ;; memorize what we are doing
  1833.     (setq pov-last-render-command pov-command)
  1834.     ;; FIXME this might be dubious
  1835.     (setf (fourth (assoc pov-command pov-command-alist))
  1836.           render-command-history)
  1837.     ;;(message (format "DEBUG proc: %s" process))
  1838.     ;;XXX 'coz pov-current-render-process is buffer-local
  1839.     ;(get-buffer old-buffer)
  1840.     (set-buffer old-buffer)
  1841.     (setq pov-current-render-process process)
  1842.     (set-process-filter process 'pov-render-filter)
  1843.     (set-process-sentinel process 'pov-render-sentinel))))
  1844.  
  1845. (defun pov-show-render-output ()
  1846.   "Pop up the output of the last render command."
  1847.   (interactive)
  1848.   (let ((buffer (get-buffer pov-render-buffer-name)))
  1849.     (if buffer
  1850.         (let ((old-buffer (current-buffer)))
  1851.           (pop-to-buffer buffer t)
  1852.           (bury-buffer buffer)
  1853.           (goto-char (point-max))
  1854.           (pop-to-buffer old-buffer))
  1855.       (error "No rendering done so far"))))
  1856.  
  1857. (defun pov-render-sentinel (process event)
  1858.  "Sentinel for povray call."
  1859.  ;;so we aren't rendering any more ;XXX
  1860.  (setq pov-current-render-process nil)
  1861.  ;;If the process exists successfully then kill the ouput buffer
  1862.  (cond ((equal 0 (process-exit-status process))
  1863.         (setq pov-rendered-succesfully t)
  1864.         (message "Image rendered succesfully"))
  1865.        (t
  1866.         (message (concat "Errors in " (process-name process)
  1867.                         ", press C-c C-l to display"))
  1868.         (setq pov-rendered-succesfully nil))))
  1869.  
  1870.  
  1871. (defun pov-render-filter (process string)
  1872.   "Filter to process povray output. Scrolls and extracts the
  1873. filename of the output image (XXX with a horrible buffer-local-hack...)"
  1874.   ;(message (format "DEBUG buffer name %s" (buffer-name (current-buffer))))
  1875.   (let ((image-file nil))
  1876.     (save-excursion
  1877.       (set-buffer (process-buffer process))
  1878.       (save-excursion
  1879.         ;; find out how our file is called
  1880.         (if (string-match "^ *Output file: \\(.*\\), [0-9]+ bpp .+$" string)
  1881.             (setq image-file (match-string 1 string)))
  1882.         (goto-char (process-mark process))
  1883.         (insert-before-markers string)
  1884.         (set-marker (process-mark process) (point))))
  1885.     (if image-file  (setq pov-image-file image-file))))
  1886.  
  1887. (defun pov-external-view-sentinel (process event)
  1888.   ;;seems like we finished viewing => remove process from hash
  1889.   (cl-remhash (process-name process) pov-current-view-processes)
  1890.   (if (equal 0 (process-exit-status process))
  1891.       (message (concat "view completed successfully")) ;XXX
  1892.     (message (format "view exit status %d"
  1893.                      (process-exit-status process)))))
  1894.  
  1895. (defun pov-display-image-externally (file verify-display)
  1896.   "Display the rendered image using external viewer"
  1897.   ;;if we don't have a file, prompt for one
  1898.   (when (or (not file) (string-equal file ""))
  1899.     (setq file
  1900.           (read-file-name "Which image file should I display? ")))
  1901.   (let ((view-command nil)
  1902.         (view-options nil)
  1903.         (view-history nil)
  1904.         (other-view (cl-gethash (concat pov-external-view file)
  1905.                                 pov-current-view-processes))
  1906.         (process nil))
  1907.     (if (and other-view (processp other-view))  ;external
  1908.         (if (not (y-or-n-p
  1909.                   (format "Do yo want to want to kill the old view of %s?" file)))
  1910.             (kill-process other-view)))
  1911.     (setq view-command (second (assoc pov-external-view pov-command-alist)))
  1912.     (setq view-options (format
  1913.                         (third (assoc pov-external-view pov-command-alist))
  1914.                         file))
  1915.     (setq view-history (fourth (assoc pov-external-view pov-command-alist)))
  1916.     (if verify-display
  1917.         (setq view-options (read-string "View with the following options: "
  1918.                                         view-options
  1919.                                         view-history)))
  1920.     (message (format "Viewing %s with %s %s" file view-command view-options))
  1921.     (setq process (apply 'start-process (concat pov-external-view file) nil
  1922.                          view-command (split-string view-options)))
  1923.     ;;; remember what we have done
  1924.     (cl-puthash (process-name process) process pov-current-view-processes)
  1925.     ;; update history
  1926.     (setf (fourth (assoc pov-external-view pov-command-alist)) view-history)
  1927.     ;;Sentinel for viewer call (XXX argl, what a hack)
  1928.     (set-process-sentinel process 'pov-external-view-sentinel)))
  1929.     ;;  '(lambda (process event)
  1930.  
  1931. (defun pov-display-image-xemacs (file)
  1932.   "Display the rendered image in a Xemacs frame"
  1933.   ;;TODO: set frame according to image-size (seems difficult)
  1934.   (when (or (not file) (string-equal file ""))
  1935.       (setq file
  1936.             (read-file-name "Which image file should I display? ")))
  1937.   (let ((buffer (get-buffer-create
  1938.                  (format "*Povray View %s*" file))))
  1939.     (save-excursion
  1940.       (set-buffer buffer)
  1941.       (toggle-read-only -1)
  1942.       (erase-buffer)
  1943.       (insert-file-contents file)
  1944.       (toggle-read-only 1)
  1945.       ;;this will either bring the old frame with the picture to the forground
  1946.       ;;or create a new one
  1947.       (make-frame-visible
  1948.        (or (get-frame-for-buffer (current-buffer))
  1949.            (get-frame-for-buffer-make-new-frame (current-buffer)))))))
  1950.   ;(concat
  1951.   ; (third (assoc pov-command pov-command-alist))
  1952.   ; file
  1953.  
  1954. ; *************
  1955. ; *** Imenu ***
  1956. ; *************
  1957. (defun pov-helper-imenu-setup ()
  1958.   (interactive)
  1959.   (require `imenu) ;; Make an index for imenu
  1960.   (make-local-variable imenu-create-index-function)
  1961.   (setq imenu-create-index-function `pov-helper-imenu-index)
  1962.   (imenu-add-to-menubar "PoV")
  1963. )
  1964.  
  1965. ;; C.H.: to avoid flooding the function menu set 'pov-imenu-only-macros'
  1966. (if pov-imenu-only-macros
  1967.     (defvar imenu-pov-declare-regexp
  1968.       (concat
  1969.        "\\(#macro\\)"          ; Begin declaration
  1970.        "\\s-+"                          ; Whitespace
  1971.        "\\([A-Za-z_][A-Za-z_0-9]*\\)"   ; Name
  1972.        ";?"                               ; A possible ; at the end
  1973.        )
  1974.       "Expression to recognize POV declares."
  1975.       )
  1976.   (defvar imenu-pov-declare-regexp
  1977.     (concat
  1978.      "#\\(declare\\|macro\\)"          ; Begin declaration
  1979.      "\\s-+"                            ; Whitespace
  1980.      "\\([A-Za-z_][A-Za-z_0-9]*\\)"     ; Name
  1981.      )
  1982.     "Expression to recognize POV declares."
  1983.     )
  1984.   )
  1985.  
  1986. ;(defvar imenu-pov-declare-regexp
  1987. ;  (concat
  1988. ;   "^[ \t]*\\<#\\(declare\\|local\\|macro\\)\\>+[ \t]?"
  1989. ;   "\\([a-zA-Z0-9_*]+\\)+[ \t]?"
  1990. ;   ))
  1991.  
  1992. (defun search-list (data-to-find list)
  1993.   (princ data-to-find)
  1994.   (message "")
  1995.   (princ list)
  1996.   (message "----")
  1997.   (cond ((null list)       nil)
  1998.         ((null (car list)) (equal (car (car list)) (car data-to-find)))
  1999.         (t                 (if (equal (car (car list)) (car data-to-find))
  2000.                                (setcar list (cons (car data-to-find)
  2001.                                                   (cons (car list) data-to-find)))
  2002.                              (search-list data-to-find (cdr list))
  2003.                              ))
  2004.         )
  2005.   )
  2006.  
  2007. (defun pov-helper-imenu-index ()
  2008.   "Return an table of contents for an html buffer for use with Imenu."
  2009.   ;(message "pov-helper-imenu-index")
  2010.   (let ((space ?\ ) ; a char
  2011.         (toc-index '())
  2012.         toc-str)
  2013.     (goto-char (point-min))
  2014.     (imenu-progress-message prev-pos 0)
  2015.     ;; Search
  2016.     (save-match-data
  2017.       (while (re-search-forward imenu-pov-declare-regexp nil t)
  2018.         ;(imenu-progress-message prev-pos)
  2019.         (setq toc-str (match-string 2))
  2020.         (beginning-of-line)
  2021.         (unless (search-list (cons toc-str (point)) toc-index)
  2022.           (setq toc-index (cons (cons toc-str (point)) toc-index)))
  2023.         (end-of-line)))
  2024.     ;(imenu-progress-message prev-pos 100)
  2025.     ;(if toc-index
  2026.     ;(princ (nreverse toc-index)))))
  2027.     (nreverse toc-index)))
  2028.  
  2029. ;;; Renderdialog
  2030. (defun pov-render-dialog ()
  2031.   "Opens a dialog to let you set the rending options"
  2032.   (interactive)
  2033.   (popup-dialog-box pov-render-dialog-desc)
  2034.   )
  2035.  
  2036. ;; Let's try to find where the InsertMenu is located...
  2037. (setq pov-insertmenu-location "EMACSLISPLIBRARY/InsertMenu")
  2038. ;;       (locate-data-directory "InsertMenu" (cons (file-name-directory
  2039. ;;                                               (locate-library "pov-mode"))
  2040. ;;                                              (if font-pov-is-Emacs
  2041. ;;                                                  data-directory
  2042. ;;                                                data-directory-list))))
  2043.  
  2044. (defun pov-im-get-submenunames ()
  2045.   (interactive)
  2046.   (pov-im-get-dirs (cddr (directory-files pov-insertmenu-location t)))
  2047.   )
  2048.  
  2049. (defun pov-im-get-dirs (dirs)
  2050.   (when (eq dirs nil)
  2051.     (return ()))
  2052.   (catch '--cl-block-nil--
  2053.     (if (file-directory-p (car dirs))
  2054.         (return (cons
  2055.                  (car dirs)
  2056.                  (if (eq (cdr dirs) nil)
  2057.                      nil
  2058.                    (pov-im-get-dirs (cdr dirs)))
  2059.                  ))
  2060.       (return (pov-im-get-dirs (cdr dirs)))))
  2061.   )
  2062.  
  2063. (defun pov-im-make-menu ()
  2064.   (easy-menu-define
  2065.    pov-im-menu
  2066.    pov-mode-map
  2067.    "The POV-Ray Insert menu"
  2068.    (cons "Insert" (pov-im-create-menu (pov-im-get-submenunames))))
  2069.   )
  2070.  
  2071. (defun pov-im-create-menu (dirs)
  2072.   (when (eq dirs nil)
  2073.     (return ()))
  2074.   (catch '--cl-block-nil--
  2075.     (return (cons
  2076.              (pov-im-create-submenu (car dirs))
  2077.              (if (eq (cdr dirs) nil)
  2078.                  nil
  2079.                (pov-im-create-menu (cdr dirs)))
  2080.              )))
  2081.   )
  2082.  
  2083. (defun pov-im-create-submenu (dir)
  2084.   (cons (substring (file-name-nondirectory dir) 5)
  2085.         (pov-im-get-menuitems (directory-files dir t ".*txt")))
  2086.   )
  2087.  
  2088. (defun pov-im-get-menuitems (items)
  2089.   (when (eq items nil)
  2090.     (return nil))
  2091.   (catch '--cl-block-nil--
  2092.     (if (string-match "-.txt" (car items))
  2093.         (return (cons
  2094.                  "----"
  2095.                  (if (eq (cdr items) nil)
  2096.                      nil
  2097.                    (pov-im-get-menuitems (cdr items)))
  2098.                  ))
  2099.       (if (string-match " - " (file-name-nondirectory (car items)))
  2100.           (return (cons
  2101.                    (vector (substring (file-name-sans-extension
  2102.                                        (file-name-nondirectory (car items))) 5)
  2103.                            (list 'pov-im-include-file (car items)) t)
  2104.                    (if (eq (cdr items) nil)
  2105.                        nil
  2106.                      (pov-im-get-menuitems (cdr items)))
  2107.                    ))
  2108.         (return (cons
  2109.                  (vector (file-name-sans-extension
  2110.                           (file-name-nondirectory (car items)))
  2111.                          (list 'pov-im-include-file (car items)) t)
  2112.                  (if (eq (cdr items) nil)
  2113.                      nil
  2114.                    (pov-im-get-menuitems (cdr items)))
  2115.                  ))
  2116.         )))
  2117.   )
  2118.  
  2119. (defun pov-im-include-file (file)
  2120.   (insert-file-contents file)
  2121.   )
  2122.  
  2123. (provide 'pov-mode)
  2124. ;;; pov-mode.el ends here
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: