From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Johnny Newsgroups: gmane.emacs.help Subject: Re: Randomly capitalise letters Date: Fri, 23 Nov 2012 00:18:57 +0000 Message-ID: <87ip8xp3wu.fsf@gmx.co.uk> References: <87a9u9qsq0.fsf@gmx.co.uk> <871uflqs2l.fsf@gmx.co.uk> <87mwy98gs5.fsf@samograd.ca> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1353629955 15290 80.91.229.3 (23 Nov 2012 00:19:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Nov 2012 00:19:15 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Burton Samograd Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 23 01:19:26 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 1TbgzN-00050i-Mg for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Nov 2012 01:19:25 +0100 Original-Received: from localhost ([::1]:38503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbgzD-0002eS-3s for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Nov 2012 19:19:15 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:55394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbgz3-0002e4-Ao for help-gnu-emacs@gnu.org; Thu, 22 Nov 2012 19:19:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tbgyz-0007Td-2U for help-gnu-emacs@gnu.org; Thu, 22 Nov 2012 19:19:05 -0500 Original-Received: from mailout-eu.gmx.com ([213.165.64.43]:53236) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Tbgyy-0007TG-OE for help-gnu-emacs@gnu.org; Thu, 22 Nov 2012 19:19:01 -0500 Original-Received: (qmail invoked by alias); 23 Nov 2012 00:18:58 -0000 Original-Received: from host86-190-100-85.wlms-broadband.com (EHLO deusexmachina) [86.190.100.85] by mail.gmx.com (mp-eu003) with SMTP; 23 Nov 2012 01:18:58 +0100 X-Authenticated: #57368918 X-Provags-ID: V01U2FsdGVkX19u+uJl+UpuPvDBA7sxLCjZo1J1QUH8fTw2aIY3xW QDiPArYOqERX3+ In-Reply-To: <87mwy98gs5.fsf@samograd.ca> (Burton Samograd's message of "Thu, 22 Nov 2012 14:32:58 -0700") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 213.165.64.43 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:87854 Archived-At: Burton Samograd writes: > 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)))) > Thanks, works great! -- Johnny