Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ninlives opened this issue Sep 3, 2017 · 4 comments
Open

Comments

@Ninlives
Copy link

Ninlives commented Sep 3, 2017

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
Copy link
Owner

zk-phi commented Sep 4, 2017

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
Copy link
Author

Ninlives commented Sep 4, 2017

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

@zk-phi
Copy link
Owner

zk-phi commented Sep 4, 2017

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
Copy link
Author

Ninlives commented Sep 7, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants