Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 980
stardiviner Avatar asked Dec 01 '13 07:12

stardiviner


3 Answers

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

like image 170
d4gg4d Avatar answered Nov 17 '22 00:11

d4gg4d


enter image description here

(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.
                       )))
like image 24
stardiviner Avatar answered Nov 17 '22 00:11

stardiviner


(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)
like image 3
bowen.li Avatar answered Nov 17 '22 02:11

bowen.li