1

While trying to use highlight-symbol in coffee mode (especially, cjsx), it interprets Something and <Something as two different symbols, while I expect < to be not part of a symbol.

Tried to trace the problem, and found that this is probably due to thighatpt symbol receives incorrect data from syntax table for coffee mode. How to fix coffee mode's syntax table to allow highlighting all symbols correctly?

(but maybe I am totally wrong with the assessment, and highlight-symbol somehow adds < to the symbol by itself. But at least in C mode it handles "less than" correctly)

GNU Emacs 24.3.1, Coffee mode 0.6.2, highlight-symbol 20160102.1209

  • Why don't you report this to the coffee-mode issue tracker? – Dmitry Mar 21 '16 at 22:27
1

Put the cursor just before the < in <symbol and hit C-u C-x =. Look at the *Help* output - search for "syntax". If it says this:

syntax: _   which means: symbol

then the character < has symbol syntax. And yes, you will need to change its syntax in coffee mode, to make it something else (e.g. so that C-u C-x = says something like this:

syntax: (>  which means: open, matches >

See the Elisp manual, node Syntax Tables and its subnodes for details about setting the syntax the way you want.

You can add a function to the coffee mode hook (probably coffee-mode-hook) that invokes modify-syntax-entry to change the syntax of character ?<. (You might want to also change the syntax of >.)

Something like this:

(defun foo ()
  (modify-syntax-entry ?< "(>  ")   ; < opens, closed by >
  (modify-syntax-entry ?> ")<  "))  ; > closes, opened by <

(add-hook 'coffee-mode-hook 'foo)
  • Great! Made entries for <> as in html mode, so your function was handy as is. Thanks! (small correction: "If it does not say this:" -> "If it says:" ?) And also = needs treatment... – Roman Susi Mar 21 '16 at 21:50
  • For the record, added (modify-syntax-entry ?= ". ") for "=" – Roman Susi Mar 21 '16 at 21:56
  • Thx - corrected the typo "does not say" -> "says". – Drew Mar 21 '16 at 22:29
  • Other characters, which need to be punctuation are: =, %, &, *, +, -, | – Roman Susi Mar 22 '16 at 6:29
  • Made <, > punctuation too as it interfered with brace-highlighting. – Roman Susi Mar 22 '16 at 8:06

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.