emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] Incorrect fontification of src blocks for indentation sensitive language modes
@ 2022-08-16 17:47 Bhavin Gandhi
  2022-08-17  9:39 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Bhavin Gandhi @ 2022-08-16 17:47 UTC (permalink / raw)
  To: emacs-orgmode

In the following Org mode file, the Ledger mode source block is not
highlighted correctly.

How to reproduce:
1. Clone Ledger mode: git clone
https://github.com/ledger/ledger-mode.git /tmp/ledger-mode
2. emacs -Q -L ~/src/org-mode/lisp
3. Evaluate the following in the *scratch* buffer.

(add-to-list 'load-path "/tmp/ledger-mode")
(require 'ledger-mode)

4. Create an Org mode file test.org with following content
--8<---------------cut here---------------start------------->8---
* Some heading
- Option one
  #+begin_src ledger
  2022/08/16 Buy books
      Expenses:Books                              ₹299
      Assets:Cash
  #+end_src
--8<---------------cut here---------------end--------------->8---

5. The block is not fontified.
6. Now go to the src block and do C-c ', you will see the block
   correctly fontified, and after doing C-c ' again, we are back to
   incorrect fontification.

I tried to debug this and found the function
org-src-font-lock-fontify-block. Turns out that the code block is
actually being fontified, but Ledger mode seems to get the block with
indentation. I found this by adding a (message string) in this function.

--8<---------------cut here---------------start------------->8---
  2022/08/16 Buy books
      Expenses:Books                              ₹299
      Assets:Cash
--8<---------------cut here---------------end--------------->8---

Notice the extra indentation at the beginning of year 2022. This block
is not valid Ledger mode content, so it just keeps it grayed out,
instead of having colors. If we remove the indentation from the src block in
the Org mode file, it gets fontified correctly.

Setting org-adapt-indentation to t didn't make any difference. Value of
org-src-fontify-natively is t by default. I even tried
https://github.com/yantar92/org/tree/feature/org-font-lock-element, it
had the same issue.
I think the language mode should get the block without the extra
indentation. Or am I missing something here?

PS: I haven't looked at the code of org-src-font-lock-fontify-block in
detail, so I could be wrong with this analysis.

-- 
Bhavin Gandhi (bhavin192) | https://geeksocket.in


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

end of thread, other threads:[~2022-08-17 11:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 17:47 [BUG] Incorrect fontification of src blocks for indentation sensitive language modes Bhavin Gandhi
2022-08-17  9:39 ` Ihor Radchenko
2022-08-17 11:42   ` Fraga, Eric

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