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

X-Case with Emacs #1

Closed
mihaiolteanu opened this issue Apr 27, 2021 · 1 comment
Closed

X-Case with Emacs #1

mihaiolteanu opened this issue Apr 27, 2021 · 1 comment

Comments

@mihaiolteanu
Copy link

I saw your X-Case feature and though about implementing it in Emacs, just for fun.

(let ((snake-case-start-pos)
      (snake-case-contents))
  (defun snake-case-start ()
    (interactive)
    (setf snake-case-start-pos (point)))

  (defun snake-case-transform (char)
    (setf snake-case-contents
          (buffer-substring-no-properties
           snake-case-start-pos (point)))
    (delete-region
     snake-case-start-pos (point))
    (insert (s-replace " " char snake-case-contents))))

The snake-case-start signals that the next words are to be interpreted for this feature and remembers the position in the buffer at the time you've called it. The snake-case-transform accepts a char, deletes the buffer contents starting from the remembered position up to the current position and then inserts back that content but with spaces replaced with the new char.

Interactive functions, for different replacement chars would then look like,

(defun snake-case-transform-underline ()
  (interactive)
  (snake-case-transform "_"))

(defun snake-case-transform-star ()
  (interactive)
  (snake-case-transform "*"))

These can then be mapped nicely on a QMK keyboard if you key-bind them, with no extra features needed on the C-side of things.

@andrewjrae
Copy link
Owner

Neat!

There was some talk on the SplitKB discord about how this was probably something that was best suited for an IDE/editor, so an Emacs implementation is neat to see.

I guess the only thing missing here is camel case support, though frankly I don't really use x-case for that since one shot shift works just as well, so perhaps it's just not necessary.

Either way, super cool!

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

No branches or pull requests

2 participants