0

I use:

(global-superword-mode t)

in my init.el because I don't want Emacs to treat _ as a word delimiter.

How do I do the same thing for -? I'd like to enable this globally.

1

(global-superword-mode t)

[Note that mode functions are not documented as accepting t as argument - you should enable modes either as (mode) or with a non-zero natural number such as (mode 1).]

How do I do the same thing for -?

That depends on the syntax table (see (info "(elisp) Syntax Tables")), and thus the modes, in use. AFAICT, superword-mode delegates all of its boundary finding to the command forward-symbol. So if forward-symbol recognises - as constituting a symbol, then so will superword-mode.

In Elisp, - already has symbol syntax (see C-u C-x =, C-h s) so forward-symbol will skip all of e.g. global-superword-mode in one go. This is also the case in e.g. fundamental-mode and text-mode.

For changing the syntax category of -, there's the command modify-syntax-entry; see (info "(elisp) Syntax Table Functions"). For example, you could do M-x modify-syntax-entry RET - _ RET to give it symbol syntax in the current buffer.

4
  • Thanks! Is there anything I can add to init.el to have this set automatically? – WickedJargon Dec 4 '20 at 14:46
  • @WickedJargon Depends on where you would want such a setting to take effect - which modes, buffers, etc. Once you have identified these, then you can add the corresponding calls to (modify-syntax-entry ...) to the corresponding mode hooks or with-eval-after-load stanzas. – Basil Dec 4 '20 at 14:51
  • How do I enable it globally? – WickedJargon Dec 4 '20 at 22:22
  • @WickedJargon Maybe you could add the call to (modify-syntax-entry ..) on after-change-major-mode-hook, so that it runs in every mode. – Basil Dec 5 '20 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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