1

For a reason I don't yet understand, superword-mode does not work in the rst-mode buffers in my Emacs. I tried Emacs 26.3 and 27.2.

The superword-mode works fine in other major modes such as text-mode.

By not not working I mean: point stops at the underscore character in something_like_this instead of moving at the end when executing the forward-word command.

For example: inside a a buffer holding the content of afile.rst, the content is the following:

This is a test for superword-mode.
Put point at_the_beginning_of_this_long_word inside this sentence.
By typing M-f it should move to the end, just after 'word' before ' inside'.
  • The major mode of the buffer is rst-mode.
  • Activate superword-mode with M-x superword-mode
  • Place point on line 2, character 10, just before at_the_beginning_of_this_long_word
  • Execute forward-word, normally bound to M-f
  • In superword-mode working properly, point should move forward by 34 character just after the 'd' of 'word'
    • That's what it does in text-mode
    • But in rst-mode, point moves forward by 2 characters only, just after the word 'at'.
      • The forward-mode command behaves just as if superword-mode was not active, stopping at the underscore.
      • But looking at the value of the superword-mode variable in the scope of that buffer, I see that it is buffer-local set to t.
      • Inside the afile.rst buffer the superword-mode lighter is shown as expected.

Is there something that is known to interfere with superword-mode or some other known reason for it to not behave as expected?

PRouleau
  • 744
  • 3
  • 10

1 Answers1

1

The problem is likely due to the difference in the syntax class of an underscore (_) between rst-mode and text-mode.

With your cursor on the underscore, use C-u C-x = to see what syntax class is assigned to that char in each of the modes.

(In text-mode it has syntax symbol, by default. In rst-mode it appears to have punctuation syntax.)

If superword-mode requires an underscore to have a particular syntax class (e.g. symbol) for it to work properly, then you'll likely have to change its syntax class in rst-mode to get superword-mode to treat it properly. You can do that this way:

(modify-syntax-entry ?_ "_" rst-mode-syntax-table)

But that might have other, negative effects in rst-mode - it's likely that rst-mode didn't assign an underscore char that syntax class on purpose. You might want to check other rst-mode buffers, to see if their content depends on _ having punctuation syntax instead of symbol syntax.

Drew
  • 75,699
  • 9
  • 109
  • 225