Nicolas Goaziou <m...@nicolasgoaziou.fr> writes:
> Hello, > > stardiviner <numbch...@gmail.com> writes: > >> Garreau, Alexandre <galex-...@galex-713.eu> writes: >> >>> Why is there no syntax highlighting for *inline* source/code blocks? >>> >>> For instance, if I type the following: >>> >>> #+BEGIN_SRC org >>> src_emacs-lisp{(foo bar (quux))} >>> #+END_SRC >>> >>> The underscore is not displayed, “emacs” is displayed in face >>> ~org-latex-and-related~ *and* in subscript display (smaller and >>> negatively raised), and all the rest in default face, with no syntax >>> highlighting, even inside the braces (that I would expect as it is done >>> inside non-inline blocks). >> >> I used to asked similar question, and answered my own question with >> a font-lock solution. This link might be helpful. >> https://stackoverflow.com/questions/20309842/how-to-syntax-highlight-for-org-mode-inline-source-code-src-lang > > Would you want to provide a patch for that? > > Thank you. > > Regards, I did a search of "font-lock-add-keywords", "begin_src", "src_" etc in Org Mode source code, but have not found exact place where fontify function are. So I don't know where to modify the source code. Now I put my current config here: #+begin_src emacs-lisp ;; inline code face => src_ruby{require 'something'} ;; ;; (REGEXP . FACE) ;; Highlight REGEXP with FACE ;; (REGEXP N FACE) ;; Highlight group N in REGEXP with FACE ;; (REGEXP (N1 FACE1) (N2 FACE2) (N3 FACE3) …) ;; Highlight group Ni in REGEXP with FACEi ;; ;; src_lang{code...}[:header arguments] / NOTE: override by `org-verbatim'. ;; result in following =[result]= ;; src_ (font-lock-add-keywords 'org-mode '(("\\(src_\\)\\([^[{]+\\)\\(\\[:.*\\]\\)\\({\\)\\([^}]*\\)\\(}\\)" (1 '(:foreground "black" :weight 'normal :height 0.1)) ; src_ part (2 '(:foreground "cyan" :weight 'bold :height 0.8 :box '(:color "light gray"))) ; "lang" part. (3 '(:foreground "#555555" :height 0.7)) ; [:header arguments] part. (4 '(:foreground "#333333")) ; { (5 'org-code) ; "code..." part. (6 '(:foreground "#333333")) ; } )) 'append) ;; src without arguments (font-lock-add-keywords 'org-mode '(("\\(src_\\)\\([^[{]+\\)\\({\\)\\([^}]*\\)\\(}\\)" (1 '(:foreground "black" :weight 'normal :height 0.1)) ; src_ part (2 '(:foreground "cyan" :weight 'bold :height 0.8 :box '(:color "light gray"))) ; "lang" part. (3 '(:foreground "#333333")) ; { (4 'org-code) ; "code..." part. (5 '(:foreground "#333333")) ; } )) 'append) ;; inline babel call ;; ... call_<name>[<inside header arguments>](<arguments>)[<end header arguments>] ... (font-lock-add-keywords 'org-mode '(("\\(call_\\)\\([^[(]*\\)\\[\\(.*\\)\\](\\(.*\\))\\[\\(.*\\)\\]" ;; "\\(call_\\)\\([^[(]*\\)\\([([][^)]*]\\)+" (1 '(:foreground "orange red" :height 0.6)) ; call_ (2 '(:foreground "yellow" :weight 'bold :underline "dark gray")) ; <name> (3 '(:foreground "gray" :height 0.6)) ; [<inside header arguments>] (4 '(:foreground "cyan" :weight 'bold)) ; (<arguments>) (5 '(:foreground "gray" :height 0.6)) ; [<end header arguments>] )) 'append) ;; call_<name>[<inside header arguments>](<arguments>) (font-lock-add-keywords 'org-mode '(("\\(call_\\)\\([^[(]*\\)\\[\\(.*\\)\\](\\(.*\\))" (1 '(:foreground "orange red" :height 0.6)) ; call_ (2 '(:foreground "yellow" :weight 'bold :underline "dark gray")) ; <name> (3 '(:foreground "gray" :height 0.6)) ; [<inside header argument>] (4 '(:foreground "cyan" :weight 'bold)) ; (<arguments>) )) 'append) ;; call_<name>(arguments) (font-lock-add-keywords 'org-mode '(("\\(call_\\)\\([^[(]*\\)\\((.*)\\)" (1 '(:foreground "orange red" :height 0.6)) ; call_ (2 '(:foreground "yellow" :weight 'bold :underline "dark gray")) ; <name> (3 '(:foreground "cyan" :weight 'bold)) ; (<arguments>) )) 'append) #+end_src -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3