Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / calc / calc-misc.el
index 350e469..ac1b262 100644 (file)
@@ -1,7 +1,6 @@
 ;;; calc-misc.el --- miscellaneous functions for Calc
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2012 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
@@ -35,6 +34,7 @@
 (declare-function calc-inv-hyp-prefix-help "calc-help" ())
 (declare-function calc-inverse-prefix-help "calc-help" ())
 (declare-function calc-hyperbolic-prefix-help "calc-help" ())
+(declare-function calc-option-prefix-help "calc-help" ())
 (declare-function calc-explain-why "calc-stuff" (why &optional more))
 (declare-function calc-clear-command-flag "calc-ext" (f))
 (declare-function calc-roll-down-with-selections "calc-sel" (n m))
@@ -57,7 +57,7 @@
 (declare-function math-pow-of-zero "calc-arith" (a b))
 (declare-function math-pow-zero "calc-arith" (a b))
 (declare-function math-pow-fancy "calc-arith" (a b))
-
+(declare-function calc-locate-cursor-element "calc-yank" (pt))
 
 ;;;###autoload
 (defun calc-dispatch-help (arg)
@@ -140,8 +140,8 @@ Calc user interface as before (either C-x * C or C-x * K; initially C-x * C).
     (if cwin
        (setq calc-full-mode
              (if kwin
-                 (and twin (eq (window-width twin) (frame-width)))
-               (eq (window-height cwin) (1- (frame-height))))))
+                 (and twin (window-full-width-p twin))
+               (window-full-height-p cwin))))
     (setq calc-full-mode (if arg
                             (> (prefix-numeric-value arg) 0)
                           (not calc-full-mode)))
@@ -219,10 +219,10 @@ Calc user interface as before (either C-x * C or C-x * K; initially C-x * C).
   (let ((msgs
         '("Press `h' for complete help; press `?' repeatedly for a summary"
           "Letter keys: Negate; Precision; Yank; Why; Xtended cmd; Quit"
-          "Letter keys: SHIFT + Undo, reDo; Keep-args; Inverse, Hyperbolic"
+          "Letter keys: SHIFT + Undo, reDo; Inverse, Hyperbolic, Option"
           "Letter keys: SHIFT + sQrt; Sin, Cos, Tan; Exp, Ln, logB"
           "Letter keys: SHIFT + Floor, Round; Abs, conJ, arG; Pi"
-          "Letter keys: SHIFT + Num-eval; More-recn; eXec-kbd-macro"
+          "Letter keys: SHIFT + Num-eval; More-recn; eXec-kbd-macro; Keep-args"
           "Other keys: +, -, *, /, ^, \\ (int div), : (frac div)"
           "Other keys: & (1/x), | (concat), % (modulo), ! (factorial)"
           "Other keys: ' (alg-entry), = (eval), ` (edit); M-RET (last-args)"
@@ -245,26 +245,28 @@ Calc user interface as before (either C-x * C or C-x * K; initially C-x * C).
                  (calc-inv-hyp-prefix-help)
                (calc-inverse-prefix-help))
            (calc-hyperbolic-prefix-help))
-       (setq calc-help-phase
-             (if (eq this-command last-command)
-                 (% (1+ calc-help-phase) (1+ (length msgs)))
-               0))
-       (let ((msg (nth calc-help-phase msgs)))
-         (message "%s" (if msg
-                           (concat msg ":"
-                                   (make-string (- (apply 'max
-                                                          (mapcar 'length
-                                                                  msgs))
-                                                   (length msg)) 32)
-                                   "  [?=MORE]")
-                         "")))))))
+        (if calc-option-flag
+            (calc-option-prefix-help)
+          (setq calc-help-phase
+                (if (eq this-command last-command)
+                    (% (1+ calc-help-phase) (1+ (length msgs)))
+                  0))
+          (let ((msg (nth calc-help-phase msgs)))
+            (message "%s" (if msg
+                              (concat msg ":"
+                                      (make-string (- (apply 'max
+                                                             (mapcar 'length
+                                                                     msgs))
+                                                      (length msg)) 32)
+                                      "  [?=MORE]")
+                            ""))))))))
 
 
 
 
 ;;;; Stack and buffer management.
 
-;; The variable calc-last-why-command is set in calc-do-handly-whys
+;; The variable calc-last-why-command is set in calc-do-handle-whys
 ;; and used in calc-why (in calc-stuff.el).
 (defvar calc-last-why-command)
 
@@ -452,6 +454,119 @@ Calc user interface as before (either C-x * C or C-x * K; initially C-x * C).
           (t
            (calc-roll-up-stack (calc-stack-size) (- nn)))))))
 
+;;;###autoload
+(defun calc-transpose-lines (&optional arg)
+  "Transpose previous line and current line.
+With argument ARG, move previous line past ARG lines.
+With argument 0, switch line point is in with line mark is in."
+  (interactive "p")
+  (setq arg (or arg 1))
+  (let (bot-line mid-line end-line
+                 old-top-list new-top-list
+                 bot-cell mid-cell
+                 prev-mid-cell post-mid-cell post-bot-cell)
+    (calc-wrapper
+     (when (eq major-mode 'calc-mode)
+       (cond
+        ;; exchange point and mark
+        ((= 0 arg)
+         (setq bot-line  (calc-locate-cursor-element (point))
+               mid-line  (mark))
+         (if mid-line
+             (setq mid-line  (calc-locate-cursor-element mid-line)
+                   end-line  (1+ mid-line))
+           (error "No mark set"))
+         (if (< bot-line mid-line)
+             (let ((temp mid-line))
+               (setq mid-line bot-line
+                     bot-line temp))))
+        ;; move bot-line to mid-line that is above bot-line on stack (that is
+        ;; to say mid-line displayed below bot-line in *Calculator* buffer)
+        ((> arg 0)
+         (setq bot-line (1+ (calc-locate-cursor-element (point)))
+               mid-line (- bot-line arg)
+               end-line mid-line))
+        ;; move bot-line to mid-line that is above bot-line on stack (that is
+        ;; to say mid-line displayed below bot-line in *Calculator* buffer)
+        ((< arg 0)
+         (setq mid-line (1+ (calc-locate-cursor-element (point)))
+               bot-line (- mid-line arg)
+               end-line bot-line)))
+       (calc-check-stack bot-line)
+       (if (= 0 mid-line)
+           (error "Can't transpose beyond top"))
+       (setq old-top-list (nreverse (calc-top-list bot-line)))
+       ;; example: (arg = 2)
+       ;; old-top-list =
+       ;; 1 <-- top of stack (bottom of *Calculator* buffer)
+       ;; 2
+       ;; 3 <-- mid-line = 3
+       ;; 4 <-- point
+       ;; 5 <-- bot-line = 5
+       (dotimes (i mid-line)
+         (setq mid-cell old-top-list
+               old-top-list (cdr old-top-list))
+         (setcdr mid-cell new-top-list)
+         (setq new-top-list  mid-cell))
+       ;; example follow-up:
+       ;; old-top-list =
+       ;; 4
+       ;; 5
+       ;; new-top-list =
+       ;; 3 <-- mid-cell
+       ;; 2
+       ;; 1
+       (setq  prev-mid-cell old-top-list)
+       (dotimes (i (- bot-line mid-line))
+         (setq bot-cell old-top-list
+               old-top-list (cdr old-top-list))
+         (setcdr bot-cell new-top-list)
+         (setq new-top-list  bot-cell))
+       (setq post-mid-cell (cdr mid-cell)
+             post-bot-cell  (cdr bot-cell))
+       ;; example follow-up:
+       ;; new-top-list =
+       ;; 5 <-- bot-cell
+       ;; 4 <-- prev-mid-cell & post-bot-cell
+       ;; 3 <-- mid-cell
+       ;; 2 <-- post-mid-cell
+       ;; 1
+       (cond
+        ((= 0 arg); swap bot and mid
+         (setcdr mid-cell            post-bot-cell)
+         (setcdr bot-cell            post-mid-cell)
+         (setcdr prev-mid-cell       bot-cell)
+         ;; example follow-up:
+         ;; 3 <-- mid-cell
+         ;; 4 <-- post-bot-cell & prev-mid-cell
+         ;; 5 <-- bot-cell
+         ;; 2 <-- post-mid-cell
+         ;; 1
+         (setq new-top-list mid-cell))
+        ((< 0 arg) ; move bot just after mid
+         (setcdr mid-cell       bot-cell)
+         (setcdr bot-cell       post-mid-cell)
+         ;; example follow-up:
+         ;; new-top-list =
+         ;; 4 <-- post-bot-cell
+         ;; 3 <-- mid-cell
+         ;; 5 <-- bot-cell
+         ;; 2 <-- post-mid-cell
+         ;; 1
+         (setq new-top-list post-bot-cell))
+        ((> 0 arg) ; move mid just before bot
+         (setcdr mid-cell       bot-cell)
+         (setcdr prev-mid-cell  post-mid-cell)
+         ;; example follow-up:
+         ;; new-top-list =
+         ;; 3 <-- mid-cell
+         ;; 5 <-- bot-cell
+         ;; 4 <-- prev-mid-cell
+         ;; 2 <-- post-mid-cell
+         ;; 1
+         (setq new-top-list mid-cell)))
+       (calc-pop-push-list bot-line new-top-list)))
+    (calc-cursor-stack-index (1- end-line))))
 
 
 
@@ -472,8 +587,8 @@ When this key is used, calc-ext (the Calculator extensions module) will be
 loaded and the keystroke automatically re-typed."
   (interactive "P")
   (require 'calc-ext)
-  (if (keymapp (key-binding (char-to-string last-command-char)))
-      (message "%s%c-" (calc-num-prefix-name n) last-command-char))
+  (if (keymapp (key-binding (char-to-string last-command-event)))
+      (message "%s%c-" (calc-num-prefix-name n) last-command-event))
   (calc-unread-command)
   (setq prefix-arg n))
 
@@ -491,7 +606,7 @@ loaded and the keystroke automatically re-typed."
   (interactive)
   (if (calc-minibuffer-contains "[-+]?\\(1[1-9]\\|[2-9][0-9]\\)#.*")
       (progn
-       (setq last-command-char (upcase last-command-char))
+       (setq last-command-event (upcase last-command-event))
        (calcDigit-key))
     (calcDigit-nondigit)))
 
@@ -847,5 +962,4 @@ doing 'M-x toggle-debug-on-error', then reproducing the bug.
 ;; generated-autoload-file: "calc-loaddefs.el"
 ;; End:
 
-;; arch-tag: 7984d9d0-62e5-41dc-afb8-e904b975f250
 ;;; calc-misc.el ends here