1

I have used modify-syntax-entry to remove underscores from being delimiting characters. e.g:

(modify-syntax-entry ?_ "w")

However I would like to temporary allow underscores to be used as a delimiter.

Normally I would temporarily override a variable with let in a function.

How can the syntax table be temporarily overridden?

1 Answer 1

1

You can create a new syntax table, then run the command in a with-syntax-table block:

This is an example of delete forward/backward word, with a modified syntax table.

(defun kill-word-sans-delimiter-impl (arg)
  (let ((table (make-syntax-table)))
    (dolist (ch (list ?- ?_))
      (modify-syntax-entry ch "_" table))
    (with-syntax-table table (kill-word arg))))

(defun kill-word-backward-sans-delimiter (arg)
  (interactive "p")
  (kill-word-sans-delimiter-impl (- arg)))

(defun kill-word-forward-sans-delimiter (arg)
  (interactive "p")
  (kill-word-sans-delimiter-impl arg))

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.