From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings Newsgroups: gmane.emacs.bugs Subject: bug#60464: 29.0.60; Regression - pcomplete-arg fails with argument 'last Date: Sun, 01 Jan 2023 18:19:20 +0000 Message-ID: <226b32f79f056489e881@heytings.org> References: <87358u5y6l.fsf@daniel-mendler.de> <226b32f79f2d431d75b6@heytings.org> <009141ba-c21a-a5cb-a81b-c72a12a26207@daniel-mendler.de> <226b32f79f728e6bfed4@heytings.org> <82cf05e4-3c3f-9804-4801-eb31988f6d7d@daniel-mendler.de> <226b32f79f325daf9c7a@heytings.org> <226b32f79fe1e154cfb4@heytings.org> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10238"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Daniel Mendler , Eli Zaretskii , 60464@debbugs.gnu.org, Jim Porter To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 01 19:20:50 2023 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 1pC2wy-0002No-5V for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Jan 2023 19:20:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pC2wM-0006ye-E9; Sun, 01 Jan 2023 13:20:10 -0500 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 1pC2wJ-0006xm-Hh for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 13:20:07 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pC2wE-00053Q-LW for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 13:20:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pC2wE-0005QI-C3 for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 13:20:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gregory Heytings Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Jan 2023 18:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60464 X-GNU-PR-Package: emacs Original-Received: via spool by 60464-submit@debbugs.gnu.org id=B60464.167259716520796 (code B ref 60464); Sun, 01 Jan 2023 18:20:02 +0000 Original-Received: (at 60464) by debbugs.gnu.org; 1 Jan 2023 18:19:25 +0000 Original-Received: from localhost ([127.0.0.1]:41715 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC2vc-0005PM-Gs for submit@debbugs.gnu.org; Sun, 01 Jan 2023 13:19:24 -0500 Original-Received: from heytings.org ([95.142.160.155]:54726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC2va-0005PC-J7 for 60464@debbugs.gnu.org; Sun, 01 Jan 2023 13:19:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20220101; t=1672597161; bh=VdyEUgsM/zMoDnWifaZ0IIGhDrdlsr34GnQcHCqyL5s=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:From; b=lC6PnYC+7i6//nfoh28qHzuqVMETfvUgl6DHz32WxB4MIz3gyIVLNzAwZbbxAsuq6 dF6kcajf9/JuGKRO6XdGqbmsTRMVa1Po1gIuq5osxO3uIgcziCOhd7IFYFJKKwl+gQ T8RJyRrKto5IeY6KbmZhK/rWACmT9dmV69THP9B2AD2gXL1RB/3MpcZfqj7L8Vk/VJ pQk9rSlbLJiVnPnx5ODDb1huyylStvA/3Lv/ax8h1+0H362erYHczGttdqTezaLM38 /MbpqCt2gTAcUG0MTyb+oI8mrYnaHxslVgytcNMMc5o6+gg09bQB1eXm7rDhpaHIdi balyfLBZK/WPg== In-Reply-To: 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:252269 Archived-At: >> After working a bit more on this bug, I concluded that what Stefan >> initially suggested, to use the string representation of the value, is >> safer than trying to extract the string corresponding to the argument >> that the user typed in from the command line. > > Could you expand on when/where it's "unsafe" or what it breaks? > I simply spent too much time trying to get the "extract the correct part of the command line from the buffer" right, and wasn't able to convince myself that the result was correct in all circumstances. Given that returning (format "%S" arg) is what you initially suggested, and that it cannot be wrong, I concluded that it was the best/safest thing to do. The semantics of the "index" argument of the pcomplete-arg function are tricky: it can be 0, "the current argument being examined", < 0, "closer to the last argument", and > 0, "closer to the first argument". And then you also have the special values 'first and 'last. And it can also be nil, which is equivalent to 0. There is a pcomplete-actual-arg function, which returns "the actual text representation of the last argument" (in fact, "the actual text representation of the INDEXth argument and the following ones"), but no function which returns the actual text representation of a given argument. Perhaps we could just use it and assume that all arguments are separated by spaces, though, in which case the patch would become: diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 5bee515246..c829b6c3b7 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -648,10 +648,11 @@ pcomplete-arg accessing absolute argument positions. When the argument has been transformed into something that is not -a string by `pcomplete-parse-arguments-function', the text -representation of the argument, namely what the user actually -typed in, is returned, and the value of the argument is stored in -the pcomplete-arg-value text property of that string." +a string by `pcomplete-parse-arguments-function' and INDEX is not +`last', the text representation of the argument, namely what the +user actually typed in, is returned, and the value of the +argument is stored in the pcomplete-arg-value text property of +that string." (let ((arg (nth (+ (pcase index ('first 0) @@ -659,11 +660,11 @@ pcomplete-arg (_ (- pcomplete-index (or index 0)))) (or offset 0)) pcomplete-args))) - (if (stringp arg) + (if (or (stringp arg) + (eq index 'last)) arg (propertize - (buffer-substring (pcomplete-begin index offset) - (pcomplete-begin (1- (or index 0)) offset)) + (car (split-string (pcomplete-actual-arg index offset))) 'pcomplete-arg-value arg)))) (defun pcomplete-begin (&optional index offset)