How to make Emacs SQL mode recognize MySQL # -style comments?

I am reading a bunch of MySQL files that use # (to end-of-line) comments, but my SQL mode does not support them. I found a sql.el syntax table table that defines / ** / and - comments, but according to this , Emacs syntax tables support only two comment styles.

Is there a way to add support for # comments in sql.el easily?

+3
source share
3 answers

Rolf's answer did not seem to work for me. AFAIK, the character class for beginning comments, the alternative comment style should be "<b", not "b". This is what I use:

    (add-hook 'sql-mode-hook 'my-sql-mode-hook) 
    (defun my-sql-mode-hook ()   
      ;; Make # start a new line comment in SQL. This is MySQL-specific
      ;; syntax.
      (modify-syntax-entry ?# "< b" sql-mode-syntax-table))
+2
source

Emacs-24 sql.el has a built-in module! Just run M-x sql-set-product MySQL RET, and the syntax table will be configured automatically, as well as keywords for blocking fonts for all additional reserved words and types, interactive mode, etc. Etc. Brilliant!!

If you look under SQLin the menu bar, you can use the submenu Productto select MySQL.

You can also M-x customize-variable sql-product RETinstall the default product from ANSI.

+2
source

? #, b, , ( - #):

(setq sql-mode-syntax-table
  (let ((table (make-syntax-table)))
    ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
    (modify-syntax-entry ?/ ". 14" table)
    (modify-syntax-entry ?* ". 23" table)
    ;; double-dash starts comments
    (modify-syntax-entry ?- ". 12b" table)
    (modify-syntax-entry ?# " b" table)
    (modify-syntax-entry ?\f "> b" table)
    ;; single quotes (') delimit strings
    (modify-syntax-entry ?' "\"" table)
    ;; double quotes (") don't delimit strings
    (modify-syntax-entry ?\" "." table)
    ;; backslash is no escape character
    (modify-syntax-entry ?\\ "." table)
    table))

( sql.el , , GPL)

+1

Source: https://habr.com/ru/post/1702322/


All Articles