From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#28323: Patchset to fix 28323 Date: Thu, 10 May 2018 21:01:25 -0400 Message-ID: <87o9hnkntm.fsf@gmail.com> References: <8737865dvh.fsf@gmail.com> <871selgaa1.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1526000410 29204 195.159.176.226 (11 May 2018 01:00:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 11 May 2018 01:00:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: 28323@debbugs.gnu.org To: Jay Kamat Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 11 03:00:06 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGwPj-0007Sl-7H for geb-bug-gnu-emacs@m.gmane.org; Fri, 11 May 2018 03:00:03 +0200 Original-Received: from localhost ([::1]:36247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGwRq-0000uh-FR for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 May 2018 21:02:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGwRj-0000mg-EU for bug-gnu-emacs@gnu.org; Thu, 10 May 2018 21:02:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGwRe-0003Xj-Ic for bug-gnu-emacs@gnu.org; Thu, 10 May 2018 21:02:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49076) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGwRe-0003Xb-Er for bug-gnu-emacs@gnu.org; Thu, 10 May 2018 21:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fGwRd-0005Tq-Tp for bug-gnu-emacs@gnu.org; Thu, 10 May 2018 21:02:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 11 May 2018 01:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28323 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed patch Original-Received: via spool by 28323-submit@debbugs.gnu.org id=B28323.152600049621032 (code B ref 28323); Fri, 11 May 2018 01:02:01 +0000 Original-Received: (at 28323) by debbugs.gnu.org; 11 May 2018 01:01:36 +0000 Original-Received: from localhost ([127.0.0.1]:56973 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGwRE-0005TA-CW for submit@debbugs.gnu.org; Thu, 10 May 2018 21:01:36 -0400 Original-Received: from mail-io0-f175.google.com ([209.85.223.175]:46024) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGwRC-0005Sr-8u for 28323@debbugs.gnu.org; Thu, 10 May 2018 21:01:34 -0400 Original-Received: by mail-io0-f175.google.com with SMTP id c9-v6so5174345iob.12 for <28323@debbugs.gnu.org>; Thu, 10 May 2018 18:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=W9uQc4ReFX6C8jvCbbg6Lakc6f2SUjveqxEX+8wAFmg=; b=oreisC6hCfIVVUfx9iaIwefHtJ8IZj9bpCw+rt5F3GtgCq1MeKx9lJp1SR/SmTswDj IzJohzHiQdh6gxbE1bVsYhKFl6ITqF8UGLuV7WFuyMEXiZl4xqmMqX0kPqQ7DYHsZusz 9p+jNn3zb3g37B6jPunzvVBk69OhPLvvJnK43KSId/0ZTKcfF5LMaUXhVgpvY1L102TH GIx2uLjrbpzSIs+JsLB52VsKTP/b2bo05KR0ataX8lv9L9rR/QHrODWLwaqSr4o9gqwI gFr0MgNwW4u/L7OJ+WQLbrPcj8+Z66LFXqCA+DXibctx1495OAWzYZ2EyDPwJkDwaQYG 85iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=W9uQc4ReFX6C8jvCbbg6Lakc6f2SUjveqxEX+8wAFmg=; b=K7g6O3HzRks7XqtEsXmecQUOHsZSR/svyezYNn5+TfpZSIvU0y4bcfuDeLcMJ0zzTQ v1tE/AOksXewGziDcwNpMVpbH/8b+Pw8XlQdIgvzAP7iWIoVOuDojdFjtOb0qCSs96bs ua7wzIvFiNX3XLFvVEbc+mtpMQL6JJ34+69fefmj5eV1k8+FmXGO8Hd5wv5CFtv0ASBp gGh9Lqqh1ZoxdeUK1fRYM6OjnbpB8EYzZ8jOomMRMfndhfHXeSTIcZLtrkE4X17d5yEo ygBlI+G02z30BvPzgNT9kKBWapBbjz2TFqZYsqRofE2o84uXPspdBnZAe3OYTGFVj78r i2zw== X-Gm-Message-State: ALKqPweMOXdForqFLnjzsHco5I9ZDULz8VP+OBGOjkUbr7hLKTe66hWX We8ol/TbAyrbbAxtWc7FC7cODA== X-Google-Smtp-Source: AB8JxZqFPNzOpPCXcTyJ68R3PDUlrhHsiYoMbZvv7Opz9FXWWDq/H7xNRkkQ+PujvVaZT5i7az+xEQ== X-Received: by 2002:a6b:248e:: with SMTP id k136-v6mr3561216iok.270.1526000488084; Thu, 10 May 2018 18:01:28 -0700 (PDT) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id d130-v6sm1079459iog.46.2018.05.10.18.01.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 18:01:26 -0700 (PDT) In-Reply-To: <871selgaa1.fsf@gmail.com> (Jay Kamat's message of "Tue, 08 May 2018 13:30:46 -0700") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:146118 Archived-At: Jay Kamat writes: > This was bugging me for other commands I was running (emerge -uDN > world), so I decided to try to write a patch for this. Thanks! > In the process, I found another blocking bug, which would have broken > the -u flag entirely. Currently, 'sudo -u root whoami' returns '-u', > because of a bug involved with processing leading positional arguments. Ah, looks like [1: 170266d096] missed a rename of args into eshell--args. [1: 170266d096]: 2013-09-12 01:20:07 -0400 Cleanup Eshell to rely less on dynamic scoping. https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=170266d096bc4d0952bee907532d14503e882bf6 > I fixed the blocking bug first in a separate patch, and then added a new > parameter for commands like sudo, which would prefer :raw-positional > arguments after the first non flag argument. I'm still not sure if this > is the best name for this idea, so if anyone has a better name I'd be > happy to change it! :parse-leading-options-only? Perhaps that's too long though. > * lisp/eshell/esh-opt.el (eshell--process-args): Refactor usage of > args to eshell--args, as we rely on modifications from > eshell--process-option and vice versa. These modifications were not ^ double space > being propogated in the (if (= ai 0)) case, since we cannot > destructively modify the first element of a list. This sentence here is a bit confusing, because of course we can modify the first element with setcar, but you meant something different. Something more like Popping the first element of a list doesn't destructively modify the underlying list object. > > Examples of broken behavior: > > sudo -u root whoami > ls -I '*.txt' /dev/null I think it would be helpful to mention how these are broken. > * lisp/eshell/esh-opt.el: Add a new :raw-positional argument which This entry should start with * lisp/eshell/esh-opt.el (eshell-eval-using-options): > ignores dash/switch arguments after the first positional > argument. Useful for eshell/sudo, to avoid parsing subcommand ^ double space > switches as switches of the root command. Though I think it would make more sense to put the second sentence in its own "* lisp/eshell/em-tramp.el (eshell/sudo)" entry. > (eshell--process-option): add a new posarg argument which signals that > we have found a positional argument already. This entry should mention eshell--process-args as well, but actually I think it would make sense to change the patch, such that only eshell--process-args is fixed, see below. > -(defun eshell--process-option (name switch kind ai options opt-vals) > +(defun eshell--process-option (name switch kind ai posarg options opt-vals) > "For NAME, process SWITCH (of type KIND), from args at index AI. > The SWITCH will be looked up in the set of OPTIONS. > > @@ -219,7 +223,10 @@ eshell--process-option > (while opts > (if (and (listp (car opts)) > (nth kind (car opts)) > - (equal switch (nth kind (car opts)))) > + (equal switch (nth kind (car opts))) > + ;; If we want to ignore arguments after a pos one, don't find. > + (not (and posarg > + (memq ':raw-positional options)))) By the way, you don't need to quote keyword symbols (though it does still work fine). > (progn > (eshell--set-option name ai (car opts) options opt-vals) > (setq found t opts nil)) > @@ -245,27 +252,33 @@ eshell--process-args > (list sym))))) > options))) > (ai 0) arg > - (eshell--args args)) > + (eshell--args args) > + (pos-argument-found nil)) > (while (< ai (length eshell--args)) > (setq arg (nth ai eshell--args)) > (if (not (and (stringp arg) > (string-match "^-\\(-\\)?\\(.*\\)" arg))) > - (setq ai (1+ ai)) > + ;; Positional argument found, skip > + (setq ai (1+ ai) > + pos-argument-found t) > + ;; dash or switch argument found, parse I think you should be able to just terminate the loop here once you have pos-argument-found and (memq :raw-positional options) is true, rather than passing an arg to eshell--process-option to make the rest of the loop iterations into nops. > - (setcdr (nthcdr (1- ai) eshell--args) > + (setcdr (nthcdr (1- ai) eshell--args) This is just a whitespace change, right?