Search code examples
emacsorg-modecapitalizationcapitalize

How to instruct Emacs auto-capitalize-mode to automatically lowercase any word that follows e.g. or i.e.?


Emacs auto-capitalize-mode misinterprets the words i.e. and e.g. to signify the end of a sentence, and, accordingly, erroneously capitalizes any word that follows them.

Does anyone have a function that can be called by entering, say, eg or ie, that will insert the characters e.g. and i.e. and then automatically lowercase whatever word gets typed next?

Bonus: Do the same thing... for ellipses.


Solution

  • Add this to your .emacs:

    (setq auto-capitalize-predicate
          (lambda () (not (looking-back
               "\\([Ee]\\.g\\|[Ii]\\.e\\)\\.[^.]*" (- (point) 20)))))
    

    Remember that the I in i.e. will be capitalized to I.e if your auto-capitalize-words variable is set to contain “I”.

    (setq auto-capitalize-words '()) This sets it to nothing.

    Here’s a version that also deals with ellipses:

    (setq auto-capitalize-predicate
          (lambda () (not (looking-back
               "\\([Ee]\\.g\\|[Ii]\\.e\\|\\.\\.\\)\\.[^.]*" (- (point) 20)))))
    

    But you might want to look into some abbrev magic that turns three periods into a unicode ellipsis instead. It's up to you.