From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Newsgroups: gmane.emacs.bugs Subject: bug#24646: [PATCH] Complete the name of PostgreSQL databases Date: Sat, 12 Nov 2016 12:11:42 +0100 Message-ID: <1478949102.7910.0@smtp.gmail.com> References: <1476006914.21082.0@smtp.gmail.com> <1477224054.3087.0@smtp.gmail.com> <960375478.674241.1477259422133@mail.yahoo.com> <1478443615.12208.0@smtp.gmail.com> <1356767530.1331843.1478491407910@mail.yahoo.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-oipu6RzHW3IKiX8mGaic" X-Trace: blaine.gmane.org 1478949304 17413 195.159.176.226 (12 Nov 2016 11:15:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 12 Nov 2016 11:15:04 +0000 (UTC) Cc: "alex@gnu.org" , "24646@debbugs.gnu.org" <24646@debbugs.gnu.org> To: Michael Mauger Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Nov 12 12:15:00 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c5WGf-00015I-CJ for geb-bug-gnu-emacs@m.gmane.org; Sat, 12 Nov 2016 12:14:41 +0100 Original-Received: from localhost ([::1]:57647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5WGg-0002NO-RU for geb-bug-gnu-emacs@m.gmane.org; Sat, 12 Nov 2016 06:14:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5WFA-0001Ol-Dn for bug-gnu-emacs@gnu.org; Sat, 12 Nov 2016 06:13:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5WF5-00075b-Au for bug-gnu-emacs@gnu.org; Sat, 12 Nov 2016 06:13:08 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39059) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c5WF5-00075X-7S for bug-gnu-emacs@gnu.org; Sat, 12 Nov 2016 06:13:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c5WF4-0005g4-HS for bug-gnu-emacs@gnu.org; Sat, 12 Nov 2016 06:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Nov 2016 11:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24646 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 24646-submit@debbugs.gnu.org id=B24646.147894917321804 (code B ref 24646); Sat, 12 Nov 2016 11:13:02 +0000 Original-Received: (at 24646) by debbugs.gnu.org; 12 Nov 2016 11:12:53 +0000 Original-Received: from localhost ([127.0.0.1]:54458 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c5WEv-0005fc-0L for submit@debbugs.gnu.org; Sat, 12 Nov 2016 06:12:53 -0500 Original-Received: from mail-lf0-f46.google.com ([209.85.215.46]:32940) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c5WEt-0005fP-O0 for 24646@debbugs.gnu.org; Sat, 12 Nov 2016 06:12:52 -0500 Original-Received: by mail-lf0-f46.google.com with SMTP id c13so28791715lfg.0 for <24646@debbugs.gnu.org>; Sat, 12 Nov 2016 03:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:subject:to:cc:message-id:in-reply-to:references :mime-version; bh=e3nPXZfpeSS+Jx2o31PAon7m84kAu/rtGYj9T8jdd8s=; b=EHFulj+Uv1V0Op/eHkTj/NkXBKIz65DYTuFPRAmKq8rE53+TkyA0GAFn+gWVAu3KIT 5Wb6NShfcPqZMvBF05ayYCDz2ILq7T3YJ23cbgMJbovmr1uP8p6wqK/Ei4lqdKYf9oJH muTH8SQX+wuj7idwMmr27LvR6omsq3YSzhfSMkrKAgxHhauacW5QaY403Xoa5jtlbi5Y xVVfVSqNem32kcV/Vkm3sOnjkOPNfxFzabk61CE1P2B+aX8twwEQvcg4NbCkkg3CEoWK 85NuASm6ievXP81fsy9XlvBsAkx0Hy8MOVhybe0pp4hcSD2/zdEuCLXc2vbR3jyVzwxH ltKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:subject:to:cc:message-id:in-reply-to :references:mime-version; bh=e3nPXZfpeSS+Jx2o31PAon7m84kAu/rtGYj9T8jdd8s=; b=AAbAvLEIKW7FMVT/AEpfjgsSad8hImyJDIEefF0sqmPzxV8RmUZeof+yv8EwC//sZ+ 5nurOP+/ra9+Osk3i9hrBPyHHsP2b8Uj3+yfQSdAGpMjFgkPCoOg6GpZCJ6lTJZcUMHY pYy28HDFZJfhIGtldvSThtUHAhRDy6uRzTxwMafqjND7zzsxmCdxB97FOCO+ijYQu+Xu ryPj+Khwm6A/Fu0VTuDapysP6rfA8jy8tDjbjubxzyXN19V+PAcU45rx99Gq8jsoIrY9 6m/opddxUTPNOBMs4z61p9NyCyPkcLWKkD72jn5HQ8zLztvg8YEF7te8J3TXolypiohS KKSw== X-Gm-Message-State: ABUngvd0A2oSq9h5RSkDFaw61lFvsav5QRpQqKpZsw9SPBvVF/HAiDuPffam7km6ux2Vlw== X-Received: by 10.25.41.203 with SMTP id p194mr4125363lfp.108.1478949165947; Sat, 12 Nov 2016 03:12:45 -0800 (PST) Original-Received: from [192.168.100.8] (cm-84.210.143.4.getinternet.no. [84.210.143.4]) by smtp.gmail.com with ESMTPSA id n201sm3147440lfn.22.2016.11.12.03.12.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 12 Nov 2016 03:12:45 -0800 (PST) In-Reply-To: <1356767530.1331843.1478491407910@mail.yahoo.com> X-Mailer: geary/0.11.2 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:125642 Archived-At: --=-oipu6RzHW3IKiX8mGaic Content-Type: text/plain; charset=utf-8; format=flowed Thank you for your detailed feedback, Michael. I agree with all of your points and have modified the patch accordingly, except for one: On Mon, Nov 7, 2016 at 5:03 AM, Michael Mauger wrote: > * `dolist' can specify the return value rather than having a separate > expression after the loop. That is, (dolist (row (process-lines ...) > (nreverse res)) ...)) is equivalent to (dolist (row (process-lines > ...)) ...) (nreverse res) I'm aware of it, but I tend to avoid using it, since I have many times myself overlooked it when reading code that uses it. If it's OK with you I'll leave it like it is, but if you insist I can change it. > * I'm concerned about the change to the `completing-read' call in > `sql-get-login-ext'. Rather than `nil', I'd suggest `confirm' so that > if the value isn't in the list, it must be confirmed. > * If the REQUIRE-MATCH parameter should really be something other > than `t', then possibbly we should add another keyword > :completion-required whose value would be used in the > `completing-read' call (default to `t' to preserve current > functionality). It's not important to me. I made the change because I thought it could be frustrating for the user if `sql-postgres-list-databases' doesn't work as it should, but I realize now that changing it probably deserves a discussion and a patch on its own. -- Simen --=-oipu6RzHW3IKiX8mGaic Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Complete-the-name-of-PostgreSQL-databases.patch Content-Transfer-Encoding: quoted-printable >From b26312bc9000f8ec39a525eefad5f0c93c767b86 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Simen=3D20Heggest=3DC3=3DB8yl?=3D Date: Thu, 6 Oct 2016 20:42:53 +0200 Subject: [PATCH] Complete the name of PostgreSQL databases * lisp/progmodes/sql.el (sql-postgres-login-params): Complete database name. (sql-postgres-list-databases): New function returning a list of available PostgreSQL databases. * test/lisp/progmodes/sql-tests.el: New file with tests for sql.el. --- lisp/progmodes/sql.el | 18 ++++++++++++--- test/lisp/progmodes/sql-tests.el | 47 ++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 test/lisp/progmodes/sql-tests.el diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index a11d456..4d0bed7 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el @@ -1072,14 +1072,26 @@ sql-postgres-options :version "20.8" :group 'SQL) =20 -(defcustom sql-postgres-login-params `((user :default ,(user-login-name)) - (database :default ,(user-login-nam= e)) - server) +(defcustom sql-postgres-login-params + `((user :default ,(user-login-name)) + (database :default ,(user-login-name) + :completion ,(completion-table-dynamic + (lambda (_) (sql-postgres-list-databases)))) + server) "List of login parameters needed to connect to Postgres." :type 'sql-login-params :version "24.1" :group 'SQL) =20 +(defun sql-postgres-list-databases () + "Return a list of available PostgreSQL databases." + (when (executable-find sql-postgres-program) + (let ((res '())) + (dolist (row (process-lines sql-postgres-program "-ltX")) + (when (string-match "^ \\([[:alnum:]-_]+\\) +|.*" row) + (push (match-string 1 row) res))) + (nreverse res)))) + ;; Customization for Interbase =20 (defcustom sql-interbase-program "isql" diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tes= ts.el new file mode 100644 index 0000000..e05247a --- /dev/null +++ b/test/lisp/progmodes/sql-tests.el @@ -0,0 +1,47 @@ +;;; sql-tests.el --- Tests for sql.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2016 Free Software Foundation, Inc. + +;; Author: Simen Heggest=C3=B8yl +;; Keywords: + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;; + +;;; Code: + +(require 'cl-lib) +(require 'ert) +(require 'sql) + +(ert-deftest sql-tests-postgres-list-databases () + "Test that output from `psql -ltX' is parsed correctly." + (cl-letf + (((symbol-function 'executable-find) + (lambda (_command) t)) + ((symbol-function 'process-lines) + (lambda (_program &rest _args) + '(" db-name-1 | foo-user | UTF8 | en_US.UTF-8 | en_US.UTF-8 = | " + " db_name_2 | foo-user | UTF8 | en_US.UTF-8 | en_US.UTF-8 = | " + "")))) + (should (equal (sql-postgres-list-databases) + '("db-name-1" "db_name_2"))))) + +(provide 'sql-tests) +;;; sql-tests.el ends here --=20 2.10.2 = --=-oipu6RzHW3IKiX8mGaic--