From mboxrd@z Thu Jan 1 00:00:00 1970 From: stardiviner Subject: Re: Inline code block syntax highlighting absence Date: Thu, 25 Oct 2018 12:12:18 +0800 Message-ID: <877ei6r7fh.fsf@gmail.com> References: <87k1m8q2sb.fsf@portable.galex-713.eu> <874ldct386.fsf@gmail.com> <87d0rzyer6.fsf@nicolasgoaziou.fr> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFX0X-0006nB-Nr for emacs-orgmode@gnu.org; Thu, 25 Oct 2018 00:12:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFX0T-0004p5-Tl for emacs-orgmode@gnu.org; Thu, 25 Oct 2018 00:12:29 -0400 Received: from [61.175.244.13] (port=3974 helo=dark.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFX0S-0004oX-21 for emacs-orgmode@gnu.org; Thu, 25 Oct 2018 00:12:24 -0400 In-reply-to: <87d0rzyer6.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Nicolas Goaziou Cc: org-mode , "Garreau, Alexandre" Nicolas Goaziou writes: > Hello, > > stardiviner writes: > >> Garreau, Alexandre 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, =E2=80=9Cemacs=E2=80=9D is displayed i= n 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 =3D> 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) =E2=80=A6) ;; Highlight group Ni in REGEXP with FACEi ;; ;; src_lang{code...}[:header arguments] / NOTE: override by `org-verbatim'. ;; result in following =3D[result]=3D ;; 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_[]()[] ... (font-lock-add-keywords 'org-mode '(("\\(call_\\)\\([^[(]*\\)\\[\\(.*\\)\\](\\(.*\\))\\[\\(.*\\)\\]" ;; "\\(call_\\)\\([^[(]*\\)\\([([][^)]*]\\)+" (1 '(:foreground "orange red" :height 0.6)) ; call_ (2 '(:foreground "yellow" :weight 'bold :underline "dark gray")) ; (3 '(:foreground "gray" :height 0.6)) ; [] (4 '(:foreground "cyan" :weight 'bold)) ; () (5 '(:foreground "gray" :height 0.6)) ; [] )) 'append) ;; call_[]() (font-lock-add-keywords 'org-mode '(("\\(call_\\)\\([^[(]*\\)\\[\\(.*\\)\\](\\(.*\\))" (1 '(:foreground "orange red" :height 0.6)) ; call_ (2 '(:foreground "yellow" :weight 'bold :underline "dark gray")) ; (3 '(:foreground "gray" :height 0.6)) ; [] (4 '(:foreground "cyan" :weight 'bold)) ; () )) 'append) ;; call_(arguments) (font-lock-add-keywords 'org-mode '(("\\(call_\\)\\([^[(]*\\)\\((.*)\\)" (1 '(:foreground "orange red" :height 0.6)) ; call_ (2 '(:foreground "yellow" :weight 'bold :underline "dark gray")) ; (3 '(:foreground "cyan" :weight 'bold)) ; () )) '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