;; Author: Eli Barzilay <eli@www.barzilay.org>
;; Keywords: tools, convenience
-;; Time-stamp: <2000-11-07 15:04:06 eli>
+;; Time-stamp: <2000-11-19 20:59:59 eli>
;; This file is part of GNU Emacs.
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
-;;;============================================================================
+;;;=====================================================================
;;; Commentary:
;;
;; A calculator for Emacs.
(defmacro defgroup (&rest forms) nil)
(defmacro defcustom (s v d &rest r) (list 'defvar s v d))))
-;;;============================================================================
+;;;=====================================================================
;;; Customization:
(defgroup calculator nil
:type '(repeat (list string symbol sexp integer integer))
:group 'calculator)
-;;;============================================================================
+;;;=====================================================================
;;; Code:
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Variables
(defvar calculator-initial-operators
(defvar calculator-restart-other-mode nil
"Used to hack restarting with the electric mode changed.")
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Key bindings
(defvar calculator-mode-map nil
(calculator-clear-saved [?\C-c] [(control delete)])
(calculator-save-and-quit [(control return)]
[(control kp-enter)])
- (calculator-paste [insert] [(shift insert)] [mouse-2])
+ (calculator-paste [insert] [(shift insert)]
+ [mouse-2])
(calculator-clear [delete] [?\C-?] [?\C-d])
(calculator-help [?h] [??] [f1] [help])
(calculator-copy [(control insert)])
["Quit" calculator-quit]))))
(setq calculator-mode-map map)))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Startup and mode stuff
(defun calculator-mode ()
(if (and calculator-restart-other-mode calculator-electric-mode)
(calculator)))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Operatos
(defun calculator-op-arity (op)
(setq calculator-operators
(append (nreverse added-ops) calculator-operators))))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Display stuff
(defun calculator-reset ()
(goto-char (1+ (length calculator-prompt)))
(goto-char (1- (point)))))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Stack computations
(defun calculator-reduce-stack (prec)
(or (fboundp 'key-press-event-p)
(defun key-press-event-p (&rest _) nil)))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Input interaction
(defun calculator-last-input (&optional keys)
(calculator-digit)
(calculator-op)))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Input/output modes (not display)
(defun calculator-dec/deg-mode ()
calculator-char-radix))))
(calculator-update-display t))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Saved values list
(defun calculator-save-on-list ()
(interactive)
(calculator-saved-move -1))
-;;;----------------------------------------------------------------------------
+;;;---------------------------------------------------------------------
;;; Misc functions
(defun calculator-open-paren ()
(interactive)
(calculator-put-value
(let ((str (current-kill 0)))
- (if calculator-paste-decimals
- (progn
- (string-match "\\([0-9]+\\)\\(\\.[0-9]+\\)?\\(e[0-9]+\\)?" str)
- (if (or (match-string 1 str)
- (match-string 2 str)
- (match-string 3 str))
- (setq str (concat (match-string 1 str)
- (or (match-string 2 str) ".0")
- (match-string 3 str))))))
+ (and calculator-paste-decimals
+ (string-match "\\([0-9]+\\)\\(\\.[0-9]+\\)?\\(e[0-9]+\\)?"
+ str)
+ (or (match-string 1 str)
+ (match-string 2 str)
+ (match-string 3 str))
+ (setq str (concat (match-string 1 str)
+ (or (match-string 2 str) ".0")
+ (match-string 3 str))))
(condition-case nil (car (read-from-string str))
(error nil)))))
(require 'ehelp)
(if calculator-electric-mode
(use-global-map calculator-saved-global-map))
- (electric-describe-mode)
+ (if (or (not calculator-electric-mode)
+ ;; XEmacs has a problem with electric-describe-mode
+ (string-match "XEmacs" (emacs-version)))
+ (describe-mode)
+ (electric-describe-mode))
(if calculator-electric-mode
(use-global-map g-map))
(select-window win) ; these are for XEmacs (also below)