mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
calc: Allow strings with character codes above Latin-1
The current behavior of the functions 'calc-display-strings', 'strings', and 'bstrings' is to skip any vector containing integers outside the Latin-1 range (0x00-0xFF). We introduce a custom variable 'calc-string-maximum-character' to replace this hard-coded maximum, and to allow vectors containing higher character codes to be displayed as strings. The default value of 0xFF preserves the existing behavior. * lisp/calc/calc.el (calc-string-maximum-character): Add custom variable 'calc-string-maximum-character'. * lisp/calc/calccomp.el (math-vector-is-string): Replace hard-coded maximum with 'calc-string-maximum-character', and the 'natnump' assertion with 'characterp'. The latter guards against the maximum being larger than '(max-char)', but not on invalid types of the maximum such as strings. * test/lisp/calc/calc-tests.el (calc-math-vector-is-string): Add tests for 'math-vector-is-string' using different values of 'calc-string-maximum-character'. * doc/misc/calc.texi (Quick Calculator, Strings, Customizing Calc): Add variable definition for 'calc-string-maximum-character' and reference thereof when discussing 'calc-display-strings'. Generalize a comment about string display and availability of 8-bit fonts. (Bug#78528)
This commit is contained in:
parent
82766b71a4
commit
5bd9fa084d
5 changed files with 164 additions and 17 deletions
|
|
@ -628,6 +628,37 @@ Otherwise, 1 / 0 is changed to uinf (undirected infinity).")
|
|||
(defcalcmodevar calc-display-strings nil
|
||||
"If non-nil, display vectors of byte-sized integers as strings.")
|
||||
|
||||
(defcustom calc-string-maximum-character #xFF
|
||||
"Maximum value of vector contents to be displayed as a string.
|
||||
|
||||
If a vector consists of characters up to this maximum value, the
|
||||
function `calc-display-strings' will toggle displaying the vector as a
|
||||
string. This maximum value must represent a character (see `characterp').
|
||||
Some natural choices (and their resulting ranges) are:
|
||||
|
||||
- `0x7F' (`ASCII'),
|
||||
- `0xFF' (`Latin-1', the default),
|
||||
- `0x10FFFF' (`Unicode'),
|
||||
- `0x3FFFFF' (`Emacs').
|
||||
|
||||
Characters for low control codes are either caret or backslash escaped,
|
||||
while others without a glyph are displayed in backslash-octal notation.
|
||||
The display of strings containing higher character codes will depend on
|
||||
your display settings and system font coverage.
|
||||
|
||||
See the following for further information:
|
||||
|
||||
- info node `(calc)Strings',
|
||||
- info node `(elisp)Text Representations',
|
||||
- info node `(emacs)Text Display'."
|
||||
:version "31.1"
|
||||
:type '(choice (restricted-sexp :tag "Character Code"
|
||||
:match-alternatives (characterp))
|
||||
(const :tag "ASCII" #x7F)
|
||||
(const :tag "Latin-1" #xFF)
|
||||
(const :tag "Unicode" #x10FFFF)
|
||||
(const :tag "Emacs" #x3FFFFF)))
|
||||
|
||||
(defcalcmodevar calc-matrix-just 'center
|
||||
"If nil, vector elements are left-justified.
|
||||
If `right', vector elements are right-justified.
|
||||
|
|
|
|||
|
|
@ -907,13 +907,20 @@
|
|||
(concat " " math-comp-right-bracket)))))
|
||||
|
||||
(defun math-vector-is-string (a)
|
||||
"Return t if A can be displayed as a string, and nil otherwise.
|
||||
|
||||
Elements of A must either be a character (see `characterp') or a complex
|
||||
number with only a real character part, each with a value less than or
|
||||
equal to the custom variable `calc-string-maximum-character'."
|
||||
(while (and (setq a (cdr a))
|
||||
(or (and (natnump (car a))
|
||||
(<= (car a) 255))
|
||||
(or (and (characterp (car a))
|
||||
(<= (car a)
|
||||
calc-string-maximum-character))
|
||||
(and (eq (car-safe (car a)) 'cplx)
|
||||
(natnump (nth 1 (car a)))
|
||||
(characterp (nth 1 (car a)))
|
||||
(eq (nth 2 (car a)) 0)
|
||||
(<= (nth 1 (car a)) 255)))))
|
||||
(<= (nth 1 (car a))
|
||||
calc-string-maximum-character)))))
|
||||
(null a))
|
||||
|
||||
(defconst math-vector-to-string-chars '( ( ?\" . "\\\"" )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue