emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper English Title Capitalization


From: Karl Voit
Subject: Re: Proper English Title Capitalization
Date: Mon, 25 May 2015 12:47:51 +0200
User-agent: slrn/pre1.0.0-18 (Linux)

* Karl Voit <address@hidden> wrote:
>
> My Elisp knowledge is sufficient to modify your code so that it
> should get the job done:

I have to post a corrected version of the code which also handles
the edge case "a a a a a" (a do-not-capitalize word as second word)
properly:

,----
| (defun my-title-capitalization (beg end)
|   (interactive "r")
|   (save-excursion
|     (let (
|       (do-not-capitalize '("a" "ago" "an" "and" "as" "at" "but" "by" "for"
|                    "from" "in" "into" "it" "next" "nor" "of" "off"
|                    "on" "onto" "or" "over" "past" "so" "the" "till"
|                    "to" "up" "yet" ))
|       )
|       ;; go to begin of first word:
|       (goto-char beg)
|       (forward-word)
|       (backward-word)
|       ;; capitalize first word in any case:
|       (capitalize-word 1)
|       (forward-word)
|       (backward-word)
|       (while (< (point) end)
|     ;; capitalize each word in between except it is list member:
|     (if (member (thing-at-point 'word t) do-not-capitalize)
|         (forward-word)
|       (capitalize-word 1) )
|     (forward-word)
|     (backward-word) )
|       ;; capitalize last word in any case:
|       (backward-word)
|       (capitalize-word 1)
|       )
|     ))
`----

-- 
All in all, one of the most disturbing things today is the definitive
fact that the NSA, GCHQ, and many more government organizations are
massively terrorizing the freedom of us and the next generations.
                                                  http://Karl-Voit.at




reply via email to

[Prev in Thread] Current Thread [Next in Thread]