magic-latex-buffer icon indicating copy to clipboard operation
magic-latex-buffer copied to clipboard

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

Open Ninlives opened this issue 8 years ago • 4 comments

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?

Ninlives avatar Sep 03 '17 15:09 Ninlives

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

zk-phi avatar Sep 04 '17 01:09 zk-phi

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

Ninlives avatar Sep 04 '17 02:09 Ninlives

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.

zk-phi avatar Sep 04 '17 11:09 zk-phi

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

Ninlives avatar Sep 07 '17 01:09 Ninlives