emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Inline code block syntax highlighting absence
@ 2018-10-23 12:13 Garreau, Alexandre
  2018-10-24  3:47 ` stardiviner
  0 siblings, 1 reply; 9+ messages in thread
From: Garreau, Alexandre @ 2018-10-23 12:13 UTC (permalink / raw)
  To: org-mode

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).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Inline code block syntax highlighting absence
  2018-10-23 12:13 Inline code block syntax highlighting absence Garreau, Alexandre
@ 2018-10-24  3:47 ` stardiviner
  2018-10-24  7:39   ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: stardiviner @ 2018-10-24  3:47 UTC (permalink / raw)
  To: Garreau, Alexandre; +Cc: org-mode


Garreau, Alexandre <galex-713@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

-- 
[ 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
      

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Inline code block syntax highlighting absence
  2018-10-24  3:47 ` stardiviner
@ 2018-10-24  7:39   ` Nicolas Goaziou
  2018-10-25  4:12     ` stardiviner
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2018-10-24  7:39 UTC (permalink / raw)
  To: stardiviner; +Cc: org-mode, Garreau, Alexandre

Hello,

stardiviner <numbchild@gmail.com> writes:

> Garreau, Alexandre <galex-713@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,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Inline code block syntax highlighting absence
  2018-10-24  7:39   ` Nicolas Goaziou
@ 2018-10-25  4:12     ` stardiviner
  2018-10-25  7:40       ` Garreau, Alexandre
  2018-10-26 15:49       ` Nicolas Goaziou
  0 siblings, 2 replies; 9+ messages in thread
From: stardiviner @ 2018-10-25  4:12 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode, Garreau, Alexandre


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> Garreau, Alexandre <galex-713@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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Inline code block syntax highlighting absence
  2018-10-25  4:12     ` stardiviner
@ 2018-10-25  7:40       ` Garreau, Alexandre
  2018-10-26 15:49       ` Nicolas Goaziou
  1 sibling, 0 replies; 9+ messages in thread
From: Garreau, Alexandre @ 2018-10-25  7:40 UTC (permalink / raw)
  To: stardiviner; +Cc: org-mode, Nicolas Goaziou

On 2018-10-25 at 12:12, stardiviner wrote:
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> 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:

I found `org-src-font-lock-fontify-block' in the middle of “org-src.el”
(is that the place you wanted?), which I found in “org.el” which I found
after searching with “C-h f” a function containing “org-[POINT]font” and
TAB, so I quickly searched for “font-lock”, “begin_”, and “src”, alone.

I have the impression org doesn’t use `add-keywords' at all and just use
setq in org-set-font-lock-defaults so to bind keywords list.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Inline code block syntax highlighting absence
  2018-10-25  4:12     ` stardiviner
  2018-10-25  7:40       ` Garreau, Alexandre
@ 2018-10-26 15:49       ` Nicolas Goaziou
  2018-10-27  2:57         ` stardiviner
  2018-11-24  8:51         ` stardiviner
  1 sibling, 2 replies; 9+ messages in thread
From: Nicolas Goaziou @ 2018-10-26 15:49 UTC (permalink / raw)
  To: stardiviner; +Cc: org-mode, Garreau, Alexandre

Hello,

stardiviner <numbchild@gmail.com> writes:

> 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:

[...]

> (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)

The first thing is to define new faces, or re-use existing one, instead
of creating them ad-hoc.

Then you need to create a function like `org-fontify-entities'.

For example:

--8<---------------cut here---------------start------------->8---
(defun org-fontify-inline-code (limit)
  (when (re-search-forward "src_..." limit t)
    ;; here you need to make as sure as possible that you are really
    ;; at some inline code.  You cannot really parse inline source code
    ;; or inline Babel calls with a regexp only.
    (org-remove-flyspell-overlays-in beg end)
    (add-text-properties beg end (list 'font-lock-fontified t 'face ...))
    t))
--8<---------------cut here---------------end--------------->8---

You then register the function above in `org-set-font-lock-defaults.

Do you want to implement this?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Inline code block syntax highlighting absence
  2018-10-26 15:49       ` Nicolas Goaziou
@ 2018-10-27  2:57         ` stardiviner
  2018-11-24  8:51         ` stardiviner
  1 sibling, 0 replies; 9+ messages in thread
From: stardiviner @ 2018-10-27  2:57 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode, Garreau, Alexandre


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> 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:
>
> [...]
>
>> (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)
>
> The first thing is to define new faces, or re-use existing one, instead
> of creating them ad-hoc.
>
> Then you need to create a function like `org-fontify-entities'.
>
> For example:
>
> --8<---------------cut here---------------start------------->8---
> (defun org-fontify-inline-code (limit)
>   (when (re-search-forward "src_..." limit t)
>     ;; here you need to make as sure as possible that you are really
>     ;; at some inline code.  You cannot really parse inline source code
>     ;; or inline Babel calls with a regexp only.
>     (org-remove-flyspell-overlays-in beg end)
>     (add-text-properties beg end (list 'font-lock-fontified t 'face ...))
>     t))
> --8<---------------cut here---------------end--------------->8---
>
> You then register the function above in `org-set-font-lock-defaults.
>
> Do you want to implement this?
>
> Regards,


I will take a try. Maybe later in few days.

-- 
[ 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
      

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Inline code block syntax highlighting absence
  2018-10-26 15:49       ` Nicolas Goaziou
  2018-10-27  2:57         ` stardiviner
@ 2018-11-24  8:51         ` stardiviner
  2018-11-28  8:05           ` [Need Help] I need help, someone can help me debug on this? stardiviner
  1 sibling, 1 reply; 9+ messages in thread
From: stardiviner @ 2018-11-24  8:51 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode, Garreau, Alexandre

[-- Attachment #1: Type: text/plain, Size: 128 bytes --]

I followed your hints, added code. But got a problem on regexp grouping.

Here is the screenshot which can show you the issue.


[-- Attachment #2: org-fontify-inline-src.png --]
[-- Type: image/png, Size: 294576 bytes --]

[-- Attachment #3: Type: text/plain, Size: 254 bytes --]


-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Need Help] I need help, someone can help me debug on this?
  2018-11-24  8:51         ` stardiviner
@ 2018-11-28  8:05           ` stardiviner
  0 siblings, 0 replies; 9+ messages in thread
From: stardiviner @ 2018-11-28  8:05 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode, Garreau, Alexandre


Check out my previous email. (Because I lost the screenshot image file...)

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-11-28  8:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-23 12:13 Inline code block syntax highlighting absence Garreau, Alexandre
2018-10-24  3:47 ` stardiviner
2018-10-24  7:39   ` Nicolas Goaziou
2018-10-25  4:12     ` stardiviner
2018-10-25  7:40       ` Garreau, Alexandre
2018-10-26 15:49       ` Nicolas Goaziou
2018-10-27  2:57         ` stardiviner
2018-11-24  8:51         ` stardiviner
2018-11-28  8:05           ` [Need Help] I need help, someone can help me debug on this? stardiviner

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).