From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Paul W. Rankin" Newsgroups: gmane.emacs.help Subject: title-case function Date: Sun, 21 Apr 2019 13:56:26 +1000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="106462"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: mu4e 1.0; emacs 26.2 To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 21 06:36:04 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 1hI4Cw-000RPd-V3 for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 06:36:04 +0200 Original-Received: from localhost ([127.0.0.1]:48762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hI4Cv-0000zX-AA for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 00:36:01 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:40251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hI4Ck-0000zE-7g for help-gnu-emacs@gnu.org; Sun, 21 Apr 2019 00:35:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hI4Cj-0003RC-6u for help-gnu-emacs@gnu.org; Sun, 21 Apr 2019 00:35:50 -0400 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:39831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hI4Ci-0003QK-UI for help-gnu-emacs@gnu.org; Sun, 21 Apr 2019 00:35:49 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 4D4E520D84 for ; Sun, 21 Apr 2019 00:35:47 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 21 Apr 2019 00:35:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paulwrankin.com; h=from:to:subject:date:message-id:mime-version:content-type; s= fm3; bh=rqeQTLXhSBBYqt29hOkp5z62VR8EIYiIgLSj2H9bfhI=; b=eoykLE55 tsOa9ktWZwQhiNP0gNgMTAYBCrpTqD9dFsa9Lk+FVraWvG2WwWXlXejoRA1kEH1h T5a+KKiahnuKw3BqTAk+6fRvsSHkyabj1iXgw4OT5Usa760QqcswfOTF1JuSiwdk u5EM+KsHZMZua4AZuz3Yynrb+9pRjufXTvJ/L50Ixdt19PQ2GWJbS8s+ILX42qiq ldDlxTdVZbS+FNvH4c0gwoEUMDS0caCMwNvy8ecdH2uinPNuOhWPCYsdAzKtEXjP jt5skd3sKsG+bOpfDxAlqqJPTOcyc4aqC7kjMKzbhabmoJt+EB6jJ8tWTKJrQfwf xmWFgYsYAdusjQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=rqeQTLXhSBBYqt29hOkp5z62VR8EI YiIgLSj2H9bfhI=; b=D2/TuLZbDbNoTsl49jnSXDicKq0hQ9utYoyLp4BuMfj8W asuuR2HATd6n7lYD6t3yeeCplJAKWcUDIgwLq1wp9URafiF55Dmmx8qoGDn3fLTB j2u4XDkpbMGTSDBwUxNtaSHPR1hDRKYiZcXLZyRatLzNN9Kc67hvFY+E6pV6oKNw wGReRIcEcGpdzgTj2wMbcRo2WFfbGIIaB5dpf3ZSM0E+tZBc4/aR6Ga2tKkZzLH3 g4vJ4osgBajUfSdyJarBivxulbJEHg8KAt3ozPRjoQdsASK1HvRVH02xFUxe6IRY S/s39SnKkCE8sOLh9LvoJMxKEWjxk62BJH3xohSpw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrgedvgdegiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfgfhvffufffkgggtsehttdertddtre dtnecuhfhrohhmpedfrfgruhhlucghrdcutfgrnhhkihhnfdcuoehhvghllhhosehprghu lhifrhgrnhhkihhnrdgtohhmqeenucffohhmrghinhepphgruhhlfihrrghnkhhinhdrtg homhenucfkphepuddvtddrvddvrddutdekrddufeelnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehhvghllhhosehprghulhifrhgrnhhkihhnrdgtohhmnecuvehluhhsthgvrhfuih iivgeptd X-ME-Proxy: Original-Received: from localhost (unknown [120.22.108.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 89596E41A1 for ; Sun, 21 Apr 2019 00:35:44 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 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:120001 Archived-At: Happy Easter to those who celebrate it! 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. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (defcustom title-case-minor-words '("the ""a" "an" "and" "but" "for" "of" "or" "nor" "is" "as" "in" "to" "into" "v" "vs" "de") "List of minor 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-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-words) "\\b")) (downcase-word 1) (capitalize-word 1))))))) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- https://www.paulwrankin.com