From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Jean-Christophe Helary Newsgroups: gmane.emacs.help Subject: Re: title-case function Date: Sun, 21 Apr 2019 14:57:36 +0900 Message-ID: <09C04C7E-B175-45A5-A4E1-4E5AC14B4B66@gmail.com> References: Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="52573"; mail-complaints-to="usenet@blaine.gmane.org" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 21 10:38:35 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hI7ze-000DW2-La for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 10:38:34 +0200 Original-Received: from localhost ([127.0.0.1]:50493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hI7zd-0006Tb-JM for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 04:38:33 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hI7zM-0006TT-Q7 for help-gnu-emacs@gnu.org; Sun, 21 Apr 2019 04:38:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hI7zL-0005bv-Qg for help-gnu-emacs@gnu.org; Sun, 21 Apr 2019 04:38:16 -0400 Original-Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:45135) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hI7zL-0005bK-H4 for help-gnu-emacs@gnu.org; Sun, 21 Apr 2019 04:38:15 -0400 Original-Received: by mail-pf1-x42a.google.com with SMTP id e24so4329137pfi.12 for ; Sun, 21 Apr 2019 01:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=og3+cDXTBtHpn0jjpSfYqEnxiLIYWFCU+ubA0QVFlcM=; b=CCi3EB0YvzIkb3esBtKVL81NW9DLNiBQCOZTQWIbP4m5Ss0VWmuGYEmeofKX++TJI2 hpdBzBctWfNOIAUUOojBVPGii4VSYQ9IsJoNbumu9lu3EtARszdge9Mxxt/3J3Cn0OOF OVaqpCsRU4XanTC2loBTIMP2D/S+zBvFoBPJ23cpP3uZfpmoWSEoQ+tVRyrxyhrLo3fv fiRi64OuX73h0aGCbX51KKtr1Nz3y7ptjzVOLQTBap7pJ++YbPjR2//iLOy7UFAcxr12 QhuZpEOD4wxDINEJyXdF/2Th1idY0/nyFPPAwouItzioESF+beGSFTCCQNpzhQT1xCZy 8fUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=og3+cDXTBtHpn0jjpSfYqEnxiLIYWFCU+ubA0QVFlcM=; b=sQN/F99eNjByCfo0C+BRocNS3gEWfM4O8fS26q4fN9yCYgmv4028nbIVAqo9LVbPj6 yzDurCsKJj0SmboNCnSxGPExJQUzmGCDfO+bKBjNtI5dGy+oUQ/oEjPcJBoTH38gW4BR 2ojx7xNfDnxF4TWnPNJlH2jy2WkXEPul3FvlNcxOAtDPqdlNN5q4LFBUEa35I9q70Jdm G2vjaKpupDnTAVb282NsB1rwRhQagJHkmNk8sSFRIIpWli4SH99ufToZzYziC3Kfm2fQ 1Mgd666tKrx4yogMKj2QDY87z3S8zBo7YEUnzrCMWgn0vYe434DafsqV5ITK+BQTfbft E/5A== X-Gm-Message-State: APjAAAVQQPTdAyPtFNJ1wJVvBwgd65DTdf3wAfPB8TNcE9oKDwXa1n4f XPKaJgHZVSzs0L3NKngdBk3t/jpX X-Google-Smtp-Source: APXvYqzdBwva42voO/+p53sD4nT3sD6gnOHl+jFSjyRnD/PwuqCOBhmRY6g8I/9DlHtmJ/f8J9qu1g== X-Received: by 2002:a63:f444:: with SMTP id p4mr13129944pgk.32.1555835893550; Sun, 21 Apr 2019 01:38:13 -0700 (PDT) Original-Received: from [192.168.1.3] (pl32040.ag0304.nttpc.ne.jp. [111.89.228.40]) by smtp.gmail.com with ESMTPSA id 10sm12995467pfh.14.2019.04.21.01.38.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Apr 2019 01:38:12 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3445.104.8) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42a X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120008 Archived-At: > On Apr 21, 2019, at 12:56, Paul W. Rankin = wrote: >=20 > Happy Easter to those who celebrate it! >=20 > I couldn't find a title-case function I considered good enough, so I = wrote the one below. Please take a look and let me know if there are any = edge cases I've missed or improvements you might have. I'm not aware that we have title-case needs in French, or in any other = language I know, but just as a precaution I renamed = "title-case-minor-words" to "title-case-minor-english-words". The day we have proper localization in Emacs we'll probably have a use = for that :) > = ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (defcustom title-case-minor-english-words '("the ""a" "an" "and" "but" "for" "of" "or" "nor" "is" "as" "in" "to" = "into" "v" "vs" "de") "List of minor English word strings that should be downcased in titles. These words should be less than four characters." :type '(repeat string) :group 'editing-basics) (defun title-case-region (beg end) "Convert region from BEG to END to Title Case. First and last words are capitalized unconditionally, as are words following colons and dashes. Words in list `title-case-minor-english-words' are downcased." (interactive "r") (save-excursion (let (last-word) (goto-char end) (forward-word -1) (setq last-word (point)) (capitalize-word 1) (goto-char beg) (unless (looking-at "\\b") (forward-word -1)) (capitalize-word 1) (while (< (point) last-word (point-max)) (if (looking-at "[:\x2013\x2014]") (capitalize-word 1) (skip-syntax-forward "-." last-word) (if (looking-at (concat "\\b" (regexp-opt = title-case-minor-english-words) "\\b")) (downcase-word 1) (capitalize-word 1))))))) Jean-Christophe Helary ----------------------------------------------- http://mac4translators.blogspot.com @brandelune