From: Lars Ingebrigtsen <larsi@gnus.org>
To: "積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Cc: 38302@debbugs.gnu.org
Subject: bug#38302: SQL[ANSI] mode sees into comments
Date: Fri, 20 May 2022 13:28:41 +0200 [thread overview]
Message-ID: <87wneg30k6.fsf@gnus.org> (raw)
In-Reply-To: <87y2wa60ev.8.fsf@jidanni.org> ("積丹尼 Dan Jacobson"'s message of "Wed, 20 Nov 2019 23:19:04 +0800")
積丹尼 Dan Jacobson <jidanni@jidanni.org> writes:
> Here you can see SQL[ANSI] mode has tons of errors:
> wrong colors for keywords that are actually in comments.
> And then a "-- what --" making the whole rest into a comment.
> $ emacs -nw -Q m.sql.bz2 # attachment below
> emacs-version "26.3"
>
> LOCK TABLES `comment` WRITE;
> /*!40000 ALTER TABLE `comment` DISABLE KEYS */;
> INSERT INTO `comment` VALUES (1,0,'',NULL),(2,-1141372718,_binary 'Importing text file',NULL),(3,28325391,_binary 'Created page with \'2009-07-12 [My answer
The only problem I could see (in Emacs 29) at least was that sql-mode
expects quotes to be quoted like '', not like \'. I.e., if I replaced
all the \' with '', then everything looked fine to me (but it was a long
snippet, so I'm not quite sure).
Is \' the correct way to escape a quote in some SQL dialects? Hm...
googling seems to indicate that MySQL uses \' as an escape for '? I
know nothing about MySQL -- does that seem correct? Anybody?
In that case, the following should fix the problem (at the expense of
computing it the rules runtime)...
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 8d25986090..ef8375e859 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -4161,28 +4161,33 @@ sql-mode
(setq-local sql-contains-names t)
(setq-local escaped-string-quote "'")
(setq-local syntax-propertize-function
- (syntax-propertize-rules
- ;; Handle escaped apostrophes within strings.
- ("''"
- (0
- (if (save-excursion (nth 3 (syntax-ppss (match-beginning 0))))
- (string-to-syntax ".")
- (forward-char -1)
- nil)))
- ;; Propertize rules to not have /- and -* start comments.
- ("\\(/-\\)" (1 "."))
- ("\\(-\\*\\)"
- (1
- (if (save-excursion
- (not (ppss-comment-depth
- (syntax-ppss (match-beginning 1)))))
- ;; If we're outside a comment, we don't let -*
- ;; start a comment.
- (string-to-syntax ".")
- ;; Inside a comment, ignore it to avoid -*/ not
- ;; being interpreted as a comment end.
- (forward-char -1)
- nil)))))
+ (eval
+ '(syntax-propertize-rules
+ ;; Handle escaped apostrophes within strings.
+ ((if (eq sql-product 'mysql)
+ "\\\\'"
+ "''")
+ (0
+ (if (save-excursion
+ (nth 3 (syntax-ppss (match-beginning 0))))
+ (string-to-syntax ".")
+ (forward-char -1)
+ nil)))
+ ;; Propertize rules to not have /- and -* start comments.
+ ("\\(/-\\)" (1 "."))
+ ("\\(-\\*\\)"
+ (1
+ (if (save-excursion
+ (not (ppss-comment-depth
+ (syntax-ppss (match-beginning 1)))))
+ ;; If we're outside a comment, we don't let -*
+ ;; start a comment.
+ (string-to-syntax ".")
+ ;; Inside a comment, ignore it to avoid -*/ not
+ ;; being interpreted as a comment end.
+ (forward-char -1)
+ nil))))
+ t))
;; Set syntax and font-face highlighting
;; Catch changes to sql-product and highlight accordingly
(sql-set-product (or sql-product 'ansi)) ; Fixes bug#13591
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
next prev parent reply other threads:[~2022-05-20 11:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-20 15:19 bug#38302: SQL[ANSI] mode sees into comments 積丹尼 Dan Jacobson
2022-05-20 11:28 ` Lars Ingebrigtsen [this message]
2022-06-19 13:31 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wneg30k6.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=38302@debbugs.gnu.org \
--cc=jidanni@jidanni.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).