Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No substitution for (or with) certain strings #2

Closed
kandread opened this issue Jan 25, 2023 · 3 comments
Closed

No substitution for (or with) certain strings #2

kandread opened this issue Jan 25, 2023 · 3 comments

Comments

@kandread
Copy link
Contributor

Hi @protesilaos! Thank you for (another) great package. I was testing it out and encountered two issues with the example

var balmoral = /* color: #ffffff */ee.Geometry.Point([172.622101, -42.7989879990594]),
    ashley = /* color: #ffffff */ee.Geometry.Point([172.560061337, -43.2241230890585]);
  1. with the cursor on color and attempting to replace with an empty string doesn't seem to work
  2. attempting to replace the comment part /* color: #ffffff */ doesn't do anything either.

I was able to trace the first issue in substitute--prompt-without-highlight with the default value in the read-string call (just used pretty-target replacing target with itself). The second issue seems to be related to the escape sequences, which cause re-search-forward to not find any matches of target. I've fixed both issues in my fork, but not sure what I did was the best option. Just wanted to bring these to your attention, and happy to create a PR.

@protesilaos
Copy link
Owner

Hello @kandread!

Thank you for (another) great package.

You are welcome!

  1. with the cursor on color and attempting to replace with an empty string doesn't seem to work. [...] I was able to trace the first issue in substitute--prompt-without-highlight with the default value in the read-string call (just used pretty-target replacing target with itself).

I am aware of this and your findings are correct. This is the minimal scenario (writing it here in case another person reads this):

(read-string "Test with empty value: ")
(read-string "Test with empty value: " nil nil "Hello")

This is a tricky case. My instinct is to treat the empty input as "I am giving you an empty string" but in Emacs this action usually means "Return the default value". I think for substitute it makes more sense to follow our intuitions of replacing something with an empty string. But I have not committed to that because there may be a canonical way of doing it and I have not discovered it yet.

  1. attempting to replace the comment part /* color: #ffffff */ doesn't do anything either. [...] The second issue seems to be related to the escape sequences, which cause re-search-forward to not find any matches of target. I've fixed both issues in my fork, but not sure what I did was the best option. Just wanted to bring these to your attention, and happy to create a PR.

In principle, I agree wih fixing both and I am happy to merge your PR. Though given what I wrote above, I say we first merge the fix for 2 and then give ourselves a chance to rethink what we should do with 1. Just so that we conform with Emacs conventions.

What do you think?

@kandread
Copy link
Contributor Author

Agreed, and it's exactly the reason I opened up an issue to get your feedback instead of submitting the PR right away. I will close the issue, but feel free to keep it open of course.

@protesilaos
Copy link
Owner

Very well! Please prepare the PR for case 2. I think we should do it for 1 as well, but let's think about it a little more.

protesilaos added a commit that referenced this issue Jan 31, 2023
We could not do that with 'read-string' as the empty input is
automatically interpreted as the value of the DEFAULT-VALUE argument.
This is standard for most Emacs minibuffer interactions, though in our
case it makes sense to accept an empty string, as we may, e.g., want
to remove a prefix from a target.

Thanks to Kostas Andreadis for discussing this with me in issue 2 on
the GitHub mirror as well as pull request 3:

- <#2>
- <#3>
protesilaos added a commit that referenced this issue Jul 1, 2023
The package has been in a stable state since its inception, to the
point where I thought I had already formalised its latest version as a
release...

The value proposition of 'substitute' is shown in the video I did for
it: <https://protesilaos.com/codelog/2023-01-16-emacs-substitute-package-demo/>.

Notable refinements:

* It is now possible to substitute a target with an empty string.  We
  could not do that with 'read-string' function that was originally in
  use, as the empty input is automatically interpreted as the value of
  the DEFAULT-VALUE argument that 'read-string' gets.  This is
  standard for most Emacs minibuffer interactions, though in our case
  it makes sense to accept an empty string that is distinct from the
  default value, as we may, e.g., want to remove a prefix from a
  target.  Thanks to Kostas Andreadis for discussing this with me in
  issue 2 on the GitHub mirror as well as pull request 3:

  - <#2>
  - <#3>

* Target strings that contain escape sequences do not confuse
  Substitute anymore.  The substitution will be performed as expected.
  Thanks to Kostas Andreadis for the contribution, which was done in
  pull request 3 on the GitHub mirror:
  <#3>.

* Calling 'undo' after a substitution no longer moves the point.  This
  is consistent with the behaviour of Substitute when it replaces the
  target text.  Thanks to Ed Tavinor for the patch, which was done via
  a private channel.

* Normally, Substitute will retain the letter casing of the underlying
  target.  This means that if it is replacing "hello" with "hey" and
  there is a "HELLO" instance, it will replace it with "HEY".  This is
  often the desired behaviour.  Though now all Substitute commands
  accept an optional prefix argument ('C-u' with default key
  bindings), which is interpreted as a "fixed case" substitution: the
  user input is applied as-is, regardless of the underlying letter
  casing.  To always have fixed letter casing, set the user option
  'substitute-fixed-letter-case' to a non-nil value.  Doing so is the
  same as always calling the commands with a prefix argument.  Thanks
  to revrari for bringing this matter to my attention in issue 4 on
  the GitHub mirror:
  <#4>.

* Substitute will not even try to perform its task in a read-only
  buffer.  Thanks to ersi-dnd for bringing this matter to my
  attention.  This was done in issue 6 on the GitHub mirror:
  <#6>.

* The built-in 'subr-x' library is explicitly required to avoid byte
  compilation warnings.  Thanks to Chunye Wang for the contribution,
  which was done in pull request 1 on the GitHub mirror:
  <#1>.

The code contributions from Ed Tavinor, Kostas Andreadis, and Chunye
Wang are small, meaning that their respective authors do not need to
assign copyright to the Free Software Foundation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants