GNU bug report logs - #38302
SQL[ANSI] mode sees into comments

Previous Next

Package: emacs;

Reported by: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>

Date: Wed, 20 Nov 2019 17:58:01 UTC

Severity: minor

Tags: moreinfo

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 38302 in the body.
You can then email your comments to 38302 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#38302; Package emacs. (Wed, 20 Nov 2019 17:58:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 20 Nov 2019 17:58:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: bug-gnu-emacs <at> gnu.org
Subject: SQL[ANSI] mode sees into comments
Date: Wed, 20 Nov 2019 23:19:04 +0800
[Message part 1 (text/plain, inline)]
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"
[m.sql.bz2 (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38302; Package emacs. (Fri, 20 May 2022 11:29:02 GMT) Full text and rfc822 format available.

Message #8 received at 38302 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
Cc: 38302 <at> debbugs.gnu.org
Subject: Re: bug#38302: SQL[ANSI] mode sees into comments
Date: Fri, 20 May 2022 13:28:41 +0200
積丹尼 Dan Jacobson <jidanni <at> 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




Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 20 May 2022 11:29:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38302; Package emacs. (Sun, 19 Jun 2022 13:32:01 GMT) Full text and rfc822 format available.

Message #13 received at 38302 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
Cc: 38302 <at> debbugs.gnu.org
Subject: Re: bug#38302: SQL[ANSI] mode sees into comments
Date: Sun, 19 Jun 2022 15:31:44 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> In that case, the following should fix the problem (at the expense of
> computing it the rules runtime)...

Nobody had any comments, so I've pushed the change to Emacs 29.
Reworking this to avoid the `eval' would be nice, but I wasn't at all
sure how.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 29.1, send any further explanations to 38302 <at> debbugs.gnu.org and 積丹尼 Dan Jacobson <jidanni <at> jidanni.org> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 19 Jun 2022 13:33:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 18 Jul 2022 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 338 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.