Non-ASCII characters in file paths break matlab-shell-save-and-go and matlab-shell-run-region (emacsrun / emacsrunregion)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 40/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- emacs-lisp
- Área
- devtools, internationalization
Línea de trabajo
The payload names no source file, so start from the two MATLAB commands the report quotes, emacsrun for matlab-shell-save-and-go and emacsrunregion for matlab-shell-run-region, and find where the Emacs side builds them. Reproduce with a path containing é and compare the string sent to the matlab-shell process with what MATLAB receives, checking the process coding system. Done means both commands pass accented paths intact under the UTF-8 locale. The reporter's advice on comint-send-string is a workaround to read, not a fix to copy.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
When a file's path contains non-ASCII characters (e.g. é, è), commands that send the file path to MATLAB fail. Paths with only ASCII characters work. I see two different symptoms, depending on the command:
matlab-shell-save-and-go(C-c C-s): the accented characters are replaced bychar(NNN)calls that are sent as separate arguments toemacsrun.matlab-shell-run-region(C-c C-r): the accented characters are dropped entirely from the path sent toemacsrunregion.
This happens even though MATLAB itself reports a UTF-8 locale and encoding (see "Locale check" below), so it doesn't seem to be a simple locale misconfiguration.
Environment
- matlab-mode version:
20260419.1224 - Emacs version:
GNU Emacs 30.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.52, cairo version 1.18.4) - OS: NixOS, MATLAB R2025a running inside an Ubuntu distrobox container, launched through a wrapper script (below)
- Major mode:
matlab-ts-mode
Configuration
(use-package matlab-mode
:hook
(matlab-ts-mode . matlab-sections-minor-mode)
:bind
(:map matlab-ts-mode-map
("C-c C-c" . matlab-sections-run-section)
("C-c C-r" . matlab-shell-run-region))
:custom
(matlab-indent-level 2)
(matlab-verify-on-save nil)
(matlab-shell-command "matlab")
(matlab-shell-command-switches '("-nodesktop" "-nosplash")))
matlab is a wrapper script that runs MATLAB inside the container. It exports a UTF-8 locale before entering the container:
#!/bin/sh
# distrobox_binary
# name: matlab-box
MATLAB_BIN="/home/user/.local/share/distrobox-homes/matlab-box/.local/share/MATLAB/R2025a/bin/matlab"
export LANG=C.UTF-8
export LC_ALL=C.UTF-8
if [ -z "${CONTAINER_ID}" ]; then
exec "/run/current-system/sw/bin/distrobox-enter" -n matlab-box -- bash -l -c 'exec "$@"' _ "$MATLAB_BIN" "$@"
elif [ -n "${CONTAINER_ID}" ] && [ "${CONTAINER_ID}" != "matlab-box" ]; then
exec distrobox-host-exec '/home/user/.local/bin/matlab' "$@"
else
exec "$MATLAB_BIN" "$@"
fi
Steps to reproduce
- Open a
.mfile whose path contains non-ASCII characters, e.g./home/user/Documents/Université/Systèmes linéaires/exercice_1_q1.m - Press
C-c C-s, or select a region and pressC-c C-r
Actual behavior
Symptom 1: matlab-shell-save-and-go (C-c C-s)
The non-ASCII characters become char(NNN) calls passed as separate arguments:
>> emacsrun('/home/user/Documents/Universit', char(233), '/2026-2027/M1/S1/Syst', char(232), 'mes lin', char(233), 'aires multivariables/.../exercice_1_q1')
Error using emacsrun (line 44)
Error: Invalid text character. Check for unsupported symbol, invisible
character, or pasting of non-ASCII characters.
Symptom 2: matlab-shell-run-region (C-c C-r)
The non-ASCII characters are missing from the path (Universit, Systmes linaires), so MATLAB can't find the file:
>> emacsrunregion('/home/user/Documents/Universit/2026-2027/M1/S1/Systmes linaires multivariables/.../exercice_1_q1.m',14,189)
Error using emacsrunregion (line 24)
You must save your region into a file accessible by MATLAB process.
Expected behavior
The full path, accents included, reaches MATLAB. For symptom 1, this works when typed by hand, with the arguments concatenated in [...]:
>> emacsrun(['/home/user/Documents/Universit', char(233), '/2026-2027/M1/S1/Syst', char(232), 'mes lin', char(233), 'aires multivariables/.../exercice_1_q1'])
Locale check
I initially suspected the container's locale (LANG is often unset in a distrobox login shell), so I added export LANG=C.UTF-8 and export LC_ALL=C.UTF-8 to the wrapper above. This did not change anything: both symptoms still occur.
feature('locale') run in the matlab-shell buffer inside Emacs reports a UTF-8 encoding everywhere:
>> feature('locale')
ans =
struct with fields:
ctype: 'en_US_POSIX.UTF-8'
collate: 'en_US_POSIX.UTF-8'
time: 'en_US_POSIX.UTF-8'
numeric: 'en_US_POSIX.UTF-8'
monetary: 'en_US_POSIX.UTF-8'
messages: 'en_US.UTF-8'
encoding: 'UTF-8'
terminalEncoding: 'UTF-8'
jvmEncoding: 'UTF-8'
status: 'MathWorks locale management system initialized.'
warning: ''
So MATLAB's side is already UTF-8, and the failures happen anyway.
Possible cause
I haven't confirmed any of this in the source, so these are guesses:
- For symptom 1, the code that builds the
emacsrun(...)command seems to escape non-ASCII characters aschar(NNN)without wrapping the result in[], so MATLAB receives several arguments. Since MATLAB reports UTF-8, thechar(NNN)escaping may be applied unconditionally rather than depending on the locale. - For symptom 2, the characters are lost somewhere between building the command and MATLAB receiving it, possibly when Emacs encodes the string for the process (the coding system of the matlab-shell process), or in the code that builds the
emacsrunregion(...)command. I haven't verified where.
Temporary workaround
An advice on comint-send-string that rewrites emacsrun* commands before they are sent. If a quoted string still contains non-ASCII characters, it turns that string into an ASCII-only MATLAB expression. If the command is already split into char(NNN) pieces, it wraps them in [].
(defun my/matlab--escape-literal (inner)
"Return a MATLAB expression for the string INNER with non-ASCII chars as char(N)."
(let (parts (run ""))
(dolist (c (string-to-list inner))
(if (< c 128)
(setq run (concat run (string c)))
(when (> (length run) 0)
(push (format "'%s'" run) parts)
(setq run ""))
(push (if (< c 256)
(format "char(%d)" c)
(format "native2unicode(uint8([%s]),'UTF-8')"
(mapconcat #'number-to-string
(string-to-list (encode-coding-string (string c) 'utf-8))
",")))
parts)))
(when (> (length run) 0)
(push (format "'%s'" run) parts))
(concat "[" (mapconcat #'identity (nreverse parts) ", ") "]")))
(defun my/matlab-fix-emacsrun-args (args)
"Make emacsrun* commands safe for paths with non-ASCII characters."
(let ((proc (nth 0 args))
(str (nth 1 args)))
(cond
((and (stringp str)
(string-prefix-p "emacsrun" str)
(string-match-p "[^[:ascii:]]" str))
(list proc
(replace-regexp-in-string
"'\\(?:[^']\\|''\\)*'"
(lambda (m)
(if (string-match-p "[^[:ascii:]]" m)
(my/matlab--escape-literal (substring m 1 -1))
m))
str t t)))
((and (stringp str)
(string-match "\\`emacsrun(\\(.*\\))\\(\n?\\)\\'" str)
(string-match-p "char([0-9]+)" str)
(not (string-match-p "\\`emacsrun(\\[" str)))
(list proc
(concat "emacsrun([" (match-string 1 str) "])" (match-string 2 str))))
(t args))))
(advice-add 'comint-send-string :filter-args #'my/matlab-fix-emacsrun-args)
With this advice, both C-c C-s (emacsrun) and C-c C-r (emacsrunregion) work on paths containing non-ASCII characters.
This is only a workaround. The proper fix would be in the code that builds these command strings and/or in how the shell process is started (encoding).
- Lenguaje dominante
- Emacs Lisp
- Estrellas
- 27
- Forks
- 5
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de mathworks/Emacs-MATLAB-Mode
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
-
enhancement help wanted
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 28/100
mathworks/Emacs-MATLAB-Mode#59 · 3 comentarios · 1 reacción ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
mathworks/Emacs-MATLAB-Mode#50 · 1 comentario ·
-
ELPA links to doc and examples from README.org don't workQuizá libre de nuevo @ouboub la tomó hace 529 días y no hay ningún pull request abierto. Abierto
mathworks/Emacs-MATLAB-Mode#47 · 1 asignado ·
Todos los issues de mathworks/Emacs-MATLAB-Mode
Issues similares
-
follow-up needs-triage S3: minor
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
manaflow-ai/cmux#36856 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area/tools bug session-analysis
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
fixes
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
astral-sh/ruff#30076 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
powersync-ja/powersync-js#1194 ·
Los mantenedores suelen responder en 1 día