all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
To: "Mattias Engdegård" <mattiase@acm.org>, "Eli Zaretskii" <eliz@gnu.org>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 36372@debbugs.gnu.org
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	[thread overview]
Message-ID: <f6bdf985-9e7d-c9e5-5169-479b44665849@gmail.com> (raw)
In-Reply-To: <AFD3ED92-B628-45A9-B310-5575A5D5F1B2@acm.org>

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.





  reply	other threads:[~2019-06-26 15:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25 12:01 bug#36372: 27.0.50; replace-regexp-in-string skips START first chars in return value Mattias Engdegård
2019-06-25 15:26 ` Eli Zaretskii
2019-06-26  9:31   ` bug#36372: 27.0.50; replace-regexp-in-string skips START first chars in return value [PATCH] Mattias Engdegård
2019-06-26  9:38     ` Robert Pluim
2019-06-26 10:01       ` Mattias Engdegård
2019-06-26 11:11         ` Robert Pluim
2019-06-26 10:22       ` Lars Ingebrigtsen
2019-06-26 12:32         ` Robert Pluim
2019-06-26 13:51           ` Lars Ingebrigtsen
2019-06-26 14:01             ` Drew Adams
2019-06-26 14:51             ` Eli Zaretskii
2019-06-26 15:20               ` Mattias Engdegård
2019-06-26 15:59                 ` Clément Pit-Claudel [this message]
2019-06-26 17:03                   ` Mattias Engdegård
2019-06-26 17:09                     ` Eli Zaretskii
2019-06-26 17:41                       ` Mattias Engdegård
2019-06-26 15:17     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f6bdf985-9e7d-c9e5-5169-479b44665849@gmail.com \
    --to=cpitclaudel@gmail.com \
    --cc=36372@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    --cc=mattiase@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.