-
Notifications
You must be signed in to change notification settings - Fork 95
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
Add s-replace-regexp #116
Add s-replace-regexp #116
Conversation
I think it makes sense to keep the optional parameters. However, the order of the required parameters should match |
Hum, sorry but https://github.com/magnars/s.el#s-replace-old-new-s says otherwise (oldtext, newtext, originalstring)?
I think it does as shown in my 1st post. Anyway, that means we are good with I'll add more example, in the meantime what do you think of |
Yes, you are right. The original string is supposed to be last. All good then. I think |
Alright, review the commit and suggest changes or merge 😉 |
Thank you guys for putting so much work into this. Regarding the necessity of s-replace-all-regexp: The normal behaviour of replace-regexp-in-string replaces every occurence: (replace-regexp-in-string "foo" "bar" "foo foo")
"bar bar" (meaning: we don't need s-replace-regexp-all, but..); if this behaviour is not wished for one shall do subexpression replacement (last argument): (replace-regexp-in-string "\\(foo\\).*\\'" "bar" " foo foo" nil nil 1)
=> " bar foo" But this usage would again conflict with (s-with)-threading, because last arg isn't any longer the input-string but as said the subexpression number. (?!) Overall problem: Cannot use &optional args of (replace-regexp-in-string) with (s-with) |
Yes, this is the case for all functions with optional args. Unfortunately my early standardisation on having the original string in the last position bites us here. |
Looks good to me! |
I think you missunderstand That is, |
replacing all pairs... of course! sorry for the noise. And thanks for this fix! |
This is what I use as a replacement for (require 'dash)
(defun replace-regexp-cons (s replacement)
"REPLACEMENT is a cons-cell. Each `car` is replaced with `cdr` in S.
n
`car` is a regexp.
`cdr` can include backreferences."
(replace-regexp-in-string (car replacement) (cdr replacement) s t))
(defun replace-all-regexp (replacements s)
"REPLACEMENTS is a list of cons-cells. Each `car` is replaced with `cdr` in S.
`car`s are regexps.
`cdr`s can include backreferences."
(-reduce-from #'replace-regexp-cons s replacements)) It works well but has a dependency on |
Don't merge this yet.
@magnars: I need your guidance for the next points
Interface is quite different:
(s-replace OLD NEW S) (s-replace-regexp REGEXP REP STRING &optional FIXEDCASE LITERAL SUBEXP START)
Do we want all the additional parameters?
TODO:
s-replace-regexp
.s-replace-all-regexp
.