unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* (unknown)
@ 2016-02-08  7:54 steve
  2016-02-08  8:01 ` (unknown) Steve Purcell
  2016-02-08 12:56 ` Artur Malabarba
  0 siblings, 2 replies; 8+ messages in thread
From: steve @ 2016-02-08  7:54 UTC (permalink / raw)
  To: emacs-devel

From: Steve Purcell <steve@sanityinc.com>
Date: Mon, 8 Feb 2016 20:47:43 +1300
Subject: [PATCH] Safer prompt-regexp for postgres/vertica in
 sql-interactive-mode
--text follows this line--

Fixes issue 22596, whereby "_" is now not considered a word constituent
character in sql-interactive-mode, so prompts like "foo_dev# " are not
correctly detected.
---
 lisp/progmodes/sql.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index fd59f46..90c8dfe 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -462,9 +462,9 @@ sql-product-alist
      :list-all ("\\d+" . "\\dS+")
      :list-table ("\\d+ %s" . "\\dS+ %s")
      :completion-object sql-postgres-completion-object
-     :prompt-regexp "^\\w*=[#>] "
+     :prompt-regexp "^[[:alpha:]_]*=[#>] "
      :prompt-length 5
-     :prompt-cont-regexp "^\\w*[-(][#>] "
+     :prompt-cont-regexp "^[[:alpha:]_]*[-(][#>] "
      :input-filter sql-remove-tabs-filter
      :terminator ("\\(^\\s-*\\\\g$\\|;\\)" . "\\g"))
 
@@ -514,9 +514,9 @@ sql-product-alist
      :sqli-comint-func sql-comint-vertica
      :list-all ("\\d" . "\\dS")
      :list-table "\\d %s"
-     :prompt-regexp "^\\w*=[#>] "
+     :prompt-regexp "^[[:alpha:]_]*=[#>] "
      :prompt-length 5
-     :prompt-cont-regexp "^\\w*[-(][#>] ")
+     :prompt-cont-regexp "^[[:alpha:]_]*[-(][#>] ")
     )
   "An alist of product specific configuration settings.
 
-- 
2.7.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: (unknown)
  2016-02-08  7:54 (unknown) steve
@ 2016-02-08  8:01 ` Steve Purcell
  2016-02-08 12:56 ` Artur Malabarba
  1 sibling, 0 replies; 8+ messages in thread
From: Steve Purcell @ 2016-02-08  8:01 UTC (permalink / raw)
  To: emacs-devel

Sorry, messed up sending that patch by email, but it's hopefully helpful
nonetheless.

-Steve



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:
  2016-02-08  7:54 (unknown) steve
  2016-02-08  8:01 ` (unknown) Steve Purcell
@ 2016-02-08 12:56 ` Artur Malabarba
  2016-02-08 19:05   ` Re: Steve Purcell
  1 sibling, 1 reply; 8+ messages in thread
From: Artur Malabarba @ 2016-02-08 12:56 UTC (permalink / raw)
  To: Steve Purcell; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 215 bytes --]

> -     :prompt-regexp "^\\w*=[#>] "
> +     :prompt-regexp "^[[:alpha:]_]*=[#>] "

One thing that comes to mind is that \\w and :alpha: are generally not the
same thing. So \\(\\w\\|_\\) might be more appropriate.

[-- Attachment #2: Type: text/html, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:
  2016-02-08 12:56 ` Artur Malabarba
@ 2016-02-08 19:05   ` Steve Purcell
  2016-02-08 20:16     ` Re: Artur Malabarba
  0 siblings, 1 reply; 8+ messages in thread
From: Steve Purcell @ 2016-02-08 19:05 UTC (permalink / raw)
  To: bruce.connor.am, emacs-devel


> On 9 Feb 2016, at 01:56, Artur Malabarba <bruce.connor.am@gmail.com> wrote:
> > -     :prompt-regexp "^\\w*=[#>] "
> > +     :prompt-regexp "^[[:alpha:]_]*=[#>] "
> 
> One thing that comes to mind is that \\w and :alpha: are generally not the same thing. So \\(\\w\\|_\\) might be more appropriate.
> 


Yes, possibly. And in fact :alnum: would be better than :alpha:, of course…

And since the rules for database names are probably much the same as for other SQL identifiers, there’s a chance \\s (symbol constituent) would work too.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:
  2016-02-08 19:05   ` Re: Steve Purcell
@ 2016-02-08 20:16     ` Artur Malabarba
  2016-02-09  8:12       ` sql-interactive-mode not recognising psql prompts Steve Purcell
  0 siblings, 1 reply; 8+ messages in thread
From: Artur Malabarba @ 2016-02-08 20:16 UTC (permalink / raw)
  To: Steve Purcell; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 433 bytes --]

On 8 Feb 2016 5:05 pm, "Steve Purcell" <steve@sanityinc.com> wrote:
> Yes, possibly. And in fact :alnum: would be better than :alpha:, of
course…
>
> And since the rules for database names are probably much the same as for
other SQL identifiers, there’s a chance \\s (symbol constituent) would work
too.

Yes. I'm not familiar with the fine details of SQL syntax, but \\w\\|\\s is
generally a better bet than just \\w.

[-- Attachment #2: Type: text/html, Size: 544 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sql-interactive-mode not recognising psql prompts
  2016-02-08 20:16     ` Re: Artur Malabarba
@ 2016-02-09  8:12       ` Steve Purcell
  2016-02-12  0:52         ` Michael R. Mauger
  0 siblings, 1 reply; 8+ messages in thread
From: Steve Purcell @ 2016-02-09  8:12 UTC (permalink / raw)
  To: emacs-devel, bruce.connor.am

On 9 Feb 2016, at 09:16, Artur Malabarba <bruce.connor.am@gmail.com> wrote:
> 
> On 8 Feb 2016 5:05 pm, "Steve Purcell" <steve@sanityinc.com> wrote:
> > Yes, possibly. And in fact :alnum: would be better than :alpha:, of course…
> >
> > And since the rules for database names are probably much the same as for other SQL identifiers, there’s a chance \\s (symbol constituent) would work too.
> 
> Yes. I'm not familiar with the fine details of SQL syntax, but \\w\\|\\s is generally a better bet than just \\w.
> 


The pathological case is pretty bad, in fact:

   createdb " foo bar "

works and creates a prompt such as " foo bar =#”.

According to the relevant section postgres manual [1], pretty much any characters are valid in a database name. So we can choose between matching “reasonable” database names with a tight regexp, e.g. one beginning “^[[:alnum:]_]*”, or matching all allowable names with a permissive regexp which will likely match all sorts of spurious output. I’d suggest the former, and will attach a patch to that effect to issue 22596.


[1] http://www.postgresql.org/docs/current/interactive/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sql-interactive-mode not recognising psql prompts
  2016-02-09  8:12       ` sql-interactive-mode not recognising psql prompts Steve Purcell
@ 2016-02-12  0:52         ` Michael R. Mauger
  2016-02-15 12:49           ` Artur Malabarba
  0 siblings, 1 reply; 8+ messages in thread
From: Michael R. Mauger @ 2016-02-12  0:52 UTC (permalink / raw)
  To: Emacs-devel

The intent of the default settings is to match the most common cases, so that
unintended consequences are avoided.  If the prompt is set to something
unusual, modifying the setting to handle the specific case:

  (sql-set-product-feature 'postgres :prompt-regexp "^.*=[#>] ")
  (sql-set-product-feature 'postgres :prompt-cont-regexp "^.*[-(][#>] ")

But I'd prefer "^\\(\\w\\|\\s_\\)*=[#>] " and "^\\(\\w\\|\\s_\\)*[-(][#>] "
as :prompt-regexp and :prompt-cont-regexp in sql.el itself.  

Please note "\\s" is an incomplete regexp in Emacs, what you'd want is
"\\s_" (syntax class: Symbol) to get all additional symbol constituent
characters beyond word characters.  ("\\w" == "\\sw")

-- Michael (maintainer sql.el)





--
View this message in context: http://emacs.1067599.n5.nabble.com/no-subject-tp386941p387533.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sql-interactive-mode not recognising psql prompts
  2016-02-12  0:52         ` Michael R. Mauger
@ 2016-02-15 12:49           ` Artur Malabarba
  0 siblings, 0 replies; 8+ messages in thread
From: Artur Malabarba @ 2016-02-15 12:49 UTC (permalink / raw)
  To: Michael R. Mauger; +Cc: emacs-devel

On 12 February 2016 at 00:52, Michael R. Mauger <michael@mauger.com> wrote:
> Please note "\\s" is an incomplete regexp in Emacs, what you'd want is
> "\\s_" (syntax class: Symbol)

Yes, my mistake.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-02-15 12:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-08  7:54 (unknown) steve
2016-02-08  8:01 ` (unknown) Steve Purcell
2016-02-08 12:56 ` Artur Malabarba
2016-02-08 19:05   ` Re: Steve Purcell
2016-02-08 20:16     ` Re: Artur Malabarba
2016-02-09  8:12       ` sql-interactive-mode not recognising psql prompts Steve Purcell
2016-02-12  0:52         ` Michael R. Mauger
2016-02-15 12:49           ` Artur Malabarba

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).