在Org-mode 8中为R代码块提供Fontify

时间:2014-10-10 02:15:11

标签: emacs elisp org-mode

我试图在Org-mode 8中更改R代码块的背景颜色。在Org-mode 7中,我能够使用:

(defface org-block-background
   '((t (:background "#dadada")))
   "Face used for the source block background.")

但是org-block-background变量似乎在版本8中消失了??

我试过了:

(defface org-block
   '((t (:background "#dadada")))
   "Face used for the source block background.")

适用于:

#+BEGIN_SRC
#+END_SRC

#+BEGIN_latex
#+END_latex

但由于某种原因,背景颜色消失了,我指定语言的那一刻,例如...

#+BEGIN_SRC R
#+END_SRC

我正在使用Mac运行Emacs 24.3并将org-mode升级到v8,使用:

cd ~/.emacs.d/lisp
git clone git://orgmode.org/org-mode.git
cd org-mode
make autoloads
make
make doc

这是我的init.el文件中的配置:

;;;----- Startup ----------------------------;

;;; Add src directory to path
(add-to-list 'load-path "~/.emacs.d/lisp/")

;;;----- Org-Mode ---------------------------;

;;; Add upgraded org-mode to load path
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/lisp")
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/contrib/lisp" t)

;;; fontify code in code blocks
(setq org-src-fontify-natively t)

(defface org-block-begin-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the begin of source blocks.")

(defface org-block
  '((t (:background "#dadada")))
  "Face used for the source block background.")

(defface org-block-end-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the end of source blocks.")

(require 'org)

;;;----- ESS/R ------------------------------;

(add-to-list 'load-path "~/.emacs.d/lisp/ess/lisp/")
(load "ess-site")

;;;------ Babel ------------------------------;

;;; Support R
(org-babel-do-load-languages
  'org-babel-load-languages
  '((R . t)
    (latex . t)))

;;;----- Look & feel ----------------------------;

;;; Set default theme
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'solarized-light t)

有什么想法吗?

谢谢!

3 个答案:

答案 0 :(得分:5)

仅供参考,在此提交http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=f8b42e8之后,这对于当前版本的Org Mode(来自Git master分支)不起作用 - 至少在发生变化之前。这是宣布here(2014年7月)并继续对组织模式用户有效,例如见here(2015年4月)。任何致力于在本地恢复旧行为的人都可以从提交的差异中做到这一点 - 我没有尝试过。未来版本的组织模式可以恢复该功能,可能以不同的方式进行。现在,这是你能得到的全部:

enter image description here

(上面的第一个SRC块获取了我org-block设置的背景信息。)

答案 1 :(得分:3)

结果org-block-background已在提交f8b42e8中的org版本8.3.1中删除了face,因此该错误。理由似乎是

  1. 导致ps导出
  2. 的错误
  3. 效率低下
  4. 也许未来会有另一种选择,但还没有。

    Fontify R code blocks in Org-mode 8

    https://lists.gnu.org/archive/html/emacs-orgmode/2015-08/msg00510.html

    目前看来,恢复旧行为的唯一方法是手动撤消commit f8b42e8中引入的更改。你可以在这里看到提交:

    http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=f8b42e8

    diff --git a/lisp/org-faces.el b/lisp/org-faces.el
    index e693dab..83453e8 100644
    --- a/lisp/org-faces.el
    +++ b/lisp/org-faces.el
    @@ -537,9 +537,6 @@ follows a #+DATE:, #+AUTHOR: or #+EMAIL: keyword."
       :group 'org-faces
       :version "22.1")
    
    -(defface org-block-background '((t ()))
    -  "Face used for the source block background.")
    -
     (org-copy-face 'org-meta-line 'org-block-begin-line
       "Face used for the line delimiting the begin of source blocks.")
    
    diff --git a/lisp/org.el b/lisp/org.el
    index a153151..7e30061 100644
    --- a/lisp/org.el
    +++ b/lisp/org.el
    @@ -5930,15 +5930,7 @@ by a #."
              (cond
               ((and lang (not (string= lang "")) org-src-fontify-natively)
            (org-src-font-lock-fontify-block lang block-start block-end)
    -       ;; remove old background overlays
    -       (mapc (lambda (ov)
    -           (if (eq (overlay-get ov 'face) 'org-block-background)
    -               (delete-overlay ov)))
    -             (overlays-at (/ (+ beg1 block-end) 2)))
    -       ;; add a background overlay
    -       (setq ovl (make-overlay beg1 block-end))
    -                (overlay-put ovl 'face 'org-block-background)
    -                (overlay-put ovl 'evaporate t)) ; make it go away when empty
    +       (add-text-properties beg1 block-end '(src-block t)))
               (quoting
            (add-text-properties beg1 (min (point-max) (1+ end1))
                         '(face org-block))) ; end of source block
    @@ -21828,9 +21820,7 @@ and end of string."
     When INSIDE is non-nil, don't consider we are within a src block
     when point is at #+BEGIN_SRC or #+END_SRC."
       (let ((case-fold-search t) ov)
    -    (or (and (setq ov (overlays-at (point)))
    -        (memq 'org-block-background
    -          (overlay-properties (car ov))))
    +    (or (and (eq (get-char-property (point) 'src-block) t))
        (and (not inside)
             (save-match-data
               (save-excursion
    

答案 2 :(得分:1)

我明白了。结果我克隆了一个org-mode的旧分支,它缺少org-block-background变量!删除了我的org-mode文件夹并使用以下命令重新安装:

cd ~/.emacs.d/lisp
git clone https://github.com/Konubinix/org-mode.git
cd org-mode
make autoloads
make
make doc

然后将我的init.el修改为:

;;;----- Org-Mode ---------------------------;


;;; Add upgraded org-mode to load path
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/lisp")
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/contrib/lisp" t)

;;; fontify code in code blocks
(setq org-src-fontify-natively t)

(defface org-block-begin-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the begin of source blocks.")

(defface org-block
  '((t (:background "#dadada")))
  "Face used for the source block background.")

(defface org-block-background
  '((t (:background "#dadada")))
  "Face used for the source block background.")

(defface org-block-end-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the end of source blocks.")

(require 'org)

并且presto!