]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-yank.el
Add new maintainer (deego).
[gnu-emacs] / lisp / calc / calc-yank.el
index 6551233416627e200ef197436250759362791d83..c8afb087ef51109a2fb859cbc15e8cf7297c96be 100644 (file)
@@ -1,6 +1,10 @@
-;; Calculator for GNU Emacs, part II [calc-yank.el]
-;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+;;; calc-yank.el --- kill-ring functionality for Calc
+
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainers: D. Goel <deego@gnufans.org> 
+;;              Colin Walters <walters@debian.org>
 
 ;; This file is part of GNU Emacs.
 
@@ -19,7 +23,9 @@
 ;; file named COPYING.  Among other things, the copyright notice
 ;; and this notice must be preserved on all copies.
 
+;;; Commentary:
 
+;;; Code:
 
 ;; This file is autoloaded from calc-ext.el.
 (require 'calc-ext)
             (if (not no-delete)
                 (calc-pop-stack n (- num n -1))))
           (setq calc-last-kill (cons (car kill-ring) stuff)))))
-    (kill-line nn))
-)
+    (kill-line nn)))
 
 (defun calc-force-refresh ()
   (if (or calc-executing-macro calc-display-dirty)
       (let ((calc-executing-macro nil))
-       (calc-refresh)))
-)
+       (calc-refresh))))
 
 (defun calc-locate-cursor-element (pt)
   (save-excursion
     (goto-char (point-max))
-    (calc-locate-cursor-scan (- calc-stack-top) calc-stack pt))
-)
+    (calc-locate-cursor-scan (- calc-stack-top) calc-stack pt)))
 
 (defun calc-locate-cursor-scan (n stack pt)
   (if (or (<= (point) pt)
          (null stack))
       n
     (forward-line (- (nth 1 (car stack))))
-    (calc-locate-cursor-scan (1+ n) (cdr stack) pt))
-)
+    (calc-locate-cursor-scan (1+ n) (cdr stack) pt)))
 
 (defun calc-kill-region (top bot &optional no-delete)
   (interactive "r")
             (calc-pop-stack num bot-num))))
     (if no-delete
        (copy-region-as-kill top bot)
-      (kill-region top bot)))
-)
+      (kill-region top bot))))
 
 (defun calc-copy-as-kill (n)
   (interactive "P")
-  (calc-kill n t)
-)
+  (calc-kill n t))
 
 (defun calc-copy-region-as-kill (top bot)
   (interactive "r")
-  (calc-kill-region top bot t)
-)
+  (calc-kill-region top bot t))
 
 ;;; This function uses calc-last-kill if possible to get an exact result,
 ;;; otherwise it just parses the yanked string.
                    (if (eq (car-safe val) 'error)
                        (error "Bad format in yanked data")
                      val))
-               val)))))))
-)
+               val))))))))
 
 (defun calc-clean-newlines (s)
   (cond
     (calc-clean-newlines (concat (math-match-substring s 1) ","
                                 (math-match-substring s 2))))
    
-   (t s))
-)
+   (t s)))
 
 
 (defun calc-do-grab-region (top bot arg)
-  (and (memq major-mode '(calc-mode calc-trail-mode))
-       (error "This command works only in a regular text buffer."))
+  (when (memq major-mode '(calc-mode calc-trail-mode))
+    (error "This command works only in a regular text buffer"))
   (let* ((from-buffer (current-buffer))
         (calc-was-started (get-buffer-window "*Calculator*"))
         (single nil)
          (forward-char (+ (nth 1 vals) (if single 0 1)))
          (error (nth 2 vals))))
     (calc-slow-wrapper
-     (calc-enter-result 0 "grab" vals)))
-)
+     (calc-enter-result 0 "grab" vals))))
 
 
 (defun calc-do-grab-rectangle (top bot arg &optional reduce)
   (and (memq major-mode '(calc-mode calc-trail-mode))
-       (error "This command works only in a regular text buffer."))
+       (error "This command works only in a regular text buffer"))
   (let* ((col1 (save-excursion (goto-char top) (current-column)))
         (col2 (save-excursion (goto-char bot) (current-column)))
         (from-buffer (current-buffer))
         data mat vals lnum pt pos)
     (if (= col1 col2)
        (save-excursion
-         (or (= col1 0)
-             (error "Point and mark must be at beginning of line, or define a rectangle"))
+         (unless (= col1 0)
+           (error "Point and mark must be at beginning of line, or define a rectangle"))
          (goto-char top)
          (while (< (point) bot)
            (setq pt (point))
     (calc)
     (setq mat (list 'vec)
          lnum 0)
-    (and arg
-        (setq arg (if (consp arg) 0 (prefix-numeric-value arg))))
+    (when arg
+      (setq arg (if (consp arg) 0 (prefix-numeric-value arg))))
     (while data
       (if (natnump arg)
          (progn
                    vals (math-read-expr (concat "[" s "]")))
              (if (eq (car-safe vals) 'error)
                  (let ((v2 (math-read-expr s)))
-                   (or (eq (car-safe v2) 'error)
-                       (setq vals (list 'vec v2)))))))))
+                   (unless (eq (car-safe v2) 'error)
+                     (setq vals (list 'vec v2)))))))))
       (if (eq (car-safe vals) 'error)
          (progn
            (if calc-was-started
            (forward-line lnum)
            (forward-char (+ (nth 1 vals) (min col1 col2) pos))
            (error (nth 2 vals))))
-      (or (equal vals '(vec))
-         (setq mat (cons vals mat)))
+      (unless (equal vals '(vec))
+       (setq mat (cons vals mat)))
       (setq data (cdr data)
            lnum (1+ lnum)))
     (calc-slow-wrapper
      (if reduce
         (calc-enter-result 0 "grb+" (list reduce '(var add var-add)
                                           (nreverse mat)))
-       (calc-enter-result 0 "grab" (nreverse mat)))))
-)
+       (calc-enter-result 0 "grab" (nreverse mat))))))
 
 
 (defun calc-copy-to-buffer (nn)
                      (delete-char 4)
                      (setq n (1+ n)))
                    (forward-line n))))
-          (if thebuf (setq movept (point)))
-          (if (get-buffer-window (current-buffer))
-              (set-window-point (get-buffer-window (current-buffer))
-                                (point)))))))
-    (if movept (goto-char movept))
-    (and (consp nn)
-        (not thebuf)
-        (progn
-          (calc-quit t)
-          (switch-to-buffer newbuf))))
-)
+          (when thebuf
+            (setq movept (point)))
+          (when (get-buffer-window (current-buffer))
+            (set-window-point (get-buffer-window (current-buffer))
+                              (point)))))))
+    (when movept
+      (goto-char movept))
+    (when (and (consp nn)
+              (not thebuf))
+      (calc-quit t)
+      (switch-to-buffer newbuf))))
 
 (defun calc-overwrite-string (str eat-lnums)
-  (if (string-match "\n\\'" str)
-      (setq str (substring str 0 -1)))
-  (if eat-lnums
-      (setq str (substring str 4)))
+  (when (string-match "\n\\'" str)
+    (setq str (substring str 0 -1)))
+  (when eat-lnums
+    (setq str (substring str 4)))
   (if (and (string-match "\\`[-+]?[0-9.]+\\(e-?[0-9]+\\)?\\'" str)
           (looking-at "[-+]?[0-9.]+\\(e-?[0-9]+\\)?"))
       (progn
                    (forward-char 1))
                  (if eat-lnums (setq i (+ i 4)))))
          (self-insert-command 1))
-       (setq i (1+ i)))))
-)
+       (setq i (1+ i))))))
 
 ;;; First, require that buffer is visible and does not begin with "*"
 ;;; Second, require only that it not begin with "*Calc"
                    (or (string-match "\\`\\*.*" (buffer-name (car buf)))
                        (not (get-buffer-window (car buf))))))
           (calc-find-writable-buffer (cdr buf) mode)
-        (car buf)))
-)
+        (car buf))))
 
 
 (defun calc-edit (n)
   (interactive "p")
   (calc-slow-wrapper
-   (if (eq n 0)
-       (setq n (calc-stack-size)))
+   (when (eq n 0)
+     (setq n (calc-stack-size)))
    (let* ((flag nil)
          (allow-ret (> n 1))
          (list (math-showing-full-precision
                           (function
                            (lambda (x)
                              (if (math-vectorp x) (setq allow-ret t))
-                             (math-format-nice-expr x (screen-width)))))
+                             (math-format-nice-expr x (frame-width)))))
                         (if (> n 0)
                             (calc-top-list n)
                           (calc-top-list 1 (- n)))))))
      (while list
        (insert (car list) "\n")
        (setq list (cdr list)))))
-  (calc-show-edit-buffer)
-)
+  (calc-show-edit-buffer))
 
 (defun calc-alg-edit (str)
   (calc-edit-mode '(calc-finish-stack-edit 0))
   (calc-show-edit-buffer)
   (insert str "\n")
   (backward-char 1)
-  (calc-set-command-flag 'do-edit)
-)
+  (calc-set-command-flag 'do-edit))
 
 (defvar calc-edit-mode-map nil "Keymap for use by the calc-edit command.")
 (if calc-edit-mode-map
   (setq calc-edit-mode-map (make-sparse-keymap))
   (define-key calc-edit-mode-map "\n" 'calc-edit-finish)
   (define-key calc-edit-mode-map "\r" 'calc-edit-return)
-  (define-key calc-edit-mode-map "\C-c\C-c" 'calc-edit-finish)
-)
+  (define-key calc-edit-mode-map "\C-c\C-c" 'calc-edit-finish))
 
 (defun calc-edit-mode (&optional handler allow-ret title)
   "Calculator editing mode.  Press RET, LFD, or C-c C-c to finish.
 To cancel the edit, simply kill the *Calc Edit* buffer."
   (interactive)
-  (or handler
-      (error "This command can be used only indirectly through calc-edit."))
+  (unless handler
+    (error "This command can be used only indirectly through calc-edit"))
   (let ((oldbuf (current-buffer))
        (buf (get-buffer-create "*Calc Edit*")))
     (set-buffer buf)
@@ -476,8 +466,7 @@ To cancel the edit, simply kill the *Calc Edit* buffer."
            (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch)
                "M-# x"
              "C-x k RET")
-           " to cancel.\n"))
-)
+           " to cancel.\n")))
 (put 'calc-edit-mode 'mode-class 'special)
 
 (defun calc-show-edit-buffer ()
@@ -488,22 +477,20 @@ To cancel the edit, simply kill the *Calc Edit* buffer."
           (select-window (get-buffer-window (aref calc-embedded-info 1))))
       (switch-to-buffer (get-buffer-create "*Calc Edit*")))
     (setq calc-return-buffer buf)
-    (if (and (< (window-width) (screen-width))
+    (if (and (< (window-width) (frame-width))
             calc-display-trail)
        (let ((win (get-buffer-window (calc-trail-buffer))))
          (if win
              (delete-window win))))
     (set-buffer-modified-p nil)
     (goto-char (point-min))
-    (forward-line 1))
-)
+    (forward-line 1)))
 
 (defun calc-edit-return ()
   (interactive)
   (if (and (boundp 'calc-allow-ret) calc-allow-ret)
       (newline)
-    (calc-edit-finish))
-)
+    (calc-edit-finish)))
 
 (defun calc-edit-finish (&optional keep)
   "Finish calc-edit mode.  Parse buffer contents and push them on the stack."
@@ -515,21 +502,21 @@ To cancel the edit, simply kill the *Calc Edit* buffer."
           (boundp 'calc-edit-handler)
           (boundp 'calc-restore-trail)
           (eq major-mode 'calc-edit-mode))
-      (error "This command is valid only in buffers created by calc-edit."))
+      (error "This command is valid only in buffers created by calc-edit"))
   (let ((buf (current-buffer))
        (original calc-original-buffer)
        (return calc-return-buffer)
        (one-window calc-one-window)
        (disp-trail calc-restore-trail))
     (save-excursion
-      (if (or (null (buffer-name original))
-             (progn
-               (set-buffer original)
-               (not (eq major-mode 'calc-mode))))
-         (error "Original calculator buffer has been corrupted.")))
+      (when (or (null (buffer-name original))
+               (progn
+                 (set-buffer original)
+                 (not (eq major-mode 'calc-mode))))
+       (error "Original calculator buffer has been corrupted")))
     (goto-char (point-min))
-    (if (looking-at "Calc Edit\\|Editing ")
-       (forward-line 1))
+    (when (looking-at "Calc Edit\\|Editing ")
+      (forward-line 1))
     (if (buffer-modified-p)
        (eval calc-edit-handler))
     (if one-window
@@ -543,16 +530,14 @@ To cancel the edit, simply kill the *Calc Edit* buffer."
     (if disp-trail
        (calc-wrapper
         (calc-trail-display 1 t)))
-    (message ""))
-)
+    (message "")))
 
 (defun calc-edit-cancel ()
   "Cancel calc-edit mode.  Ignore the Calc Edit buffer and don't change stack."
   (interactive)
   (let ((calc-edit-handler nil))
     (calc-edit-finish))
-  (message "(Cancelled)")
-)
+  (message "(Cancelled)"))
 
 (defun calc-finish-stack-edit (num)
   (let ((buf (current-buffer))
@@ -567,11 +552,10 @@ To cancel the edit, simply kill the *Calc Edit* buffer."
                      (math-expr-opers math-standard-opers))
                  (and (string-match "[^\n\t ]" str)
                       (math-read-exprs str)))))
-      (if (eq (car-safe vals) 'error)
-         (progn
-           (switch-to-buffer buf)
-           (goto-char (+ start (nth 1 vals)))
-           (error (nth 2 vals))))
+      (when (eq (car-safe vals) 'error)
+       (switch-to-buffer buf)
+       (goto-char (+ start (nth 1 vals)))
+       (error (nth 2 vals)))
       (calc-wrapper
        (if (symbolp num)
           (progn
@@ -585,9 +569,6 @@ To cancel the edit, simply kill the *Calc Edit* buffer."
                                          calc-simplify-mode)))
                (if (>= num 0)
                    (calc-enter-result num "edit" vals)
-                 (calc-enter-result 1 "edit" vals (- num)))))))))
-)
-
-
-
+                 (calc-enter-result 1 "edit" vals (- num))))))))))
 
+;;; calc-yank.el ends here