Subject: Re: bug#77326: [PATCH] Add symbol-mode

From: Ship Mints <[email-masked]>
Date: Sat, 5 Apr 2025 10:20:10 -0400

On Sat, Apr 5, 2025 at 10:10 AM Gabriel Santos <
[email-masked]> wrote:

> >One nice feature this patch could have is to cycle among symbol naming
> >conventions: CamelCase, snakeCase, hyphen-case, underscore_case (any
> >others?) and that would make it convenient when a variable name with the
> >same components are used across modalities; e.g. in config files, json,
> >xml, protobufs, C/C++ vs. python, and in emacs-lisp-mode and Emacs C code,
> >cycling among to Fsymbol_name or Ssymbol_name?
>
> There are multiple packages like this[1, 2, 3, 4, 5, 6].
>
> Despite that, I think I could give it a try, I just have to
> avoid looking into them because of copyright.
>
> So a comnand that changes between different symbol naming conventions,
> Like how the capitalization commands work?
>
> Point is "|":
>
> >M-x cycle-convention-symbol
> >|this-is-a-symbol
> >thisIsASymbol|
>

It would be most convenient if point could be anywhere in or around a
symbol when cycling.

> >cycle among symbol naming conventions:
>
> So subsequent calls would switch to another convention? I think this
> would be ok if the point didn't move.
>

I'd think the default cycling options would be mode specific as I
mentioned.  In Python mode, for example, kebabs aren't tasty as
identifiers, unless they're in a quoted string or comment so some context
would be helpful.  The code would not have to know what constitutes a valid
identifier, though, so if in Python I want to convert my/tasty-kebab to
my/tasty_kebab, it would fail as a Python identifier unless we also offer
some kind of character or syntax-table driven kind of trickery?  Not an
expert with the syntax tables so I'm just guessing.

> >M-x mark-sexp
> >this-is-a-symbol
> >M-x cycle-convention-symbol
> >thisIsASymbol
> >M-x cycle-convention-symbol
> >this_is_a_symbol
> >M-x cycle-convention-symbol
> >ThisIsASymbol
>
> Besides cycling, maybe choosing a convention with
> completion?
>
> >CamelCase, snakeCase, hyphen-case, underscore_case
>
> This could be another issue. The names I know these as
> are, respectively:
>
> - PascalCase
> - camelCase
> - kebab-case (yes, really)
> - snake_case
>

Right, the snake bit me, it's PC, cC, k-C, s_c. Pop culture names.

>There are multiple packages like this[1, 2, 3, 4, 5, 6].
>
> Another interesting option would be to contact the author
> of one of these packages for inclusion in this file.
>

It seems "easy" enough to just do it without the hassle and as part of
core Emacs?  Especially if the implementations below aren't optimal and
perhaps if tree sitter was leveraged this could be easier. I don't think
the below use any of that infrastructure.

> [1] <https://github.com/HKey/caseformat>
> [2] <https://hg.sr.ht/~zck/caser.el>
> [3] <https://github.com/TakesxiSximada/change-case.el>
> [4] <https://github.com/jcs-elpa/cycle-case-style>
> [5] <https://codeberg.org/acdw/titlecase.el>
> [6] <https://github.com/akicho8/string-inflection>
>