unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#68745: [PATCH] 30.0.50; calc can't parse matrices with trailing newlines
@ 2024-01-26 22:51 Paul Nelson
  0 siblings, 0 replies; only message in thread
From: Paul Nelson @ 2024-01-26 22:51 UTC (permalink / raw)
  To: 68745

[-- Attachment #1: Type: text/plain, Size: 4308 bytes --]

calc reports an error when parsing (e.g., via C-x * g) latex matrix
environments with trailing newlines.

Steps to reproduce (all with emacs -Q): use "C-x * * d L" to start
calc and set the language mode to latex, then (math-read-expr
"\\begin{pmatrix} a & b \\\\ c & d \\\\ \\end{pmatrix}") gives an
error.

The core issue has nothing to do with latex: use "C-x * * d N" to
reset the language mode to normal, then (math-read-expr
"[[a,b],[c,d],]") gives an error.

I would like to propose that it should instead return the same as
(math-read-expr "[[a,b],[c,d]]"), and similarly, that (math-read-expr
"[u;v;]") should return the same as (math-read-expr "[u;v]").  In
other words, we should simply ignore commas or semicolons when they
appear at the end of a vector or matrix.

The attached patch has the effect that, when a comma or semicolon is
followed by a closing delimiter, we do not attempt to further enlarge
the vector/matrix.  The patch makes it so more expressions can be
parsed, but should not modify how anything that can already be parsed
is parsed.



In GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin22.5.0, NS
 appkit-2299.60 Version 13.4.1 (Build 22F82)) of 2023-08-17 built on
 d51735
Repository revision: 5856ea5e4e897f4cb5cd1c3c28d14b335fe5cf54
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2487
System Description:  macOS 14.2.1

Configured using:
 'configure --with-ns --with-native-compilation --with-tree-sitter
 --with-gif --with-png --with-jpeg --with-rsvg --with-tiff
 --with-imagemagick --with-x-toolkit=gtk3 --with-xwidgets'

Configured features:
ACL DBUS GLIB GNUTLS IMAGEMAGICK JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP XIM XWIDGETS ZLIB

Important settings:
  value of $LC_CTYPE: UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils calc-vec calc-aent calc-yank calc-lang
calc-ext calc-misc calc-menu calc calc-loaddefs rect calc-macs compile
text-property-search comint ansi-osc ansi-color ring comp comp-cstr
warnings icons rx cl-seq cl-macs gv cl-extra help-mode bytecomp
byte-compile time-date subr-x cl-loaddefs cl-lib rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/ns-win ns-win ucs-normalize mule-util
term/common-win touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads xwidget-internal dbusbind kqueue cocoa ns lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 125047 12021) (symbols 48 11032 0) (strings 32 28904 1662)
 (string-bytes 1 811127) (vectors 16 18887)
 (vector-slots 8 383681 18510) (floats 8 39 179) (intervals 56 273 0)
 (buffers 992 14))

[-- Attachment #2: 0001-allow-trailing-delimiters-when-parsing-vectors-matri.patch --]
[-- Type: application/octet-stream, Size: 1437 bytes --]

From d9b3ee0110916e672ef03baf994616d00ed1ab05 Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@gmail.com>
Date: Fri, 26 Jan 2024 23:23:21 +0100
Subject: [PATCH] allow trailing delimiters when parsing vectors/matrices

If a comma or semicolon occurs immediately before the end of the
vector or matrix, then that entry is ignored.  For example, [a,b,]
now parses the same as [a,b], and [a;b;] as [a;b].
---
 lisp/calc/calc-vec.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lisp/calc/calc-vec.el b/lisp/calc/calc-vec.el
index 39ac6fa0347..ba26cf03fb6 100644
--- a/lisp/calc/calc-vec.el
+++ b/lisp/calc/calc-vec.el
@@ -1658,9 +1658,10 @@ math-read-vector
 	  (math-read-token))
       (while (eq math-exp-token 'space)
 	(math-read-token))
-      (let ((rest (list (math-read-expr-level 0))))
-	(setcdr last rest)
-	(setq last rest)))
+      (when (not (equal math-expr-data math-rb-close))
+        (let ((rest (list (math-read-expr-level 0))))
+	  (setcdr last rest)
+	  (setq last rest))))
     (cons 'vec val)))
 
 (defun math-read-matrix (mat)
@@ -1668,7 +1669,8 @@ math-read-matrix
     (math-read-token)
     (while (eq math-exp-token 'space)
       (math-read-token))
-    (setq mat (nconc mat (list (math-read-vector)))))
+    (when (not (equal math-expr-data math-rb-close))
+      (setq mat (nconc mat (list (math-read-vector))))))
   mat)
 
 (provide 'calc-vec)
-- 
2.39.3 (Apple Git-145)


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-26 22:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-26 22:51 bug#68745: [PATCH] 30.0.50; calc can't parse matrices with trailing newlines Paul Nelson

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).