emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] Fontification error when unknown or missing lang
       [not found] <DU2P250MB02061B822C34827749815A7DDBED2@DU2P250MB0206.EURP250.PROD.OUTLOOK.COM>
@ 2025-01-26 17:52 ` Aitenate
  0 siblings, 0 replies; only message in thread
From: Aitenate @ 2025-01-26 17:52 UTC (permalink / raw)
  To: emacs-orgmode

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

There appears to be a minor bug with fontification and certain block
configurations.

The following example block results in a fontification error.

#+begin_example
  	<-- two spaces followed by a tab
#+end_example

It looks like org-src-font-lock-fontify-block is the culprit because
native-tab-width is only set when the block has a valid lang. Testing
with source blocks show they also suffer from the issue.

#+begin_src
  	<-- two spaces followed by a tab
#+end_src

#+begin_src foo
  	<-- two spaces followed by a tab
#+end_src

I've attached a diff with, what I believe is, one possible way to
address the issue.

Regards,
Aitenate

[-- Attachment #2: fontification_error.diff --]
[-- Type: text/x-patch, Size: 1901 bytes --]

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 74343bde1..a39a4066b 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -740,20 +740,21 @@ as `org-src-fontify-natively' is non-nil."
         (font-lock-append-text-property start end 'face src-face))
       (font-lock-append-text-property start end 'face 'org-block))
     ;; Display native tab indentation characters as spaces
-    (save-excursion
-      (goto-char start)
-      (let ((indent-offset
-	     (if (org-src-preserve-indentation-p) 0
-	       (+ (progn (backward-char)
-                         (org-current-text-indentation))
-	          org-edit-src-content-indentation))))
-        (while (re-search-forward "^[ ]*\t" end t)
-          (let* ((b (and (eq indent-offset (move-to-column indent-offset))
-                         (point)))
-                 (e (progn (skip-chars-forward "\t") (point)))
-                 (s (and b (make-string (* (- e b) native-tab-width) ? ))))
-            (when (and b (< b e)) (add-text-properties b e `(display ,s)))
-            (forward-char)))))
+    (when native-tab-width
+      (save-excursion
+        (goto-char start)
+        (let ((indent-offset
+	       (if (org-src-preserve-indentation-p) 0
+	         (+ (progn (backward-char)
+                           (org-current-text-indentation))
+	            org-edit-src-content-indentation))))
+          (while (re-search-forward "^[ ]*\t" end t)
+            (let* ((b (and (eq indent-offset (move-to-column indent-offset))
+                           (point)))
+                   (e (progn (skip-chars-forward "\t") (point)))
+                   (s (and b (make-string (* (- e b) native-tab-width) ? ))))
+              (when (and b (< b e)) (add-text-properties b e `(display ,s)))
+              (forward-char))))))
     (add-text-properties
      start end
      '(font-lock-fontified t fontified t font-lock-multiline t))

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-26 17:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <DU2P250MB02061B822C34827749815A7DDBED2@DU2P250MB0206.EURP250.PROD.OUTLOOK.COM>
2025-01-26 17:52 ` [BUG] Fontification error when unknown or missing lang Aitenate

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