I would like the period at the end of a sentence to be added automatically when two spaces are typed (similar to how typing works in iPhones).

I use two spaces between sentences, so the transformation I would like to happen would look like this:

b l a h SPC SPC  -->  b l a h . SPC SPC

I plan to use this along with the auto-capitalize mode.

Many thanks!

2 Answers 2


Give this a go:

(defun freaky-space ()
  (cond ((looking-back "\\(?:^\\|\\.\\)  +")
         (insert " "))
        ((eq this-command
         (backward-delete-char 1)
         (insert ".  "))
         (insert " "))))

(define-key text-mode-map " " 'freaky-space)
  • Great. One nice thing about this solution is that it takes into account the context (e.g., only insert a period if there's no period already there). Nov 28, 2014 at 5:52

Keychords would let you do this. You would also want SPC SPC to be translated to . SPC only when you type them fast enough. That's exactly what keychords would do. After installing key-chord you can define something like this:

(key-chord-define-local (kbd "SPC SPC") (lambda () (insert ". ")))
  • I tried exactly that with key-chord. It makes it so that typing a space between words is very slow. I guess it's waiting to see if you'll type a second space. I turned it off. Jun 26, 2015 at 7:32
  • 1
    @incandescentman Yes, you are right. Using a one-key keychord on a common key does have this issue. You could try tweaking key-chord-one-key-delay to your liking.
    – Pradhan
    Jun 26, 2015 at 16:05
  • The fastest I could get it to recognize discrete key presses was (setq key-chord-one-key-delay 0.11), which still creates a long lag when typing a single space. Jul 9, 2015 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.