summaryrefslogtreecommitdiff
path: root/lisp/calc
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/calc')
-rw-r--r--lisp/calc/calc-aent.el52
-rw-r--r--lisp/calc/calc-lang.el1
-rw-r--r--lisp/calc/calc.el2
-rw-r--r--lisp/calc/calccomp.el17
4 files changed, 55 insertions, 17 deletions
diff --git a/lisp/calc/calc-aent.el b/lisp/calc/calc-aent.el
index ee9c6e61e4c..5b93a544397 100644
--- a/lisp/calc/calc-aent.el
+++ b/lisp/calc/calc-aent.el
@@ -49,7 +49,7 @@
(declare-function math-read-string "calc-ext" ())
(declare-function math-read-brackets "calc-vec" (space-sep math-rb-close))
(declare-function math-read-angle-brackets "calc-forms" ())
-
+(declare-function math-to-percentsigns "calccomp" (x))
(defvar calc-quick-calc-history nil
"The history list for quick-calc.")
@@ -595,10 +595,14 @@ in Calc algebraic input.")
(math-exp-keep-spaces nil)
math-exp-token math-expr-data)
(setq math-exp-str (math-read-preprocess-string math-exp-str))
+ (if (memq calc-language calc-lang-allow-percentsigns)
+ (setq math-exp-str (math-remove-percentsigns math-exp-str)))
(if calc-language-input-filter
(setq math-exp-str (funcall calc-language-input-filter math-exp-str)))
- (while (setq math-exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
- (setq math-exp-str (concat (substring math-exp-str 0 math-exp-token) "\\dots"
+ (while (setq math-exp-token
+ (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
+ (setq math-exp-str
+ (concat (substring math-exp-str 0 math-exp-token) "\\dots"
(substring math-exp-str (+ math-exp-token 2)))))
(math-build-parse-table)
(math-read-token)
@@ -694,17 +698,23 @@ in Calc algebraic input.")
(math-read-token)))
((and (memq ch calc-user-token-chars)
(let ((case-fold-search nil))
- (eq (string-match calc-user-tokens math-exp-str math-exp-pos)
+ (eq (string-match
+ calc-user-tokens math-exp-str math-exp-pos)
math-exp-pos)))
(setq math-exp-token 'punc
math-expr-data (math-match-substring math-exp-str 0)
math-exp-pos (match-end 0)))
((or (and (>= ch ?a) (<= ch ?z))
(and (>= ch ?A) (<= ch ?Z)))
- (string-match (if (memq calc-language calc-lang-allow-underscores)
- "[a-zA-Z0-9_#]*"
- "[a-zA-Z0-9'#]*")
- math-exp-str math-exp-pos)
+ (string-match
+ (cond
+ ((and (memq calc-language calc-lang-allow-underscores)
+ (memq calc-language calc-lang-allow-percentsigns))
+ "[a-zA-Z0-9_'#]*")
+ ((memq calc-language calc-lang-allow-underscores)
+ "[a-zA-Z0-9_#]*")
+ (t "[a-zA-Z0-9'#]*"))
+ math-exp-str math-exp-pos)
(setq math-exp-token 'symbol
math-exp-pos (match-end 0)
math-expr-data (math-restore-dashes
@@ -1009,17 +1019,31 @@ in Calc algebraic input.")
(concat (math-match-substring x 1) "#" (math-match-substring x 2)))
x))
+(defun math-remove-percentsigns (x)
+ (if (string-match "\\`\\(.*\\)%\\(.*\\)\\'" x)
+ (math-remove-percentsigns
+ (concat (math-match-substring x 1) "o'o" (math-match-substring x 2)))
+ x))
+
(defun math-restore-dashes (x)
(if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x)
(math-restore-dashes
(concat (math-match-substring x 1) "-" (math-match-substring x 2)))
x))
-(defun math-restore-underscores (x)
- "Replace pound signs by underscores in the symbol x.
-If the current Calc language does not allow underscores, return nil."
- (if (memq calc-language calc-lang-allow-underscores)
- (intern-soft (math-string-restore-underscores (symbol-name x)))))
+(defun math-restore-placeholders (x)
+ "Replace placeholders by the proper characters in the symbol x.
+This includes `#' for `_' and `'' for `%'.
+If the current Calc language does not use placeholders, return nil."
+ (if (or (memq calc-language calc-lang-allow-underscores)
+ (memq calc-language calc-lang-allow-percentsigns))
+ (let ((sx (symbol-name x)))
+ (when (memq calc-language calc-lang-allow-percentsigns)
+ (require 'calccomp)
+ (setq sx (math-to-percentsigns sx)))
+ (if (memq calc-language calc-lang-allow-underscores)
+ (setq sx (math-string-restore-underscores sx)))
+ (intern-soft sx))))
(defun math-string-restore-underscores (x)
"Replace pound signs by underscores in the string x."
@@ -1131,7 +1155,7 @@ If the current Calc language does not allow underscores, return nil."
(symbol-name sym)))))))
(let ((v (or
(assq (nth 1 val) math-expr-variable-mapping)
- (assq (math-restore-underscores (nth 1 val))
+ (assq (math-restore-placeholders (nth 1 val))
math-expr-variable-mapping))))
(and v (setq val (if (consp (cdr v))
(funcall (car (cdr v)) v val)
diff --git a/lisp/calc/calc-lang.el b/lisp/calc/calc-lang.el
index 6773049c391..8d01914a06e 100644
--- a/lisp/calc/calc-lang.el
+++ b/lisp/calc/calc-lang.el
@@ -43,6 +43,7 @@
;; Declare variables which are defined elsewhere.
(defvar calc-lang-slash-idiv)
(defvar calc-lang-allow-underscores)
+(defvar calc-lang-allow-percentsigns)
(defvar math-comp-left-bracket)
(defvar math-comp-right-bracket)
(defvar math-comp-comma)
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el
index fa98b161567..76b01a61ec4 100644
--- a/lisp/calc/calc.el
+++ b/lisp/calc/calc.el
@@ -971,6 +971,8 @@ If nil, selections displayed but ignored.")
"A list of languages in which / might represent integer division.")
(defvar calc-lang-allow-underscores nil
"A list of languages which allow underscores in variable names.")
+(defvar calc-lang-allow-percentsigns nil
+ "A list of languages which allow percent signs in variable names.")
(defvar calc-lang-c-type-hex nil
"Languages in which octal and hex numbers are written with leading 0 and 0x,")
(defvar calc-lang-brackets-are-subscripts nil
diff --git a/lisp/calc/calccomp.el b/lisp/calc/calccomp.el
index dd59b366881..2b81363af47 100644
--- a/lisp/calc/calccomp.el
+++ b/lisp/calc/calccomp.el
@@ -71,7 +71,7 @@
(defvar math-comp-comma)
(defun math-compose-var (a)
- (let (v)
+ (let (v sn)
(if (and math-compose-hash-args
(let ((p calc-arg-values))
(setq v 1)
@@ -82,9 +82,12 @@
(if (eq math-compose-hash-args 1)
"#"
(format "#%d" v))
+ (setq sn (symbol-name (nth 1 a)))
+ (if (memq calc-language calc-lang-allow-percentsigns)
+ (setq sn (math-to-percentsigns sn)))
(if (memq calc-language calc-lang-allow-underscores)
- (math-to-underscores (symbol-name (nth 1 a)))
- (symbol-name (nth 1 a))))))
+ (setq sn (math-to-underscores sn)))
+ sn)))
(defun math-compose-expr (a prec)
(let ((math-compose-level (1+ math-compose-level))
@@ -805,6 +808,8 @@
(symbol-name func))
(math-match-substring (symbol-name func) 1)
(symbol-name func))))
+ (if (memq calc-language calc-lang-allow-percentsigns)
+ (setq func (math-to-percentsigns func)))
(if (memq calc-language calc-lang-allow-underscores)
(setq func (math-to-underscores func)))
(if (setq spfn (get calc-language 'math-func-formatter))
@@ -939,6 +944,12 @@
(concat (math-match-substring x 1) "_" (math-match-substring x 2)))
x))
+(defun math-to-percentsigns (x)
+ (if (string-match "\\`\\(.*\\)o'o\\(.*\\)\\'" x)
+ (math-to-underscores
+ (concat (math-match-substring x 1) "%" (math-match-substring x 2)))
+ x))
+
(defun math-tex-expr-is-flat (a)
(or (Math-integerp a)
(memq (car a) '(float var))