LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Emacs: Enable minor mode in all buffers (https://www.linuxquestions.org/questions/programming-9/emacs-enable-minor-mode-in-all-buffers-718839/)

nb85 04-13-2009 02:25 PM

Emacs: Enable minor mode in all buffers
 
Hi all,

Does anyone know how to enable an emacs minor mode by default for all buffers?

For example, I have the minor mode highlight-80+-mode that I can toggle with M-x highlight-80+mode, however I would like this to be on by default.

Any pointers to documentation/config/lisp stuff appreciated.

Many thanks,

Nick

kandiru 04-13-2009 03:14 PM

Hello,

may be you can find something useful here

http://www.linuxjournal.com/node/2801/print

in the section related to "Using hooks"

Hope this could help you

Bye

David

nb85 04-13-2009 03:56 PM

Quote:

Originally Posted by kandiru (Post 3507673)
Hello,

may be you can find something useful here

http://www.linuxjournal.com/node/2801/print

in the section related to "Using hooks"

Hope this could help you

Bye

David

Thanks for your reply. The site you provided was very useful indeed. I have added a hook to my .emacs for c-mode that does exactly what was required.

Thanks again,

Nick

just-a-guest 12-18-2014 07:03 AM

I am wonder why the author was satisfied with the answer that isn't an answer to the question at all… It took me for a while to find a way, so I am decided to share a real answer:

Emacs have the macro «define-global-minor-mode». It was a bit hard to me to figure out the right way of passing arguments — I all the time thought that the first arg is a string, and the second should be quoted. Until I found an example in a mailing list — then I saw: it's a macro, not a function! So, an example with one useful minor mode:

Code:

(define-global-minor-mode global-highlight-symbol-mode ;;the name of the new global mode
  highlight-symbol-mode ;;the name of the minor mode you want to turn on
  (lambda () (highlight-symbol-mode t) ;;the function to turn on the mode
        ))

I didn't quite understood, though, what is the need of the second argument, since the mode is enabled in the last one.
Don't forget to enable it with «M-x global-highlight-symbol-mode» (or whatever the name you used).

ntubski 12-18-2014 10:32 AM

Quote:

Originally Posted by just-a-guest (Post 5286885)
I didn't quite understood, though, what is the need of the second argument, since the mode is enabled in the last one.

You can pass a function that only sometimes enables the mode. But regardless, the macro needs to know the name of the mode, which it learns from the second argument.


All times are GMT -5. The time now is 12:10 AM.