3

I am trying to add the verbatim character ~ (tilde) as an electric-pair character in org-mode. Here is my attempt:

(with-eval-after-load 'org
 (modify-syntax-entry ?/ "(/" org-mode-syntax-table)
 (modify-syntax-entry ?= "(=" org-mode-syntax-table)
 (modify-syntax-entry ?~ "(~" org-mode-syntax-table))

This works for the / and = characters, but not for ~. What do I need to do to add ~?

5

The syntax of ~ is changed by org-mode itself: as part of the definition of the mode, the file org.el contains

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

inside (define-derived-mode org-mode...). Since the command org-mode is not necessarily run at the time the file is loaded, you need to put your modification in to org-mode-hook instead, e.g.

(add-hook 'org-mode-hook (lambda ()  (modify-syntax-entry ?~ "$~" org-mode-syntax-table)))

so this run after the built-in syntax entry. Your other definitions work, because org does not set the syntax for the those characters.

Note, as ~ is meant to match with itself, you should use the syntax class $ rather than (. The syntax class ( indicates that the given character is paired with a different symbol.

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.