From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Pettersson Newsgroups: gmane.emacs.bugs Subject: bug#57905: [PATCH] Fix eshell directory and executable completion on action t Date: Sun, 18 Sep 2022 00:55:48 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38306"; mail-complaints-to="usenet@ciao.gmane.io" To: 57905@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 18 09:08:40 2022 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 1oZoPv-0009ka-Sh for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Sep 2022 09:08:39 +0200 Original-Received: from localhost ([::1]:50256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZoPu-0000k0-Bs for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Sep 2022 03:08:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZoPM-0000j7-CE for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 03:08:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48579) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZoPM-0000uG-45 for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 03:08:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oZoPL-00078P-UM for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 03:08:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Pettersson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Sep 2022 07:08:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57905 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166348485227355 (code B ref -1); Sun, 18 Sep 2022 07:08:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Sep 2022 07:07:32 +0000 Original-Received: from localhost ([127.0.0.1]:47653 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZoOp-000772-4Q for submit@debbugs.gnu.org; Sun, 18 Sep 2022 03:07:32 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:54136) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZgjD-0000pJ-Gk for submit@debbugs.gnu.org; Sat, 17 Sep 2022 18:56:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZgjD-0005HF-BO for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 18:56:03 -0400 Original-Received: from mail-qt1-f175.google.com ([209.85.160.175]:40798) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZgjB-0001X5-DR for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 18:56:03 -0400 Original-Received: by mail-qt1-f175.google.com with SMTP id cj27so6255390qtb.7 for ; Sat, 17 Sep 2022 15:56:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date; bh=G3CCUqwlXtuA8qd5oJvg7sy/8/jbLGcSdqkFDXIX0cE=; b=RGagsxerzbJ7i9f7/THpkDcF4ZxwbTnTosQE8WtptKQ7NHlnu/iKspBHZfJ0klyB1I VmK+/bdLGuu9jOnVR9Ldo/eCV123Y7ioOPO+oo9k5lqeTGxXVFJ+FUWQ/JgRcHKVeUQD UaxYO3V0yqWE3BXuO3npSlJTBlRjk6XOeR9LekP5IxgAHWdecebLYIIHg9hfbKDa7knw fWuhStdXtY1DJyKL2pI/3b5Nt4s5bGlpxSulhZQm3LarLdGEpsRKaKT6bcm7Ejs4uFkL aOnwqI4N+XHrAsD9R6RnE9CCteXoDhDNVAFhoYqcPC1s5kpzm5pjI64OpiSbqye0GyDu KxBg== X-Gm-Message-State: ACrzQf25Ef0muQeqh/7K2mhLFME9euQtXl4iit5+NwNWBo1qsLQk2vLn Da7NVNNUvq1fn6eQDFAdZXtfc6R25BEYKA== X-Google-Smtp-Source: AMsMyM5CQ/Abm8nZ5dnxuGrbteeo4/TOEmJjQT+X2TI7fjEGpNXhOjLiVsoCLGgrzN0zPXQBxIHG8A== X-Received: by 2002:a05:622a:4cb:b0:35c:be68:784e with SMTP id q11-20020a05622a04cb00b0035cbe68784emr9914173qtx.331.1663455359995; Sat, 17 Sep 2022 15:55:59 -0700 (PDT) Original-Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com. [209.85.219.179]) by smtp.gmail.com with ESMTPSA id de20-20020a05620a371400b006bb49cfe147sm8956513qkb.84.2022.09.17.15.55.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Sep 2022 15:55:59 -0700 (PDT) Original-Received: by mail-yb1-f179.google.com with SMTP id g5so37578733ybg.11 for ; Sat, 17 Sep 2022 15:55:59 -0700 (PDT) X-Received: by 2002:a5b:38f:0:b0:66e:c99f:ec49 with SMTP id k15-20020a5b038f000000b0066ec99fec49mr9797015ybp.33.1663455359462; Sat, 17 Sep 2022 15:55:59 -0700 (PDT) X-Gmail-Original-Message-ID: Received-SPF: pass client-ip=209.85.160.175; envelope-from=daniel.dpettersson.net@gmail.com; helo=mail-qt1-f175.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 18 Sep 2022 03:07:26 -0400 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:242929 Archived-At: When eshell directory/executable completion results in multiple candidates the candidates are striped of their file path. emacs -Q M-x eshell RET touch test1 test2 chmod +x test1 test2 ./test In *Completions* buffer: 2 possible completions: test1 test2 Expected: ./test1 ./test2 Same issue for directories: mkdir test_dir1 test_dir2 ./test_dir In *Completions* buffer: 2 possible completions: test1_dir1 test2_dir2 This also the case when the candidates are not in the working directory: mkdir -p 1/2/3/4 touch 1/2/3/4/test1 1/2/3/4/test2 chmod +x 1/2/3/4/test1 1/2/3/4/test2 ./1/2/3/4/test In *Completions* buffer: 2 possible completions: test1 test2 This issue is not present with one completion as further down the call stack `completion-file-name-table' is called with action t, which concates completion string directory with completion candidate. Possible solution: --- lisp/eshell/em-cmpl.el | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lisp/eshell/em-cmpl.el b/lisp/eshell/em-cmpl.el index 822cc94149..d9261fae27 100644 --- a/lisp/eshell/em-cmpl.el +++ b/lisp/eshell/em-cmpl.el @@ -378,6 +378,31 @@ eshell-complete-parse-arguments args) posns))) +(defun eshell--pcomplete-executables () + "Complete amongs a list of directories and executables. + +Wrapper for `pcomplete-executables' or `pcomplete-dirs-or-entries', +depending on the value of `eshell-force-execution'. + +Adds path prefix to candidates independent of `action' value." + ;; `pcomplete-entries' returns filenames without path on `action' t + ;; use current string directory as done in `completion-file-name-table' + ;; when `action' is nil to construct executable candidates. + (let* ((table (if eshell-force-execution + (pcomplete-dirs-or-entries nil #'file-readable-p) + (pcomplete-executables)))) + (lambda (string pred action) + (let ((cands (funcall table string pred action))) + (if (eq action t) + (let ((specdir (file-name-directory string))) + (mapcar + (lambda (cand) + (if (stringp cand) + (concat specdir cand) + cand)) + cands)) + cands))))) + (defun eshell--complete-commands-list () "Generate list of applicable, visible commands." ;; Building the commands list can take quite a while, especially over Tramp @@ -392,9 +417,7 @@ eshell--complete-commands-list (completion-table-dynamic (lambda (filename) (if (file-name-directory filename) - (if eshell-force-execution - (pcomplete-dirs-or-entries nil #'file-readable-p) - (pcomplete-executables)) + (eshell--pcomplete-executables) (let* ((paths (eshell-get-path)) (cwd (file-name-as-directory (expand-file-name default-directory))) -- 2.30.1 (Apple Git-130) Issue on 28.2.0 as well. In GNU Emacs 29.0.50 (build 1, aarch64-apple-darwin20.6.0, NS appkit-2022.60 Version 11.5.2 (Build 20G95)) of 2022-09-16 built on Daniels-Air Repository revision: fe7c015b20b5bca07aa178d28b9fd5cc66ad16f9 Repository branch: master Windowing system distributor 'Apple', version 10.3.2022 System Description: macOS 11.5.2 Configured features: ACL DBUS GLIB GNUTLS JSON LCMS2 LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TOOLKIT_SCROLL_BARS WEBP XIM ZLIB Important settings: value of $LC_CTYPE: UTF-8 locale-coding-system: utf-8-unix Major mode: Eshell Minor modes in effect: shell-dirtrack-mode: t eshell-prompt-mode: t eshell-hist-mode: t eshell-pred-mode: t eshell-cmpl-mode: t eshell-proc-mode: t eshell-arg-mode: t tooltip-mode: t global-eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message mailcap yank-media puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils pcmpl-unix cl-seq cl-macs vc-git diff-mode easy-mmode vc-dispatcher bug-reference byte-opt gv bytecomp byte-compile cconv time-date em-unix em-term term disp-table shell subr-x ehelp em-script em-prompt em-ls em-hist em-pred em-glob em-extpipe em-cmpl em-dirs esh-var pcomplete comint ansi-color ring em-basic em-banner em-alias esh-mode eshell esh-cmd generator cl-loaddefs cl-lib esh-ext esh-opt esh-proc esh-io esh-arg esh-module esh-groups esh-util rmc iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads dbusbind kqueue cocoa ns lcms2 multi-tty make-network-process emacs) Memory information: ((conses 16 71482 9836) (symbols 48 8490 0) (strings 32 24424 2081) (string-bytes 1 760661) (vectors 16 16661) (vector-slots 8 215237 12871) (floats 8 32 63) (intervals 56 573 57) (buffers 1000 13))