unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Barry Fishman <barry_fishman@acm.org>
To: emacs-devel@gnu.org
Subject: Re: Proper English Title Capitalization
Date: Tue, 26 May 2015 11:38:45 -0400	[thread overview]
Message-ID: <m37frv2vsq.fsf@barry_fishman.acm.org> (raw)
In-Reply-To: 2015-05-25T12-45-36@devnull.Karl-Voit.at


On 2015-05-25 12:47:51 +0200, Karl Voit wrote:
> * Karl Voit <devnull@Karl-Voit.at> 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)
> |       )
> |     ))
> `----

If you are looking for more alternative coding:

--8<---------------cut here---------------start------------->8---
;; This is probably subject for debate and tuning.
(defvar own-stop-words '("a" "an" "the" "at" "by" "for" "in"
                         "of" "on" "to" "up" "and" "as" "but"
                         "it" "or" "nor" "n" "t" "es" "s")
  "Words that are not capitalized in titles.")

(defun own-title-region (beg end)
  "Capitalize region as a title,"
  (interactive "r")
  (save-excursion
    (goto-char beg)
    (capitalize-word 1)
    (while (< (point) end)
      (skip-syntax-forward "^w" end)
      (let ((word (thing-at-point 'word t)))
        (if (stringp word)
            (if (member (downcase word) own-stop-words)
                (downcase-word 1)
              (capitalize-word 1)))))
    (backward-word 1)
    (if (and (>= (point) beg)
             (not (member (or (thing-at-point 'word t) "s")
                          '("n" "t" "es" "s"))))
        (capitalize-word 1))))
--8<---------------cut here---------------end--------------->8---

--
Barry Fishman




  parent reply	other threads:[~2015-05-26 15:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-24 11:10 Proper English Title Capitalization Karl Voit
2015-05-24 21:00 ` Emanuel Berg
2015-05-25 10:13   ` Karl Voit
2015-05-25 10:36     ` Rasmus
2015-05-25 10:47     ` Karl Voit
2015-05-25 12:22       ` Karl Voit
2015-05-25 16:18         ` Rasmus
2015-05-26 15:38       ` Barry Fishman [this message]
2015-06-11 20:10         ` Karl Voit
2015-06-03 15:05       ` Karl Voit
2015-05-25 16:59     ` Emanuel Berg
2015-06-17 13:48 ` Karl Voit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m37frv2vsq.fsf@barry_fishman.acm.org \
    --to=barry_fishman@acm.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).