Non-ASCII characters in file paths break matlab-shell-save-and-go and matlab-shell-run-region (emacsrun / emacsrunregion)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 40/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- emacs-lisp
- Lĩnh vực
- devtools, internationalization
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Emacs Lisp
- Star
- 27
- Fork
- 5
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mathworks/Emacs-MATLAB-Mode
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
-
enhancement help wanted
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 28/100
mathworks/Emacs-MATLAB-Mode#59 · 3 bình luận · 1 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
mathworks/Emacs-MATLAB-Mode#50 · 1 bình luận ·
-
ELPA links to doc and examples from README.org don't workCó thể làm lại được @ouboub đã nhận 529 ngày trước và không có pull request nào đang mở. Đang mở
mathworks/Emacs-MATLAB-Mode#47 · 1 người được giao ·
Tất cả issue của mathworks/Emacs-MATLAB-Mode
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
richardcase/skills#26 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
pending close triaging
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
anomalyco/opencode#62040 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
beginner blocked
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
hiero-ledger/hiero-sdk-js#4670 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nvim-tree/nvim-tree.lua#3383 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Skill: support MSVC debuggerĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày