Recently I found out about isearch-forward-symbol-at-point but in tcl it's rather useless, because when dereferencing a variable the $ is part of the symbol and so the symbol-at-point $var does not match ${var} or var.

In the following example code look at each symbol with M-: (symbol-at-point)

set var 1
puts "var = $var"
puts "${var}23"

Funny enough the syntax highlighting clearly differentiates between the symbol and the syntactic character. In perl-mode this is working well.

So the question is: what has to be changed in tcl.el (the one that comes with emacs 24.5.1) to exclude $ from the symbol?

2 Answers 2


With a bit of searching I found that syntactic elements like parentheses, comment delimiters, characters that can be used for syntactic symbols and others are managed by a syntax table (look it up in the elisp reference manual) . With the help of describe-syntax I compared the syntax tables for perl-mode and tcl-mode. In perl-mode the character $ is given the class character quote but in tcl-mode it is class symbol.

So the solution is, to give $ another class than symbol but I think, character quote is not the right one, because the manual states about this class:

Characters used to quote the following character so that it loses its normal syntactic meaning. This differs from an escape character in that only the character immediately following is ever affected.

AFAIK the class expression prefix is far better suited:

Characters used for syntactic operators that are considered as part of an expression if they appear next to one. In Lisp modes, these characters include the apostrophe, ‘'’ (used for quoting), the comma, ‘,’ (used in macros), and ‘#’ (used in the read syntax for certain data types).


The following form changes the tcl syntax table after it is defined:

(with-eval-after-load "tcl"
  (modify-syntax-entry ?$ "'" tcl-mode-syntax-table))

with-eval-after-load was introduced in 24.4 for older version, there is the function eval-after-load (see: What is “with-eval-after-load” in Emacs Lisp)


Adding a hook that modifies the syntax of $ as suggested by a FIXME comment in tcl.el seems to work:

(defun my-tcl-modify-dollar-syntax ()
  (modify-syntax-entry ?$ "'" tcl-mode-syntax-table))

(add-hook 'tcl-mode-hook #'my-tcl-modify-dollar-syntax)
  • You have beaten me by some minutes ;-) I don't think it's necessary to add this to the hook, cause the syntax table is a normal global variable, isn't it? Commented Feb 5, 2016 at 23:19
  • @UweKoloska: I bet you're right! Commented Feb 14, 2016 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.