dominikh / go-mode.el

Emacs mode for the Go programming language
BSD 3-Clause "New" or "Revised" License
1.37k stars 209 forks source link

`_` is treated as word syntax rather than symbol syntax #431

Open darkfeline opened 7 months ago

darkfeline commented 7 months ago

Read comments for context.

Old title: Syntax highlighting doesn't support _ in named return

Old description:

The syntax highlighting fails on the _ in cases like:


func getPort() (port int, _ error) {
    // do stuff
}
darkfeline commented 7 months ago

This is the same bug that causes _ in test function names to fail syntax highlighting. Identifiers are [:word:] and _ is not marked as a word syntax class I think.

Edit: _ is marked as word syntax but somehow it still doesn't work.

(defvar go-mode-syntax-table
  (let ((st (make-syntax-table)))
    ;; snip
    ;; TODO make _ a symbol constituent now that xemacs is gone
    (modify-syntax-entry ?_  "w" st)

    st)
  "Syntax table for Go mode.")

Changing [[:word:][:multibyte:]] in the various regexps to [[:word:]_[:multibyte:]] does fix the issue.

Edit 2: I'm an idiot, I set _ back to symbol syntax in my personal config. However, noting the TODO I quoted above, this will (?) eventually need to be fixed.