0

Have been using highlight-sexp using hooks

(add-hook 'lisp-mode-hook 'highlight-sexp-mode)
(add-hook 'emacs-lisp-mode-hook 'highlight-sexp-mode)

Would like to enable highlight-sexp-mode as buffer local with an on and off mechanism. As I am writing this in my init file, the commands should be suitable for inclusion in elisp code, rather than calling highlight-sex commands directly in the minibuffer.

9
  • 1
    Just do M-x highlight-sexp-mode in the target buffer? Or do I misunderstand what you are after here? Jun 22, 2022 at 20:48
  • That's an answer, @FranBurstall (IMO, it's the answer). Please consider posting it as an answer. (Comments can be deleted at any time. Q&A need to stand on their own, to be searchable etc.)
    – Drew
    Jun 22, 2022 at 20:56
  • Not sure I understand. How are you going to select the buffers where you want to turn the mode on from yr init (which is loaded before those buffers exist)? Jun 23, 2022 at 11:30
  • The highlight would be off in init, but will provide interactive functions for switching highlighting on and off for the current buffer. Because highlight-sexp-mode highlights large chunks I do not want the features enabled by default through a major mode hook or globally.
    – Dilna
    Jun 23, 2022 at 13:22
  • There already such a function! It is called highlight-sexp-mode and does exactly what you want! Am I missing something here? Jun 23, 2022 at 13:50

1 Answer 1

1

Interactively, just do M-x highlight-sexp-mode in the target buffer to toggle the mode.

From elisp,

(highlight-sexp-mode 1)

turns it on and

(highlight-sexp-mode -1)

turns it off. In both cases, this should apply to the current buffer only.

You can detect whether the mode is active by inspecting the value of the variable highlight-sexp-mode with C-h v highlight-sexp-mode. It will be t if the mode is active in the current buffer. In elisp:

(if hightlight-sexp-mode
  (message "it's on!")
 (message "it's off!"))

Disclaimer: I do not have this package installed. I am simply assuming that highlight-sexp-mode is a well-behaved minor mode. You are much better placed to find all this out: simply do C-h f highlight-sexp-mode and the docs should tell you, near the top, how to turn on/off from elisp. Once again: Ask emacs.

5
  • In elisp code, would the command be (highlight-sexp-mode). Would that be only buffer local? Would need to be able to enable it and disable it.
    – Dilna
    Jun 23, 2022 at 5:28
  • Is there a way to determine if a minor mode is active or not?
    – Dilna
    Jun 23, 2022 at 6:35
  • See revised version of my answer. Jun 23, 2022 at 7:09
  • Thank you. I would still need an example showing whether the minor-mode is on or off when done in elisp code. Because I am focusing on elisp files at this moment that automates the highlighting of exprossions through different settings and functionalities provided by several packages. Without requiring the user to know all much about the different packages.
    – Dilna
    Jun 23, 2022 at 8:08
  • @Ephram: the question has changed a couple of times now. Please edit yr original question to ask what you really want to know. Jun 23, 2022 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.