Elisp: Modify Syntax Table Temporarily

By Xah Lee. Date: . Last updated: .

Here's a example of how to use a temporary syntax table just for 1 command.

Suppose, we want the curly quote to be considered as a bracket.

Emacs's standard-syntax-table considers the curly quote as punctuation character.

[see Elisp: Find Syntax of a Char]

(defun test ()
  "move cursor to the right 1 char, but if it is a left curly quote, jump to the right curly quote.
Version 2017-02-13"
  (interactive)
  (let (($temp-syn-table (make-syntax-table)))

    (modify-syntax-entry ?\“ "(”" $temp-syn-table)
    (modify-syntax-entry ?\” ")“" $temp-syn-table)

    (with-syntax-table $temp-syn-table
      (if (looking-at "\\s(")
          (forward-sexp 1)
        (right-char )))))

test “xyz” text

(info "(elisp) Syntax Table Functions")

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


ELisp Write Major Mode

Basics

Package Name/Load

Syntax Table