[Top][All Lists]

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

Re: Randomly capitalise letters

From: Burton Samograd
Subject: Re: Randomly capitalise letters
Date: Thu, 22 Nov 2012 14:32:58 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Johnny <> writes:

> Johnny <> 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
  ;; Do the upcasing
  (let ((start (point))
        (end (progn 
    (goto-char start)
    (while (not (= start end))
      (if (= 0 (random downcase-factor))
          (upcase-region start (1+ start)))
      (incf start))))

Burton Samograd

reply via email to

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