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

Reply via email to