Create function for custom selection of string used for inflection#44
Conversation
Create new user custom variable 'string-inflection-bounds-function' which allows for the customisation of the buffer string which inflection is performed on. It defaults to (bounds-of-thing-at-point 'symbol) which maintains the current behaviour.
|
I have to admit that I am skeptical if that is a good solution. I would rather suggest to introduce a function like |
|
@johannes-mueller Thank you for your feedback and additional information. |
|
@LaurenceWarne Hi! Thanks for your interest and for trying out the package. I believe you might be using string-inflection-all-cycle, which performs conversions like:
However, please note that If you're using Python, for example, Hope that helps! |
|
That said— Originally, string-inflection did not rely on mode-specific word boundaries. Thanks to the recent PR, word boundaries are now clearly defined per mode. That said, there are still situations where having mode-independent word boundaries can be desirable. So when foo-bar is written without spaces, it is often more useful to treat it as a single compound (like a variable name) rather than two separate tokens. Therefore, even though the PR improves things significantly and does not change the original behavior, I’m still wondering if we should consider keeping some flexibility—perhaps by allowing users to customize how word boundaries are determined. |
|
I just noticed this: in Python mode, when converting One possible solution might be to treat the hyphen as part of a word in that mode by using: This way, |
Yes sorry if I did not mention that, I've been using it for a while.
Thanks for the insight, personally I found non-mode specific inflection more useful (IIRC that's how
I think I'd prefer a solution which didn't modify syntax tables - seems there would be a lot that could effect? |
|
While the variables are now clearly defined for each mode, I suppose the previous approach—which was independent of the major mode—also had its merits. By the way, how are you planning to define Here’s one idea I came up with: (setq string-inflection-bounds-function
(lambda ()
(cons
(progn (skip-chars-forward "a-zA-Z0-9_-") (point))
(progn (skip-chars-backward "a-zA-Z0-9_-") (point)))))However, if we apply this as-is, it would cause the issue mentioned in #30 to resurface in C++ mode: |
The one I defined is very ad-hoc, it just delegates to a couple of smartparens commands, the one you've given looks equivalent but a lot more concise 🙂
That doesn't look too great I agree, though if we make it so that words starting/ending in (setq string-inflection-bounds-function
(lambda ()
(cons
(progn (skip-chars-forward "a-zA-Z0-9_-") (skip-chars-backward "_-") (point))
(progn (skip-chars-backward "a-zA-Z0-9_-") (skip-chars-forward "_-") (point))))) |
|
I see — it's not the most elegant solution, but it works exactly as intended. |
|
I’ve confirmed that customizing That said, I do have two minor concerns: Since forward-symbol is used, the implementation relies on symbol-based motion. If someone customizes string-inflection/string-inflection.el Line 228 in 617df25 Characters with umlauts or full-width alphabets may no longer be supported. Of course, since this doesn’t affect the current default behavior, maybe it’s not a big deal — but it still leaves me feeling a little uneasy. |
|
After giving it a lot of thought, I’ve decided to merge the PR—since it preserves the current behavior while also accommodating the need to revert to the previous one. |
|
Thanks! |
Hi, I find in some modes
string-inflectionused repeatedly may change the string acted upon according to(bounds-of-thing-at-point 'symbol), for example in python mode:fooBar -> foo-bar -> foo-BAR -> foo-Bar(after the first inflection, only the
barpart is inflected). The change proposed by this PR is to introduce a new custom variablestring-inflection-bounds-functionwhich allows for the customisation of the string selected for inflection. The default behaviour should remain the same.Thanks!