From 1e253dcb115e9c30fbc190427f26e9a1da332f65 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 19 Nov 2001 07:34:59 +0000 Subject: [PATCH] (calc-keypad-mode): New. (calc-do-keypad): Use it. (calc-keypad-map): Move into `calc-keypad-mode'. 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. --- lisp/calc/calc-keypd.el | 447 ++++++++++++++++++++-------------------- 1 file changed, 221 insertions(+), 226 deletions(-) diff --git a/lisp/calc/calc-keypd.el b/lisp/calc/calc-keypd.el index 550ba4e7f50..834736a3cf1 100644 --- a/lisp/calc/calc-keypd.el +++ b/lisp/calc/calc-keypd.el @@ -1,6 +1,9 @@ -;; Calculator for GNU Emacs, part II [calc-keypd.el] +;;; calc-keypd.el --- mouse-capable keypad input for Calc + ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. -;; Written by Dave Gillespie, daveg@synaptics.com. + +;; Author: David Gillespie +;; Maintainer: Colin Walters ;; This file is part of GNU Emacs. @@ -19,6 +22,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. @@ -29,9 +35,6 @@ (defun calc-Need-calc-keypd () nil) - -;;; Pictorial interface to Calc using a mouse. - (defvar calc-keypad-buffer nil) (defvar calc-keypad-menu 0) (defvar calc-keypad-full-layout nil) @@ -39,30 +42,216 @@ (defvar calc-keypad-prev-input nil) (defvar calc-keypad-said-hello nil) -(defvar calc-keypad-map nil) -(unless calc-keypad-map - (let ((map (make-sparse-keymap))) - (define-key map " " 'calc-keypad-press) - (define-key map (kbd "RET") 'calc-keypad-press) - (define-key map (kbd "TAB") 'calc-keypad-menu) - (define-key map "q" 'calc-keypad-off) - (define-key map [(mouse-3)] 'calc-keypad-right-click) - (define-key map [(mouse-2)] 'calc-keypad-middle-click) - (define-key map [(mouse-1)] 'calc-keypad-left-click) - (setq calc-keypad-map map))) +;;; |----+----+----+----+----+----| +;;; | ENTER |+/- |EEX |UNDO| <- | +;;; |-----+---+-+--+--+-+---++----| +;;; | INV | 7 | 8 | 9 | / | +;;; |-----+-----+-----+-----+-----| +;;; | HYP | 4 | 5 | 6 | * | +;;; |-----+-----+-----+-----+-----| +;;; |EXEC | 1 | 2 | 3 | - | +;;; |-----+-----+-----+-----+-----| +;;; | OFF | 0 | . | PI | + | +;;; |-----+-----+-----+-----+-----| +(defvar calc-keypad-layout + '( ( ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over ) + ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over ) + ( "+/-" calc-change-sign calc-inv (progn -4 calc-pack) ) + ( "EEX" ("e") (progn calc-num-prefix calc-pack-interval) + (progn -5 calc-pack) ) + ( "UNDO" calc-undo calc-redo calc-last-args ) + ( "<-" calc-pop (progn 0 calc-pop) + (progn calc-num-prefix calc-pop) ) ) + ( ( "INV" calc-inverse ) + ( "7" ("7") calc-round ) + ( "8" ("8") (progn 2 calc-clean-num) ) + ( "9" ("9") calc-float ) + ( "/" calc-divide (progn calc-inverse calc-power) ) ) + ( ( "HYP" calc-hyperbolic ) + ( "4" ("4") calc-ln calc-log10 ) + ( "5" ("5") calc-exp calc-exp10 ) + ( "6" ("6") calc-abs ) + ( "*" calc-times calc-power ) ) + ( ( "EXEC" calc-keypad-execute ) + ( "1" ("1") calc-arcsin calc-sin ) + ( "2" ("2") calc-arccos calc-cos ) + ( "3" ("3") calc-arctan calc-tan ) + ( "-" calc-minus calc-conj ) ) + ( ( "OFF" calc-keypad-off ) + ( "0" ("0") calc-imaginary ) + ( "." (".") calc-precision ) + ( "PI" calc-pi ) + ( "+" calc-plus calc-sqrt ) ) )) + +(defvar calc-keypad-menus '( calc-keypad-math-menu + calc-keypad-funcs-menu + calc-keypad-binary-menu + calc-keypad-vector-menu + calc-keypad-modes-menu + calc-keypad-user-menu ) ) + +;;; |----+----+----+----+----+----| +;;; |FLR |CEIL|RND |TRNC|CLN2|FLT | +;;; |----+----+----+----+----+----| +;;; | LN |EXP | |ABS |IDIV|MOD | +;;; |----+----+----+----+----+----| +;;; |SIN |COS |TAN |SQRT|y^x |1/x | + +(defvar calc-keypad-math-menu + '( ( ( "FLR" calc-floor ) + ( "CEIL" calc-ceiling ) + ( "RND" calc-round ) + ( "TRNC" calc-trunc ) + ( "CLN2" (progn 2 calc-clean-num) ) + ( "FLT" calc-float ) ) + ( ( "LN" calc-ln ) + ( "EXP" calc-exp ) + ( "" nil ) + ( "ABS" calc-abs ) + ( "IDIV" calc-idiv ) + ( "MOD" calc-mod ) ) + ( ( "SIN" calc-sin ) + ( "COS" calc-cos ) + ( "TAN" calc-tan ) + ( "SQRT" calc-sqrt ) + ( "y^x" calc-power ) + ( "1/x" calc-inv ) ) )) + +;;; |----+----+----+----+----+----| +;;; |IGAM|BETA|IBET|ERF |BESJ|BESY| +;;; |----+----+----+----+----+----| +;;; |IMAG|CONJ| RE |ATN2|RAND|RAGN| +;;; |----+----+----+----+----+----| +;;; |GCD |FACT|DFCT|BNOM|PERM|NXTP| + +(defvar calc-keypad-funcs-menu + '( ( ( "IGAM" calc-inc-gamma ) + ( "BETA" calc-beta ) + ( "IBET" calc-inc-beta ) + ( "ERF" calc-erf ) + ( "BESJ" calc-bessel-J ) + ( "BESY" calc-bessel-Y ) ) + ( ( "IMAG" calc-imaginary ) + ( "CONJ" calc-conj ) + ( "RE" calc-re calc-im ) + ( "ATN2" calc-arctan2 ) + ( "RAND" calc-random ) + ( "RAGN" calc-random-again ) ) + ( ( "GCD" calc-gcd calc-lcm ) + ( "FACT" calc-factorial calc-gamma ) + ( "DFCT" calc-double-factorial ) + ( "BNOM" calc-choose ) + ( "PERM" calc-perm ) + ( "NXTP" calc-next-prime calc-prev-prime ) ) )) + +;;; |----+----+----+----+----+----| +;;; |AND | OR |XOR |NOT |LSH |RSH | +;;; |----+----+----+----+----+----| +;;; |DEC |HEX |OCT |BIN |WSIZ|ARSH| +;;; |----+----+----+----+----+----| +;;; | A | B | C | D | E | F | + +(defvar calc-keypad-binary-menu + '( ( ( "AND" calc-and calc-diff ) + ( "OR" calc-or ) + ( "XOR" calc-xor ) + ( "NOT" calc-not calc-clip ) + ( "LSH" calc-lshift-binary calc-rotate-binary ) + ( "RSH" calc-rshift-binary ) ) + ( ( "DEC" calc-decimal-radix ) + ( "HEX" calc-hex-radix ) + ( "OCT" calc-octal-radix ) + ( "BIN" calc-binary-radix ) + ( "WSIZ" calc-word-size ) + ( "ARSH" calc-rshift-arith ) ) + ( ( "A" ("A") ) + ( "B" ("B") ) + ( "C" ("C") ) + ( "D" ("D") ) + ( "E" ("E") ) + ( "F" ("F") ) ) )) + +;;; |----+----+----+----+----+----| +;;; |SUM |PROD|MAX |MAP*|MAP^|MAP$| +;;; |----+----+----+----+----+----| +;;; |INV |DET |TRN |IDNT|CRSS|"x" | +;;; |----+----+----+----+----+----| +;;; |PACK|UNPK|INDX|BLD |LEN |... | + +(defvar calc-keypad-vector-menu + '( ( ( "SUM" calc-vector-sum calc-vector-alt-sum calc-vector-mean ) + ( "PROD" calc-vector-product nil calc-vector-sdev ) + ( "MAX" calc-vector-max calc-vector-min calc-vector-median ) + ( "MAP*" (lambda () (interactive) + (calc-map '(2 calcFunc-mul "*"))) ) + ( "MAP^" (lambda () (interactive) + (calc-map '(2 calcFunc-pow "^"))) ) + ( "MAP$" calc-map-stack ) ) + ( ( "MINV" calc-inv ) + ( "MDET" calc-mdet ) + ( "MTRN" calc-transpose calc-conj-transpose ) + ( "IDNT" (progn calc-num-prefix calc-ident) ) + ( "CRSS" calc-cross ) + ( "\"x\"" "\excalc-algebraic-entry\rx\r" + "\excalc-algebraic-entry\ry\r" + "\excalc-algebraic-entry\rz\r" + "\excalc-algebraic-entry\rt\r") ) + ( ( "PACK" calc-pack ) + ( "UNPK" calc-unpack ) + ( "INDX" (progn calc-num-prefix calc-index) "\C-u\excalc-index\r" ) + ( "BLD" (progn calc-num-prefix calc-build-vector) ) + ( "LEN" calc-vlength ) + ( "..." calc-full-vectors ) ) )) + +;;; |----+----+----+----+----+----| +;;; |FLT |FIX |SCI |ENG |GRP | | +;;; |----+----+----+----+----+----| +;;; |RAD |DEG |FRAC|POLR|SYMB|PREC| +;;; |----+----+----+----+----+----| +;;; |SWAP|RLL3|RLL4|OVER|STO |RCL | + +(defvar calc-keypad-modes-menu + '( ( ( "FLT" calc-normal-notation + (progn calc-num-prefix calc-normal-notation) ) + ( "FIX" (progn 2 calc-fix-notation) + (progn calc-num-prefix calc-fix-notation) ) + ( "SCI" calc-sci-notation + (progn calc-num-prefix calc-sci-notation) ) + ( "ENG" calc-eng-notation + (progn calc-num-prefix calc-eng-notation) ) + ( "GRP" calc-group-digits "\C-u-3\excalc-group-digits\r" ) + ( "" nil ) ) + ( ( "RAD" calc-radians-mode ) + ( "DEG" calc-degrees-mode ) + ( "FRAC" calc-frac-mode ) + ( "POLR" calc-polar-mode ) + ( "SYMB" calc-symbolic-mode ) + ( "PREC" calc-precision ) ) + ( ( "SWAP" calc-roll-down ) + ( "RLL3" (progn 3 calc-roll-up) (progn 3 calc-roll-down) ) + ( "RLL4" (progn 4 calc-roll-up) (progn 4 calc-roll-down) ) + ( "OVER" calc-over ) + ( "STO" calc-keypad-store ) + ( "RCL" calc-keypad-recall ) ) )) + +(define-derived-mode calc-keypad-mode fundamental-mode "Calculator" + "Major mode for Calc keypad input." + (define-key calc-keypad-mode-map " " 'calc-keypad-press) + (define-key calc-keypad-mode-map (kbd "RET") 'calc-keypad-press) + (define-key calc-keypad-mode-map (kbd "TAB") 'calc-keypad-menu) + (define-key calc-keypad-mode-map "q" 'calc-keypad-off) + (define-key calc-keypad-mode-map [(mouse-3)] 'calc-keypad-right-click) + (define-key calc-keypad-mode-map [(mouse-2)] 'calc-keypad-middle-click) + (define-key calc-keypad-mode-map [(mouse-1)] 'calc-keypad-left-click) + (put 'calc-keypad-mode 'mode-class 'special) + (make-local-variable 'calc-main-buffer)) (defun calc-do-keypad (&optional full-display interactive) (calc-create-buffer) (let ((calcbuf (current-buffer))) - (unless (and calc-keypad-buffer - (buffer-name calc-keypad-buffer)) - (setq calc-keypad-buffer (get-buffer-create "*Calc Keypad*")) - (set-buffer calc-keypad-buffer) - (use-local-map calc-keypad-map) - (setq major-mode 'calc-keypad) - (setq mode-name "Calculator") - (put 'calc-keypad 'mode-class 'special) - (make-local-variable 'calc-main-buffer) + (unless (bufferp calc-keypad-buffer) + (set-buffer (setq calc-keypad-buffer (get-buffer-create "*Calc Keypad*"))) + (calc-keypad-mode) (setq calc-main-buffer calcbuf) (calc-keypad-redraw) (calc-trail-buffer)) @@ -114,7 +303,7 @@ (split-window win (- (window-height win) height 1)) (set-window-buffer win calcbuf)) (select-window old-win) - (message "Welcome to GNU Emacs Calc! Use the left and right mouse buttons.") + (message "Welcome to GNU Emacs Calc! Use the left and right mouse buttons") (run-hooks 'calc-keypad-start-hook) (and calc-keypad-said-hello interactive (progn @@ -193,16 +382,15 @@ (defun calc-keypad-press () (interactive) - (or (eq major-mode 'calc-keypad) - (error "Must be in *Calc Keypad* buffer for this command")) + (unless (eq major-mode 'calc-keypad-mode) + (error "Must be in *Calc Keypad* buffer for this command")) (let* ((row (save-excursion (beginning-of-line) (count-lines (point-min) (point)))) (y (/ row 2)) (x (/ (current-column) (if (>= y 4) 6 5))) radix frac inv - (hyp (save-excursion - (set-buffer calc-main-buffer) + (hyp (with-current-buffer calc-main-buffer (setq radix calc-number-radix frac calc-prefer-frac inv calc-inverse-flag) @@ -363,7 +551,7 @@ (defun calc-keypad-menu () (interactive) - (unless (eq major-mode 'calc-keypad) + (unless (eq major-mode 'calc-keypad-mode) (error "Must be in *Calc Keypad* buffer for this command")) (while (progn (setq calc-keypad-menu (% (1+ calc-keypad-menu) (length calc-keypad-menus))) @@ -372,7 +560,7 @@ (defun calc-keypad-menu-back () (interactive) - (or (eq major-mode 'calc-keypad) + (or (eq major-mode 'calc-keypad-mode) (error "Must be in *Calc Keypad* buffer for this command")) (while (progn (setq calc-keypad-menu (% (1- (+ calc-keypad-menu (length calc-keypad-menus))) @@ -391,7 +579,7 @@ (defun calc-pack-interval (mode) (interactive "p") (if (or (< mode 0) (> mode 3)) - (error "Open/close code should be in the range from 0 to 3.")) + (error "Open/close code should be in the range from 0 to 3")) (calc-pack (- -6 mode))) (defun calc-keypad-execute () @@ -424,197 +612,4 @@ (error "Not a Calc command: %s" (key-description keys))))) -;;; |----+----+----+----+----+----| -;;; | ENTER |+/- |EEX |UNDO| <- | -;;; |-----+---+-+--+--+-+---++----| -;;; | INV | 7 | 8 | 9 | / | -;;; |-----+-----+-----+-----+-----| -;;; | HYP | 4 | 5 | 6 | * | -;;; |-----+-----+-----+-----+-----| -;;; |EXEC | 1 | 2 | 3 | - | -;;; |-----+-----+-----+-----+-----| -;;; | OFF | 0 | . | PI | + | -;;; |-----+-----+-----+-----+-----| - -(defvar calc-keypad-layout - '( ( ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over ) - ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over ) - ( "+/-" calc-change-sign calc-inv (progn -4 calc-pack) ) - ( "EEX" ("e") (progn calc-num-prefix calc-pack-interval) - (progn -5 calc-pack) ) - ( "UNDO" calc-undo calc-redo calc-last-args ) - ( "<-" calc-pop (progn 0 calc-pop) - (progn calc-num-prefix calc-pop) ) ) - ( ( "INV" calc-inverse ) - ( "7" ("7") calc-round ) - ( "8" ("8") (progn 2 calc-clean-num) ) - ( "9" ("9") calc-float ) - ( "/" calc-divide (progn calc-inverse calc-power) ) ) - ( ( "HYP" calc-hyperbolic ) - ( "4" ("4") calc-ln calc-log10 ) - ( "5" ("5") calc-exp calc-exp10 ) - ( "6" ("6") calc-abs ) - ( "*" calc-times calc-power ) ) - ( ( "EXEC" calc-keypad-execute ) - ( "1" ("1") calc-arcsin calc-sin ) - ( "2" ("2") calc-arccos calc-cos ) - ( "3" ("3") calc-arctan calc-tan ) - ( "-" calc-minus calc-conj ) ) - ( ( "OFF" calc-keypad-off ) - ( "0" ("0") calc-imaginary ) - ( "." (".") calc-precision ) - ( "PI" calc-pi ) - ( "+" calc-plus calc-sqrt ) ) )) - -(defvar calc-keypad-menus '( calc-keypad-math-menu - calc-keypad-funcs-menu - calc-keypad-binary-menu - calc-keypad-vector-menu - calc-keypad-modes-menu - calc-keypad-user-menu ) ) - -;;; |----+----+----+----+----+----| -;;; |FLR |CEIL|RND |TRNC|CLN2|FLT | -;;; |----+----+----+----+----+----| -;;; | LN |EXP | |ABS |IDIV|MOD | -;;; |----+----+----+----+----+----| -;;; |SIN |COS |TAN |SQRT|y^x |1/x | - -(defvar calc-keypad-math-menu - '( ( ( "FLR" calc-floor ) - ( "CEIL" calc-ceiling ) - ( "RND" calc-round ) - ( "TRNC" calc-trunc ) - ( "CLN2" (progn 2 calc-clean-num) ) - ( "FLT" calc-float ) ) - ( ( "LN" calc-ln ) - ( "EXP" calc-exp ) - ( "" nil ) - ( "ABS" calc-abs ) - ( "IDIV" calc-idiv ) - ( "MOD" calc-mod ) ) - ( ( "SIN" calc-sin ) - ( "COS" calc-cos ) - ( "TAN" calc-tan ) - ( "SQRT" calc-sqrt ) - ( "y^x" calc-power ) - ( "1/x" calc-inv ) ) )) - -;;; |----+----+----+----+----+----| -;;; |IGAM|BETA|IBET|ERF |BESJ|BESY| -;;; |----+----+----+----+----+----| -;;; |IMAG|CONJ| RE |ATN2|RAND|RAGN| -;;; |----+----+----+----+----+----| -;;; |GCD |FACT|DFCT|BNOM|PERM|NXTP| - -(defvar calc-keypad-funcs-menu - '( ( ( "IGAM" calc-inc-gamma ) - ( "BETA" calc-beta ) - ( "IBET" calc-inc-beta ) - ( "ERF" calc-erf ) - ( "BESJ" calc-bessel-J ) - ( "BESY" calc-bessel-Y ) ) - ( ( "IMAG" calc-imaginary ) - ( "CONJ" calc-conj ) - ( "RE" calc-re calc-im ) - ( "ATN2" calc-arctan2 ) - ( "RAND" calc-random ) - ( "RAGN" calc-random-again ) ) - ( ( "GCD" calc-gcd calc-lcm ) - ( "FACT" calc-factorial calc-gamma ) - ( "DFCT" calc-double-factorial ) - ( "BNOM" calc-choose ) - ( "PERM" calc-perm ) - ( "NXTP" calc-next-prime calc-prev-prime ) ) )) - -;;; |----+----+----+----+----+----| -;;; |AND | OR |XOR |NOT |LSH |RSH | -;;; |----+----+----+----+----+----| -;;; |DEC |HEX |OCT |BIN |WSIZ|ARSH| -;;; |----+----+----+----+----+----| -;;; | A | B | C | D | E | F | - -(defvar calc-keypad-binary-menu - '( ( ( "AND" calc-and calc-diff ) - ( "OR" calc-or ) - ( "XOR" calc-xor ) - ( "NOT" calc-not calc-clip ) - ( "LSH" calc-lshift-binary calc-rotate-binary ) - ( "RSH" calc-rshift-binary ) ) - ( ( "DEC" calc-decimal-radix ) - ( "HEX" calc-hex-radix ) - ( "OCT" calc-octal-radix ) - ( "BIN" calc-binary-radix ) - ( "WSIZ" calc-word-size ) - ( "ARSH" calc-rshift-arith ) ) - ( ( "A" ("A") ) - ( "B" ("B") ) - ( "C" ("C") ) - ( "D" ("D") ) - ( "E" ("E") ) - ( "F" ("F") ) ) )) - -;;; |----+----+----+----+----+----| -;;; |SUM |PROD|MAX |MAP*|MAP^|MAP$| -;;; |----+----+----+----+----+----| -;;; |INV |DET |TRN |IDNT|CRSS|"x" | -;;; |----+----+----+----+----+----| -;;; |PACK|UNPK|INDX|BLD |LEN |... | - -(defvar calc-keypad-vector-menu - '( ( ( "SUM" calc-vector-sum calc-vector-alt-sum calc-vector-mean ) - ( "PROD" calc-vector-product nil calc-vector-sdev ) - ( "MAX" calc-vector-max calc-vector-min calc-vector-median ) - ( "MAP*" (lambda () (interactive) - (calc-map '(2 calcFunc-mul "*"))) ) - ( "MAP^" (lambda () (interactive) - (calc-map '(2 calcFunc-pow "^"))) ) - ( "MAP$" calc-map-stack ) ) - ( ( "MINV" calc-inv ) - ( "MDET" calc-mdet ) - ( "MTRN" calc-transpose calc-conj-transpose ) - ( "IDNT" (progn calc-num-prefix calc-ident) ) - ( "CRSS" calc-cross ) - ( "\"x\"" "\excalc-algebraic-entry\rx\r" - "\excalc-algebraic-entry\ry\r" - "\excalc-algebraic-entry\rz\r" - "\excalc-algebraic-entry\rt\r") ) - ( ( "PACK" calc-pack ) - ( "UNPK" calc-unpack ) - ( "INDX" (progn calc-num-prefix calc-index) "\C-u\excalc-index\r" ) - ( "BLD" (progn calc-num-prefix calc-build-vector) ) - ( "LEN" calc-vlength ) - ( "..." calc-full-vectors ) ) )) - -;;; |----+----+----+----+----+----| -;;; |FLT |FIX |SCI |ENG |GRP | | -;;; |----+----+----+----+----+----| -;;; |RAD |DEG |FRAC|POLR|SYMB|PREC| -;;; |----+----+----+----+----+----| -;;; |SWAP|RLL3|RLL4|OVER|STO |RCL | - -(defvar calc-keypad-modes-menu - '( ( ( "FLT" calc-normal-notation - (progn calc-num-prefix calc-normal-notation) ) - ( "FIX" (progn 2 calc-fix-notation) - (progn calc-num-prefix calc-fix-notation) ) - ( "SCI" calc-sci-notation - (progn calc-num-prefix calc-sci-notation) ) - ( "ENG" calc-eng-notation - (progn calc-num-prefix calc-eng-notation) ) - ( "GRP" calc-group-digits "\C-u-3\excalc-group-digits\r" ) - ( "" nil ) ) - ( ( "RAD" calc-radians-mode ) - ( "DEG" calc-degrees-mode ) - ( "FRAC" calc-frac-mode ) - ( "POLR" calc-polar-mode ) - ( "SYMB" calc-symbolic-mode ) - ( "PREC" calc-precision ) ) - ( ( "SWAP" calc-roll-down ) - ( "RLL3" (progn 3 calc-roll-up) (progn 3 calc-roll-down) ) - ( "RLL4" (progn 4 calc-roll-up) (progn 4 calc-roll-down) ) - ( "OVER" calc-over ) - ( "STO" calc-keypad-store ) - ( "RCL" calc-keypad-recall ) ) )) - ;;; calc-keypd.el ends here -- 2.39.5