From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Carlos Pita Newsgroups: gmane.emacs.bugs Subject: bug#19755: python.el: native completion: more problems (and solutions) Date: Thu, 5 Feb 2015 23:22:17 -0300 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1423189395 3612 80.91.229.3 (6 Feb 2015 02:23:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Feb 2015 02:23:15 +0000 (UTC) To: 19755@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 06 03:23:11 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YJYZa-00082Q-DM for geb-bug-gnu-emacs@m.gmane.org; Fri, 06 Feb 2015 03:23:10 +0100 Original-Received: from localhost ([::1]:46371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJYZZ-0002hX-IE for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Feb 2015 21:23:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJYZV-0002hF-B9 for bug-gnu-emacs@gnu.org; Thu, 05 Feb 2015 21:23:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJYZS-0000XF-4s for bug-gnu-emacs@gnu.org; Thu, 05 Feb 2015 21:23:05 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:43884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJYZS-0000X8-1G for bug-gnu-emacs@gnu.org; Thu, 05 Feb 2015 21:23:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YJYZR-0003px-QH for bug-gnu-emacs@gnu.org; Thu, 05 Feb 2015 21:23:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Carlos Pita Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 06 Feb 2015 02:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19755 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 19755-submit@debbugs.gnu.org id=B19755.142318936714700 (code B ref 19755); Fri, 06 Feb 2015 02:23:01 +0000 Original-Received: (at 19755) by debbugs.gnu.org; 6 Feb 2015 02:22:47 +0000 Original-Received: from localhost ([127.0.0.1]:35124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJYZC-0003oz-Gs for submit@debbugs.gnu.org; Thu, 05 Feb 2015 21:22:47 -0500 Original-Received: from mail-lb0-f176.google.com ([209.85.217.176]:33004) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJYZA-0003oc-Ct for 19755@debbugs.gnu.org; Thu, 05 Feb 2015 21:22:45 -0500 Original-Received: by mail-lb0-f176.google.com with SMTP id u10so659503lbd.7 for <19755@debbugs.gnu.org>; Thu, 05 Feb 2015 18:22:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:cc:content-type; bh=eivLdXQujWQrsGfOStgNZf+9/9kObCzrNwwTzbwUFu4=; b=TuUMnwj/fo5UEIWIA4eR3c1w6+UzqTddupITMVt1OFdUywt28hm1/3IL1X0HmkjqUT B/P7KkCtvLITnaJs8Jr8l2/W/DhIzdHDiTVvNSo37a6HOoSoAM4WgbCPrlbcrRz+VOYc o3KclxSinaD/nZSNfZvahSX/N/zbJaDJzyyiO4+RHDX7GDnsN14Sxde6Fy8JFUWxHVmw DrK5PYmXH8F3PgpjnT6xoTLpP0c5Vc4O6LMwPIlLKt0v5ODrDvprmKN4bGFDpM690cuP JPzHlgjgEx3DsOly3nJD3pQEG7xpP9GxITcTk59IBmWJ4AN/v8zd74VrQhdMGWH/pEvO Dikg== X-Received: by 10.112.212.42 with SMTP id nh10mr812019lbc.102.1423189358165; Thu, 05 Feb 2015 18:22:38 -0800 (PST) Original-Received: by 10.112.124.202 with HTTP; Thu, 5 Feb 2015 18:22:17 -0800 (PST) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:99085 Archived-At: Here is a quick prototype of how the client/server approach would look like. The setup code could be structured around a single class PythonElHelper, say. The class will listen on a socket in a dedicated thread. I have coded its output as json in order to allow to pass structured information to the elisp side and easily parse this information as elisp data with json-read-from-string. I don't see a need to use a full-fledged http server, although that could be done with url.el if desired. The server would provide tooltips for eldoc, documentation for the help buffer and completions for completion-at-point in a way that doesn't interfere with history, prompt numbers, block editing, etc. and doesn't require to deal with the shell input/output. Do you think this approach is sensible? I'm available for coding this along the next two months or so. ######################## python server ################# class PythonElServer: def __init__(self): # detect python2/3, ipython, readline, set completer, etc pass def complete(self, symbol): return ["a", "b", "c"] def tooltip(self, symbol): return "func(a, b, c)" def documentation(self, symbol): return "A function that does something" def serve(self, port): import socket, json server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('', port)) server.listen(1) (client, address) = server.accept() while True: request = client.recv(1024) action, symbol = request.split() response = getattr(self, action)(symbol) client.send(json.dumps(response)) PythonElServer().serve(9090) ######################## elisp client ################# ;; -*- lexical-binding: t -*- (setq python-shell-server (open-network-stream "pyserver" "pyserver" "localhost" 9091)) (defun python-shell-server-request (action symbol) (set-process-filter python-shell-server (lambda (proc out) (let ((response (json-read-from-string out))) (pcase action (`complete (python-shell-complete response)) (`tooltip (python-shell-tooltip response)) (`documentation (python-shell-documentation response)))))) (process-send-string python-shell-server (concat (symbol-name action) " " symbol))) (defun python-shell-complete (response) (print (concat "complete: " response))) (defun python-shell-tooltip (response) (print (concat "tooltip: " response))) (defun python-shell-documentation (response) (print (concat "documentation: " response))) (python-shell-server-request 'documentation "xxx")