From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.bugs Subject: bug#47575: python-shell-completion-at-point omits %magic commands Date: Sat, 3 Apr 2021 00:21:54 -0400 Message-ID: <0F56B58F-840F-45EA-B538-02FF19E16A90@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_D3DF062D-5B74-43B5-93DF-F30EFA51B52A" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31002"; mail-complaints-to="usenet@ciao.gmane.io" To: 47575@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 03 06:23:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lSXoU-0007xF-SD for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Apr 2021 06:23:10 +0200 Original-Received: from localhost ([::1]:40458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSXoT-00018A-Bp for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Apr 2021 00:23:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSXoM-00017q-85 for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 00:23:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSXoM-0008U4-1P for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 00:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lSXoL-0005rc-SL for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 00:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: JD Smith Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 03 Apr 2021 04:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47575 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161742372322452 (code B ref -1); Sat, 03 Apr 2021 04:23:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Apr 2021 04:22:03 +0000 Original-Received: from localhost ([127.0.0.1]:33074 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lSXnO-0005q4-Tl for submit@debbugs.gnu.org; Sat, 03 Apr 2021 00:22:03 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:42054) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lSXnN-0005px-Sr for submit@debbugs.gnu.org; Sat, 03 Apr 2021 00:22:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSXnN-000138-NA for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 00:22:01 -0400 Original-Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:39833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSXnL-0007qQ-VH for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 00:22:01 -0400 Original-Received: by mail-qk1-x72e.google.com with SMTP id q26so6891061qkm.6 for ; Fri, 02 Apr 2021 21:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=56r5r+pwOwBkywck5e2BIrwxN6pV+6vDif4wIjuvz+k=; b=dZPGY0Ln9td5S4S7+NMuXacIUS7G74o7raNL4IHRiOTsxQFbYOIKWHHRQbdW51ulmd Fgf29xqvgwER9+K/4pQpKKWRsdm6RNk3x+Pttun0PRj2wN0mfU3X69oVGxjJ62E1Z87V pETp5mQh2uSxVumgle6YgwlKHIRJvdOjK4cPEBe1rIWPSaq+1VOG7zFIPz9ZrxKItkyg yXksWcp56ztdeser71Whu7rsmMNPN0bcTTrA9+97tnqnuUvt0S8f26/zQ+R36OQ0rcq8 U5a0dlzsdO4sFJdyqhZF31PG28M56t4Ez17cw1amkrTeI1/jT5JWZsF9wiyVEcjZPTNG apjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=56r5r+pwOwBkywck5e2BIrwxN6pV+6vDif4wIjuvz+k=; b=o5z4SdOuXR5Sriw3VRJkk9CUGoisBsmmwOrQku2+ccpavSqJnAhvxzgJgipY32JKyd XQno7O1AFfmBImjUzX0HcRXVaXVhGmlteltSxYRyaWMcc/Uhds9fn3eupk6qukDSo4Aj NKXP5ziqnspt0uY/vL74zXR6/aGcChA6bYU90k6idMK83zDi8D0fun5JYXUl5YJgXRdp FOdawhKK2p3eDv4lSJUZhvoR0baerpZCN3fKdzqqY2j21qsGWLFPBsOmKv9EtLpjrI2S bv5kcL6LFyRwIVgncunEzouQXFWe6p+tbN38IG9dTK02DUDNssvU3b9Bq80SS6C8u4hV RYDA== X-Gm-Message-State: AOAM531TTL0j6Y/7kWfKVNEZfVQqMW7/cgOu1Gu5AQdNZMIGsn6nojLB 3wOpnxUbJ9cMBen+VZAp5ZHVHVweJ65vQQ== X-Google-Smtp-Source: ABdhPJyUCRxq1Xit6VM+hFa3IEgUG8jprDoMpn0hNxGzRv2hEiFFHhUbay4SCWjgXGWHyuromCv01w== X-Received: by 2002:a05:620a:553:: with SMTP id o19mr16090701qko.491.1617423717985; Fri, 02 Apr 2021 21:21:57 -0700 (PDT) Original-Received: from [192.168.0.108] (cm-134-228-54-223.buckeyecom.net. [134.228.54.223]) by smtp.gmail.com with ESMTPSA id l16sm8626968qkg.91.2021.04.02.21.21.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Apr 2021 21:21:57 -0700 (PDT) X-Mailer: Apple Mail (2.3608.120.23.2.4) Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=jdtsmith@gmail.com; helo=mail-qk1-x72e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:203484 Archived-At: --Apple-Mail=_D3DF062D-5B74-43B5-93DF-F30EFA51B52A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 When using iPython as the inferior shell of python.el, = `python-shell-completion-at-point' skips a `simple-operator=E2=80=99 = regexp which include ?%. In iPython, magic commands begin with =E2=80=98%= =E2=80=99, and the fallback completion method happily provides them for = completion: In [67]: __PYTHON_EL_get_completions("%ru") Out[91]: ['%%ruby', '%run=E2=80=99] python-shell-completion-at-point trims this to =E2=80=9Cru=E2=80=9D, = which also provides the same completions above, but which = `try-completions=E2=80=99 rejects as non-matching. So that: In [1]: %ru[Tab] Leads to =E2=80=9CNo matches=E2=80=9D. The solution would be to not skip the ?% character if it is at the start = of the line. The modulo operator cannot occur there in any case.=20 One other point: the fallback mechanism sends and compiles the = relatively long __PYTHON_EL_get_completions function each and every time = it is called. Because of how CAPF functions, this actually occurs 3 = times in quick succession with a single Tab press like the above! A = more performant approach (esp. over remote buffer connections) would be = to just call __PYTHON_EL_get_completions, and check for failure, setting = up that function again if necessary. This would parallel the readline = completer native method, which is only setup once.=20 --Apple-Mail=_D3DF062D-5B74-43B5-93DF-F30EFA51B52A Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
When using iPython as the inferior shell of python.el, = `python-shell-completion-at-point' skips a `simple-operator=E2=80=99 = regexp which include ?%.  In iPython, magic commands begin with = =E2=80=98%=E2=80=99, and the fallback completion method happily provides = them for completion:

In [67]: = __PYTHON_EL_get_completions("%ru")
Out[91]: ['%%ruby', '%run=E2=80=99]

python-shell-completion-at-point trims this = to =E2=80=9Cru=E2=80=9D, which also provides the same = completions above, but which `try-completions=E2=80=99 rejects as = non-matching.   So that:

In [1]: = %ru[Tab]

Leads to =E2=80=9CNo = matches=E2=80=9D.

The solution would be to not = skip the ?% character if it is at the start of the line.  The = modulo operator cannot occur there in any case. 

One other point: the fallback mechanism sends and compiles = the relatively long __PYTHON_EL_get_completions function each and every = time it is called.  Because of how CAPF functions, this actually = occurs 3 times in quick succession with a single Tab press like the = above!  A more performant approach (esp. over remote buffer = connections) would be to just = call __PYTHON_EL_get_completions, and check for failure, setting up = that function again if necessary.  This would parallel the = readline completer native method, which is only setup = once. 

= --Apple-Mail=_D3DF062D-5B74-43B5-93DF-F30EFA51B52A--