diff options
| author | Jacob S. Gordon | 2025-05-19 15:05:37 -0400 |
|---|---|---|
| committer | Eli Zaretskii | 2025-06-14 17:07:19 +0300 |
| commit | 5bd9fa084dcf0ce8efaaf9212c24addec48d824f (patch) | |
| tree | e032a62cd687f5a15d24595684bfd1d16647e0ae /doc | |
| parent | 82766b71a45a691e19386422d3a12a3e0321b2e8 (diff) | |
| download | emacs-5bd9fa084dcf0ce8efaaf9212c24addec48d824f.tar.gz emacs-5bd9fa084dcf0ce8efaaf9212c24addec48d824f.zip | |
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)
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/misc/calc.texi | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi index 61466b55201..eda442ecb38 100644 --- a/doc/misc/calc.texi +++ b/doc/misc/calc.texi | |||
| @@ -10179,7 +10179,7 @@ result @samp{[120]} (because 120 is the ASCII code of the lower-case | |||
| 10179 | is displayed only according to the current mode settings. But | 10179 | is displayed only according to the current mode settings. But |
| 10180 | running Quick Calc again and entering @samp{120} will produce the | 10180 | running Quick Calc again and entering @samp{120} will produce the |
| 10181 | result @samp{120 (16#78, 8#170, x)} which shows the number in its | 10181 | result @samp{120 (16#78, 8#170, x)} which shows the number in its |
| 10182 | decimal, hexadecimal, octal, and ASCII forms. | 10182 | decimal, hexadecimal, octal, and character forms. |
| 10183 | 10183 | ||
| 10184 | Please note that the Quick Calculator is not any faster at loading | 10184 | Please note that the Quick Calculator is not any faster at loading |
| 10185 | or computing the answer than the full Calculator; the name ``quick'' | 10185 | or computing the answer than the full Calculator; the name ``quick'' |
| @@ -10836,11 +10836,11 @@ from 1 to @samp{n}. | |||
| 10836 | @cindex Strings | 10836 | @cindex Strings |
| 10837 | @cindex Character strings | 10837 | @cindex Character strings |
| 10838 | Character strings are not a special data type in the Calculator. | 10838 | Character strings are not a special data type in the Calculator. |
| 10839 | Rather, a string is represented simply as a vector all of whose | 10839 | Rather, a string is represented simply as a vector all of whose elements |
| 10840 | elements are integers in the range 0 to 255 (ASCII codes). You can | 10840 | are integers in the Latin-1 range 0 to 255. You can enter a string at |
| 10841 | enter a string at any time by pressing the @kbd{"} key. Quotation | 10841 | any time by pressing the @kbd{"} key. Quotation marks and backslashes |
| 10842 | marks and backslashes are written @samp{\"} and @samp{\\}, respectively, | 10842 | are written @samp{\"} and @samp{\\}, respectively, inside strings. |
| 10843 | inside strings. Other notations introduced by backslashes are: | 10843 | Other notations introduced by backslashes are: |
| 10844 | 10844 | ||
| 10845 | @example | 10845 | @example |
| 10846 | @group | 10846 | @group |
| @@ -10857,21 +10857,24 @@ inside strings. Other notations introduced by backslashes are: | |||
| 10857 | 10857 | ||
| 10858 | @noindent | 10858 | @noindent |
| 10859 | Finally, a backslash followed by three octal digits produces any | 10859 | Finally, a backslash followed by three octal digits produces any |
| 10860 | character from its ASCII code. | 10860 | character from its code. |
| 10861 | 10861 | ||
| 10862 | @kindex d " | 10862 | @kindex d " |
| 10863 | @pindex calc-display-strings | 10863 | @pindex calc-display-strings |
| 10864 | Strings are normally displayed in vector-of-integers form. The | 10864 | Strings are normally displayed in vector-of-integers form. The |
| 10865 | @w{@kbd{d "}} (@code{calc-display-strings}) command toggles a mode in | 10865 | @w{@kbd{d "}} (@code{calc-display-strings}) command toggles a mode in |
| 10866 | which any vectors of small integers are displayed as quoted strings | 10866 | which any vectors of small integers are displayed as quoted strings |
| 10867 | instead. | 10867 | instead. The display of strings containing higher character codes can |
| 10868 | be enabled by increasing the custom variable | ||
| 10869 | @code{calc-string-maximum-character} (@pxref{Customizing Calc}). | ||
| 10868 | 10870 | ||
| 10869 | The backslash notations shown above are also used for displaying | 10871 | The backslash notations shown above are also used for displaying |
| 10870 | strings. Characters 128 and above are not translated by Calc; unless | 10872 | strings. For ASCII control characters (below 32), and for the |
| 10871 | you have an Emacs modified for 8-bit fonts, these will show up in | 10873 | @code{DEL} character (127), Calc uses the backslash-letter combination |
| 10872 | backslash-octal-digits notation. For characters below 32, and | 10874 | if there is one, or otherwise uses a @samp{\^} sequence. Control |
| 10873 | for character 127, Calc uses the backslash-letter combination if | 10875 | characters above 127 are not translated by Calc, and will show up in |
| 10874 | there is one, or otherwise uses a @samp{\^} sequence. | 10876 | backslash-octal-digits notation. The display of higher character codes |
| 10877 | will depend on your display settings and system font coverage. | ||
| 10875 | 10878 | ||
| 10876 | The only Calc feature that uses strings is @dfn{compositions}; | 10879 | The only Calc feature that uses strings is @dfn{compositions}; |
| 10877 | @pxref{Compositions}. Strings also provide a convenient | 10880 | @pxref{Compositions}. Strings also provide a convenient |
| @@ -35684,6 +35687,33 @@ choose from, or the user can enter their own date. | |||
| 35684 | The default value of @code{calc-gregorian-switch} is @code{nil}. | 35687 | The default value of @code{calc-gregorian-switch} is @code{nil}. |
| 35685 | @end defvar | 35688 | @end defvar |
| 35686 | 35689 | ||
| 35690 | @defvar calc-string-maximum-character | ||
| 35691 | @xref{Strings}.@* | ||
| 35692 | |||
| 35693 | The variable @code{calc-string-maximum-character} is the maximum value | ||
| 35694 | of a vector's elements for @code{calc-display-strings}, @code{string}, | ||
| 35695 | and @code{bstring} to display the vector as a string. This maximum | ||
| 35696 | @emph{must} represent a character, i.e. it's a non-negative integer less | ||
| 35697 | than or equal to @code{(max-char)} or @code{0x3FFFFF}. Any negative | ||
| 35698 | value effectively disables the display of strings, and for values larger | ||
| 35699 | than @code{0x3FFFFF} the display acts as if the maximum were | ||
| 35700 | @code{0x3FFFFF}. Some natural choices (and their resulting ranges) are: | ||
| 35701 | |||
| 35702 | @itemize | ||
| 35703 | @item | ||
| 35704 | @code{0x7F} or 127 (ASCII), | ||
| 35705 | @item | ||
| 35706 | @code{0xFF} or 255 (Latin-1, the default), | ||
| 35707 | @item | ||
| 35708 | @code{0x10FFFF} (Unicode), | ||
| 35709 | @item | ||
| 35710 | @code{0x3FFFFF} (Emacs). | ||
| 35711 | @end itemize | ||
| 35712 | |||
| 35713 | The default value of @code{calc-string-maximum-character} is @code{0xFF} | ||
| 35714 | or 255. | ||
| 35715 | @end defvar | ||
| 35716 | |||
| 35687 | @node Reporting Bugs | 35717 | @node Reporting Bugs |
| 35688 | @appendix Reporting Bugs | 35718 | @appendix Reporting Bugs |
| 35689 | 35719 | ||