在 Emacs 中编织 Markdown 高亮显示?

在 Emacs 中打开时,是否对现有工具或新工具进行了任何修改,以便在一个针织降价文档中突出显示 R 代码的语法(颜色)块?

我正在查看的针织块是包含内部 R 代码的三重回勾块 [```]

编辑: 到目前为止我尝试过的事情:

- Ubuntu12.04和 Emacs 23

emacs --version
GNU Emacs 23.3.1

1. 多模

Https://github.com/vitoshka/polymode/issues/3

我试图让 polymode 来语法突出显示我的 Rmd 文件,但它抱怨一个“彩色”加载文件:

cd ~/.emacs.d
git clone https://github.com/vitoshka/polymode.git

在我的.emacs 文件中:

(add-to-list 'load-path "/home/avilella/.emacs.d/polymode/")
(add-to-list 'load-path "/home/avilella/.emacs.d/polymode/modes/")


;; Require any polymode bundles that you are interested in:


(require 'poly-R)
(require 'poly-markdown)

Eval-buffer:

Cannot open load file: color

- 森托斯及 Emacs 24:

emacs --version
GNU Emacs 24.2.1

1. 多模安装正确

打开一个 Rmd 文件,abc 0,不改变语法突显。


emacs --version
GNU Emacs 24.3.1

1. 多模安装正确

打开一个 Rmd 文件,M-x poly-markdown+r-mode,一些语法突显开始出现,但是我需要手动修改每个代码块中的测试来完全显示语法。

Enter image description here

Enter image description here

第二个图像是刚刚键入 Return 之后,编织块。

6732 次浏览

This might help: http://sjp.co.nz/posts/emacs-ess-knitr/

Knitr markdown in Emacs through ESS

Your problem

First of all, you say you have GNU Emacs 23.3.1, but in polymode readme.md, it reads:

Tested with Emacs 24.3.1 and 24.4.5.

As for your error: "Cannot open load file: color", in polymode.el, there is the line:

(require 'color)

this package is in Emacs 24, but it might well miss in your version.

Solution

  1. Upgrade to a recent (therefore supported) version of Emacs.

  2. Extract the polymode.zip in a directory where you keep Emacs material, e.g.:

    ~\conf\emacs
    

and change the resulting polymode-master dir to polymode

  1. Add this in your init file (and if you used different names above, change names below accordingly):

    ;; Just an Emacs personal dir containing polymode packages etc.
    (setq MY-EMACS  "~/conf/emacs")
    
    
    (defun my-emacs  (subfolder)
    "Get path to personal dir + subfolder"
    (concat (expand-file-name MY-EMACS) "/" subfolder))
    
    
    ;; ESS Markdown
    ;; -------------
    (defun rmd-mode ()
    "ESS Markdown mode for rmd files"
    (interactive)
    (setq load-path
    (append (list (my-emacs "polymode/")
    (my-emacs "polymode/modes/"))
    load-path))
    (require 'poly-R)
    (require 'poly-markdown)
    (poly-markdown+r-mode))
    
    
    ;; Wrap line in markdown. Comment if you don't dislike words cut in the middle
    (add-hook 'markdown-mode-hook (lambda () (visual-line-mode 1)))
    
    
    ;; Let you use markdown buffer easily
    (setq ess-nuke-trailing-whitespace-p nil)
    
  2. Meta+rmd when the Rmd-file is open or set the mode in <!-- Local Variables: -->
    ... enjoy a dramatic change in your productivity.

PS
Do not overlook last elisp line. It will allow to save markdown properly. Otherwise, when you reopen your doc, you'll have unpleasant surprises.

A note to Windows users

Skip this if you are a Linux guy, but, despite the question mention Ubuntu, my answer applies perfectly to Windows Emacs too. Just with respect to:

  • Step 2) You will extract polymode.zip in:

    %USERPROFILE%\conf\emacs
    

    As you guess, the environment variable %USERPROFILE% contains the path to your user profile directory. If you are not sure what it is, execute set USERPROFILE in the CLI prompt.
    As a Windows user you might be used to store things in My Documents. In that case your dir will be:

    %USERPROFILE%\Documents\conf\emacs
    
  • Step 3) If in Step 2) you used the path %USERPROFILE%\Documents\conf\emacs, change accordingly the first code line from:

    (setq MY-EMACS  "~/conf/emacs")
    

    to (note the slashes):

    (setq MY-EMACS  "~/Documents/conf/emacs")
    

    In both cases (with and without "My Documents"), you might prefer the more Windows style:

    (setq MY-EMACS (substitute-in-file-name "$USERPROFILE/Documents/conf/emacs"))