我在Emacs中成功地使用了mathematica.el和Mathematica 10。然而,我在字符编码方面遇到了一些问题,当我在数学表达式上调用mathematica-execute时,结果会打印很多^M个字符到输出(我在OS X Mavericks上运行所有进程)。我最初确保Mathematica中的$CharacterEncoding与Emacs的文件和进程编码相匹配,以便尽可能地使用缓冲区: utf-8。那里可能仍然存在一个问题,但这条路线没有产生解决方案。接下来,我想,为什么不创建我自己的函数来调用mathematica-execute,然后从结果输出中删除^M字符。相关代码如下:
(defun delete-to-out ()
(next-line)
(set-mark-command nil)
(search-forward "]=")
(previous-line)
(delete-region (region-beginning) (region-end)))
(defun remove-^M ()
"Get rid of ^M characters"
(interactive)
(message "remove-^M called!")
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\r" nil t)
(replace-match ""))))
(defun my-mathematica-execute (arg)
"Call mathematica-execute and then clean out the ^M characters
it inserts by calling remove-^M"
(interactive "P")
(save-excursion
(mathematica-execute arg)
(remove-^M)
;; (delete-to-out)
))
;;; Define some mathematica mode keyboard bindings
(if mathematica-mode-map
(progn
(define-key mathematica-mode-map [remap mathematica-execute]
'my-mathematica-execute)
(define-key mathematica-mode-map (kbd "C-c m")
'remove-^M)))调用my-mathematica-execute可以工作,但不能成功删除^M个字符。随后,调用remove-^M或delete-to-out可以在隔离状态下正常工作。一定是同步问题还是时间问题?任何帮助都将不胜感激。替代的解决方案当然是受欢迎的。
发布于 2014-12-07 06:11:12
^M看起来确实像是解码问题,但问题不在于字符编码,而在于EOL编码。两者通常在Emacs中一起指定,因此您可能需要在某个地方使用utf-8-dos而不是utf-8。
https://stackoverflow.com/questions/27334525
复制相似问题