Define a character as a word boundary

I defined a character \to behave as part of a word in latex mode, and I am very pleased with the results. My only concern is that a sequence like this \alpha\betais treated as one word (this, of course, is the expected behavior).

Is there a way to make emacs interpret a certain character as the word "starter"? Thus, this will always be considered part of the next word, but will never be part of the word preceding it.

For clarity, here is an example:

\alpha\beta
^          ^
1          2

If the dot is in 1and I click M-d, the string "\ alpha" should be killed. If the dot is in 2and I click M-<backspace>, the string "\ beta" should be killed.

How can i achieve this?

+5
source share
2 answers

Another thought:
Your requirement is very similar to what subword-modecamelCase provides.

You cannot configure the behavior in sublayer mode - regular expressions are hardcoded, but you can, of course, copy this library and modify it for your own purposes.

M-x find-library RET subword RET

This is likely to be a pretty reliable solution.

Edit: updated from comments as suggested:

For the record, changing each instance [[:upper:]]to [\\\\[:upper:]]in functions subword-forward-internaland subword-backward-internalinside subword.el works fine =) (so far the "\" is defined as the "w" syntax).

, , , , - .

2: Emacs 24.3 ( ), subword-forward-regexp subword-backward-regexp ( ) subword-forward-function subword-backward-function ( ).

regexp buffer-local , .

+3

, :

M-: (info "(elisp) Syntax Properties") RET

: , , ?

( ) , M-<backspace> 2 "", "\".

, backward-kill-word , , "\", ​​ . , , , , .

; , - .

(modify-syntax-entry ?\\ "w")
(setq parse-sexp-lookup-properties t)
(setq syntax-propertize-function 'my-propertize-syntax)
(defun my-propertize-syntax (start end)
  "Set custom syntax properties."
  (save-excursion
    (goto-char start)
    (while (re-search-forward "\\w\\\\" end t)
      (put-text-property
       (1- (point)) (point) 'syntax-table (cons "." ?\\)))))
+2

All Articles