[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Randomly capitalise letters
From: |
Johnny |
Subject: |
Re: Randomly capitalise letters |
Date: |
Fri, 23 Nov 2012 00:18:57 +0000 |
User-agent: |
Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1 (gnu/linux) |
Burton Samograd <burton@samograd.ca> writes:
> Johnny <yggdrasil@gmx.co.uk> writes:
>
>> Johnny <yggdrasil@gmx.co.uk> writes:
>>
>>> Hi all,
>>>
>>> I am looking for a way to randomly capitalise letters in a word or a
>>> region, but haven't found anything in the manual or online (someone must
>>> have had this odd idea before I am sure!). Any help on how to achieve
>>> this would be great! For clarity, I'd like to AchiEVe soMeTHiNg LIke
>>> thIs.
>>>
>>>
>>> Thanks!
>>
>> P.S.
>> I have tried 'studlify-region', but this seems to be a
>> deterministic function and does not set case randomly (as seen by
>> repeating the command on the same region).
>
> This should work but you should (require 'cl) first:
>
> (defun random-upcase-letters (downcase-factor)
> "Randomly upper case letters in the current/next word.
> Downcase factor is tied to how many letters are left
> lower case; use 2 for 50/50 probabilty, 3 for 66/33, etc."
> (interactive "P")
> ;; Move to the start of the next word
> (forward-word)
> (backward-word)
> ;; Do the upcasing
> (let ((start (point))
> (end (progn
> (forward-word)
> (point))))
> (goto-char start)
> (while (not (= start end))
> (if (= 0 (random downcase-factor))
> (upcase-region start (1+ start)))
> (incf start))))
>
Thanks, works great!
--
Johnny