From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Cl=C3=A9ment?= Pit-Claudel Newsgroups: gmane.emacs.bugs Subject: bug#36372: 27.0.50; replace-regexp-in-string skips START first chars in return value [PATCH] Date: Wed, 26 Jun 2019 11:59:35 -0400 Message-ID: References: <83tvcdlm8x.fsf@gnu.org> <8336jwl7sa.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="72879"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 Cc: Lars Ingebrigtsen , 36372@debbugs.gnu.org To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 26 18:00:47 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hgALm-000Inq-FB for geb-bug-gnu-emacs@m.gmane.org; Wed, 26 Jun 2019 18:00:46 +0200 Original-Received: from localhost ([::1]:41454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgALl-0001oq-AE for geb-bug-gnu-emacs@m.gmane.org; Wed, 26 Jun 2019 12:00:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51201) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgAL8-0001mr-RK for bug-gnu-emacs@gnu.org; Wed, 26 Jun 2019 12:00:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hgAL6-0002YR-Io for bug-gnu-emacs@gnu.org; Wed, 26 Jun 2019 12:00:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51584) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hgAL4-0002V2-7Y for bug-gnu-emacs@gnu.org; Wed, 26 Jun 2019 12:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hgAL4-0001Im-6B for bug-gnu-emacs@gnu.org; Wed, 26 Jun 2019 12:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Cl=C3=A9ment?= Pit-Claudel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 Jun 2019 16:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36372 X-GNU-PR-Package: emacs Original-Received: via spool by 36372-submit@debbugs.gnu.org id=B36372.15615647864944 (code B ref 36372); Wed, 26 Jun 2019 16:00:02 +0000 Original-Received: (at 36372) by debbugs.gnu.org; 26 Jun 2019 15:59:46 +0000 Original-Received: from localhost ([127.0.0.1]:36895 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hgAKn-0001Hf-V3 for submit@debbugs.gnu.org; Wed, 26 Jun 2019 11:59:46 -0400 Original-Received: from mail-qt1-f176.google.com ([209.85.160.176]:45301) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hgAKl-0001HQ-Lp for 36372@debbugs.gnu.org; Wed, 26 Jun 2019 11:59:44 -0400 Original-Received: by mail-qt1-f176.google.com with SMTP id j19so2892493qtr.12 for <36372@debbugs.gnu.org>; Wed, 26 Jun 2019 08:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=9gtBXZhnFVhiT34+TZ/uwRZCYASW8sjoXTibHqKldII=; b=sVcGXoG/xOXFBJQrokLqJ2MCp2Z5Va4LAauN3Q2tKcd9MfWVyA7yPJKHUaS1mfE6eS SizkoPgc2R7pZTe9WbO6U49M1AQwNGvG5he5jN10Or4Dur9DMaBUom/2IXp5I1nM2u9k NTJCqa59BYRkdILEHYPNLW1i4ttf8xYJCNTolUIbjbT+QSEjDdMOesJFO7vnnzNndVzA kAKroMdib1RUpAQROTZQxp0/mszfs4OCgUUxvAi8K29O24mKogmD/Ec7lMsHDBa+b6Vp fWVtiToOGSosQuYrCXL5bykz+xc3u8uE0IucosXvpxf/R0gdCQXWB0DVODnlldNbHYq8 icLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9gtBXZhnFVhiT34+TZ/uwRZCYASW8sjoXTibHqKldII=; b=PZrQyTd/4g22iEAQDCnMvqhrsxnJs4f3uWOwp3jQktCRUTgpt9+xwsQ2EkWPiPVt3H YwX2puTmAoq82GUATelKUTXmnOIHO8ie2YXEqhG3YuZH1pAkFTw8azA/P+nWxoHg/fW/ edk6oNgLbJVLOmn2wQc2e1wAT+BG/cRGNPZCWtJJXnGu+Ht45fKU7ugFulpZsn2+8kqt /PKfDnoF7EA5teivvKJ8CD7Ku7ixrTiksnxJmgK/U1f57nzkewcEPm34Zp5JA6pisVOG yGIQBjw4Lj8Yk7+A/99tFv1mqnf+2sgJuMHyf3CEXc6FpbibnBy/+GJ+KrcEtjNoMtsj GJJg== X-Gm-Message-State: APjAAAUbPGDncrb945d/fKRykF4oWf0S28HrRBefr8zDCMYBWj40kWb9 aQ0QiIEHa+OROsw4KgZF1I82pULG X-Google-Smtp-Source: APXvYqzf9/tEYcWCyg8GYoFTtur8APBRYZAOztZPf4EXwRxj2VS3LIvmBZyoWctHCylhrG+vHa4zYw== X-Received: by 2002:a0c:b163:: with SMTP id r32mr4191731qvc.169.1561564776790; Wed, 26 Jun 2019 08:59:36 -0700 (PDT) Original-Received: from [128.30.93.186] (30-93-186.dynamic.csail.mit.edu. [128.30.93.186]) by smtp.googlemail.com with ESMTPSA id o54sm11444024qtb.63.2019.06.26.08.59.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jun 2019 08:59:36 -0700 (PDT) In-Reply-To: Content-Language: en-GB 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: 209.51.188.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:161525 Archived-At: On 2019-06-26 11:20, Mattias Engdegård wrote: > Clément, apologies for dragging you into the discussion, but when you woke up this morning, you probably didn't know that you were possibly the only man in history to use the last argument to replace-regexp-in-string. Well, my morning just got a lot more interesting :) > Now I would be curious to know: > > (1) Does this code, in company-coq--loc-fully-qualified-name, actually work the way you intended? (Looks like it.) Yes, I think it does. It's a bit inscrutable, so here's an annotated copy: (defun company-coq--loc-fully-qualified-name (fqn) ;; assume fqn is Coq.Init.Nat.max (let* ((spec (company-coq-longest-matching-path-spec fqn)) ;; … spec is ("Coq.Init" . "/build/coq/theories/Init/") (logical (if spec (concat (car spec) ".") "")) ;; … logical is "Coq.Init." (mod-name (replace-regexp-in-string "\\..*\\'" "" fqn nil nil nil (length logical)))) ;; … mod-name is "Nat" (company-coq-library-path logical mod-name spec))) ;; … return /build/coq/theories/Init/Nat.v The reason for this odd dance is that a Coq identifier is essentially a directory path (Coq.Init.) + a file name (here Nat.) + an identifier name (max). But in some cases there can be modules in the path too, like maybe Coq.Init.Nat.XYZ.max, and in those cases the file is still only 'Nat.' This code would probably be clearer if I just used a substring to trim out the beginning of the string ^^ > (2) Did you learn how the START parameter affects the return value by reading the doc string, the manual, the source code, or by testing? Almost certainly the docstring, confirmed by testing. I haven't looked at this section of the manual. > (3) Are you aware of other code using the START parameter to replace-regexp-in-string? Nothing off the top of my head, but I probably wouldn't have thought of the instance in company-coq either. A quick grep through my local sources doesn't turn up anything else, but a quick visual check isn't a very reliable method (did you use a plain grep to find the instance in company-coq, or do you have a more sophisticated trick?). Hope this helps, Clément.