Reputation: 2144
In most cases I'm writing german texts. Most words start with an uppercase letter followed by lower case letters. Sometimes I'm typing too fast and also the second letter of a word is typed upper case. To work around this issue I asked myself if it is poosible to write a function which automatically changes the case of the second letter. Optional this should only happen if the third and following are in lower case. Do you know if this is possible and do you have any suggestions?
Upvotes: 2
Views: 602
Reputation: 19727
You could setup a minor mode mapping all upcase characters to special input function.
See:
Upvotes: 2
Reputation: 660
Here's an 'always on' version that fixes as you type. It will let you type all uppercase words, but as soon as it detects mixed case it will capitalize.
(defun blah (s e l)
(let ((letter (string-to-char (word-before-point))))
(if (and (eq letter (upcase letter))
(not (eq (char-before) (upcase (char-before)))))
(capitalize-word -1))))
(add-to-list 'after-change-functions 'blah)
Upvotes: 3
Reputation: 29772
Here's a command that will convert to lowercase the second letter of each word if the first letter is uppercase and all other letters in the word are lowercase:
(defun fix-double-uppercase-at-start-of-words ()
(interactive)
(let ((case-fold-search nil))
(save-match-data
(while (re-search-forward "\\b\\([[:upper:]]\\)\\([[:upper:]]\\)\\([[:lower:]]*\\)\\b" nil t)
(replace-match (concat (match-string 1)
(downcase (match-string 2))
(match-string 3))
t)))))
The command will work on all words from the current cursor position to the (visible) end of the buffer.
Upvotes: 3