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

ggtags-fontify-code conflicts with hl-line-mode #212

Open
mohkale opened this issue Sep 2, 2021 · 1 comment
Open

ggtags-fontify-code conflicts with hl-line-mode #212

mohkale opened this issue Sep 2, 2021 · 1 comment

Comments

@mohkale
Copy link

mohkale commented Sep 2, 2021

See here.

Whenever ggtags looks up a tag and highlights it with ggtags-fontify-code the active hl-line in the original buffer is removed. I've narrowed the issue down to ggtags-fontify-code after some trial debugging.

Doing (advice-add 'ggtags-fontify-code :override #'identity) fixes the issue for now (but removes tag highlighting 😢.

You need to set (setq hl-line-sticky-flag nil) to get this bug to appear.

@mohkale
Copy link
Author

mohkale commented Sep 2, 2021

I really think emacs needs better support for just highlighting an arbitrary string. Different packages keep re-implementing this and none really reach the same quality as just writing them into a buffer and running font-lock on it.

Personally I think org-mode src block highlighting is the best. It even supports tree-sitter faces which makes the highlighted code identical to if I had just written it out myslef.

Here's a way to make ggtags use org for syntax highlighting. It should work reasonably well until we find a better implementation for ggtags itself.

(require 'org-src)

(defun ggtags-fontify-code-with-org+ (code &optional mode)
  (or mode (setq mode major-mode))
  (if (stringp code)
      (let* ((lang (s-chop-suffix "-mode" (symbol-name mode)))
             ;; Fallback to default-face not org-block-face.
             (org-src-block-faces `((,lang . (default)))))
        (with-temp-buffer
          (insert code)
          (org-src-font-lock-fontify-block lang (point-min) (point-max))
          (buffer-substring (point-min) (point-max))))
    code))

(advice-add #'ggtags-fontify-code :override #'ggtags-fontify-code-with-org+)

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

1 participant