abo-abo / auto-yasnippet

quickly create disposable yasnippets
245 stars 15 forks source link

add new option: aya-case-fold #26

Closed gilbertw1 closed 6 years ago

gilbertw1 commented 6 years ago

This pull request adds support for the option aya-case-fold. This option essentially allows auto-yasnippet to create templates where variables that are identical apart from the case of the first character are linked together to a single variable with case in the resulting snippet is preserved.

I know that sounds like a mouthful, but the easiest way to see the behavior is in this screencast (first with this setting disabled, then again with it enabled):

screencast

I modeled this feature after the ability to find and replace text while preserving the case of the initial character: https://www.emacswiki.org/emacs/CaseFoldSearch.

The code is fairly straightforward. I'm now returning an alist from aya--parse that contains the id of the match, it's value, and ucase (whether or not the value was uppercase or not). That alist is used to both recreate the current line with proper casing and create a yas template that conditionally uppercases the value to match the original casing.

abo-abo commented 6 years ago

Comments:

  1. When does it make sense for aya-case-fold to be off? Seems like a straight upgrade.
  2. Please use cl-lib in place of seq functions (seq-some, seq-filter) etc.
  3. I'm not sure about when alist-get was introduced, please check.
gilbertw1 commented 6 years ago

Hey,

  1. I wasn't sure if this would be desired behavior for everyone. I could either A) make it on by default or B) remove the setting and just make this how it works all the time.
  2. Will do.
  3. Looks like Emacs 25. What's your target minimum version? I can use an alternative if it's <25.

Thanks!

gilbertw1 commented 6 years ago

I've replaced the seq-* functions with cl-* functions, and I've replaced the alist-get function calls as well. Let me know how you' like me to handle 1.

abo-abo commented 6 years ago

make it on by default

Let's do it like that.

What's your target minimum version?

24.3.

gilbertw1 commented 6 years ago

Cool, I've defaulted the feature to on by default.

abo-abo commented 6 years ago

Thanks.