]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-graph.el
* font-lock.el (font-lock-maximum-decoration): Mention what numeric levels mean.
[gnu-emacs] / lisp / calc / calc-graph.el
index c2ca50ac6f7e0aaebe5272b5b4627f27cc091010..d5d8f0aaf35873b974d00dd685731dc779dc5e6d 100644 (file)
@@ -1,7 +1,6 @@
 ;;; calc-graph.el --- graph output functions for Calc
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2011 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
@@ -85,8 +84,7 @@
   (interactive "P")
   (calc-wrapper
    (calc-graph-init)
-   (save-excursion
-     (set-buffer calc-gnuplot-input)
+   (with-current-buffer calc-gnuplot-input
      (and (calc-graph-find-plot t all)
          (progn
            (if (looking-at "s?plot")
   (let ((num (calc-graph-count-curves))
        (pstyle (calc-var-value 'var-PointStyles))
        (lstyle (calc-var-value 'var-LineStyles)))
-    (save-excursion
-      (set-buffer calc-gnuplot-input)
+    (with-current-buffer calc-gnuplot-input
       (goto-char (point-min))
       (if (re-search-forward (if zdata "^plot[ \t]" "^splot[ \t]")
                             nil t)
 (defun calc-graph-juggle (arg)
   (interactive "p")
   (calc-graph-init)
-  (save-excursion
-    (set-buffer calc-gnuplot-input)
+  (with-current-buffer calc-gnuplot-input
     (if (< arg 0)
        (let ((num (calc-graph-count-curves)))
          (if (> num 0)
       (calc-graph-do-juggle))))
 
 (defun calc-graph-count-curves ()
-  (save-excursion
-    (set-buffer calc-gnuplot-input)
+  (with-current-buffer calc-gnuplot-input
     (if (re-search-forward "^s?plot[ \t]" nil t)
        (let ((num 1))
          (goto-char (point-min))
                     "set xlabel\nset ylabel\nset title\n"
                     "set noclip points\nset clip one\nset clip two\n"
                     "set format \"%g\"\nset tics\nset xtics\nset ytics\n"
-                    "set data style linespoints\n"
+                    "set style data linespoints\n"
                     "set nogrid\nset nokey\nset nopolar\n"))
         (if (>= ver 3)
             (insert "set surface\nset nocontour\n"
           (while (memq (preceding-char) '(?\s ?\t))
             (forward-char -1))
           (if (eq (preceding-char) ?\,)
-              (delete-backward-char 1))))
-       (save-excursion
-        (set-buffer calcbuf)
+              (delete-char -1))))
+       (with-current-buffer calcbuf
         (setq cache-env (list calc-angle-mode
                               calc-complex-mode
                               calc-simplify-mode
                filename)
           (delete-region (match-beginning 0) (match-end 0))
           (setq filename (calc-temp-file-name calc-graph-curve-num))
-          (save-excursion
-            (set-buffer calcbuf)
+          (with-current-buffer calcbuf
             (let (tempbuftop
                   (calc-graph-xp calc-graph-xvalue)
                   (calc-graph-yp calc-graph-yvalue)
                 (let ((calc-group-digits nil)
                       (calc-leading-zeros nil)
                       (calc-number-radix 10)
+                       (calc-twos-complement-mode nil)
                       (entry (and (not calc-graph-is-splot)
                                   (list calc-graph-xp calc-graph-yp calc-graph-xhigh calc-graph-numsteps))))
                   (or (equal entry
                (setq calc-graph-xstep 1)
              (error "%s is not a suitable basis for %s" calc-graph-xname calc-graph-yname)))))
     (or (math-realp calc-graph-yvalue)
-       (let ((arglist nil))
+       (let ((math-arglist nil))
          (setq calc-graph-yvalue (math-evaluate-expr calc-graph-yvalue))
          (calc-default-formula-arglist calc-graph-yvalue)
-         (or arglist
+         (or math-arglist
              (error "%s does not contain any unassigned variables" calc-graph-yname))
-         (and (cdr arglist)
+         (and (cdr math-arglist)
               (error "%s contains more than one variable: %s"
-                     calc-graph-yname arglist))
+                     calc-graph-yname math-arglist))
          (setq calc-graph-yvalue (math-expr-subst calc-graph-yvalue
-                                       (math-build-var-name (car arglist))
+                                       (math-build-var-name (car math-arglist))
                                        '(var DUMMY var-DUMMY)))))
     (setq calc-graph-ycache (assoc calc-graph-yvalue calc-graph-data-cache))
     (delq calc-graph-ycache calc-graph-data-cache)
              calc-graph-zp calc-graph-yvalue
              calc-graph-xvec t))
     (or (math-realp calc-graph-yvalue)
-       (let ((arglist nil))
+       (let ((math-arglist nil))
          (setq calc-graph-yvalue (math-evaluate-expr calc-graph-yvalue))
          (calc-default-formula-arglist calc-graph-yvalue)
-         (setq arglist (sort arglist 'string-lessp))
-         (or (cdr arglist)
+         (setq math-arglist (sort math-arglist 'string-lessp))
+         (or (cdr math-arglist)
              (error "%s does not contain enough unassigned variables" calc-graph-yname))
-         (and (cdr (cdr arglist))
-              (error "%s contains too many variables: %s" calc-graph-yname arglist))
+         (and (cdr (cdr math-arglist))
+              (error "%s contains too many variables: %s" calc-graph-yname math-arglist))
          (setq calc-graph-yvalue (math-multi-subst calc-graph-yvalue
                                         (mapcar 'math-build-var-name
-                                                arglist)
+                                                math-arglist)
                                         '((var DUMMY var-DUMMY)
                                           (var DUMMY2 var-DUMMY2))))))
     (if (setq calc-graph-xvec (eq (car-safe calc-graph-xvalue) 'vec))
               (= (length calc-graph-yval) 4))
          (progn
            (or calc-graph-surprise-splot
-               (save-excursion
-                 (set-buffer (get-buffer-create "*Gnuplot Temp*"))
+               (with-current-buffer (get-buffer-create "*Gnuplot Temp*")
                  (save-excursion
                    (goto-char (point-max))
                    (re-search-backward "^plot[ \t]")
@@ -1072,8 +1065,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
 
 (defun calc-graph-set-styles (lines points &optional yerr)
   (calc-graph-init)
-  (save-excursion
-    (set-buffer calc-gnuplot-input)
+  (with-current-buffer calc-gnuplot-input
     (or (calc-graph-find-plot nil nil)
        (error "No data points have been set!"))
     (let ((base (point))
@@ -1161,8 +1153,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
 (defun calc-graph-name (name)
   (interactive "sTitle for current curve: ")
   (calc-graph-init)
-  (save-excursion
-    (set-buffer calc-gnuplot-input)
+  (with-current-buffer calc-gnuplot-input
     (or (calc-graph-find-plot nil nil)
        (error "No data points have been set!"))
     (let ((base (point))
@@ -1297,16 +1288,14 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
 
 (defun calc-graph-find-command (cmd)
   (calc-graph-init)
-  (save-excursion
-    (set-buffer calc-gnuplot-input)
+  (with-current-buffer calc-gnuplot-input
     (goto-char (point-min))
     (if (re-search-forward (concat "^set[ \t]+" cmd "[ \t]*\\(.*\\)$") nil t)
        (buffer-substring (match-beginning 1) (match-end 1)))))
 
 (defun calc-graph-set-command (cmd &rest args)
   (calc-graph-init)
-  (save-excursion
-    (set-buffer calc-gnuplot-input)
+  (with-current-buffer calc-gnuplot-input
     (goto-char (point-min))
     (if (re-search-forward (concat "^set[ \t]+" cmd "[ \t\n]") nil t)
        (progn
@@ -1374,8 +1363,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
        (if (setq win (get-buffer-window buf))
            (or need
                (and (eq buf calc-gnuplot-buffer)
-                    (save-excursion
-                      (set-buffer buf)
+                    (with-current-buffer buf
                       (not (pos-visible-in-window-p (point-max) win))))
                (progn
                  (bury-buffer buf)
@@ -1388,11 +1376,10 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
              (set-window-buffer win buf)
            (if (eq major-mode 'calc-mode)
                (if (or need
-                       (< (window-height) (1- (frame-height))))
+                       (not (window-full-height-p)))
                    (display-buffer buf))
              (switch-to-buffer buf)))))
-    (save-excursion
-      (set-buffer buf)
+    (with-current-buffer buf
       (if (and (eq buf calc-gnuplot-buffer)
               (setq win (get-buffer-window buf))
               (not (pos-visible-in-window-p (point-max) win)))
@@ -1419,8 +1406,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
   (let ((cmd (concat (mapconcat 'identity args " ") "\n")))
     (or (string= calc-gnuplot-name "pgnuplot")
        (accept-process-output))
-    (save-excursion
-      (set-buffer calc-gnuplot-buffer)
+    (with-current-buffer calc-gnuplot-buffer
       (calc-gnuplot-check-for-errors)
       (goto-char (point-max))
       (setq calc-gnuplot-trail-mark (point))
@@ -1454,8 +1440,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
              (delete-process calc-gnuplot-process)
              (setq calc-gnuplot-process nil)))
        (calc-graph-init-buffers)
-       (save-excursion
-         (set-buffer calc-gnuplot-buffer)
+       (with-current-buffer calc-gnuplot-buffer
          (insert "\nStarting gnuplot...\n")
          (setq origin (point)))
        (setq calc-graph-last-device nil)
@@ -1489,8 +1474,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
          (file-error
           (error "Sorry, can't find \"%s\" on your system"
                  calc-gnuplot-name)))
-       (save-excursion
-         (set-buffer calc-gnuplot-buffer)
+       (with-current-buffer calc-gnuplot-buffer
          (while (and (not (string= calc-gnuplot-name "pgnuplot"))
                      (not (save-excursion
                             (goto-char origin)
@@ -1510,8 +1494,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
                                           (match-end 1))))
                (setq calc-gnuplot-version 1)))
          (goto-char (point-max)))))
-  (save-excursion
-    (set-buffer calc-gnuplot-input)
+  (with-current-buffer calc-gnuplot-input
     (if (= (buffer-size) 0)
        (insert "# Commands for running gnuplot\n\n\n")
       (or calc-graph-no-auto-view
@@ -1522,5 +1505,4 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
 
 (provide 'calc-graph)
 
-;; arch-tag: e4b06a52-c386-4d54-a2bb-7c0a0ef533c2
 ;;; calc-graph.el ends here