Getting psql to redisplay command after \e
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2019-10-29T03:00:28Z
Lists: pgsql-hackers
Attachments
- psql-echo-unexecuted-edited-text-1.patch (text/x-diff) patch
The attached patch teaches psql to redisplay any not-yet-executed query text after editing with \e. The fact that you don't get to see what you're about to execute has been complained of before, most recently at bug #16034 [1]. In that thread I complained that we needed some probably-not-very-portable readline functionality to make this work. However, after experimenting with trying to shove text back into readline's buffer, I realized that there's not really any need to do that: we just need to print the waiting text and then collect another line. (As a bonus, it works the same even if you turned off readline with -n.) It also seems like to make this not confusing, we need to regurgitate a prompt before the query text. As an example, if I do regression=# \e and then put this into the edited file: select 1, 2, 3 what I see after exiting the editor is now regression=# select 1, 2, 3 regression-# Without the initial prompt it looks (to me anyway) like output from the command, rather than something I've sort of automagically typed. In the cited bug, Pavlo argued that we should also print any completed commands that get sent to the backend immediately after \e. It'd be possible to do that by extending this patch (basically, dump about-to-be-executed commands if need_redisplay is still true), but on the whole I think that that would be overly chatty, so I didn't do it. This could stand some review and testing (e.g. does it interact badly with any other psql features), so I'll add it to the upcoming CF. regards, tom lane [1] https://www.postgresql.org/message-id/flat/16034-a7ebf0622970a1dd%40postgresql.org
Commits
-
Make psql redisplay the query buffer after \e.
- d1c866e57f11 13.0 landed