Mercurial > emacs
comparison lisp/calc/calc-graph.el @ 41271:fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
author | Colin Walters <walters@gnu.org> |
---|---|
date | Mon, 19 Nov 2001 07:43:43 +0000 |
parents | 73f364fd8aaa |
children | 54abc38794d9 |
comparison
equal
deleted
inserted
replaced
41270:711f18abaf57 | 41271:fcd507927105 |
---|---|
1 ;; Calculator for GNU Emacs, part II [calc-graph.el] | 1 ;;; calc-graph.el --- graph output functions for Calc |
2 | |
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
3 ;; Written by Dave Gillespie, daveg@synaptics.com. | 4 |
5 ;; Author: David Gillespie <daveg@synaptics.com> | |
6 ;; Maintainer: Colin Walters <walters@debian.org> | |
4 | 7 |
5 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
6 | 9 |
7 ;; GNU Emacs is distributed in the hope that it will be useful, | 10 ;; GNU Emacs is distributed in the hope that it will be useful, |
8 ;; but WITHOUT ANY WARRANTY. No author or distributor | 11 ;; but WITHOUT ANY WARRANTY. No author or distributor |
17 ;; supposed to have been given to you along with GNU Emacs so you | 20 ;; supposed to have been given to you along with GNU Emacs so you |
18 ;; can know your rights and responsibilities. It should be in a | 21 ;; can know your rights and responsibilities. It should be in a |
19 ;; file named COPYING. Among other things, the copyright notice | 22 ;; file named COPYING. Among other things, the copyright notice |
20 ;; and this notice must be preserved on all copies. | 23 ;; and this notice must be preserved on all copies. |
21 | 24 |
22 | 25 ;;; Commentary: |
26 | |
27 ;;; Code: | |
23 | 28 |
24 ;; This file is autoloaded from calc-ext.el. | 29 ;; This file is autoloaded from calc-ext.el. |
25 (require 'calc-ext) | 30 (require 'calc-ext) |
26 | 31 |
27 (require 'calc-macs) | 32 (require 'calc-macs) |
30 | 35 |
31 | 36 |
32 ;;; Graphics | 37 ;;; Graphics |
33 | 38 |
34 ;;; Note that some of the following initial values also occur in calc.el. | 39 ;;; Note that some of the following initial values also occur in calc.el. |
35 (defvar calc-gnuplot-tempfile "/tmp/calc") | 40 (defvar calc-gnuplot-tempfile (expand-file-name "calc" temporary-file-directory)) |
36 | 41 |
37 (defvar calc-gnuplot-default-device "default") | 42 (defvar calc-gnuplot-default-device "default") |
38 (defvar calc-gnuplot-default-output "STDOUT") | 43 (defvar calc-gnuplot-default-output "STDOUT") |
39 (defvar calc-gnuplot-print-device "postscript") | 44 (defvar calc-gnuplot-print-device "postscript") |
40 (defvar calc-gnuplot-print-output "auto") | 45 (defvar calc-gnuplot-print-output "auto") |
56 (defvar calc-graph-last-output nil) | 61 (defvar calc-graph-last-output nil) |
57 (defvar calc-graph-file-cache nil) | 62 (defvar calc-graph-file-cache nil) |
58 (defvar calc-graph-var-cache nil) | 63 (defvar calc-graph-var-cache nil) |
59 (defvar calc-graph-data-cache nil) | 64 (defvar calc-graph-data-cache nil) |
60 (defvar calc-graph-data-cache-limit 10) | 65 (defvar calc-graph-data-cache-limit 10) |
66 (defvar calc-graph-no-auto-view nil) | |
67 (defvar calc-graph-no-wait nil) | |
61 | 68 |
62 (defun calc-graph-fast (many) | 69 (defun calc-graph-fast (many) |
63 (interactive "P") | 70 (interactive "P") |
64 (let ((calc-graph-no-auto-view t)) | 71 (let ((calc-graph-no-auto-view t)) |
65 (calc-graph-delete t) | 72 (calc-graph-delete t) |
906 (define-key calc-dumb-map "}" 'scroll-up) | 913 (define-key calc-dumb-map "}" 'scroll-up) |
907 (define-key calc-dumb-map "q" 'exit-recursive-edit) | 914 (define-key calc-dumb-map "q" 'exit-recursive-edit) |
908 (define-key calc-dumb-map "\C-c\C-c" 'exit-recursive-edit))) | 915 (define-key calc-dumb-map "\C-c\C-c" 'exit-recursive-edit))) |
909 (use-local-map calc-dumb-map) | 916 (use-local-map calc-dumb-map) |
910 (setq truncate-lines t) | 917 (setq truncate-lines t) |
911 (message "Type `q'%s to return to Calc." | 918 (message "Type `q'%s to return to Calc" |
912 (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch) | 919 (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch) |
913 " or `M-# M-#'" "")) | 920 " or `M-# M-#'" "")) |
914 (recursive-edit) | 921 (recursive-edit) |
915 (bury-buffer "*Gnuplot Trail*"))) | 922 (bury-buffer "*Gnuplot Trail*"))) |
916 | 923 |
1149 (defun calc-graph-num-points (res flag) | 1156 (defun calc-graph-num-points (res flag) |
1150 (interactive "sNumber of data points: \nP") | 1157 (interactive "sNumber of data points: \nP") |
1151 (if flag | 1158 (if flag |
1152 (if (> (prefix-numeric-value flag) 0) | 1159 (if (> (prefix-numeric-value flag) 0) |
1153 (if (equal res "") | 1160 (if (equal res "") |
1154 (message "Default resolution is %d." | 1161 (message "Default resolution is %d" |
1155 calc-graph-default-resolution) | 1162 calc-graph-default-resolution) |
1156 (setq calc-graph-default-resolution (string-to-int res))) | 1163 (setq calc-graph-default-resolution (string-to-int res))) |
1157 (if (equal res "") | 1164 (if (equal res "") |
1158 (message "Default 3D resolution is %d." | 1165 (message "Default 3D resolution is %d" |
1159 calc-graph-default-resolution-3d) | 1166 calc-graph-default-resolution-3d) |
1160 (setq calc-graph-default-resolution-3d (string-to-int res)))) | 1167 (setq calc-graph-default-resolution-3d (string-to-int res)))) |
1161 (calc-graph-set-command "samples" (if (not (equal res "")) res)))) | 1168 (calc-graph-set-command "samples" (if (not (equal res "")) res)))) |
1162 | 1169 |
1163 (defun calc-graph-device (name flag) | 1170 (defun calc-graph-device (name flag) |
1167 (calc-gnuplot-command "set terminal") | 1174 (calc-gnuplot-command "set terminal") |
1168 (calc-graph-view-trail)) | 1175 (calc-graph-view-trail)) |
1169 (if flag | 1176 (if flag |
1170 (if (> (prefix-numeric-value flag) 0) | 1177 (if (> (prefix-numeric-value flag) 0) |
1171 (if (equal name "") | 1178 (if (equal name "") |
1172 (message "Default GNUPLOT device is \"%s\"." | 1179 (message "Default GNUPLOT device is \"%s\"" |
1173 calc-gnuplot-default-device) | 1180 calc-gnuplot-default-device) |
1174 (setq calc-gnuplot-default-device name)) | 1181 (setq calc-gnuplot-default-device name)) |
1175 (if (equal name "") | 1182 (if (equal name "") |
1176 (message "GNUPLOT device for Print command is \"%s\"." | 1183 (message "GNUPLOT device for Print command is \"%s\"" |
1177 calc-gnuplot-print-device) | 1184 calc-gnuplot-print-device) |
1178 (setq calc-gnuplot-print-device name))) | 1185 (setq calc-gnuplot-print-device name))) |
1179 (calc-graph-set-command "terminal" (if (not (equal name "")) | 1186 (calc-graph-set-command "terminal" (if (not (equal name "")) |
1180 name))))) | 1187 name))))) |
1181 | 1188 |
1191 (setq name "")) | 1198 (setq name "")) |
1192 (t (setq name (expand-file-name name)))) | 1199 (t (setq name (expand-file-name name)))) |
1193 (if flag | 1200 (if flag |
1194 (if (> (prefix-numeric-value flag) 0) | 1201 (if (> (prefix-numeric-value flag) 0) |
1195 (if (equal name "") | 1202 (if (equal name "") |
1196 (message "Default GNUPLOT output file is \"%s\"." | 1203 (message "Default GNUPLOT output file is \"%s\"" |
1197 calc-gnuplot-default-output) | 1204 calc-gnuplot-default-output) |
1198 (setq calc-gnuplot-default-output name)) | 1205 (setq calc-gnuplot-default-output name)) |
1199 (if (equal name "") | 1206 (if (equal name "") |
1200 (message "GNUPLOT output file for Print command is \"%s\"." | 1207 (message "GNUPLOT output file for Print command is \"%s\"" |
1201 calc-gnuplot-print-output) | 1208 calc-gnuplot-print-output) |
1202 (setq calc-gnuplot-print-output name))) | 1209 (setq calc-gnuplot-print-output name))) |
1203 (calc-graph-set-command "output" (if (not (equal name "")) | 1210 (calc-graph-set-command "output" (if (not (equal name "")) |
1204 (prin1-to-string name))))) | 1211 (prin1-to-string name))))) |
1205 | 1212 |
1206 (defun calc-graph-display (name) | 1213 (defun calc-graph-display (name) |
1207 (interactive "sX display name: ") | 1214 (interactive "sX display name: ") |
1208 (if (equal name "") | 1215 (if (equal name "") |
1209 (message "Current X display is \"%s\"." | 1216 (message "Current X display is \"%s\"" |
1210 (or calc-gnuplot-display "<none>")) | 1217 (or calc-gnuplot-display "<none>")) |
1211 (setq calc-gnuplot-display name) | 1218 (setq calc-gnuplot-display name) |
1212 (if (calc-gnuplot-alive) | 1219 (if (calc-gnuplot-alive) |
1213 (calc-gnuplot-command "exit")))) | 1220 (calc-gnuplot-command "exit")))) |
1214 | 1221 |
1215 (defun calc-graph-geometry (name) | 1222 (defun calc-graph-geometry (name) |
1216 (interactive "sX geometry spec (or \"default\"): ") | 1223 (interactive "sX geometry spec (or \"default\"): ") |
1217 (if (equal name "") | 1224 (if (equal name "") |
1218 (message "Current X geometry is \"%s\"." | 1225 (message "Current X geometry is \"%s\"" |
1219 (or calc-gnuplot-geometry "default")) | 1226 (or calc-gnuplot-geometry "default")) |
1220 (setq calc-gnuplot-geometry (and (not (equal name "default")) name)) | 1227 (setq calc-gnuplot-geometry (and (not (equal name "default")) name)) |
1221 (if (calc-gnuplot-alive) | 1228 (if (calc-gnuplot-alive) |
1222 (calc-gnuplot-command "exit")))) | 1229 (calc-gnuplot-command "exit")))) |
1223 | 1230 |
1324 (goto-char (point-max)) | 1331 (goto-char (point-max)) |
1325 (vertical-motion (- 6 (window-height win))) | 1332 (vertical-motion (- 6 (window-height win))) |
1326 (set-window-start win (point)) | 1333 (set-window-start win (point)) |
1327 (goto-char (point-max))))) | 1334 (goto-char (point-max))))) |
1328 (or calc-graph-no-auto-view (sit-for 0)))) | 1335 (or calc-graph-no-auto-view (sit-for 0)))) |
1329 (setq calc-graph-no-auto-view nil) | |
1330 | 1336 |
1331 (defun calc-gnuplot-check-for-errors () | 1337 (defun calc-gnuplot-check-for-errors () |
1332 (if (save-excursion | 1338 (if (save-excursion |
1333 (prog2 | 1339 (prog2 |
1334 (progn | 1340 (progn |
1357 (accept-process-output (and (not calc-graph-no-wait) | 1363 (accept-process-output (and (not calc-graph-no-wait) |
1358 calc-gnuplot-process)) | 1364 calc-gnuplot-process)) |
1359 (calc-gnuplot-check-for-errors) | 1365 (calc-gnuplot-check-for-errors) |
1360 (if (get-buffer-window calc-gnuplot-buffer) | 1366 (if (get-buffer-window calc-gnuplot-buffer) |
1361 (calc-graph-view-trail))))) | 1367 (calc-graph-view-trail))))) |
1362 (setq calc-graph-no-wait nil) | |
1363 | 1368 |
1364 (defun calc-graph-init-buffers () | 1369 (defun calc-graph-init-buffers () |
1365 (or (and calc-gnuplot-buffer | 1370 (or (and calc-gnuplot-buffer |
1366 (buffer-name calc-gnuplot-buffer)) | 1371 (buffer-name calc-gnuplot-buffer)) |
1367 (setq calc-gnuplot-buffer (get-buffer-create "*Gnuplot Trail*"))) | 1372 (setq calc-gnuplot-buffer (get-buffer-create "*Gnuplot Trail*"))) |
1399 calc-gnuplot-buffer | 1404 calc-gnuplot-buffer |
1400 calc-gnuplot-name | 1405 calc-gnuplot-name |
1401 args)) | 1406 args)) |
1402 (process-kill-without-query calc-gnuplot-process)) | 1407 (process-kill-without-query calc-gnuplot-process)) |
1403 (file-error | 1408 (file-error |
1404 (error "Sorry, can't find \"%s\" on your system." | 1409 (error "Sorry, can't find \"%s\" on your system" |
1405 calc-gnuplot-name))) | 1410 calc-gnuplot-name))) |
1406 (save-excursion | 1411 (save-excursion |
1407 (set-buffer calc-gnuplot-buffer) | 1412 (set-buffer calc-gnuplot-buffer) |
1408 (while (and (not (save-excursion | 1413 (while (and (not (save-excursion |
1409 (goto-char origin) | 1414 (goto-char origin) |
1410 (search-forward "gnuplot> " nil t))) | 1415 (search-forward "gnuplot> " nil t))) |
1411 (memq (process-status calc-gnuplot-process) '(run stop))) | 1416 (memq (process-status calc-gnuplot-process) '(run stop))) |
1412 (accept-process-output calc-gnuplot-process)) | 1417 (accept-process-output calc-gnuplot-process)) |
1413 (or (memq (process-status calc-gnuplot-process) '(run stop)) | 1418 (or (memq (process-status calc-gnuplot-process) '(run stop)) |
1414 (error "Unable to start GNUPLOT process.")) | 1419 (error "Unable to start GNUPLOT process")) |
1415 (if (save-excursion | 1420 (if (save-excursion |
1416 (goto-char origin) | 1421 (goto-char origin) |
1417 (re-search-forward | 1422 (re-search-forward |
1418 "G N U P L O T.*\n.*version \\([0-9]+\\)\\." nil t)) | 1423 "G N U P L O T.*\n.*version \\([0-9]+\\)\\." nil t)) |
1419 (setq calc-gnuplot-version (string-to-int (buffer-substring | 1424 (setq calc-gnuplot-version (string-to-int (buffer-substring |