Open luciferasm opened 11 years ago
I suppose the reason is that it's only designed (and tested) to be used during coding. As you found out yourself (#10), it won't work in all buffers, and I have no idea what would happen in other special buffers.
I don't want to add a global mode unless somebody has an idea how to limit it to reasonably compatible buffers.
I use this code:
(setq highlight-symbol-disable '())
(add-hook 'after-change-major-mode-hook
(lambda ()
(if (null (memql major-mode highlight-symbol-disable))
(highlight-symbol-mode))))
If I will need to disable the mode for some buffers I just append the name of that major mode to the list.
Hi, thanks for your answer!
But sometimes it is not enough to detect an incompatible environment by just looking at the major-mode. E.g. M-x list-colors-display or M-x list-faces-display uses Help major mode, but you don't want to always disable highlight-symbol in Help mode in general. Also, it seems more high-level to define a proper global-mode than using hooks. Therefore I currently use:
(defun highlight-symbol-mode-on () (unless (or (minibufferp) (member major-mode '()) ;;list of incompatible major modes (member (buffer-name) '("Faces" "Colors"))) ;;list of incompatible buffer names (highlight-symbol-mode 1)))
(define-globalized-minor-mode global-highlight-symbol-mode highlight-symbol-mode highlight-symbol-mode-on)
(global-highlight-symbol-mode 1)
Best regards,
/Stefan Guath
On 24 feb 2014, at 23:07, Jakub Jankiewicz notifications@github.com wrote:
I use this code:
(setq highlight-symbol-disable '()) (add-hook 'after-change-major-mode-hook (lambda () (if (null (memql major-mode highlight-symbol-disable)) (highlight-symbol-mode)))) If I will need to disable the mode for some buffers I just append the name of that major mode to the list.
— Reply to this email directly or view it on GitHub.
It would be great if you could add @luciferasm code
I don't think a manual list of incompatible modes and buffer names is safe enough to ship. I think that only works if customized for the actual user.
A whitelist approach might work, though.
in emacs 24 you can use prog-mode-hook
(and also text-mode-hook
if you want) to hook into all programming language modes (and text modes), which is quite a sane way to enable highlight-symbol-mode
for anything that is not a special buffer.
(defun my-hls-hook ()
(when (featurep 'highlight-symbol)
(highlight-symbol-mode t)
(highlight-symbol-nav-mode t)
))
(add-hook 'find-file-hook 'my-hls-hook)
I always use highlight-symbol globally, and have therefore added the usual: (defun highlight-symbol-mode-on () (highlight-symbol-mode 1)) (define-globalized-minor-mode global-highlight-symbol-mode highlight-symbol-mode highlight-symbol-mode-on)
in order to just enable it globally with
(global-highlight-symbol-mode 1)
Is there a reason why this standard global construct is left out?