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

global mode? #11

Open
luciferasm opened this issue Jul 16, 2013 · 7 comments
Open

global mode? #11

luciferasm opened this issue Jul 16, 2013 · 7 comments

Comments

@luciferasm
Copy link

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
Copy link
Owner

nschum commented Jul 16, 2013

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
Copy link

jcubic commented Feb 24, 2014

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
Copy link
Author

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.

@unbalancedparentheses
Copy link

It would be great if you could add @luciferasm code

@nschum
Copy link
Owner

nschum commented Sep 23, 2014

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 nschum mentioned this issue Apr 21, 2015
@wbolster
Copy link

wbolster commented Mar 3, 2016

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
Copy link

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

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

6 participants