Emacs has convenient functions for upcasing and downcasing, but why not title casing? This package provides just that. Based on the code originally developed in this blog post.
This package isn’t on MELPA yet.
If you aren’t using Doom Emacs, the easiest way is probably to use straight.el like this:
(straight-use-package
'(titular :type git :host github :repo "hungyiloo/titular.el"))
If you are using Doom like me, put this snippet in your packages.el
then run doom sync
:
(package! titular
:recipe (:host github :repo "hungyiloo/titular.el"))
titular-titlecase-dwim
will title case the selection region, or the entire line if no region is selected.
titular-titlecase-region
will strictly title case the selected region only.
This will convert text to title case like:
original text | title cased text |
---|---|
the quick brown fox jumps over the lazy dog | The Quick Brown Fox Jumps Over the Lazy Dog |
“To be, or not to be, that is the question” | “To Be, or Not to Be, That Is the Question” |
they told me I could be anything I wanted; so I became an emacs lisp package | They Told Me I Could Be Anything I Wanted; So I Became an Emacs Lisp Package |
Put this in your config.el
somewhere:
(evil-define-operator my/evil-titlecase-operator (beg end)
(interactive "<r>")
(save-excursion
(set-mark beg)
(goto-char end)
(titular-titlecase-dwim)))
(after! evil
(map! :nv "g`" #'my/evil-titlecase-operator))
Now in normal mode you can use g``
to title case a whole line, or in visual mode g`
to title case the actively selected region.
Execute the bash script test.sh
, which runs the ERT tests defined in titular-test.el
.