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

Handle strings with escape sequences #3

Merged
merged 1 commit into from Jan 26, 2023

Conversation

kandread
Copy link
Contributor

@kandread kandread commented Jan 25, 2023

Have done some ad-hoc testing, but pretty sure there might be something I've missed.

@protesilaos protesilaos merged commit 75298b6 into protesilaos:main Jan 26, 2023
@protesilaos
Copy link
Owner

Merged. Thank you!

I still need to turn the README into an Org file in order to produce the Info manual. I will add an "Acknowledgements" section there and add your name to the list.

I am still interested in the 1st case we discussed in #2. Maybe we can find a way that (i) has future history and (ii) accepts an empty string.

This may be interesting, but I have not explored it in depth:

(read-from-minibuffer "Empty input: " nil nil nil nil "Hello")

@kandread kandread deleted the fix/special-strings branch January 26, 2023 11:05
@kandread
Copy link
Contributor Author

You're right, I think read-from-minibuffer should do the trick. I replaced the call to read-string in substitute--prompt-without-highlight and it does retain history as well as allow for the empty string.

protesilaos added a commit that referenced this pull request 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 pull request 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

Successfully merging this pull request may close these issues.

None yet

2 participants