diff options
| author | Eli Barzilay | 2015-11-22 22:37:11 -0500 |
|---|---|---|
| committer | Eli Barzilay | 2015-11-29 12:49:06 -0500 |
| commit | 5d74a02eb7c063aeea8f16ea2dcd4dd8b5ee85a1 (patch) | |
| tree | f1344f737dab440d28dfb15c6d7ab3fc2aca7b9e | |
| parent | fb9ed79c396ed6040a0def1a6da93809a31b6ebf (diff) | |
| download | emacs-5d74a02eb7c063aeea8f16ea2dcd4dd8b5ee85a1.tar.gz emacs-5d74a02eb7c063aeea8f16ea2dcd4dd8b5ee85a1.zip | |
* lisp/calculator.el: better reading of register names
Use `register-read-with-preview' with a dynamically bound
`register-alist' and a proper preview function to read register names.
| -rw-r--r-- | lisp/calculator.el | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/lisp/calculator.el b/lisp/calculator.el index 7ff1a337d58..b1cda28bd25 100644 --- a/lisp/calculator.el +++ b/lisp/calculator.el | |||
| @@ -1486,20 +1486,6 @@ Optional string argument KEYS will force using it as the keys entered." | |||
| 1486 | (kill-new (replace-regexp-in-string | 1486 | (kill-new (replace-regexp-in-string |
| 1487 | "^\\([^ ]+\\) *\\(\\[[0-9/]+\\]\\)? *$" "\\1" s)))))) | 1487 | "^\\([^ ]+\\) *\\(\\[[0-9/]+\\]\\)? *$" "\\1" s)))))) |
| 1488 | 1488 | ||
| 1489 | (defun calculator-set-register (reg) | ||
| 1490 | "Set a register value for REG." | ||
| 1491 | ;; FIXME: this should use `register-read-with-preview', but it uses | ||
| 1492 | ;; calculator-registers rather than `register-alist'. (Maybe | ||
| 1493 | ;; dynamically rebinding it will get blessed?) Also in to | ||
| 1494 | ;; `calculator-get-register'. | ||
| 1495 | (interactive "cRegister to store into: ") | ||
| 1496 | (let* ((as (assq reg calculator-registers)) | ||
| 1497 | (val (progn (calculator-enter) (car calculator-stack)))) | ||
| 1498 | (if as | ||
| 1499 | (setcdr as val) | ||
| 1500 | (push (cons reg val) calculator-registers)) | ||
| 1501 | (calculator-message "[%c] := %S" reg val))) | ||
| 1502 | |||
| 1503 | (defun calculator-put-value (val) | 1489 | (defun calculator-put-value (val) |
| 1504 | "Paste VAL as if entered. | 1490 | "Paste VAL as if entered. |
| 1505 | Used by `calculator-paste' and `get-register'." | 1491 | Used by `calculator-paste' and `get-register'." |
| @@ -1528,9 +1514,33 @@ Used by `calculator-paste' and `get-register'." | |||
| 1528 | (or (match-string 3 str) "")))) | 1514 | (or (match-string 3 str) "")))) |
| 1529 | (ignore-errors (calculator-string-to-number str))))) | 1515 | (ignore-errors (calculator-string-to-number str))))) |
| 1530 | 1516 | ||
| 1517 | (defun calculator-register-read-with-preview (prompt) | ||
| 1518 | "Similar to `register-read-with-preview' but for calculator | ||
| 1519 | registers." | ||
| 1520 | (let ((register-alist calculator-registers) | ||
| 1521 | (register-preview-delay 1) | ||
| 1522 | (register-preview-function | ||
| 1523 | (lambda (r) | ||
| 1524 | (format "%s: %s\n" | ||
| 1525 | (single-key-description (car r)) | ||
| 1526 | (calculator-number-to-string (cdr r)))))) | ||
| 1527 | (register-read-with-preview prompt))) | ||
| 1528 | |||
| 1529 | (defun calculator-set-register (reg) | ||
| 1530 | "Set a register value for REG." | ||
| 1531 | (interactive (list (calculator-register-read-with-preview | ||
| 1532 | "Register to store value into: "))) | ||
| 1533 | (let* ((as (assq reg calculator-registers)) | ||
| 1534 | (val (progn (calculator-enter) (car calculator-stack)))) | ||
| 1535 | (if as | ||
| 1536 | (setcdr as val) | ||
| 1537 | (push (cons reg val) calculator-registers)) | ||
| 1538 | (calculator-message "[%c] := %S" reg val))) | ||
| 1539 | |||
| 1531 | (defun calculator-get-register (reg) | 1540 | (defun calculator-get-register (reg) |
| 1532 | "Get a value from a register REG." | 1541 | "Get a value from a register REG." |
| 1533 | (interactive "cRegister to get value from: ") | 1542 | (interactive (list (calculator-register-read-with-preview |
| 1543 | "Register to get value from: "))) | ||
| 1534 | (calculator-put-value (cdr (assq reg calculator-registers)))) | 1544 | (calculator-put-value (cdr (assq reg calculator-registers)))) |
| 1535 | 1545 | ||
| 1536 | (declare-function electric-describe-mode "ehelp" ()) | 1546 | (declare-function electric-describe-mode "ehelp" ()) |