我在Mathematica 10中成功地在Emacs中使用了mathematica.el。但是,我遇到了一些與字符編碼有關的問題,當我調用Mathematica時 - 在Mathematica表達式上執行時,結果會在輸出中打印大量^ M字符(I我正在OS X Mavericks上運行所有進程)。我最初確定Mathematica中的$ CharacterEncoding與Emacs的文件和進程編碼相匹配,以便儘可能使用緩衝區:utf-8。那裏可能還存在一個問題,但是這條路線沒有提供解決方案。接下來我想,爲什麼不創建我自己的函數來調用mathematica-execute,然後從結果輸出中移除^ M個字符。以下是相關的代碼:如何解決Emacs,mathematica.el和Mathematica 10的字符編碼問題?
(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或從零開始刪除。它必須是同步問題或計時問題?任何幫助,將不勝感激。替代解決方案當然受到歡迎
感謝@Stefan的建議。我和你一樣想,但發現不是這樣。 Mathematica使用utf-8,就像我的Emacs(盡我所知)相關的上下文(也就是說,這是Emacs,我們有終端,鍵盤,文件,進程和可能的其他上下文來設置編碼)。 – Joe 2014-12-06 22:41:53
我能找到一個合適的位置來破解一個名爲mathematica-filter的函數,它被設置爲mathematica過程輸出的過程過濾器。在那裏我插入了一個replace-regexp-in-string調用來擺脫所有\ r字符。這樣可行。現在我只是稍微調整一下它:它現在迴應輸出到輸出(和結果一起),我可能不希望這樣。通常這是由於底層shell回顯(因爲Mathematica在shell中執行,zsh)。至少我現在有了我的切入點,我可以根據自己的喜好操縱輸出流。 ... – Joe 2014-12-06 22:42:13
希望有人會過來告訴我如何使Emacs和zsh一起工作來阻止輸入的迴應,但這可能是另一個問題,我可能會單獨提出。再次感謝您的幫助。 – Joe 2014-12-06 22:42:50