From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Burton Samograd Newsgroups: gmane.emacs.help Subject: Re: Randomly capitalise letters Date: Thu, 22 Nov 2012 14:32:58 -0700 Message-ID: <87mwy98gs5.fsf@samograd.ca> References: <87a9u9qsq0.fsf@gmx.co.uk> <871uflqs2l.fsf@gmx.co.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1353621449 16496 80.91.229.3 (22 Nov 2012 21:57:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Nov 2012 21:57:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 22 22:57:38 2012 Return-path: Envelope-to: geh-help-gnu-emacs@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 1Tbem9-0006ua-N7 for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Nov 2012 22:57:37 +0100 Original-Received: from localhost ([::1]:49944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbelz-00041U-3j for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Nov 2012 16:57:27 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:43425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbelt-00041N-Sn for help-gnu-emacs@gnu.org; Thu, 22 Nov 2012 16:57:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tbels-0006SI-L8 for help-gnu-emacs@gnu.org; Thu, 22 Nov 2012 16:57:21 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:35768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbels-0006SE-EX for help-gnu-emacs@gnu.org; Thu, 22 Nov 2012 16:57:20 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Tbem0-0006ok-Q6 for help-gnu-emacs@gnu.org; Thu, 22 Nov 2012 22:57:28 +0100 Original-Received: from samograd.ca ([69.90.114.176]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 22 Nov 2012 22:57:28 +0100 Original-Received: from burton by samograd.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 22 Nov 2012 22:57:28 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 43 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: samograd.ca User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:GD9RFBKggzr/omm17jD3el3kID0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87852 Archived-At: 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 (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)))) -- Burton Samograd