emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bhavin Gandhi <bhavin7392@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [BUG] Incorrect fontification of src blocks for indentation sensitive language modes
Date: Tue, 16 Aug 2022 23:17:48 +0530	[thread overview]
Message-ID: <CAOn=hbevUMGS0-qMTy8kB4-db65s1Tmn0cQJcw8b++PZZ=vULA@mail.gmail.com> (raw)

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


             reply	other threads:[~2022-08-16 18:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16 17:47 Bhavin Gandhi [this message]
2022-08-17  9:39 ` [BUG] Incorrect fontification of src blocks for indentation sensitive language modes Ihor Radchenko
2022-08-17 11:42   ` Fraga, Eric

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOn=hbevUMGS0-qMTy8kB4-db65s1Tmn0cQJcw8b++PZZ=vULA@mail.gmail.com' \
    --to=bhavin7392@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).