polymode / poly-org

Polymode for org-mode
56 stars 12 forks source link

Font lock is not reapplied when org-indent-mode is turned on #20

Open srnnkls opened 4 years ago

srnnkls commented 4 years ago

I updated my setup recently and now (with org 9.3) I have issues with font-locking. While the spans are identified correctly and the mode changes appropriately, the font lock is only applied initially and and not reapplied through edits within the indirect buffer. Further, at some point the font-lock is lost at all. I had a look and disabling org-indent-mode or setting org-startup-indented to nil seems to make font-locking work again.

Here is the output of pm-debug-relevant-variables:

================== thesis.org ===================
((:change
  (before-change-functions whitespace-buffer-changed org-ref-delete-labels org-indent-notify-modified-headline org-before-change-function t sp--reset-memoization)
  (after-change-functions polymode-flush-syntax-ppss-cache poly-lock-after-change flycheck-handle-change org-indent-refresh-maybe t ws-butler-after-change))
 (:command
  (pre-command-hook polymode-pre-command-synchronize-state eldoc-pre-command-refresh-echo-area evil--jump-hook company-pre-command t)
  (post-command-hook polymode-post-command-select-buffer whitespace-post-command-hook eldoc-schedule-timer evil-normal-post-command company-post-command flycheck-hide-error-buffer flycheck-display-error-at-point-soon flycheck-error-list-highlight-errors flycheck-error-list-update-source flycheck-perform-deferred-syntax-check hl-line-maybe-unhighlight hl-line-highlight yas--post-command-handler t))
 (:font-lock
  (fontification-functions poly-lock-function)
  (font-lock-function . poly-lock-mode)
  (font-lock-flush-function . poly-lock-flush)
  (font-lock-ensure-function . poly-lock-fontify-now)
  (font-lock-fontify-region-function . font-lock-default-fontify-region)
  (font-lock-fontify-buffer-function . poly-lock-flush)
  (font-lock-unfontify-region-function . org-unfontify-region)
  (font-lock-unfontify-buffer-function . font-lock-default-unfontify-buffer)
  (jit-lock-after-change-extend-region-functions font-lock-extend-jit-lock-region-after-change t)
  (jit-lock-functions font-lock-fontify-region org-ref-add-labels)
  (poly-lock-defer-after-change . t))
 (:search
  (parse-sexp-lookup-properties . t)
  (parse-sexp-ignore-comments)
  (case-fold-search . t))
 (:indent
  (indent-line-function . pm-indent-line-dispatcher)
  (indent-region-function . pm-indent-region)
  (pm--indent-line-function-original . org-indent-line))
 (:revert
  (revert-buffer-function . revert-buffer--default)
  (before-revert-hook flycheck-teardown t ws-butler-before-revert)
  (after-revert-hook t ws-butler-after-save))
 (:save
  (after-save-hook flycheck-handle-save t ws-butler-after-save)
  (before-save-hook +org-update-cookies-h toc-org-insert-toc org-encrypt-entries t ws-butler-before-save)
  (write-contents-functions)
  (local-write-file-hooks)
  (write-file-functions whitespace-write-file-hook recentf-track-opened-file doom--recentf-touch-buffer-h undo-tree-save-history-hook))
 (:syntax
  (syntax-propertize-function . polymode-syntax-propertize)
  (syntax-propertize-extend-region-functions syntax-propertize-wholelines)
  (pm--syntax-propertize-function-original)))
srnnkls commented 4 years ago

Okay, further testing revealed:

Everything works fine even with org-indent-mode enabled, when I disable evil-mode. In fact fontification still works if I reenable evil-mode after loading the buffer with evil-mode disabled.

vspinu commented 4 years ago

@srnnkls Did you continue using poly-org? I am not an evil user, so it's hard for me to test/devlop on it. I see no reason why evil-mode should interfere with font-lock though.

dvzubarev commented 4 years ago

Hi, I have this issue while editing a large buffer (159KiB). But I cant reliably reproduce this behavior, often it occurs when I move outside of src block to the header of this block. I was trying to catch errors with toggle-debug-on-errors with no luck. If I kill the buffer after the fontification has gone with the point inside src block, and reopen it fontification won't work (point is inside src block). But if I leave the point outside of the src block, then fontification works as usual on reopening of the file.
I use org-indent-mode and evil-mode too.

dvzubarev commented 4 years ago

Actually, I was able to reproduce it with this config and emacs 26.3.

(setq load-path
      (append '("path/to/polymode-20200411.915/"
 "path/to/poly-org-20200316.1315/")
              load-path))
(require 'poly-org)
(setq org-src-fontify-natively nil)
;;uncomment to reproduce
;;(setq org-startup-indented t)

and this org file:

* TEMP

#+BEGIN_SRC python
import math

#+END_SRC

When org-indent-mode is enabled (org-startup-indented is t), then fontification won't work (e.g. try to comment import math).

lsiksous commented 4 years ago

Same problem. I tried everything but can't figure what causes this behaviour. Does the same trick whatever language : I have an org file mixing emacs-lisp, python and R.

dustinlacewell commented 4 years ago

Hmm, this issue is starting to drive me a little loopy.

ugurbolat commented 1 year ago

fyi: the issue is not caused by org-indent but org-src-fontify-natively being disabled.

the fix is: pr42

kchanqvq commented 1 year ago

fyi: the issue is not caused by org-indent but org-src-fontify-natively being disabled.

the fix is: pr42

org-indent still breaks font-lock after applying this patch 😭