How to syntax highlight for Org-mode inline source code src_lang{}?

核能气质少年 提交于 2020-01-12 14:53:28

问题


Is there a way to syntax highlight Org-mode inline source code which is marked with src_ruby{Array.new} ?

Does Org-mode has default option for this ? Or Is there other method to do this ?


回答1:


UPDATE: the correct answer to this particular question is following https://stackoverflow.com/a/28059832/462601 . Answer presented here is related to this question Syntax highlighting within #+begin_src block in emacs orgmode not working

You mean like syntax-highlighting source blocks in buffer?

#+BEGIN_SRC ruby
Array.new
#+END_SRC

You need to set (setq org-src-fontify-natively t)

Ref: http://orgmode.org/worg/org-contrib/babel/examples/fontify-src-code-blocks.html




回答2:


(font-lock-add-keywords 'org-mode
                    '(("\\(src_\\)\\([^[{]+\\)\\(\\[:.*\\]\\){\\([^}]*\\)}"
                       (1 '(:foreground "black" :weight 'normal :height 10)) ; src_ part
                       (2 '(:foreground "cyan" :weight 'bold :height 75 :underline "red")) ; "lang" part.
                       (3 '(:foreground "#555555" :height 70)) ; [:header arguments] part.
                       (4 'org-code) ; "code..." part.
                       )))



回答3:


(defun org-fontify-inline-src-block (limit)
  "Fontify inline source block."
  (when (re-search-forward org-babel-inline-src-block-regexp limit t)
    (add-text-properties
     (match-beginning 1) (match-end 0)
     '(font-lock-fontified t face (t (:foreground "#008ED1" :background "#FFFFEA"))))
    (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
    t))

add to function org-set-font-lock-defaults in org.el

;; Drawers
'(org-fontify-drawers)
;; Inline source block
'(org-fontify-inline-src-block)


来源:https://stackoverflow.com/questions/20309842/how-to-syntax-highlight-for-org-mode-inline-source-code-src-lang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!