gnuplot-gui.el 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  1. ;;;; gnuplot-gui.el -- GUI interface to setting options in gnuplot-mode
  2. ;; Copyright (C) 1998-2000 Bruce Ravel
  3. ;; Author: Bruce Ravel <ravel@phys.washington.edu>
  4. ;; Maintainer: Bruce Ravel <ravel@phys.washington.edu>
  5. ;; Created: 19 December 1998
  6. ;; Updated: 16 November 2000
  7. ;; Version: (same as gnuplot.el)
  8. ;; Keywords: gnuplot, plotting, interactive, GUI
  9. ;; This file is not part of GNU Emacs.
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ;; This program is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15. ;;
  16. ;; This lisp script is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. ;;
  20. ;; Permission is granted to distribute copies of this lisp script
  21. ;; provided the copyright notice and this permission are preserved in
  22. ;; all copies.
  23. ;;
  24. ;; You should have received a copy of the GNU General Public License
  25. ;; along with this program; if not, you can either send email to this
  26. ;; program's maintainer or write to: The Free Software Foundation,
  27. ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. ;; send bug reports to the authors (ravel@phys.washington.edu)
  30. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31. ;;
  32. ;;; Commentary:
  33. ;;
  34. ;; This file provides a graphical user interface to setting arguments
  35. ;; to gnuplot commands. Positioning point near a command and invoking
  36. ;; `gnuplot-gui-set-options-and-insert' (C-c C-c or shift-mouse-2)
  37. ;; will pop open a frame with widgets for setting the various
  38. ;; arguments appropriate the the item that was near point. The goal
  39. ;; is to provide point-and-click functionality to gnuplot-mode.
  40. ;;
  41. ;; gnuplot-gui is designed for gnuplot 3.7, but since much of 3.7 is
  42. ;; backward compatible to 3.5, it will work well for that version
  43. ;; also.
  44. ;;
  45. ;; gnuplot-gui.el was developed using Emacs 19.34 and is known to work
  46. ;; on Emacs 20.x and XEmacs 20.x. I do not know what is the earliest
  47. ;; version for which it will work, but I make no guarantees for
  48. ;; versions before 19.34. Note that this makes heavy use of the
  49. ;; widget package, so this will not work on Emacs 19.34 unless you
  50. ;; install the widget package separately.
  51. ;;
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. ;;
  54. ;;; To do:
  55. ;;
  56. ;; Widgets I need:
  57. ;; -- 'position: two or three comma separated numbers used to denote a
  58. ;; position or a tic start/end/increment (see arrow,
  59. ;; need a prefix)
  60. ;; -- 'modifier: colon separated fields used for datafile modifiers
  61. ;;
  62. ;; command types which are currently unsupported or contain mistakes
  63. ;; -- unsupported: cntrparam
  64. ;; -- plot, splot, fit: rather lame
  65. ;; -- label: position information missing
  66. ;; -- label: font string handled in overly simple manner
  67. ;; -- hidden3d: not really suited to 'list, but all options are exclusive...
  68. ;; -- pointstyle argument to "set label"
  69. ;;
  70. ;; overall:
  71. ;; -- continuation lines (ugh!)
  72. ;; -- multiple frames end up displaying same window after setting options
  73. ;;
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ;;; Code:
  76. (require 'gnuplot)
  77. (eval-and-compile
  78. (condition-case ()
  79. (progn
  80. (require 'widget)
  81. (require 'wid-edit))
  82. (error nil)))
  83. (require 'cl)
  84. (eval-when-compile ; suppress some compiler warnings
  85. (defvar gnuplot-xemacs-p nil)
  86. (defvar gnuplot-quote-character nil)
  87. (defvar gnuplot-info-display nil)
  88. (defvar gnuplot-mode-map nil))
  89. ;; (eval-when-compile
  90. ;; (require 'wid-edit))
  91. (eval-and-compile ; I need this!
  92. (if (fboundp 'split-string)
  93. ()
  94. (defun split-string (string &optional pattern)
  95. "Return a list of substrings of STRING which are separated by PATTERN.
  96. If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
  97. (or pattern
  98. (setq pattern "[ \f\t\n\r\v]+"))
  99. ;; The FSF version of this function takes care not to cons in case
  100. ;; of infloop. Maybe we should synch?
  101. (let (parts (start 0))
  102. (while (string-match pattern string start)
  103. (setq parts (cons (substring string start (match-beginning 0)) parts)
  104. start (match-end 0)))
  105. (nreverse (cons (substring string start) parts)))) ))
  106. ;;; customizable variables
  107. (defgroup gnuplot-gui nil
  108. "Graphical interface to setting arguments in gnuplot scrips."
  109. :prefix "gnuplot-gui-"
  110. :group 'gnuplot)
  111. (defcustom gnuplot-gui-popup-flag nil
  112. "*Non-nil means to open arguments pop-ups automatically.
  113. This would be done after menu insertion of Gnuplot commands."
  114. :group 'gnuplot-gui
  115. :type 'boolean)
  116. (defvar gnuplot-gui-frame nil
  117. "Frame used to hold the buffer for setting options.")
  118. (defcustom gnuplot-gui-frame-plist
  119. '(height 18 width 65 border-width 0
  120. user-position t top 150 left 150
  121. internal-border-width 0 unsplittable t
  122. default-toolbar-visible-p nil has-modeline-p nil
  123. menubar-visible-p nil)
  124. "Frame plist for the input run-time display frame in XEmacs."
  125. :type '(repeat (group :inline t
  126. (symbol :tag "Property")
  127. (sexp :tag "Value")))
  128. :group 'gnuplot-gui)
  129. (defcustom gnuplot-gui-frame-parameters
  130. '((height . 18)
  131. (width . 65)
  132. (user-position . t)
  133. (top . 150)
  134. (left . 150)
  135. (border-width . 0)
  136. (menu-bar-lines . 0)
  137. (unsplittable . t))
  138. "Frame parameters for the input run-time display frame in Emacs."
  139. :group 'gnuplot-gui
  140. :type '(repeat (sexp :tag "Parameter:")))
  141. (defcustom gnuplot-gui-fontname-list
  142. '(" " "\"Helvetica\"" "\"Times-Roman\"")
  143. "List of known font names.
  144. These *must* be quoted, like so \"\\\"Helvetica\\\"\". This allows
  145. for fonts with names like \"\\\"Arial Bold Italic\\\"\" to be treated
  146. as single entries in the menu-buttons. And it is really important that
  147. the first entry in the list be a blank string."
  148. :group 'gnuplot-gui
  149. :type '(repeat (string :tag "Font name:")))
  150. ;; some global variables
  151. (defvar gnuplot-current-frame nil)
  152. (defvar gnuplot-current-buffer nil)
  153. (defvar gnuplot-current-buffer-point nil)
  154. (defvar gnuplot-gui-alist nil)
  155. (defvar gnuplot-gui-current-string nil)
  156. ;;; various tools for handling data structures and text in the buffer
  157. ;; tools for accessing the elements of the lists in `gnuplot-gui-all-types'
  158. (defsubst gnuplot-gui-type-tag (obj) (elt obj 0))
  159. (defsubst gnuplot-gui-type-symbol (obj) (elt obj 1))
  160. (defsubst gnuplot-gui-type-default (obj) (elt obj 2))
  161. (defsubst gnuplot-gui-type-prefix (obj) (elt obj 3)) ; also 'range seperator
  162. (defsubst gnuplot-gui-type-fourth (obj) (elt obj 4))
  163. (defsubst gnuplot-gui-type-list (obj) (cddr obj))
  164. (defun gnuplot-this-word ()
  165. "Return the word under point."
  166. (let ((begin (save-excursion (beginning-of-line) (point-marker)))
  167. (end (save-excursion (end-of-line) (point-marker))))
  168. (save-excursion
  169. (or (looking-at "\\<") (= (current-column) 0) (forward-word -1))
  170. (if (> (point) begin) (setq begin (point-marker)))
  171. (forward-word 1)
  172. (if (> (point) end) (goto-char end))
  173. (buffer-substring-no-properties begin (point)))))
  174. ;;; data structures containing regarding options in Gnuplot 3.7
  175. ;; various constants used for options that take the same sorts of arguments
  176. (defconst gnuplot-gui-mtics-list
  177. '(("FREQUENCY" 'number " ")
  178. ("DEFAULT" 'list " " "default")))
  179. (defconst gnuplot-gui-data-list
  180. '(("DATA TYPE" 'list " " "time")))
  181. (defconst gnuplot-gui-label-list
  182. '(("LABEL" 'string " ")
  183. ("POSITION" 'position " " "" 2)
  184. ("FONTNAME" 'list " " gnuplot-gui-fontname-list)
  185. ("FONTSIZE" 'fontsize " ")))
  186. (defconst gnuplot-gui-range-list
  187. '(("RANGE" 'range (" " . " ") ":")
  188. ("REVERSE" 'list " " "reverse" "noreverse")
  189. ("WRITEBACK" 'list " " "writeback" "nowriteback")))
  190. (defconst gnuplot-gui-tics-list
  191. '(("WHERE" 'list " " "axis" "border")
  192. ("MIRROR" 'list " " "mirror" "nomirror")
  193. ("ROTATE" 'list " " "rotate" "norotate")
  194. ("SERIES" 'position " " "" 3)
  195. ("LABEL ARRAY" 'labels () )))
  196. (defconst gnuplot-gui-zeroaxis-list
  197. '(("LINETYPE" 'number " ")))
  198. (defvar gnuplot-gui-terminal-types nil
  199. "Associated list of terminal descriptions.
  200. See the doc-string for `gnuplot-gui-all-types'.")
  201. (setq gnuplot-gui-terminal-types
  202. (list (cons "aifm"
  203. '(("COLOR" 'list " " "monochrome" "gray" "color")
  204. ("FONTNAME" 'list " " gnuplot-gui-fontname-list)
  205. ("FONTSIZE" 'fontsize " ")))
  206. (cons "cgm"
  207. '(("MODE" 'list " " "landscape" "portrait" "default")
  208. ("COLOR" 'list " " "color" "monochrome")
  209. ("ROTATION" 'list " " "rotate" "norotate")
  210. ("WIDTH" 'number " " "width")
  211. ("LINEWIDTH" 'number " " "linewidth")
  212. ("FONTNAME" 'list " " "\"Arial\"" "\"Arial Italic\""
  213. "\"Arial Bold\"" "\"Arial Bold Italic\""
  214. "\"Times Roman\"" "\"Times Roman Italic\""
  215. "\"Times Roman Bold\"" "\"Times Roman Bold Italic\""
  216. "\"Helvetica\"" "\"Roman\"")
  217. ("FONTSIZE" 'fontsize " ")))
  218. (cons "corel"
  219. '(("COLOR" 'list " " "default" "color" "monochrome")
  220. ("FONTNAME" 'list " " "\"SwitzerlandLight\""
  221. "\"Helvetica\"" "\"Times-Roman\"")
  222. ("FONTSIZE " 'number " ")
  223. ("X-SIZE " 'number " ")
  224. ("Y-SIZE " 'number " ")
  225. ("LINEWIDTH" 'number " ")))
  226. (cons "dumb"
  227. '(("LINEFEED" 'list " " "feed" "nofeed")
  228. ("X-SIZE" 'number " ")
  229. ("Y-SIZE" 'number " ")))
  230. (cons "emf"
  231. '(("COLOR" 'list " " "color" "monochrome")
  232. ("LINE" 'list " " "solid" "dashed")
  233. ("FONTNAME" 'string " ")
  234. ("FONTSIZE" 'number " ")))
  235. (cons "emtex"
  236. '(("FONTNAME" 'list " " "courier" "roman")
  237. ("FONTSIZE" 'fontsize " ")))
  238. (cons "fig"
  239. '(("COLOR" 'list " " "color" "monochrome")
  240. ("FRAMESIZE" 'list " " "small" "big")
  241. ("POINTSMAX" 'number " " "pointsmax")
  242. ("ORIENTATION" 'list " " "landscape" "portrait")
  243. ("UNITS" 'list " " "metric" "inches")
  244. ("FONT SIZE" 'number " " "fontsize")
  245. ("SIZE" 'pair (" " . " ") "size")
  246. ("LINE THICKNESS" 'number " " "thickness")
  247. ("LAYER DEPTH" 'number " " "depth")))
  248. (cons "hp500c"
  249. '(("RESOLUTION" 'list " " "75" "100" "150" "300")
  250. ("COMPRESSION" 'list " " "rle" "tiff")))
  251. (cons "hpgl"
  252. '(("PENS" 'number " ")
  253. ("EJECT" 'list " " "eject")))
  254. (cons "hpdj"
  255. '(("RESOLUTION" 'list " " "75" "100" "150" "300")))
  256. (cons "hpljii"
  257. '(("RESOLUTION" 'list " " "75" "100" "150" "300")))
  258. (cons "hppj"
  259. '(("FONT" 'list " " "FNT9X17" "FNT5X9" "FNT13X25")))
  260. (cons "imagen"
  261. '(("FONT SIZE" 'number " ")
  262. ("LAYOUT" 'list " " "portrait" "landscape")
  263. ("NUMBER OF GRAPHS" 'range (" " . " ") ",")))
  264. (cons "gpic"
  265. '(("X ORIGIN" 'number " ")
  266. ("Y ORIGIN" 'number " " ",")))
  267. (cons "latex"
  268. '(("FONTNAME" 'list " " "courier" "roman")
  269. ("FONTSIZE" 'fontsize " ")))
  270. (cons "mif"
  271. '(("COLOUR" 'list " " "colour" "monochrome")
  272. ("LINETYPE" 'list " " "polyline" "vectors")))
  273. (cons "nec-cp6"
  274. '(("MODE" 'list " " "monochrome" "colour" "draft")))
  275. (cons "pbm"
  276. '(("SIZE" 'list " " "small" "medium" "large")
  277. ("COLOR" 'list " " "monochrome" "gray" "color")))
  278. (cons "pcl5L"
  279. '(("MODE" 'list " " "landscape" "portrait")
  280. ("FONTNAME" 'list " " "stick" "univers" "cg_times")
  281. ("FONTSIZE" 'fontsize " ")))
  282. (cons "png"
  283. '(("SIZE" 'list " " "small" "medium" "large")
  284. ("COLOR" 'list " " "monochrome" "gray" "color")))
  285. (cons "postscript"
  286. '(("MODE" 'list " " "landscape" "portrait" "eps" "default")
  287. ("ENHANCED" 'list " " "enhanced" "noenhanced")
  288. ("COLOR" 'list " " "color" "monochrome")
  289. ("SOLID" 'list " " "solid" "dashed")
  290. ("DUPLEXING" 'list " " "defaultplex" "simplex" "duplex")
  291. ("FONTNAME" 'list " " gnuplot-gui-fontname-list)
  292. ("FONTSIZE" 'fontsize " ")))
  293. (cons "pslatex"
  294. '(("COLOR" 'list " " "monochrome" "color")
  295. ("DASHED" 'list " " "dashed")
  296. ("ROTATION" 'list " " "rotate" "norotate")
  297. ("AUXFILE" 'list " " "auxfile")))
  298. (cons "pstex"
  299. '(("COLOR" 'list " " "monochrome" "color")
  300. ("DASHED" 'list " " "dashed")
  301. ("ROTATION" 'list " " "rotate" "norotate")
  302. ("AUXFILE" 'list " " "auxfile")))
  303. (cons "pstricks"
  304. '(("HACK TEXT" 'list " " "hacktext" "nohacktext")
  305. ("PLOT SCALING" 'list " " "nounit" "unit")))
  306. (cons "regis"
  307. '(("COLOR DEPTH" 'list "4" "16")))
  308. (cons "tgif"
  309. '(("LAYOUT" 'list " " "portrait" "landscape")
  310. ("NUMBER OF GRAPHS" 'range (" " . " ") ",")
  311. ("LINE TYPE" 'list " " "solid" "dashed")
  312. ("FONTNAME" 'list " " gnuplot-gui-fontname-list)
  313. ("FONTSIZE" 'fontsize " ")))
  314. (cons "tpic"
  315. '(("POINTSIZE" 'number " ")
  316. ("LINEWIDTH" 'number " ")
  317. ("INTERVAL " 'number " ")))
  318. (cons "vgagl" ; for pm3d patch (also persist, raise in x11) <MT>
  319. '(("BACKGROUND" 'position " " "background" 3)
  320. ("INTERPOLATION" 'list " " "uniform" "interpolate")
  321. ("DUMP" 'file " ")
  322. ("MODE" 'string " " "")))
  323. (cons "x11"
  324. '(("RESET" 'list " " "reset")
  325. ("TERMINAL NUMBER" 'number " ")
  326. ("PERSIST" 'list " " "persist" "nopersist")
  327. ("RAISE" 'list " " "raise" "noraise"))) ))
  328. (defvar gnuplot-gui-terminal-list nil)
  329. (setq gnuplot-gui-terminal-list
  330. (append (list " ") (mapcar 'car gnuplot-gui-terminal-types)))
  331. (defvar gnuplot-gui-set-types nil
  332. "Associated list of set option descriptions.
  333. See the doc-string for `gnuplot-gui-all-types'.")
  334. (setq gnuplot-gui-set-types
  335. (list (cons "angles"
  336. '(("UNITS" 'list " " "degrees" "radians")))
  337. (cons "arrow"
  338. '(("TAG" 'tag " ")
  339. ("FROM" 'position " " "from" 3)
  340. ("TO" 'position " " "to" 3)
  341. ("HEAD" 'list " " "head" "nohead")
  342. ("LINESTYLE" 'number " " "ls")
  343. ("LINETYPE " 'number " " "lt")
  344. ("LINEWIDTH" 'number " " "lw")))
  345. (cons "noarrow"
  346. '(("TAG" 'tag " ")))
  347. (cons "autoscale"
  348. '(("AXIS" 'list " " "x" "y" "z" "x2" "y2" "xy"
  349. "xmin" "ymin" "zmin" "x2min" "y2min" "xymin"
  350. "xmax" "ymax" "zmax" "x2max" "y2max" "xymax")))
  351. (cons "noautoscale"
  352. '(("AXIS" 'list " " "x" "y" "z" "x2" "y2" "xy"
  353. "xmin" "ymin" "zmin" "x2min" "y2min" "xymin"
  354. "xmax" "ymax" "zmax" "x2max" "y2max" "xymax")))
  355. (cons "bar"
  356. '(("SIZE" 'list " " "small" "large")))
  357. (cons "border"
  358. '(("BORDER CODE" 'number " ")
  359. ("LINE STYLE" 'list " " "lines"
  360. "dots" "points" "linespoints")
  361. ("LINESTYLE" 'number " " "ls")
  362. ("LINETYPE" 'number " " "lt")
  363. ("LINEWIDTH" 'number " " "lw")
  364. ))
  365. (cons "boxwidth"
  366. '(("WIDTH" 'number " ")))
  367. (cons "clabel"
  368. '(("FORMAT" 'format " ")))
  369. (cons "clip"
  370. '(("CLIP TYPE" 'list " " "points" "one" "two")))
  371. (cons "noclip"
  372. '(("CLIP TYPE" 'list " " "points" "one" "two")))
  373. ;;(cons "cntrparam"
  374. ;; '(("INTERPOLATION" 'list " " "linear" "cubicspline" "bspline")
  375. ;; ("POINTS" 'number " " "points")
  376. ;; ("ORDER" 'number " " "order")))
  377. (cons "contour"
  378. '(("WHERE" 'list " " "base" "surface" "both")))
  379. (cons "dgrid3d"
  380. '(("ROW,COLUMN,NORM" 'position " " "" 3)))
  381. (cons "encoding"
  382. '(("ENCODING" 'list " " "default" "iso_8859_1"
  383. "cp850" "cp437")))
  384. (cons "format"
  385. '(("AXIS" 'list " " "x" "y" "z" "xy" "x2" "y2")
  386. ("FORMAT" 'format " ")))
  387. (cons "dummy"
  388. '(("VAR 1" 'string " " "")
  389. ("VAR 2" 'string " " ",")))
  390. (cons "grid"
  391. '(("XTICS" 'list " " "xtics" "mxtics" "noxtics" "nomxtics")
  392. ("YTICS" 'list " " "ytics" "mytics" "noytics" "nomytics")
  393. ("ZTICS" 'list " " "ztics" "mztics" "noztics" "nomztics")
  394. ("X2TICS" 'list " " "x2tics" "mx2tics" "nox2tics" "nomx2tics")
  395. ("Y2TICS" 'list " " "y2tics" "my2tics" "noy2tics" "nomy2tics")
  396. ("POLAR" 'number " " "polar")
  397. ("MAJOR LINETYPE" 'number " ")
  398. ("MINOR LINETYPE" 'number " ")))
  399. (cons "hidden3d"
  400. '(("ALGORITHM" 'list " " "defaults"
  401. "offset"
  402. "nooffset"
  403. ;;"trianglepattern # bitpattern between 0 and 7"
  404. "trianglepattern 0" "trianglepattern 1"
  405. "trianglepattern 2" "trianglepattern 3"
  406. "trianglepattern 4" "trianglepattern 5"
  407. "trianglepattern 6" "trianglepattern 7"
  408. ;;"undefined # level between 0 and 3"
  409. "undefined 0" "undefined 1" "undefined 2" "undefined 3"
  410. "noundefined" "altdiagonal" "noaltdiagonal"
  411. "bentover" "nobentover")))
  412. (cons "historysize"
  413. '(("SIZE" 'number " ")))
  414. (cons "isosamples"
  415. '(("ISO_U LINES" 'number " ")
  416. ("ISO_V LINES" 'number " " ",")))
  417. (cons "key"
  418. '(("LOCATION" 'list " " "left" "right" "top" "bottom"
  419. "outside" "below")
  420. ("POSITION" 'position " " "" 3)
  421. ("JUSTIFICATION" 'list " " "Left" "Right")
  422. ("REVERSE" 'list " " "reverse" "noreverse")
  423. ("SAMPLE LENGTH" 'number " " "samplen")
  424. ("SPACING" 'number " " "spacing")
  425. ("WIDTH" 'number " " "width")
  426. ("TITLE" 'string " " "title ")
  427. ("BOX LINETYPE" 'number " " "box") ;; linetype data
  428. ("NOBOX" 'list " " "nobox")))
  429. (cons "label"
  430. '(("TAG" 'tag " ")
  431. ("LABEL TEXT" 'string " ")
  432. ("POSITION" 'position " " "at" 3)
  433. ;; first, second, graph, screen
  434. ("JUSTIFICATION" 'list " " "left" "right" "center")
  435. ("ROTATE" 'list " " "rotate" "norotate")
  436. ("FONT" 'string " " "font"))) ;; font "name,size"
  437. (cons "nolabel"
  438. '(("TAG" 'tag " ")))
  439. (cons "linestyle"
  440. '(("TAG " 'tag " ")
  441. ("LINE STYLE" 'list " " "boxerrorbars" "boxes"
  442. "boxxyerrorbars" "candlesticks" "dots"
  443. "financebars" "fsteps" "histeps" "impulses"
  444. "lines" "linespoints" "points" "steps" "vector"
  445. "xerrorbars" "xyerrorbars" "yerrorbars")
  446. ("LINETYPE " 'number " " "lt")
  447. ("LINEWIDTH" 'number " " "lw")
  448. ("POINTTYPE" 'number " " "pt")
  449. ("POINTSIZE" 'number " " "ps")))
  450. (cons "locale"
  451. '(("LOCALE" 'string " ")))
  452. (cons "logscale"
  453. '(("AXIS" 'list " " "x" "y" "z" "xy" "xz" "yz" "xyz"
  454. "x2" "y2")
  455. ("BASE" 'number " ")))
  456. (cons "nologscale"
  457. '(("AXIS" 'list " " "x" "y" "z" "xy" "xz" "yz" "xyz"
  458. "x2" "y2")))
  459. (cons "mapping"
  460. '(("COORDINATE SYSTEM" 'list " " "cartesian" "spherical"
  461. "cylindrical")))
  462. ; _margin
  463. (cons "bmargin"
  464. '(("BOTTOM MARGIN" 'number " ")))
  465. (cons "lmargin"
  466. '(("LEFT MARGIN" 'number " ")))
  467. (cons "rmargin"
  468. '(("RIGHT MARGIN" 'number " ")))
  469. (cons "tmargin"
  470. '(("TOP MARGIN" 'number " ")))
  471. (cons "missing"
  472. '(("CHARACTER" 'string " " 1)))
  473. ; m_tics
  474. (cons "mxtics" gnuplot-gui-mtics-list)
  475. (cons "mytics" gnuplot-gui-mtics-list)
  476. (cons "mztics" gnuplot-gui-mtics-list)
  477. (cons "mx2tics" gnuplot-gui-mtics-list)
  478. (cons "my2tics" gnuplot-gui-mtics-list)
  479. ; pm3d additions <MT>
  480. (cons "mouse"
  481. '(("DOUBLECLICK" 'number " " "doubleclick")
  482. ("ZOOM" 'list " " "zoomcoordinates" "nozoomcoordinates")
  483. ("POLAR" 'list " " "polarcoordinates" "nopolarcoordinates")
  484. ("FORMAT" 'string " " "format")
  485. ("CLIPBOARDFORMAT" 'string " " "clipboardformat")
  486. ("MOUSEFORMAT" 'string " " "mouseformat")
  487. ("LABELS" 'list " " "labels" "nolabels")
  488. ("LABELOPTIONS" 'string " " "labeloptions")
  489. ("ZOOMJUMP" 'list " " "zoomjump" "nozoomjump")
  490. ("VERBOSE" 'list " " "verbose" "noverbose")))
  491. (cons "palette"
  492. '(("COLOR" 'list " " "gray" "color")
  493. ("RGBFORMULAE" 'position " " "rgbformulae" 3)
  494. ("PARITY" 'list " " "positive" "negative")
  495. ("FORMULAE" 'list " " "nops_allcF" "ps_allcF")
  496. ("MAXCOLORS" 'number " ")
  497. ("COLOR_BOX" 'list " " "nocb" "cbdefault" "cbuser")
  498. ("ORIENTATION" 'list " " "cbvertical" "cbhorizontal")
  499. ("ORIGIN" 'position " " "origin" 2)
  500. ("SIZE" 'position " " "size" 2)
  501. ("BORDER" 'number " ")
  502. ("NOBORDER" 'list " " "bdefault" "noborder")))
  503. (cons "pm3d"
  504. '(("AT" 'list* " " "b" "s" "t" "bs" "bt" "st" "bst")
  505. ("SCANS" 'list " " "scansautomatic" "scansforward" "scansbackward")
  506. ("FLUSH" 'list* " " "begin" "center" "end")
  507. ("CLIP" 'list " " "clip1in" "clip4in")
  508. ("ZRANGE" 'range (" " . " ") ":")
  509. ("HIDDEN3D" 'number " ")
  510. ("NOHIDDEN3D" 'list " " "nohidden3d")
  511. ("FILLING" 'list " " "transparent" "solid")
  512. ("MAP" 'list " " "map")))
  513. (cons "offsets"
  514. '(("LEFT " 'number " ")
  515. ("RIGHT " 'number " " ",")
  516. ("TOP " 'number " " ",")
  517. ("BOTTOM" 'number " " ",")))
  518. (cons "origin"
  519. '(("X ORIGIN" 'number " ")
  520. ("Y ORIGIN" 'number " " ",")))
  521. (cons "output"
  522. '(("FILENAME" 'file " ")))
  523. (cons "pointsize"
  524. '(("MULTIPLIER" 'number " ")))
  525. (cons "samples"
  526. '(("2D PLOT" 'number " ")
  527. ("3D PLOT" 'number " " ",")))
  528. (cons "size"
  529. '(("ASPECT" 'list " " "square" "nosquare"
  530. "ratio" "noratio")
  531. ("X-SCALE OR RATIO" 'number " ")
  532. ("Y-SCALE" 'number " " ",")))
  533. (cons "style"
  534. '(("DATA TYPE" 'list " " "data" "function")
  535. ("PLOT STYLE" 'list " " "boxerrorbars" "boxes"
  536. "boxxyerrorbars" "candlesticks" "dots"
  537. "financebars" "fsteps" "histeps" "impulses"
  538. "lines" "linespoints" "points" "steps" "vector"
  539. "xerrorbars" "xyerrorbars" "yerrorbars")))
  540. (cons "terminal"
  541. '(("TERMINAL TYPE" 'list " " gnuplot-gui-terminal-list)))
  542. (cons "tics"
  543. '(("DIRECTION" 'list " " "in" "out")))
  544. (cons "ticslevel"
  545. '(("RELATIVE HEIGHT" 'number " ")))
  546. (cons "ticscale"
  547. '(("MAJOR" 'number " ")
  548. ("MINOR" 'number " ")))
  549. (cons "timestamp"
  550. '(("FORMAT STRING" 'format " ")
  551. ("WHERE" 'list " " "top" "bottom")
  552. ("ROTATE" 'list " " "rotate" "norotate")
  553. ("X-OFFSET" 'number " ")
  554. ("Y-OFFSET" 'number " " ",")
  555. ("FONTNAME" 'list " " gnuplot-gui-fontname-list)))
  556. (cons "timefmt"
  557. '(("FORMAT STRING" 'string " ")))
  558. (cons "title"
  559. '(("TITLE" 'string " ")))
  560. (cons "view"
  561. '(("X-ROTATION" 'number " ")
  562. ("Z-ROTATION" 'number " " ",")
  563. ("SCALE" 'number " " ",")
  564. ("Z-SCALE" 'number " " ",")))
  565. ;; ("SCALE" 'position " " "," 4)
  566. ; _data
  567. (cons "xdata" gnuplot-gui-data-list)
  568. (cons "ydata" gnuplot-gui-data-list)
  569. (cons "zdata" gnuplot-gui-data-list)
  570. (cons "x2data" gnuplot-gui-data-list)
  571. (cons "y2data" gnuplot-gui-data-list)
  572. ; _label
  573. (cons "xlabel" gnuplot-gui-label-list)
  574. (cons "ylabel" gnuplot-gui-label-list)
  575. (cons "zlabel" gnuplot-gui-label-list)
  576. (cons "x2label" gnuplot-gui-label-list)
  577. (cons "y2label" gnuplot-gui-label-list)
  578. ; _range, note that the [] syntax for
  579. ; the writeback argument is
  580. ; not properly supported
  581. (cons "xrange" gnuplot-gui-range-list)
  582. (cons "yrange" gnuplot-gui-range-list)
  583. (cons "zrange" gnuplot-gui-range-list)
  584. (cons "x2range" gnuplot-gui-range-list)
  585. (cons "y2range" gnuplot-gui-range-list)
  586. (cons "trange" gnuplot-gui-range-list)
  587. (cons "rrange" gnuplot-gui-range-list)
  588. (cons "urange" gnuplot-gui-range-list)
  589. (cons "vrange" gnuplot-gui-range-list)
  590. ; _tics
  591. (cons "xtics" gnuplot-gui-tics-list)
  592. (cons "ytics" gnuplot-gui-tics-list)
  593. (cons "ztics" gnuplot-gui-tics-list)
  594. (cons "x2tics" gnuplot-gui-tics-list)
  595. (cons "y2tics" gnuplot-gui-tics-list)
  596. ; zeroaxis
  597. (cons "zeroaxis" gnuplot-gui-zeroaxis-list)
  598. (cons "xzeroaxis" gnuplot-gui-zeroaxis-list)
  599. (cons "yzeroaxis" gnuplot-gui-zeroaxis-list)
  600. (cons "y2zeroaxis" gnuplot-gui-zeroaxis-list)
  601. (cons "x2zeroaxis" gnuplot-gui-zeroaxis-list)
  602. (cons "zero"
  603. '(("THRESHOLD" 'number " ")))
  604. ))
  605. (defvar gnuplot-gui-command-types nil
  606. "Associated list of command descriptions.
  607. See the doc-string for `gnuplot-gui-all-types'.")
  608. (setq gnuplot-gui-command-types
  609. (list (cons "cd"
  610. '(("FILENAME" 'file " ")))
  611. (cons "call"
  612. '(("INPUT FILE" 'file " ")
  613. ("PARAMETER LIST" 'string " ")))
  614. (cons "load"
  615. '(("INPUT FILE" 'file " ")))
  616. (cons "pause"
  617. '(("TIME" 'number " ")
  618. ("MESSAGE" 'string " ")))
  619. (cons "print"
  620. '(("EXPRESSION" 'string " ")))
  621. (cons "save"
  622. '(("SAVE" 'list " " "functions" "variables" "set")
  623. ("FILE" 'file " ")))
  624. (cons "update"
  625. '(("INITIAL FILE" 'file " " t)
  626. ("UPDATED FILE" 'file " " t))) ))
  627. (defcustom gnuplot-gui-plot-splot-fit-style 'simple
  628. "Control the complexity of the GUI display for plot, splot, and fit.
  629. The values are 'simple, which causes a limited set of plot, splot, or
  630. fit options to be displayed, and 'complete, which attempts to display
  631. all options. The 'complete setting is prone to making errors when
  632. parsing values already in the script buffer."
  633. :group 'gnuplot-gui
  634. :type '(radio (const :tag "Simple listing" simple)
  635. (const :tag "Complete listing" complete)))
  636. (defconst gnuplot-gui-plot-simple-list
  637. '(("X RANGE" 'range (" " . " ") ":")
  638. ("Y RANGE" 'range (" " . " ") ":")
  639. ("DATA FILE" 'file " ")
  640. ("THRU" 'string* " " "thru")
  641. ("USING" 'modifier " ")
  642. ("TITLE" 'string " ")
  643. ("WITH" 'list* " " "boxerrorbars" "boxes"
  644. "boxxyerrorbars" "candlesticks" "dots" "financebars"
  645. "fsteps" "histeps" "impulses" "lines" "linespoints"
  646. "points" "steps" "vector" "xerrorbars" "xyerrorbars"
  647. "yerrorbars")))
  648. (defconst gnuplot-gui-plot-full-list
  649. '(;;("T RANGE" 'range (" " . " ") ":")
  650. ("X RANGE" 'range (" " . " ") ":")
  651. ("Y RANGE" 'range (" " . " ") ":")
  652. ("xa" 'text "\t---------------------")
  653. ("FUNCTION" 'string " ")
  654. ("xc" 'text " or")
  655. ("DATA FILE" 'file " ")
  656. ("INDEX" 'modifier " ")
  657. ("EVERY" 'modifier " ")
  658. ("THRU" 'string* " " "thru")
  659. ("USING" 'modifier " ")
  660. ("SMOOTH" 'list* " " "unique" "csplines" "acsplines"
  661. "bezier" "sbezier")
  662. ;; datafile modifiers
  663. ("AXES" 'list* " " "x1y1" "x2y2" "x1y2" "x2y1")
  664. ("TITLE" 'string " ")
  665. ("NOTITLE" 'list " " "notitle")
  666. ("xf" 'text "\t---------------------")
  667. ("xi" 'text "Select a standard plotting style")
  668. ("WITH" 'list* " " "boxerrorbars" "boxes"
  669. "boxxyerrorbars" "candlesticks" "dots" "financebars"
  670. "fsteps" "histeps" "impulses" "lines" "linespoints"
  671. "points" "steps" "vector" "xerrorbars" "xyerrorbars"
  672. "yerrorbars")
  673. ("xo" 'text " or a previously defined style")
  674. ("LINE STYLE " 'number " " "ls")
  675. ("xr" 'text " or specify a style in-line")
  676. ("LINE TYPE " 'number " " "lt")
  677. ("LINE WIDTH " 'number " " "lw")
  678. ("POINT TYPE " 'number " " "pt")
  679. ("POINT STYLE" 'number " " "ps")
  680. ))
  681. (defconst gnuplot-gui-splot-simple-list
  682. '(("DATA FILE" 'file " ")
  683. ("TITLE" 'string " ")
  684. ("WITH" 'list* " " "lines" "linespoints" "points" "dots" "impulses")))
  685. (defconst gnuplot-gui-splot-full-list
  686. '(;;("U RANGE" 'range (" " . " ") ":")
  687. ;;("V RANGE" 'range (" " . " ") ":")
  688. ("X RANGE" 'range (" " . " ") ":")
  689. ("Y RANGE" 'range (" " . " ") ":")
  690. ("Z RANGE" 'range (" " . " ") ":")
  691. ("xa" 'text "\t---------------------")
  692. ("FUNCTION" 'string " ")
  693. ("xc" 'text " or")
  694. ("DATA FILE" 'file " ")
  695. ("INDEX" 'modifier " ")
  696. ("EVERY" 'modifier " ")
  697. ("THRU" 'string* " " "thru")
  698. ("USING" 'modifier " ")
  699. ("SMOOTH" 'list* " " "unique" "csplines" "acsplines"
  700. "bezier" "sbezier")
  701. ("TITLE" 'string " ")
  702. ("NOTITLE" 'list " " "notitle")
  703. ("WITH" 'list* " " "lines" "linespoints" "points" "dots" "impulses")))
  704. (defconst gnuplot-gui-fit-simple-list
  705. '(("FUNCTION" 'string* " " "")
  706. ("DATA FILE" 'file " ")
  707. ("VIA (params)" 'string* " " "via") ))
  708. (defconst gnuplot-gui-fit-full-list
  709. '(("X RANGE" 'range (" " . " ") ":")
  710. ("Y RANGE" 'range (" " . " ") ":")
  711. ("xa" 'text "----- fitting functionn and file --------")
  712. ("FUNCTION" 'string* " " "")
  713. ("DATA FILE" 'file " ")
  714. ("xb" 'text "----- datafile modifiers ----------------")
  715. ("INDEX" 'modifier " ")
  716. ("EVERY" 'modifier " ")
  717. ("THRU" 'string* " " "thru")
  718. ("USING" 'modifier " ")
  719. ("SMOOTH" 'list* " " "unique" "csplines" "acsplines"
  720. "bezier" "sbezier")
  721. ("xc" 'text "----- parameters (file or parameters) ---")
  722. ("VIA (file)" 'string " " "via")
  723. ("VIA (params)" 'string* " " "via") ))
  724. (defvar gnuplot-gui-plot-splot-fit nil
  725. "Associated list of plot, splot, and fit descriptions.
  726. See the doc-string for `gnuplot-gui-all-types'.")
  727. (setq gnuplot-gui-plot-splot-fit
  728. (list (cons "plot" (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
  729. gnuplot-gui-plot-full-list
  730. gnuplot-gui-plot-simple-list))
  731. (cons "splot" (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
  732. gnuplot-gui-splot-full-list
  733. gnuplot-gui-splot-simple-list))
  734. (cons "fit" (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
  735. gnuplot-gui-fit-full-list
  736. gnuplot-gui-fit-simple-list))) )
  737. (defvar gnuplot-gui-test-type nil)
  738. (setq gnuplot-gui-test-type
  739. (list (cons "test"
  740. '(("TAG" 'tag " ")
  741. ("LIST" 'list " " "1" "2" "3")
  742. ("LIST*" 'list* " " "1" "2" "3")
  743. ("NUMBER" 'number " " "number")
  744. ("RANGE" 'range (" " . " ") ":")
  745. ("PAIR" 'pair (" " . " ") "pair")
  746. ("LABELS" 'labels ())
  747. ("FILE" 'file " ")
  748. ("TEXT" 'text "this is text")
  749. ("STRING" 'string " ")
  750. ("STRING*" 'string* " " "string*")
  751. ("FORMAT" 'format " ")
  752. ("POSITION" 'position " " "at" 3)
  753. ("FONTSIZE" 'fontsize " ") ))))
  754. (defvar gnuplot-gui-all-types nil
  755. "Associated list of terminal, set option, and command arguments.
  756. Each entry in the list is a cons cell of the form
  757. (OPTION . ALIST)
  758. where OPTION is one of the recognized options in Gnuplot, either a
  759. command, something that is set, or a terminal type. Only those
  760. commands, set options, and terminal types that actually take arguments
  761. are in this associated list.
  762. ALIST is itself an associated list where each entry is of the form:
  763. (TAG TYPE DEFAULT REST)
  764. TAG is the name used on the widget and indicates one of the options
  765. for this command, set option, or terminal type.
  766. TYPE is one of
  767. 'list a menu-list of strings
  768. 'list* a menu-list of strings with a prefix
  769. 'number a number with an optional prefix
  770. 'tag like number but must be the first argument
  771. 'fontsize like number but must be the last argument
  772. 'range a pair of numbers like [#,#] or [#:#]
  773. 'pair a pair of numbers with no punctuation and a prefix
  774. 'file a quoted string and a file browser
  775. 'string a quoted string with an optional prefix
  776. 'string* an unquoted string with a prefix
  777. 'format a quoted string and an info-link to (gnuplot)format
  778. 'labels an array as needed for xtics, ytics, etc
  779. 'position 2 or 3 comma separated numbers with an optional prefix
  780. DEFAULT is the default value for this option. Note that the default
  781. for 'range and 'pair is a cons cell and the default for 'labels is a
  782. list. For most things, the best choice of DEFAULT is a string of
  783. white space or a cons cell of two strings of white space. Strings of
  784. white space are better defaults than empty strings or nil.
  785. The value of REST depends upon TYPE:
  786. For 'list & REST is the list of options that will go into the
  787. 'list* menu-button. This can also be a symbol which
  788. evaluates to a list containing the options to go into
  789. the menu-button. This list variable must contain the
  790. DEFAULT.
  791. For 'number REST is the prefix string (if it exists) for that number.
  792. For 'range REST is the separator, \":\" for plot ranges and
  793. \",\" for plot dimensions (see for example the tgif
  794. terminal type)
  795. For 'string & REST may a number denoting the width of the editable-text
  796. 'string* field or it may be a string denoting a prefix. By
  797. default, the width is half the width of the frame
  798. and there is no prefix. It may be useful to
  799. specify \"1\" when the input is a single character
  800. as in 'set missing'.
  801. For 'file REST determines the label placed before the file insertion
  802. field. If non-nil, then TAG is used. If nil, then
  803. the default \"File\" is used.
  804. For 'position REST is the prefix and the number of comma separated numbers
  805. For others REST is not used.
  806. Here is an example entry for the png terminal type:
  807. (cons \"png\"
  808. '((\"SIZE\" 'list \" \" \"small\" \"medium\" \"large\")
  809. (\"COLOR\" 'list \" \" \"monochrome\" \"gray\" \"color\")))
  810. This alist is formed at load time by appending together
  811. `gnuplot-gui-terminal-types', `gnuplot-gui-set-types' and
  812. `gnuplot-gui-command-types'.")
  813. (setq gnuplot-gui-all-types (append gnuplot-gui-terminal-types
  814. gnuplot-gui-set-types
  815. gnuplot-gui-command-types
  816. gnuplot-gui-plot-splot-fit
  817. gnuplot-gui-test-type
  818. ))
  819. (defun gnuplot-gui-swap-simple-complete ()
  820. (interactive)
  821. (setq gnuplot-gui-plot-splot-fit-style
  822. (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
  823. 'simple 'complete))
  824. (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
  825. (progn
  826. (setcdr (assoc "plot" gnuplot-gui-all-types) gnuplot-gui-plot-full-list)
  827. (setcdr (assoc "splot" gnuplot-gui-all-types) gnuplot-gui-splot-full-list)
  828. (setcdr (assoc "fit" gnuplot-gui-all-types) gnuplot-gui-fit-full-list))
  829. (setcdr (assoc "plot" gnuplot-gui-all-types) gnuplot-gui-plot-simple-list)
  830. (setcdr (assoc "splot" gnuplot-gui-all-types) gnuplot-gui-splot-simple-list)
  831. (setcdr (assoc "fit" gnuplot-gui-all-types) gnuplot-gui-fit-simple-list))
  832. (message "Using %s lists for plot, splot, and fit."
  833. gnuplot-gui-plot-splot-fit-style) )
  834. ;;; user interface to the widget-y stuff
  835. (defun gnuplot-gui-mouse-set (event)
  836. "Use the mouse to begin setting options using a GUI interface.
  837. EVENT is a mouse event. Bound to \\[gnuplot-gui-mouse-set]
  838. Note that \"plot\", \"splot\", \"fit\", and \"cntrparam\" are not
  839. currently supported."
  840. (interactive "@e")
  841. (when (fboundp 'widget-create)
  842. (save-excursion
  843. (mouse-set-point event)
  844. (gnuplot-gui-set-options-and-insert))))
  845. (defun gnuplot-gui-get-frame-param (param)
  846. (if gnuplot-xemacs-p
  847. (plist-get gnuplot-gui-frame-plist param)
  848. (cdr (assoc param gnuplot-gui-frame-parameters))))
  849. (defun gnuplot-gui-set-frame-param (param value)
  850. (if gnuplot-xemacs-p
  851. (plist-put gnuplot-gui-frame-plist param value)
  852. (setcdr (assoc param gnuplot-gui-frame-parameters) value)))
  853. (defun gnuplot-gui-set-options-and-insert ()
  854. "Insert arguments using a GUI interface.
  855. Determine contents of current line and set up the appropriate GUI
  856. frame. Bound to \\[gnuplot-gui-set-options-and-insert]
  857. Note that \"cntrparam\" is not currently supported."
  858. (interactive)
  859. (when (fboundp 'widget-create)
  860. (let ((begin (save-excursion (beginning-of-line) (point-marker)))
  861. (end (save-excursion (end-of-line) (point-marker)))
  862. (termin (concat "\\(,\\s-*" (regexp-quote "\\") "\\|;\\)"))
  863. (set nil) (term nil))
  864. (save-excursion
  865. ;; there can be more then one command per line
  866. (if (search-backward ";" begin "to_limit")
  867. (progn (forward-char 1) (setq begin (point-marker))))
  868. (if (re-search-forward termin end "to_limit")
  869. (progn (backward-char (length (match-string 1)))
  870. (setq end (point-marker))))
  871. (goto-char begin)
  872. (skip-syntax-forward "-" end)
  873. ;; various constructions are recognized here. at the end of this
  874. ;; cond, point should be just after the word whose arguments are
  875. ;; to be set
  876. (cond ((looking-at "set\\s-+")
  877. (setq set t)
  878. (goto-char (match-end 0))
  879. (if (looking-at "\\sw+") (goto-char (match-end 0)))
  880. (when (string-match "^ter" (gnuplot-this-word)) ; terminal?
  881. (setq term t)
  882. (forward-word 1))
  883. (when (string-match "^\\(da\\|fu\\)" (gnuplot-this-word))
  884. (unless (looking-at "\\s-+st")
  885. (insert " style") (forward-word 1))
  886. (forward-word 1)))
  887. ((looking-at (concat "\\(cd\\|ca\\|lo\\|pa\\|pr\\|sa\\|u\\)"
  888. "\\w*"
  889. "[\\s-\\']"))
  890. (forward-word 1))
  891. ;;(goto-char (match-end 0)))
  892. (t
  893. (forward-word 1)))
  894. (if (> (point) end) (goto-char end))
  895. (let* ((w (gnuplot-this-word))
  896. (wd (try-completion w gnuplot-gui-all-types))
  897. (word "") wrd list)
  898. (cond ((equal wd t) (setq word w))
  899. ((equal wd nil) (setq word w))
  900. ((assoc wd gnuplot-gui-all-types) (setq word wd))
  901. (t (setq wd nil)))
  902. (cond ((equal (string-match "^\\s-*$" w) 0)
  903. (message "Blank line"))
  904. ((and wd (stringp word))
  905. (gnuplot-gui-correct-command word set term begin)
  906. (setq gnuplot-gui-alist nil
  907. gnuplot-gui-current-string
  908. (buffer-substring-no-properties (point) end))
  909. (gnuplot-gui-set-alist word gnuplot-gui-current-string)
  910. (let* ((old-height (gnuplot-gui-get-frame-param 'height))
  911. (old-top (gnuplot-gui-get-frame-param 'top)))
  912. (when (or
  913. (and (equal gnuplot-gui-plot-splot-fit-style 'complete)
  914. (member* word '("plot" "splot" "fit")
  915. :test 'string=))
  916. (equal word "test"))
  917. (gnuplot-gui-set-frame-param 'height 32)
  918. (gnuplot-gui-set-frame-param 'top 50))
  919. (gnuplot-gui-prompt-for-frame word)
  920. (when (or
  921. (and (equal gnuplot-gui-plot-splot-fit-style 'complete)
  922. (member* word '("plot" "splot" "fit")
  923. :test 'string=))
  924. (equal word "test"))
  925. (gnuplot-gui-set-frame-param 'height old-height)
  926. (gnuplot-gui-set-frame-param 'top old-top)) ))
  927. ((setq wrd (car (all-completions w '(("cntrparam")))))
  928. (message
  929. "Setting arguments for %S is currently unsuported in gnuplot-mode"
  930. wrd))
  931. ((setq list (all-completions w gnuplot-gui-all-types))
  932. (message "%S could be one of %S" w list))
  933. (t
  934. (message
  935. "%S is not a gnuplot command which takes options" w)))) ))))
  936. (defun gnuplot-gui-toggle-popup ()
  937. (interactive)
  938. (setq gnuplot-gui-popup-flag (not gnuplot-gui-popup-flag))
  939. (message (if gnuplot-gui-popup-flag
  940. "Argument popup will appear after insertions."
  941. "Argument popup will no longer appear after insertions.")))
  942. (defun gnuplot-gui-y-n (foo))
  943. (if gnuplot-xemacs-p
  944. (defalias 'gnuplot-gui-y-n 'y-or-n-p-maybe-dialog-box)
  945. (defalias 'gnuplot-gui-y-n 'y-or-n-p))
  946. (defun gnuplot-gui-correct-command (word set term begin)
  947. "Check syntax of set command and terminal specifications.
  948. WORD is the item being set. SET and TERM are non-nil if the words
  949. \"set\" and \"terminal\" were found preceding WORD in the buffer.
  950. BEGIN is the beginning of the command."
  951. (save-excursion
  952. (cond ((assoc word gnuplot-gui-terminal-types)
  953. (when (and (not (and set term))
  954. (gnuplot-gui-y-n
  955. (format
  956. "%S must be preceded by \"set terminal\". Add it? "
  957. word)))
  958. (backward-word 1)
  959. (let ((e (point-marker)))
  960. (goto-char begin)
  961. (skip-syntax-forward "-" e)
  962. (delete-region (point) e)
  963. (insert "set terminal "))))
  964. ((assoc word gnuplot-gui-set-types)
  965. (when (and (not set)
  966. (gnuplot-gui-y-n
  967. (format
  968. "%S must be preceded by \"set\". Add \"set\"? " word)))
  969. (backward-word 1)
  970. (let ((e (point-marker)))
  971. (goto-char begin)
  972. (skip-syntax-forward "-" e)
  973. (delete-region (point) e)
  974. (insert "set "))))))
  975. (message nil))
  976. ;;; handle the actual arguments
  977. (defun gnuplot-gui-fix-arg-list (list)
  978. "Correct the result of splitting `gnuplot-gui-current-string'.
  979. LIST is the split string. This removes empty and all-blank strings
  980. from the list and concatenates the strings that are part of a quoted
  981. argument, for example an axis label or a font name. It also replaces
  982. bounding single quotes with double quotes, since double quotes are
  983. used in `gnuplot-gui-all-types'."
  984. (let (fixed-list quote quoted) ; remove blanks
  985. (setq list (remove* "\\s-+" list :test 'string-match)
  986. list (remove* "" list :test 'string=))
  987. (while list ; concatinate parts of quoted string
  988. (if (not (string-match "^\\([\]\[()'\"]\\)" (car list)))
  989. (setq fixed-list (append fixed-list (list (car list))))
  990. (setq quote (match-string 1 (car list))
  991. quoted (car list))
  992. (if (string= quote "[") (setq quote "]"))
  993. (if (string= quote "(") (setq quote ")"))
  994. (while (and list
  995. (or (equal (length quoted) 1)
  996. (not (string-match (concat (regexp-quote quote) "$")
  997. quoted))))
  998. (setq quoted (concat quoted " " (cadr list))
  999. list (cdr list)))
  1000. (if (string= quote "'")
  1001. (setq quoted (concat "\"" (substring quoted 1))
  1002. quoted (concat (substring quoted 0 -1) "\"")))
  1003. (setq fixed-list (append fixed-list (list quoted))))
  1004. (setq list (cdr list)) )
  1005. fixed-list))
  1006. (defun gnuplot-gui-set-alist (word string)
  1007. "Set defaults for arguments, using text from buffer if appropriate.
  1008. WORD is the Gnuplot expression whose arguments are being set. STRING
  1009. is text from the buffer containing the previous values for WORD's
  1010. arguments."
  1011. (let ((alist (cdr (assoc word gnuplot-gui-all-types)))
  1012. (arg-list (gnuplot-gui-fix-arg-list (split-string string)) ))
  1013. ;; arg-list contains the arguments taken from the buffer
  1014. (setq gnuplot-gui-alist nil)
  1015. (while alist
  1016. (let* ((list (car alist))
  1017. (tag (gnuplot-gui-type-tag list))
  1018. (symbol (eval (gnuplot-gui-type-symbol list)))
  1019. (default (gnuplot-gui-type-default list))
  1020. (prefix (gnuplot-gui-type-prefix list))
  1021. (values (gnuplot-gui-type-list list))
  1022. (this-cons (cond ((stringp default) (cons tag default))
  1023. ((consp default) ; set cons valued default w/care
  1024. (cons tag (cons (car default) (cdr default))))
  1025. (t (cons tag default))))
  1026. (temp-list arg-list) )
  1027. ;;(message "%S" temp-list) ; want to lop values off arg-list
  1028. ; as they are found
  1029. (if (symbolp (cadr values))
  1030. (setq values (symbol-value (cadr values))))
  1031. ;; check if an argument of this type is in arg-list
  1032. ;; set the current cons cell if it is
  1033. (while temp-list
  1034. (cond
  1035. ;; ---------------------------- list
  1036. ((member* symbol '(list list*) :test 'equal)
  1037. (let* ((case-fold-search nil)
  1038. (match-cons (member* (concat "^" (car temp-list))
  1039. values :test 'string-match)))
  1040. (if (and (car match-cons) ; " " may be first elem. of list
  1041. (not (string= " " (car match-cons))))
  1042. (setq this-cons (cons tag (car match-cons))
  1043. arg-list (remove* (car temp-list) arg-list
  1044. :test 'string= :count 1)
  1045. temp-list nil)
  1046. (setq temp-list (cdr temp-list)))))
  1047. ;; ---------------------------- tag (first number in list)
  1048. ((equal symbol 'tag)
  1049. (if (string-match "^[-0-9.]+$" (car arg-list))
  1050. (setq this-cons (cons tag (car arg-list))
  1051. temp-list nil)
  1052. (setq temp-list (cdr temp-list))) )
  1053. ;; ---------------------------- fontsize (last number in list)
  1054. ((equal symbol 'fontsize)
  1055. (if (string-match "^[-0-9.]+$" (car (last arg-list)))
  1056. (setq this-cons (cons tag (car (last arg-list)))
  1057. temp-list nil)
  1058. (setq temp-list (cdr temp-list))) )
  1059. ;; ---------------------------- number with prefix
  1060. ((equal symbol 'number)
  1061. (cond ((and (string= prefix (car temp-list))
  1062. (string-match "^[-0-9.]+$" (cadr temp-list)))
  1063. (setq this-cons (cons tag (cadr temp-list))
  1064. arg-list (remove* (car temp-list) arg-list
  1065. :test 'string= :count 1)
  1066. arg-list (remove* (cadr temp-list) arg-list
  1067. :test 'string= :count 1)
  1068. temp-list nil))
  1069. ;; --------------------- number without prefix
  1070. ((and (not prefix)
  1071. (string-match "^[-0-9.]+$" (car temp-list)))
  1072. (setq this-cons (cons tag (car temp-list))
  1073. arg-list (remove* (car temp-list) arg-list
  1074. :test 'string= :count 1)
  1075. temp-list nil))
  1076. (t
  1077. (setq temp-list (cdr temp-list)))))
  1078. ;; ---------------------------- pair with prefix
  1079. ((equal symbol 'pair)
  1080. (if (and (string= prefix (car temp-list))
  1081. (string-match "^[-0-9.]+$" (cadr temp-list)))
  1082. (let ((this-car (cadr temp-list))
  1083. (this-cdr (if (string-match "^[-0-9.]+$" (caddr temp-list))
  1084. (caddr temp-list) "")))
  1085. (setq this-cons (cons tag (cons this-car this-cdr))
  1086. temp-list nil))
  1087. (setq temp-list (cdr temp-list))))
  1088. ;; ---------------------------- range
  1089. ((equal symbol 'range)
  1090. (if (string-match (concat "\\[\\s-*" ; opening bracket
  1091. "\\([^:, \t]*\\)" ; first argument
  1092. "\\s-*[:,]\\s-*" ; separator
  1093. "\\([^\] \t]*\\)" ; second argument
  1094. "\\s-*\\]") ; closing bracket
  1095. (car temp-list))
  1096. (setq this-cons
  1097. (cons tag (cons (match-string 1 (car temp-list))
  1098. (match-string 2 (car temp-list))))
  1099. arg-list (remove* (car temp-list) arg-list
  1100. :test 'string= :count 1)
  1101. temp-list nil)
  1102. (setq temp-list (cdr temp-list)) ))
  1103. ;; ---------------------------- labels
  1104. ((equal symbol 'labels)
  1105. (if (string-match (concat "(" ; opening paren
  1106. "\\([^\)]*\\)" ; string
  1107. ")") ; closing paren
  1108. (car temp-list))
  1109. (let* ((list (split-string (car temp-list) "[ \t(),]+"))
  1110. (list (remove* "" list :test 'string=))
  1111. (return ()))
  1112. (while list
  1113. (if (string-match "['\"]\\([^'\"]*\\)['\"]" (car list))
  1114. (setq return (append return
  1115. (list (match-string 1 (car list))))
  1116. list (cdr list)
  1117. return (append return (list (car list))) )
  1118. (setq return (append return (list "" (car list)))))
  1119. (setq list (cdr list)) )
  1120. (setq this-cons (cons tag return)
  1121. arg-list (remove* (car temp-list) arg-list
  1122. :test 'string= :count 1)
  1123. temp-list nil))
  1124. (setq temp-list (cdr temp-list))) )
  1125. ;; ---------------------------- string, file, format
  1126. ((member* symbol '(string file format) :test 'equal)
  1127. (if (string-match (concat "['\"]" ; opening quote
  1128. "\\([^'\"]*\\)" ; string
  1129. "['\"]") ; closing quote
  1130. (car temp-list))
  1131. (setq this-cons (cons tag (match-string 0 (car temp-list)))
  1132. arg-list (remove* (car temp-list) arg-list
  1133. :test 'string= :count 1)
  1134. temp-list nil)
  1135. (setq temp-list (cdr temp-list)) ))
  1136. ;; ---------------------------- string*
  1137. ((equal symbol 'string*)
  1138. (if (string= prefix (car temp-list))
  1139. (setq this-cons (cons tag (cadr temp-list))
  1140. arg-list (remove* (car temp-list) arg-list
  1141. :test 'string= :count 1)
  1142. arg-list (remove* (cadr temp-list) arg-list
  1143. :test 'string= :count 1)
  1144. temp-list nil)
  1145. (setq temp-list (cdr temp-list)) ) )
  1146. ;; ---------------------------- other or unknown
  1147. (t
  1148. (setq temp-list nil))
  1149. ))
  1150. (setq gnuplot-gui-alist
  1151. (append gnuplot-gui-alist (list this-cons))))
  1152. (setq alist (cdr alist))) ))
  1153. (defun gnuplot-gui-post-process-alist (type)
  1154. "A few types need some additional processing.
  1155. 'range, 'pair, and 'labels are cons or list valued and need to b made
  1156. into strings. This is called right before inserting the arguments
  1157. into the buffer. TYPE is the object whose arguments are being set."
  1158. (let ((alist gnuplot-gui-alist)
  1159. (types (cdr (assoc type gnuplot-gui-all-types))) )
  1160. (while alist ;; loop thru alist looking for tyeps needing post-processing
  1161. (let* ((list (assoc (caar alist) types))
  1162. (value (cdr (assoc (caar alist) gnuplot-gui-alist)))
  1163. (prefix (gnuplot-gui-type-prefix list))
  1164. (symb (gnuplot-gui-type-symbol list)) )
  1165. (cond
  1166. ;;-------------------------- flat text
  1167. ((equal (eval symb) 'text)
  1168. (setcdr (assoc (caar alist) gnuplot-gui-alist) ""))
  1169. ;;-------------------------- range [#:#] or [#,#]
  1170. ((equal (eval symb) 'range)
  1171. (if (and (string-match "^\\s-*$" (car value))
  1172. (string-match "^\\s-*$" (cdr value)))
  1173. (setcdr (assoc (caar alist) gnuplot-gui-alist) "")
  1174. (setcdr (assoc (caar alist) gnuplot-gui-alist)
  1175. (concat "[" (car value) prefix (cdr value) "]")) ) )
  1176. ;;-------------------------- pair
  1177. ((equal (eval symb) 'pair)
  1178. (if (and (string-match "^\\s-*$" (car value))
  1179. (string-match "^\\s-*$" (cdr value)))
  1180. (setcdr (assoc (caar alist) gnuplot-gui-alist) "")
  1181. (setcdr (assoc (caar alist) gnuplot-gui-alist)
  1182. (concat prefix " " (car value) " " (cdr value) )) ) )
  1183. ;;-------------------------- labels
  1184. ((equal (eval symb) 'labels)
  1185. (if (consp value)
  1186. (let ((word "") (list value))
  1187. (while list
  1188. (if (string-match "^\\s-*$" (car list))
  1189. (setq word (concat word (format "%s, " (cadr list))))
  1190. (setq word (concat word (format "%S %s, " (car list)
  1191. (cadr list)))))
  1192. (setq list (cddr list)) )
  1193. (setq value (concat "(" (substring word 0 -2) ")")))
  1194. (setq value "") )
  1195. (setcdr (assoc (caar alist) gnuplot-gui-alist) value) ))
  1196. (setq alist (cdr alist))) )))
  1197. ;;; GUI frames
  1198. (defun gnuplot-gui-prompt-for-frame (&optional option save-frame)
  1199. (setq option (or option (completing-read "Option: " gnuplot-gui-all-types
  1200. nil t nil t)))
  1201. (gnuplot-gui-make-frame
  1202. option (cdr (assoc option gnuplot-gui-all-types)) save-frame) )
  1203. (defface gnuplot-gui-error-face '((((class color) (background light))
  1204. (:foreground "grey30"))
  1205. (((class color) (background dark))
  1206. (:foreground "grey70")))
  1207. "Face used to display message about unknown widget types."
  1208. :group 'gnuplot-faces)
  1209. (defface gnuplot-gui-flat-text-face '((((class color) (background light))
  1210. (:foreground "MediumBlue"))
  1211. (((class color) (background dark))
  1212. (:foreground "LightSteelBlue")))
  1213. "Face used to display message about unknown widget types."
  1214. :group 'gnuplot-faces)
  1215. (defun gnuplot-gui-make-frame (item alist &optional save-frame)
  1216. "Open the frame and populate it with widgets.
  1217. ITEM is the object for which arguments are being set. ALIST is
  1218. the alist of arguments for ITEM taken from `gnuplot-gui-all-types'.
  1219. SAVE-FRAME is non-nil when the widgets are being reset."
  1220. (unless save-frame
  1221. (setq gnuplot-current-frame (selected-frame)
  1222. gnuplot-current-buffer (current-buffer)
  1223. gnuplot-current-buffer-point (point-marker))
  1224. (unless (and gnuplot-gui-frame (frame-live-p gnuplot-gui-frame))
  1225. (setq gnuplot-gui-frame (if gnuplot-xemacs-p
  1226. (make-frame gnuplot-gui-frame-plist)
  1227. (make-frame gnuplot-gui-frame-parameters))))
  1228. (select-frame gnuplot-gui-frame)
  1229. ;;(set-frame-position gnuplot-gui-frame 150 150) ;; so herky-jerky
  1230. (if gnuplot-xemacs-p
  1231. (set-mouse-position (selected-window) 0 0)
  1232. (set-mouse-position gnuplot-gui-frame 0 0)))
  1233. (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
  1234. (switch-to-buffer (get-buffer-create "*Gnuplot GUI*"))
  1235. (kill-all-local-variables)
  1236. (if gnuplot-xemacs-p
  1237. (progn
  1238. (set (make-local-variable 'frame-title-format)
  1239. "Set Gnuplot Options")
  1240. (set (make-local-variable 'frame-icon-title-format)
  1241. "Set Gnuplot Options"))
  1242. (modify-frame-parameters (selected-frame)
  1243. '((title . "Set Gnuplot Options"))) )
  1244. (widget-insert "\nSet options for \"" item "\" ")
  1245. (let (tag help val)
  1246. (cond ((string-match "^[xyz]2?tics" item)
  1247. (setq tag "info on tic labels"
  1248. help "Open a frame displaying the info entry for tic labels"
  1249. val "xtics"))
  1250. ((string-match "^no" item)
  1251. (setq tag (concat "info on " (substring item 2))
  1252. help (format "Open a frame displaying the info entry for %S"
  1253. item)
  1254. val item))
  1255. (t
  1256. (setq tag (concat "info on " item)
  1257. help (format "Open a frame displaying the info entry for %S"
  1258. item)
  1259. val item)))
  1260. (widget-create 'gnuplot-gui-info-link :tag tag :help-echo help :value val))
  1261. (widget-insert "\n\n")
  1262. (while alist
  1263. (let* ((this (car alist))
  1264. (tag (gnuplot-gui-type-tag this))
  1265. (wtype (gnuplot-gui-type-symbol this))
  1266. (prefix (gnuplot-gui-type-prefix this))
  1267. (default (cdr (assoc tag gnuplot-gui-alist)))
  1268. (list (gnuplot-gui-type-list this)))
  1269. (if (symbolp (cadr list))
  1270. (setq list (symbol-value (cadr list))))
  1271. (widget-insert "\t") ; insert the appropriate widget
  1272. (cond
  1273. ;;------------------------------ list, list* ------------
  1274. ((member* (eval wtype) '(list list*) :test 'equal)
  1275. (let ((starred (if (equal (eval wtype) 'list*) t nil)))
  1276. (gnuplot-gui-menu-choice tag default list starred)))
  1277. ;;------------------------------ number, tag, fontsize --
  1278. ((member* (eval wtype) '(number tag fontsize) :test 'equal)
  1279. (gnuplot-gui-number tag default prefix))
  1280. ;;------------------------------ position ---------------
  1281. ;;------------------------------ range, pair ------------
  1282. ((member* (eval wtype) '(range pair) :test 'equal)
  1283. (let ((is-range (equal (eval wtype) 'range)))
  1284. (gnuplot-gui-range tag default prefix is-range)))
  1285. ;;------------------------------ string, string* --------
  1286. ((member* (eval wtype) '(string string*) :test 'equal)
  1287. (let ((starred (if (equal (eval wtype) 'string) nil t)))
  1288. (gnuplot-gui-string tag default prefix starred)))
  1289. ;;------------------------------ format -----------------
  1290. ((equal (eval wtype) 'format)
  1291. (gnuplot-gui-format tag default))
  1292. ;;------------------------------ file -------------------
  1293. ((equal (eval wtype) 'file)
  1294. (gnuplot-gui-file tag default prefix))
  1295. ;;------------------------------ labels -----------------
  1296. ((equal (eval wtype) 'labels)
  1297. (gnuplot-gui-labels tag default))
  1298. ;;------------------------------ text -------------------
  1299. ((equal (eval wtype) 'text)
  1300. (let ((str (gnuplot-gui-type-default this)))
  1301. (put-text-property 0 (length str) 'face 'gnuplot-gui-flat-text-face str)
  1302. (widget-insert str "\n")))
  1303. ;;------------------------------ unknown ----------------
  1304. (t
  1305. (let ((str (concat "<" (downcase tag) "> ('"
  1306. (symbol-name (eval wtype))
  1307. " arguments are not yet supported)\n")))
  1308. (put-text-property 0 (length str) 'face 'gnuplot-gui-error-face str)
  1309. (widget-insert str)) )))
  1310. (setq alist (cdr alist)))
  1311. ;; insert control buttons: [Set options] [Reset] [Clear] [Cancel]
  1312. (widget-insert "\n\t")
  1313. (widget-create 'push-button
  1314. :value "Set options"
  1315. :doc item
  1316. :button-face 'gnuplot-gui-button-face
  1317. :help-echo "Push this button to set options"
  1318. :notify
  1319. (lambda (widget &rest ignore)
  1320. (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
  1321. (delete-frame)
  1322. (select-frame gnuplot-current-frame)
  1323. (switch-to-buffer gnuplot-current-buffer)
  1324. (goto-char gnuplot-current-buffer-point)
  1325. (gnuplot-gui-post-process-alist
  1326. (widget-get widget :doc))
  1327. (let ((alist gnuplot-gui-alist) marker
  1328. (eol (save-excursion (end-of-line) (point-marker) )) )
  1329. (if (re-search-forward ";" eol "to_limit")
  1330. (backward-char 1))
  1331. (delete-region gnuplot-current-buffer-point (point-marker))
  1332. (delete-horizontal-space)
  1333. (setq marker (point-marker))
  1334. (while alist
  1335. (let ((val (cdar alist)))
  1336. (if (string-match "^\\s-+$" val) ()
  1337. (if (string-match "^['\"]\\(.*\\)['\"]$" val)
  1338. (setq val (concat gnuplot-quote-character
  1339. (match-string 1 val)
  1340. gnuplot-quote-character)))
  1341. (insert (format " %s" val))))
  1342. (setq alist (cdr alist)))
  1343. (setq eol (point-marker))
  1344. (goto-char marker)
  1345. (while (< (point) eol) ; a few odd cases
  1346. (unless (looking-at (concat "[" (regexp-quote "(")
  1347. (regexp-quote "*") ",]"))
  1348. (just-one-space))
  1349. (forward-sexp)))
  1350. (delete-horizontal-space)
  1351. (if (string= "terminal" (widget-get widget :doc))
  1352. (gnuplot-gui-set-options-and-insert)) ))
  1353. (widget-insert " ")
  1354. (widget-create 'push-button :value "Reset"
  1355. :help-echo "Push this button to reset all values"
  1356. :button-face 'gnuplot-gui-button-face
  1357. :doc item
  1358. :notify
  1359. (lambda (widget &rest ignore)
  1360. (let ((word (widget-get widget :doc)))
  1361. (gnuplot-gui-set-alist word gnuplot-gui-current-string)
  1362. (gnuplot-gui-prompt-for-frame word t))))
  1363. (widget-insert " ")
  1364. (widget-create 'push-button :value "Clear"
  1365. :help-echo "Push this button to clear all values"
  1366. :button-face 'gnuplot-gui-button-face
  1367. :doc item
  1368. :notify
  1369. (lambda (widget &rest ignore)
  1370. (let* ((word (widget-get widget :doc))
  1371. (alist (cdr (assoc word gnuplot-gui-all-types))))
  1372. (while alist
  1373. (setcdr (assoc (gnuplot-gui-type-tag (car alist))
  1374. gnuplot-gui-alist)
  1375. (gnuplot-gui-type-default (car alist)))
  1376. (setq alist (cdr alist)))
  1377. (gnuplot-gui-prompt-for-frame word t))) )
  1378. (widget-insert " ")
  1379. (widget-create 'push-button :value "Cancel"
  1380. :help-echo "Quit setting options and dismiss frame"
  1381. :button-face 'gnuplot-gui-button-face
  1382. :notify (lambda (widget &rest ignore)
  1383. (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
  1384. (setq gnuplot-gui-alist nil
  1385. gnuplot-gui-current-string nil)
  1386. (delete-frame)
  1387. (select-frame gnuplot-current-frame)))
  1388. (goto-char (point-min))
  1389. (use-local-map widget-keymap)
  1390. (widget-setup))
  1391. ;;; widgets
  1392. (defface gnuplot-gui-menu-face '((((class color) (background light))
  1393. (:bold t :foreground "darkolivegreen"))
  1394. (((class color) (background dark))
  1395. (:bold t :foreground "seagreen"))
  1396. (t
  1397. (:italic t)))
  1398. "Face used for menu-buttons."
  1399. :group 'gnuplot-faces)
  1400. (defface gnuplot-gui-button-face '((((class color) (background light))
  1401. (:bold t :foreground "sienna"))
  1402. (((class color) (background dark))
  1403. (:bold t :foreground "tan"))
  1404. (t
  1405. (:italic t)))
  1406. "Face used for push-buttons.
  1407. Only used in Emacs. XEmacs displays push-buttons with a pixmap."
  1408. :group 'gnuplot-faces)
  1409. (defface gnuplot-gui-labels-face '((((class color) (background light))
  1410. (:bold t :foreground "darkslateblue"))
  1411. (((class color) (background dark))
  1412. (:bold t :foreground "lightslateblue"))
  1413. (t
  1414. (:italic t)))
  1415. "Face used for insert and delete button in the labels widget."
  1416. :group 'gnuplot-faces)
  1417. (defun gnuplot-gui-menu-choice (item default list &optional starred)
  1418. "Create a menu widget for the Gnuplot GUI.
  1419. ITEM is the object whose arguments are set by this widget, DEFAULT
  1420. is the default argument value, LIST contains the items for the pop-up
  1421. menu. STARRED is true if this a 'list* widget."
  1422. (let ((widget
  1423. (apply 'widget-create
  1424. 'menu-choice :value default :tag item :doc starred
  1425. :button-face 'gnuplot-gui-menu-face
  1426. :button-prefix "[" :button-suffix "]"
  1427. :help-echo (format "Mouse-2 to view the %S menu" (downcase item))
  1428. :notify
  1429. (lambda (widget &rest ignore)
  1430. (let ((lab (if (widget-get widget :doc)
  1431. (concat (downcase (widget-get widget :tag)) " ")
  1432. "" )))
  1433. (setcdr (assoc (widget-get widget :tag) gnuplot-gui-alist)
  1434. (if (string= (widget-value widget) " ") ""
  1435. (format "%s%s" lab (widget-value widget))) )))
  1436. (mapcar (lambda (x) (list 'item :value x))
  1437. list))))
  1438. (widget-value-set widget default)
  1439. (if (and starred (not (string-match "^\\s-*$" default)))
  1440. (setcdr (assoc item gnuplot-gui-alist)
  1441. (format "%s %s" (downcase item) default)))
  1442. widget))
  1443. (defun gnuplot-gui-number (item default &optional prefix)
  1444. "Create a number widget for the Gnuplot GUI.
  1445. ITEM is the object whose arguments are set by this widget, DEFAULT
  1446. is the default value for the widget, PREFIX is a text string preceding
  1447. the numerical argument."
  1448. (let ((help-label (or prefix (downcase item))))
  1449. (widget-insert (capitalize item) ": ")
  1450. (widget-create 'editable-field
  1451. :size 2 :tag item :value default :doc prefix
  1452. :help-echo (format "Insert new value of %S here" help-label)
  1453. :notify (lambda (widget &rest ignore)
  1454. (let ((val (widget-value widget))
  1455. (pre (concat (widget-get widget :doc) " ")))
  1456. (setcdr (assoc (widget-get widget :tag)
  1457. gnuplot-gui-alist)
  1458. (if (string-match
  1459. "^\\s-*[-0-9.*]+\\s-*$" val)
  1460. (format "%s%s" pre val) "") )))))
  1461. (unless (string-match "^\\s-*$" default)
  1462. (setcdr (assoc item gnuplot-gui-alist) (format "%s %s" prefix default)))
  1463. (widget-insert " " (make-string (- 40 (current-column)) ?.)
  1464. " (numeric value)\n"))
  1465. (defun gnuplot-gui-string (item default &optional width_or_prefix starred)
  1466. "Create a string widget for the Gnuplot GUI.
  1467. ITEM is the object whose arguments are set by this widget, DEFAULT is
  1468. the default value for the widget, and WIDTH_OR_PREFIX is the width of
  1469. the text entry field (which defaults to half the frame width) or the
  1470. prefix for the string. STARRED is t if quotes are not to be used."
  1471. (let ((help-label (downcase item)) width (prefix "") (pp ""))
  1472. (cond ((stringp width_or_prefix)
  1473. (setq prefix width_or_prefix
  1474. pp prefix)
  1475. (if starred (setq prefix (concat prefix "_star"))) )
  1476. ((numberp width_or_prefix)
  1477. (setq width width_or_prefix)))
  1478. (setq width (or width (/ (frame-width) 2)))
  1479. (if (string-match "^['\"]" default)
  1480. (setq default (replace-match "" nil nil default)))
  1481. (if (string-match "['\"]$" default)
  1482. (setq default (replace-match "" nil nil default)))
  1483. (widget-insert (capitalize item) ": ")
  1484. (widget-create
  1485. 'editable-field
  1486. :size width :tag item :doc prefix :value default
  1487. :help-echo (format "Insert new value of %S here" help-label)
  1488. :notify (lambda (widget &rest ignore)
  1489. (let ((val (widget-value widget))
  1490. (q gnuplot-quote-character)
  1491. (p (widget-get widget :doc)) )
  1492. (setcdr (assoc (widget-get widget :tag) gnuplot-gui-alist)
  1493. (if (string-match "^\\s-*$" val)
  1494. ""
  1495. (progn
  1496. (if (string-match "_star$" p)
  1497. (setq p (concat (substring p 0 -5) " ")
  1498. q ""))
  1499. (if (string-match "^\\s-+" val)
  1500. (setq val (replace-match "" nil nil val)))
  1501. (if (string-match "\\s-+$" val)
  1502. (setq val (replace-match "" nil nil val)))
  1503. (format "%s%s%s%s" p q val q)))))))
  1504. (unless (string-match "^\\s-*$" default)
  1505. (setcdr (assoc item gnuplot-gui-alist) (format "%s %s" pp default)))
  1506. (widget-insert "\n")))
  1507. (defun gnuplot-gui-format (item default)
  1508. "Create a string widget for the Gnuplot GUI.
  1509. ITEM is the object whose arguments are set by this widget, DEFAULT is
  1510. the default value for the widget, and WIDTH_OR_PREFIX is the width of
  1511. the text entry field (which defaults to half the frame width) or the
  1512. prefix for the string."
  1513. (if (string-match "^['\"]" default)
  1514. (setq default (replace-match "" nil nil default)))
  1515. (if (string-match "['\"]$" default)
  1516. (setq default (replace-match "" nil nil default)))
  1517. (widget-insert (capitalize item) ": ")
  1518. (widget-create 'editable-field
  1519. :size (/ (frame-width) 3) :tag item :value default
  1520. :help-echo (format "Insert new format string here")
  1521. :notify (lambda (widget &rest ignore)
  1522. (let ((val (widget-value widget)))
  1523. (setcdr (assoc (widget-get widget :tag)
  1524. gnuplot-gui-alist)
  1525. (format "%s%s%s"
  1526. gnuplot-quote-character
  1527. val
  1528. gnuplot-quote-character)))))
  1529. (widget-insert " ")
  1530. (widget-create 'gnuplot-gui-info-link
  1531. :tag (concat "info on format")
  1532. :help-echo "Open a frame displaying the info entry for format"
  1533. :value "format")
  1534. (widget-insert "\n"))
  1535. ;; swiped from widget-color-complete
  1536. (defun gnuplot-gui-file-completion (widget)
  1537. "Complete the filename in WIDGET."
  1538. (let* ((str (buffer-substring-no-properties (widget-field-start widget)
  1539. (point)))
  1540. (file (or (file-name-nondirectory str) ""))
  1541. (dir (or (file-name-directory str) "./"))
  1542. (val (file-name-completion file dir)) )
  1543. (cond ((eq val t)
  1544. (message "Exact match"))
  1545. ((null val)
  1546. (error "Can't find completion for \"%s\"" str))
  1547. ((not (string-equal str val))
  1548. (insert (substring val (length file))))
  1549. (t
  1550. (message "Making completion list...")
  1551. (let ((list (file-name-all-completions file dir)))
  1552. (with-output-to-temp-buffer "*Completions*"
  1553. (display-completion-list list)))
  1554. (message "Making completion list...done")))))
  1555. (defun gnuplot-gui-file (item default &optional tag)
  1556. "Create a file widget for the Gnuplot GUI.
  1557. ITEM is the object whose arguments is set by this widget, DEFAULT is
  1558. the default value for the argument. TAG is non-nil if ITEM rather than
  1559. \"File:\" is to be used as the tag."
  1560. (setq tag (if tag (capitalize item) "File"))
  1561. (if (string-match "^['\"]" default)
  1562. (setq default (replace-match "" nil nil default)))
  1563. (if (string-match "['\"]$" default)
  1564. (setq default (replace-match "" nil nil default)))
  1565. (let ((widg (widget-create
  1566. 'file
  1567. :value default :tag tag
  1568. :size (- (/ (frame-width) 2) 3)
  1569. :doc item :help-echo "Insert a filename here"
  1570. :complete 'gnuplot-gui-file-completion
  1571. :notify
  1572. (lambda (widget &rest ignore)
  1573. (setcdr (assoc (widget-get widget :doc) gnuplot-gui-alist)
  1574. (format "%s%s%s" gnuplot-quote-character
  1575. (widget-value widget)
  1576. gnuplot-quote-character)) )) ))
  1577. (widget-insert " ")
  1578. (widget-create
  1579. 'push-button :value "Browse"
  1580. :doc item :help-echo "Browse directories for a filename."
  1581. :parent widg
  1582. :notify (lambda (widget &rest ignore)
  1583. (let ((fname (file-relative-name (read-file-name "File: ")
  1584. default-directory))
  1585. (q gnuplot-quote-character))
  1586. (widget-value-set (widget-get widget :parent) fname)
  1587. (setcdr (assoc (widget-get widget :doc) gnuplot-gui-alist)
  1588. (format "%s%s%s" q fname q))
  1589. (widget-setup))))
  1590. (widget-insert "\n")))
  1591. (defun gnuplot-gui-labels (item default)
  1592. "Create a labels widget for the Gnuplot GUI.
  1593. ITEM is the object whose arguments is set by this widget, DEFAULT is
  1594. the default value for the argument."
  1595. (widget-create
  1596. '(editable-list
  1597. (list :inline t :tag "Tic label"
  1598. (string :tag "label" :size 10
  1599. :help-echo "Enter the tic label here" )
  1600. (string :tag " position" :size 10
  1601. :help-echo "Enter an expression for the tic location here" )))
  1602. :tag (capitalize item)
  1603. :value default
  1604. :format "%{%t%}:\n%v\t %i\n"
  1605. :entry-format "\t %i %d %v\n"
  1606. :button-face 'gnuplot-gui-labels-face
  1607. :notify (lambda (widget &rest ignore)
  1608. (setcdr (assoc (upcase (widget-get widget :tag))
  1609. gnuplot-gui-alist)
  1610. (widget-value widget)))))
  1611. (defun gnuplot-gui-range (item default separator is-range)
  1612. "Create a range or pair widget for the Gnuplot GUI.
  1613. ITEM is the object whose arguments are set by this widget, DEFAULT is
  1614. the default value for the widget, SEPARATOR is a text string preceding
  1615. the numerical argument, or the prefix for a pair operator. IS-RANGE
  1616. is non-nil if this is a 'range widget."
  1617. (widget-insert (capitalize item) ": ")
  1618. (if is-range (widget-insert "["))
  1619. (widget-create 'editable-field
  1620. :size 4 :tag item :value (car default)
  1621. :help-echo (format "Insert the first value of the %S here"
  1622. (downcase item))
  1623. :notify (lambda (widget &rest ignore)
  1624. (setcar (cdr (assoc (widget-get widget :tag)
  1625. gnuplot-gui-alist))
  1626. (format "%s" (widget-value widget)))))
  1627. (if is-range (widget-insert separator) (widget-insert " "))
  1628. (widget-create 'editable-field
  1629. :size 4 :tag item :value (cdr default)
  1630. :help-echo (format "Insert the second value of the %S here"
  1631. (downcase item))
  1632. :notify (lambda (widget &rest ignore)
  1633. (setcdr (cdr (assoc (widget-get widget :tag)
  1634. gnuplot-gui-alist))
  1635. (format "%s" (widget-value widget)))))
  1636. (if is-range (widget-insert "]"))
  1637. (widget-insert " " (make-string (- 39 (current-column)) ?.)
  1638. " (numeric values)\n"))
  1639. ;; suppress compiler warning
  1640. ;;(eval-when-compile (defun gnuplot-info-lookup-symbol (sym mode)))
  1641. (define-widget 'gnuplot-gui-info-link 'info-link
  1642. "A link to an info file for the Gnuplot GUI."
  1643. :action '(lambda (widget &optional event)
  1644. (let ((gnuplot-info-display 'frame))
  1645. (if gnuplot-keywords-pending ; <HW>
  1646. (gnuplot-setup-info-look))
  1647. (gnuplot-info-lookup-symbol (widget-value widget)
  1648. 'gnuplot-mode))))
  1649. ;;; just about done
  1650. (provide 'gnuplot-gui)
  1651. ;;;============================================================================
  1652. ;;;
  1653. ;;; gnuplot-gui.el ends here