From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Federico Tedin via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70198: M-x shell: deal with environment variables present when tab expanding Date: Wed, 10 Jul 2024 18:22:35 +0200 Message-ID: <87plrlz06s.fsf@gmx.de> References: Reply-To: Federico Tedin Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23047"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 70198@debbugs.gnu.org To: Dan Jacobson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jul 10 18:51:23 2024 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 1sRaXK-0005iq-Ua for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Jul 2024 18:51:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRaWw-0000gZ-Kj; Wed, 10 Jul 2024 12:50:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRaWv-0000dI-8R for bug-gnu-emacs@gnu.org; Wed, 10 Jul 2024 12:50:57 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRaWu-0007Lv-VT for bug-gnu-emacs@gnu.org; Wed, 10 Jul 2024 12:50:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sRaX0-0002bX-EX for bug-gnu-emacs@gnu.org; Wed, 10 Jul 2024 12:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Federico Tedin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Jul 2024 16:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70198 X-GNU-PR-Package: emacs Original-Received: via spool by 70198-submit@debbugs.gnu.org id=B70198.17206302199963 (code B ref 70198); Wed, 10 Jul 2024 16:51:02 +0000 Original-Received: (at 70198) by debbugs.gnu.org; 10 Jul 2024 16:50:19 +0000 Original-Received: from localhost ([127.0.0.1]:57024 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sRaWH-0002ab-5r for submit@debbugs.gnu.org; Wed, 10 Jul 2024 12:50:19 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:59111) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sRa5l-0007Up-GA for 70198@debbugs.gnu.org; Wed, 10 Jul 2024 12:22:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1720628557; x=1721233357; i=federicotedin@gmx.de; bh=lLWDZpeg8ypaxrRiFdb35Y/TfHzFOYmFUj6pvsuiGPk=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=bWishouhf+kBahB67OlorGkj0z2IIuZEd1hAah6Ubg7RWqPXIxtBhXn9WIPj7V71 IpTLPnayq6x3k4Tm6WryI/+IyZqnsc26TPYEiOqn5+mSDu7Y/bjBFjdqMYO4KRXI1 /Q3RrTW4WrN2LV+wMkAnnrA5YHBJ94C+JNSvn9xvkuPbSpH9O0cuuYIuzcXQH2crs CDe6vEkOe+ZJlb/YmC+tCAwDmGgAwpB9eLEgrWYkg6vcf09e6A8olkCferr1fU7Gi urlFO4QvMqwN8+KIsu0ccl2c+KI1fF3bjkLLvbKRF++R/JEUNHnzvy6Q9ZcMqI3kI N2Wtj6igq4JPICesVQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from seele ([62.214.67.158]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MCbIx-1sa4Y21chf-001So5; Wed, 10 Jul 2024 18:22:37 +0200 In-Reply-To: (Dan Jacobson's message of "Thu, 4 Apr 2024 21:51:01 +0800") X-Provags-ID: V03:K1:k7kEHa//Rh1bDiqMc3YS1/2xYpdn1fl6bLp1+MgUJaQzTrCET/i LvEZ8Mhxk6MPNpC/uCu7uSfmg4fDWVaDr6UWFSar2gfrbXX8iOzpnOcFKxeZBthvaZGjVUf WZySkNZ2h29RQzqIoIuec+IwJ/zxGbrRpRNPik+1KiIvn7qh0tuX4sZo8F0Qf4oAl48umw8 n6E9al7bqPIYO0J0KZBtQ== UI-OutboundReport: notjunk:1;M01:P0:r9oIaRksZW0=;nSdfjgYRlmjJdK2sJYkW4fXjx0v Bk/VHnos6sD+lOhEo8R9utw3xj3P9hHVBpuD3pnKD65RQpQvNIi3LBtGd5yfCz76U2VK7TLD3 X1aWeRT2l0neKmhDRL9LYmOtIf+6u99DNrDEgQljLJU0xOucWQRThlgdoTyg9HZkDO/LlAh3W XoxrVdFI/XEyWZMj6K9XuEYSbfsCYx+7C/d6X5t/NRb6IyFC/EFqdgECqubV2yrGP3FqSgk2u jpGWkUGMc/Q6r9TqGGjuNB4hmw/HIYYWF1w3a6t9ECbwR6Z3EvbRZKsLSCVqLzEQCkyU16FQ+ Lxtgr+Q/OdBTFjnHDl2l67wx3OFpabFvIPNOKLPJ/yqb69/Nphu45HdP8m55/Rrw6JKQPvNwa MC/B8qfnfWt292TjgefRW3I0Mt+JQI8L5N3gJ9gT2OBOKpW8VgtEB0PD74cfWLs7LSTTLOy96 IkW4S1SVxUWI2Iykm++Rg/0LS3AFTaeeDTec1fZKYgWMUqw1z53ya5OHhGfQLFD+MRof3dCNV 0LrIDXznKb0m34TqXu9YzEAvD0Y6zh20a72Kr33onX03ggOAcehIh6e/EC4JJEm1MgPbdUhjH eD8gxZSojsLq3CkBct/F6WhMGoYQP5f5bY62KKIQi95CIy7LQyM70O4w1iiYeiaGsjYX5jXHn lTnxJSQK9yUc3m6x7jFNOGlkMyVa4bsj+xX59nekTV+BRUEovZ5qQnO3rGSLoIMFtT0wy8Ig/ XJ7EiWtMh9fF5shfs67U5SGfd1R53El9hlYvPMAoUGHYJgAjUo+ed+OPsZmdbXxt9gdi5mS9 X-Mailman-Approved-At: Wed, 10 Jul 2024 12:50:15 -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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:288689 Archived-At: --=-=-= Content-Type: text/plain Dan Jacobson writes: > In M-x shell > $ dat > expands to date. > Alas, unlike bash readline, > $ LC_ALL=C dat > doesn't yet. > > emacs-version "29.3" I took a crack at fixing this, I'm attaching a patch. It's been some time since my last contribution, but I've kept the copyright assignment updated (should be under federicotedin@gmail.com). There's a chance the formatting for the patch may be a bit off too but I tried to re-read the guide at CONTRIBUTE. I've also found something interesting with the `shell-dynamic-complete-command' function. I do not see it being called, referred to, or assigned to a key anywhere in the Emacs code, but the manual mentions it as if it being were actively used: > Some implementation details of the shell command completion may also be found > in the lisp documentation of the @code{shell-dynamic-complete-command} > function. Maybe the manual is outdated? - Fede --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-tab-expanding-not-working-in-shell-mode-bug-7019.patch Content-Description: patch Content-Transfer-Encoding: quoted-printable =46rom 9250d0c78fbc1c23469c125279604bbb8c965626 Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Mon, 8 Jul 2024 14:47:33 +0200 Subject: [PATCH] Fix tab expanding not working in shell-mode (bug#70198) In shell-mode, fix tab expanding when environment variables are present before the command. * lisp/shell.el (shell-command-completion): Fix indentation and call use `shell--skip-environment-variables'. (shell--skip-environment-variables): New function. * test/lisp/shell-tests.el (shell-skip-environment-variables): Test new function. =2D-- lisp/shell.el | 22 +++++++++++++++++----- test/lisp/shell-tests.el | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lisp/shell.el b/lisp/shell.el index e1936ff1119..fff7bdd4d71 100644 =2D-- a/lisp/shell.el +++ b/lisp/shell.el @@ -1385,12 +1385,24 @@ shell-dynamic-complete-command (defun shell-command-completion () "Return the completion data for the command at point, if any." - (let ((filename (comint-match-partial-filename))) + (let ((filename (comint-match-partial-filename)) + (pt (point))) (if (and filename - (save-match-data (not (string-match "[~/]" filename))) - (eq (match-beginning 0) - (save-excursion (shell-backward-command 1) (point)))) - (shell--command-completion-data)))) + (save-match-data (not (string-match "[~/]" filename))) + (eq (match-beginning 0) + (save-excursion + ;; Go back to beginning of command + (shell-backward-command 1) + ;; Skip any potential environment variables + (shell--skip-environment-variables pt) + (point)))) + (shell--command-completion-data)))) + +(defun shell--skip-environment-variables (pt) + "Move forward up to PT through any present environment variables." + (while (re-search-forward "=3D" pt t) + (skip-syntax-forward "^ " pt) + (skip-syntax-forward " " pt))) (defun shell--command-completion-data () "Return the completion data for the command at point." diff --git a/test/lisp/shell-tests.el b/test/lisp/shell-tests.el index 9bdf6b1c0eb..f07166d5995 100644 =2D-- a/test/lisp/shell-tests.el +++ b/test/lisp/shell-tests.el @@ -95,4 +95,21 @@ shell-directory-tracker-cd (should (not (equal start-dir list-buffers-directory))) (should (string-prefix-p list-buffers-directory start-dir))))) +(ert-deftest shell-skip-environment-variables () + (with-temp-buffer + (shell-mode) + (insert "FOO=3DBAR BAZ=3D QUUX=3Dabc=3Ddef whoami") + (let ((pt (point))) + (shell-backward-command 1) + (shell--skip-environment-variables pt)) + (should (looking-at-p "whoami")) + + (shell-backward-command 1) + (delete-line) + (insert "echo") + (let ((pt (point))) + (shell-backward-command 1) + (shell--skip-environment-variables pt)) + (should (looking-at-p "echo")))) + ;;; shell-tests.el ends here =2D- 2.43.0 --=-=-=--