help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: title-case function


From: Paul W. Rankin
Subject: Re: title-case function
Date: Sun, 21 Apr 2019 16:40:55 +1000
User-agent: mu4e 1.0; emacs 26.2


On Sun, Apr 21 2019, Emanuel Berg wrote:
Did you look into this [2] ?
BTW make a search for "Emanuel Berg" :)

Ah right, no I didn't find that one. Nice.

Given that there are no definitive rules regarding title case minor words, I think I prefer using a defcustom for these (i.e. I wouldn't consider "over" or "past" as a minor words because they're four letters).

I've found thing-at-point to be quite resource hungry so I try to avoid using it unless absolutely necessary.

I am curious about the comparative performance of using (member WORDS) vs (looking-at (regexp-opt WORDS)).

       (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)))

It seems to work alright, but I don't
understand it? You don't need `progn' anymore?

The regexp "[:\x2013\x2014]" just looks for a colon, an en dash or an em dash and makes sure to capitalize a word following one of those. I used the character codes for the dashes because otherwise they're difficult to discern from hyphens in monospace.

Do you mean using progn for the ELSE in the if expression? From the documentation on `if':

(if COND THEN ELSE...)

THEN must be one expression, but ELSE... can be zero or more expressions.

So yeah, progn is unnecessary.

Thanks for the trance, but I'm already spending my rainy Easter day listening to this: https://www.discogs.com/Various-Dark-Was-The-Night/release/1655481

--
https://www.paulwrankin.com



reply via email to

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