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
Comments
Hello @kandread!
You are welcome!
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
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? |
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. |
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. |
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>
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.
Hi @protesilaos! Thank you for (another) great package. I was testing it out and encountered two issues with the example
color
and attempting to replace with an empty string doesn't seem to work/* 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 theread-string
call (just usedpretty-target
replacingtarget
with itself). The second issue seems to be related to the escape sequences, which causere-search-forward
to not find any matches oftarget
. 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.The text was updated successfully, but these errors were encountered: