zk-phi / magic-latex-buffer

Magical syntax highlighting for LaTeX-mode buffers
152 stars 13 forks source link

Add back-slash before '{' or '}' will immediately change the font face. #29

Open Ninlives opened 7 years ago

Ninlives commented 7 years ago

But in the screen-cast it don't behave like this....this can be annoying sometime.

I don't know if this is because I'm using spacemacs?

zk-phi commented 7 years ago

magic-latex-buffer tries not to immediately apply the faces if the cursor is inside a command, thus it seems a strange behavior ...

this is the expected behavior: (consider | as the cursor)

{|   type {
|{   move cursor leftward
\|{  type \ (magic-latex-buffer does not apply the face since the cursor is inside the command `\{`)
\{ | move cursor outside the command and type something, then magic-latex-buffer applies the faces
Ninlives commented 7 years ago

Weird....which piece of code do you use to ensure whether the cursor is inside the command?

zk-phi commented 7 years ago

Here's the code (as far as I remember ...) https://github.com/zk-phi/magic-latex-buffer/blob/master/magic-latex-buffer.el#L255

ml/jit-point is bound to the current cursor position while jit-lock highlighters are running.

Ninlives commented 7 years ago

Hi, I did some test today and I think I found the problem: the cursor position is set to 1 for some reason everytime the font-prettifier was activate.

But I did not find the reason though :P I'm not interested in reading all the related code and find the root cause.

So here is my workaround, for people who also have the same issue: In the config file, add:

(use-package magic-latex-buffer
  :config
  ;;use-package to ensure the code below was executed after magic-latex-buffer was loaded
  (add-hook 'magic-latex-buffer-hook (lambda()
                                       (defvar-local ml/current-point (point))
                                       (add-hook 'post-self-insert-hook (lambda() (setq-local ml/current-point (point))) nil t)
                                       (ad-remove-advice #'jit-lock-fontify-now 'around #'ml/ad-jit-lock)
                                       (defadvice jit-lock-fontify-now (around ml/ad-jit-lock-workaround activate)
                                         (let ((ml/jit-point ml/current-point))
                                           ad-do-it)))))