2013-03-21 30 views
2

我正在編輯emacs中的Mathematica代碼。 Mathematica的希臘字母明文表示看起來像Emacs僅用於顯示的縮寫

\[Alpha], \[Beta], \[Gamma], ... 

我不介意打字這些了,但由此產生的代碼是大而笨重的前瞻性,如:

k[\[Beta]_,z_]:=z^(\[Beta]/2) Hypergeometric2F1[\[Beta]/2,\[Beta]/2,\[Beta],z]; 

有一些方法,使emacs自動將某些字符串(如\[Alpha])顯示爲其他字符串(如alpha的Unicode字符)?注意,我不想實際上用另一個字符串替換一個字符串(如果我理解正確,這是什麼縮寫),因爲Mathematica應該仍然可以正確讀取該文件。

+0

其他模式(比如組織模式)這樣做的方式是隱形規範。可能是一個項目實施,但檢查http://www.gnu.org/software/emacs/manual/html_node/elisp/Invisible-Text.html – Rob 2013-03-21 21:54:34

+0

可能的重複[如何讓Emacs顯示不同從實際存儲的字符?](http://stackoverflow.com/questions/13600160/how-to-let-emacs-display-a-different-character-from-that-actually-stored) – Francesco 2013-03-22 07:05:40

回答

5

是的,有一種方法。普通的Emacs解決方案就是使用compose-region函數。這個片段將定義你的函數compose-greek-symbols將激活請求的縮寫更換當前緩衝區,如果字體鎖定有效:

(setq 
greek-symbols 
(loop 
    ;; characters are entered with `ucs-insert' 
    ;; 'α' is "GREEK SMALL LETTER ALPHA" 
    for ch from ?α to ?ω 
    collect (let ((str (get-char-code-property ch 'name))) 
     (setq str 
      (upcase-initials 
      (downcase 
      (replace-regexp-in-string "greek small letter " "" str)))) 
     (cons str ch)))) 


(defun compose-greek-symbols() 
    (interactive) 
    (font-lock-add-keywords 
    nil 
    '(("\\\\\\[\\([^]]+\\)\\]" 
     (0 (progn (let 
      ((sym (cdr-safe (assoc (match-string 1) greek-symbols)))) 
      (when sym 
      (compose-region (match-beginning 0) 
        (match-end 0) 
        sym))))))))) 

EmacsWiki提供夫妻more solutions。如果你願意安裝新的軟件包,你可以隨時嘗試更復雜的東西,比如pretty-symbols-mode