emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 732d259: Have calc-yank recognize numbers in differ


From: Jay Belanger
Subject: [Emacs-diffs] master 732d259: Have calc-yank recognize numbers in different bases.
Date: Sun, 11 Oct 2015 20:36:16 +0000

branch: master
commit 732d259948833935c343ed88b08316253e12b306
Author: Jay Belanger <address@hidden>
Commit: Jay Belanger <address@hidden>

    Have calc-yank recognize numbers in different bases.
    
    * lisp/calc/calc-yank.el (math-number-regexp): New function.
    (calc-yank): Use `math-number-regexp' to recognize numbers.
---
 lisp/calc/calc-yank.el |   56 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/lisp/calc/calc-yank.el b/lisp/calc/calc-yank.el
index cd44750..5105ba9 100644
--- a/lisp/calc/calc-yank.el
+++ b/lisp/calc/calc-yank.el
@@ -107,6 +107,46 @@
   (interactive "r")
   (calc-kill-region top bot t))
 
+(defun math-number-regexp (radix-num)
+  "Return a regexp which will match a Calc number base RADIX-NUM."
+  (let* ((digit-range
+          (cond
+           ;; radix 2 to 10
+           ((and (<= 2 radix-num)
+                 (>= 10 radix-num))
+            (concat "[0-"
+                    (number-to-string (1- radix-num))
+                    "]"))
+           ;; radix 11
+           ((= 11 radix-num) "[0-9aA]")
+           ;; radix 12+
+           (t
+            (concat "[0-9"
+                    "a-" (format "%c" (+ (- ?a 11) radix-num))
+                    "A-" (format "%c" (+ (- ?A 11) radix-num))
+                    "]"))))
+         (integer-regexp (concat digit-range "+"))
+         (decimal-regexp (concat digit-range "+\\." digit-range "*")))
+    (concat
+     " *\\("
+     ;; "e" notation
+     "[-_+]?" decimal-regexp "[eE][-+]?[0-9]+"
+     "\\|"
+     "[-_+]?" integer-regexp "[eE][-+]?[0-9]+"
+     "\\|"
+     ;; Integer+fractions
+     "[-_+]?" integer-regexp "*[:/]" integer-regexp "[:/]" integer-regexp
+     "\\|"
+     ;; Fractions
+     "[-_+]?" integer-regexp "[:/]" integer-regexp
+     "\\|"
+     ;; Decimal point
+     "[-_+]?" decimal-regexp
+     "\\|"
+     ;; Integers
+     "[-_+]?" integer-regexp
+     "\\) *\\(\n\\|\\'\\)")))
+
 ;; This function uses calc-last-kill if possible to get an exact result,
 ;; otherwise it just parses the yanked string.
 ;; Modified to use Emacs 19 extended concept of kill-ring. -- daveg 12/15/96
@@ -171,21 +211,7 @@ alteration."
                       (setq radix-notation
                             (concat (number-to-string radix-num) "#"))
                       (setq valid-num-regexp
-                            (cond
-                             ;; radix 2 to 10
-                             ((and (<= 2 radix-num)
-                                   (>= 10 radix-num))
-                              (concat "[0-"
-                                      (number-to-string (1- radix-num))
-                                      "]+"))
-                             ;; radix 11
-                             ((= 11 radix-num) "[0-9aA]+")
-                             ;; radix 12+
-                             (t
-                              (concat "[0-9"
-                                      "a-" (format "%c" (+ (- ?a 11) 
radix-num))
-                                      "A-" (format "%c" (+ (- ?A 11) 
radix-num))
-                                      "]+"))))
+                            (math-number-regexp radix-num))
                       ;; Ensure that the radix-notation is prefixed
                       ;; correctly even for multi-line yanks like below,
                       ;;   111



reply via email to

[Prev in Thread] Current Thread [Next in Thread]