From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Fishman Newsgroups: gmane.emacs.devel Subject: Re: Proper English Title Capitalization Date: Tue, 26 May 2015 11:38:45 -0400 Message-ID: References: <2015-05-24T13-06-14@devnull.Karl-Voit.at> <87fv6lelmr.fsf@debian.uxu> <2015-05-25T12-05-49@devnull.Karl-Voit.at> <2015-05-25T12-45-36@devnull.Karl-Voit.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1432654763 22664 80.91.229.3 (26 May 2015 15:39:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 May 2015 15:39:23 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 26 17:39:14 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YxGwk-00022H-7n for ged-emacs-devel@m.gmane.org; Tue, 26 May 2015 17:39:14 +0200 Original-Received: from localhost ([::1]:48728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxGwj-0002AV-Er for ged-emacs-devel@m.gmane.org; Tue, 26 May 2015 11:39:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxGwc-00029X-Ef for emacs-devel@gnu.org; Tue, 26 May 2015 11:39:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxGwY-0005mA-7r for emacs-devel@gnu.org; Tue, 26 May 2015 11:39:06 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:52429) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxGwY-0005lh-0i for emacs-devel@gnu.org; Tue, 26 May 2015 11:39:02 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YxGwQ-0001qi-0v for emacs-devel@gnu.org; Tue, 26 May 2015 17:38:54 +0200 Original-Received: from fl-71-48-235-33.dhcp.embarqhsd.net ([71.48.235.33]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 26 May 2015 17:38:54 +0200 Original-Received: from barry_fishman by fl-71-48-235-33.dhcp.embarqhsd.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 26 May 2015 17:38:54 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 74 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: fl-71-48-235-33.dhcp.embarqhsd.net Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAALVBMVEXG87t8xXThBQWq85q9 87AvUC6PUVH/BgamyajC87a/87P////r6+ud7oq49KsBy7dJAAACKUlEQVQ4jc3Sv2vbQBQH 8CulwcEdeoOKwM1QD/bSzVktKDEdMpRqeMKQFNqAhEGbh3aVB5sDafAYL106xZMzuAiehnqI EciLMR2viz0Vor+hdydZMa6z97sI9NH7cYdI9ZGQr4/kP4Fu1akehFqHDaoHoOviPLD3oVtz 7PIErFCeeRdqOuvptwDMYSyfpKB7iYh3DOCTeOKzegGvk8hD1O22eD2B9tUWum9wbpXYy6NA wAzMeQFu1AeT2VAW0Af4sYUvfmRbCWLciXq0B2ZYf4C+GL/AGBIcOP4O4MzFKbiTAGOPYg7V mu1j5OIdfIgT7FtHGKoZIHKB6IuK9kDODpNsK0pPVnqCFbyFSyYWMMPnIA9CVsbm5l2HuRjZ FVERBXFPs8QQMhIZvqUX8jJmiTzIRy5FwWhEdAmR4y1KnQbn1KrnMOrLj6PPDnW8bw2+1K7I OINrecF9jwyJyBlfAvkzvlEy6DBHJ3m+8yU5HY9V0TWl+nALx+slMQTkRWKHQprEOJeST3qg p8RoHZRjsmm1ctrrJ0HkX0mFvG+uTnf7qe3SNG2dcc4bm70iAemaHxAJ91zF2G2noMl/UVVk bAoihgINlKwa6XkuhBsKGJgnPBuVEeG/5Wzqz3tZ0bYh4SsBS+qXZtTMRTWUcC/Bnybi7+R5 VoaAdZNz7ZU/RT8u2nEuQTw0VpmjH/7UChHQlFAGT1Rg8GS7Hcm+0F4EDgvYIohLAFS++wvs R0Pau3fdJgAAAABJRU5ErkJggg== User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux) Cancel-Lock: sha1:NVFJr3kT91SNb5B04MoXBx8CbD8= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:186817 Archived-At: On 2015-05-25 12:47:51 +0200, Karl Voit wrote: > * Karl Voit 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