Transform words in Emacs (upcase, downcase, capitalize, etc.)
Switch branches/tags
Nothing to show
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore added .gitignore file Jun 4, 2015
.travis.yml Do not test against git snapshot Feb 25, 2018
Cask Upgrade Travis script (#2) Aug 2, 2017 Include 2018 into the copyright years range Jan 1, 2018
fix-word.el Include 2018 into the copyright years range Jan 1, 2018

Fix Word

License GPL 3 MELPA Build Status

This is a package that allows to transform words intelligently. It provides the function fix-word that lifts functions that do string transformation into commands with interesting behavior. There are also some built-in commands based on fix-word, see below.


Download this package and place it somewhere, so Emacs can see it. Then put (require 'fix-word) into your configuration file. Done!

It's now available via MELPA, so you can just M-x package-install RET fix-word RET.

API description

fix-word fnc

Lift function fnc into command that operates on words and regions.

The following behaviors are implemented:

  1. If the point is placed outside of a word, apply fnc to previous word. When the command is invoked repeatedly, every its invocation transforms one more word moving from the right to the left. For example (upcasing, ^ shows position of point/cursor):

    The quick brown fox jumps over the lazy dog.^
    The quick brown fox jumps over the lazy DOG.^
    The quick brown fox jumps over the LAZY DOG.^
    The quick brown fox jumps over THE LAZY DOG.^

    The point doesn't move, this allows user to fix recently entered words and continue typing.

  2. If the point is placed inside of any part of a word, the whole word is transformed. The point is moved to first character of the next word. This allows to transform words repeatedly using the dedicated key binding.

    ^The quick brown fox jumps over the lazy dog.
    THE ^quick brown fox jumps over the lazy dog.
    THE QUICK ^brown fox jumps over the lazy dog.
    THE QUICK BROWN ^fox jumps over the lazy dog.
  3. If there is an active region, all words in that region are transformed.

Use fix-word to create new commands like this:

(defalias 'command-name (fix-word #'upcase)
  "Description of the command.")

There is also a macro that defines such commands for you: fix-word-define-command.

fix-word-define-command name fnc &optional doc

Define fix-word-based command named name. fnc is the processing function and doc is documentation string.

Built-in commands

Default commands to upcase/downcase/capitalize stuff are not very convenient to say the least, for the following reasons:

  1. There are three different commands to upcase thing, for example. User needs to remember three commands, their key bindings, and when to use each of them. There should be one command per action: one for upcasing, one for downcasing, and one for capitalizing.

  2. Commands on regions don't have dedicated key bindings and what's even worse—they are disabled by default!

  3. Commands like upcase-word depend on the position of pointer inside word, now tell me what's expected result of upcase command here: "fo^o"? I bet you want "FOO", not "foO". The same applies to capitalization, etc. These commands should work on entire word no matter what.

  4. You need to use arguments for commands like upcase-word to make them correct words that you've just written. What's even worse, you can fix only the last word this way. What if you want to fix a couple of them?

Here are commands that are trying to fix all these flaws:

  • fix-word-upcase
  • fix-word-downcase
  • fix-word-capitalize

I propose replacing of old functions with these, you can do it this way:

(global-set-key (kbd "M-u") #'fix-word-upcase)
(global-set-key (kbd "M-l") #'fix-word-downcase)
(global-set-key (kbd "M-c") #'fix-word-capitalize)


Copyright © 2015–2018 Mark Karpov

Distributed under GNU GPL, version 3.