highlight-symbol.el icon indicating copy to clipboard operation
highlight-symbol.el copied to clipboard

global mode?

Open luciferasm opened this issue 10 years ago • 7 comments

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?

luciferasm avatar Jul 16 '13 18:07 luciferasm

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.

nschum avatar Jul 16 '13 20:07 nschum

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.

jcubic avatar Feb 24 '14 22:02 jcubic

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 [email protected] 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.

luciferasm avatar Feb 25 '14 09:02 luciferasm

It would be great if you could add @luciferasm code

unbalancedparentheses avatar Sep 19 '14 21:09 unbalancedparentheses

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.

nschum avatar Sep 23 '14 13:09 nschum

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.

wbolster avatar Mar 03 '16 19:03 wbolster

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

SwagDevOps avatar Apr 01 '18 14:04 SwagDevOps