Re: Correct handling of blank/commented lines in PSQL interactive-mode history - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Correct handling of blank/commented lines in PSQL interactive-mode history
Date
Msg-id 3210474.1631042185@sss.pgh.pa.us
Whole thread Raw
In response to Re: Correct handling of blank/commented lines in PSQL interactive-mode history  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Responses Re: Correct handling of blank/commented lines in PSQL interactive-mode history
List pgsql-hackers
[ this is a digression from the main point of the thread, but ... ]

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> I am particularly bothered by the uselessness
> that M-# results in -- namely, inserting a # at the start of the buffer.

Fixing that might be as simple as the attached.  I've not beat on
it hard though.

            regards, tom lane

diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index f926bc98dc..1dcd95a7b9 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -353,8 +353,13 @@ initializeInput(int flags)
 
         useReadline = true;
 
-        /* these two things must be done in this order: */
+        /* set appropriate values for Readline's global variables */
         initialize_readline();
+
+        /* set comment-begin to a useful value for SQL */
+        (void) rl_variable_bind("comment-begin", "-- ");
+
+        /* this reads ~/.inputrc, so do it after rl_variable_bind */
         rl_initialize();
 
         useHistory = true;

pgsql-hackers by date:

Previous
From: Gavin Flower
Date:
Subject: Re: Data loss when '"json_populate_recorset" with long column name
Next
From: Andres Freund
Date:
Subject: Re: Don't clean up LLVM state when exiting in a bad way