nschum / highlight-symbol.el

Emacs: automatic and manual symbol highlighting
http://nschum.de/src/emacs/highlight-symbol/
274 stars 41 forks source link

global mode? #11

Open luciferasm opened 11 years ago

luciferasm commented 11 years ago

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?

nschum commented 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.

jcubic commented 10 years ago

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.

luciferasm commented 10 years ago

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.

unbalancedparentheses commented 10 years ago

It would be great if you could add @luciferasm code

nschum commented 10 years ago

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.

wbolster commented 8 years ago

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.

SwagDevOps commented 6 years ago
(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)