* bug#38302: SQL[ANSI] mode sees into comments
@ 2019-11-20 15:19 積丹尼 Dan Jacobson
2022-05-20 11:28 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: 積丹尼 Dan Jacobson @ 2019-11-20 15:19 UTC (permalink / raw)
To: 38302
[-- Attachment #1: Type: text/plain, Size: 236 bytes --]
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"
[-- Attachment #2: SQL --]
[-- Type: application/octet-stream, Size: 2308 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#38302: SQL[ANSI] mode sees into comments
2019-11-20 15:19 bug#38302: SQL[ANSI] mode sees into comments 積丹尼 Dan Jacobson
@ 2022-05-20 11:28 ` Lars Ingebrigtsen
2022-06-19 13:31 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-20 11:28 UTC (permalink / raw)
To: 積丹尼 Dan Jacobson; +Cc: 38302
積丹尼 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#38302: SQL[ANSI] mode sees into comments
2022-05-20 11:28 ` Lars Ingebrigtsen
@ 2022-06-19 13:31 ` Lars Ingebrigtsen
0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-19 13:31 UTC (permalink / raw)
To: 積丹尼 Dan Jacobson; +Cc: 38302
Lars Ingebrigtsen <larsi@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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-19 13:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 15:19 bug#38302: SQL[ANSI] mode sees into comments 積丹尼 Dan Jacobson
2022-05-20 11:28 ` Lars Ingebrigtsen
2022-06-19 13:31 ` Lars Ingebrigtsen
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).