ggtags
ggtags copied to clipboard
ggtags-fontify-code conflicts with hl-line-mode
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 :cry:.
You need to set (setq hl-line-sticky-flag nil)
to get this bug to appear.
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+)