[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Randomly capitalise letters
From: |
Pascal J. Bourguignon |
Subject: |
Re: Randomly capitalise letters |
Date: |
Thu, 22 Nov 2012 22:42:49 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
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.
That's not a library command, that's for sure, but it's easy to write
it. You can learn how to configure emacs to do this kind of things by
reading:
An Introduction to Programming in Emacs Lisp
http://www.gnu.org/software/emacs/emacs-lisp-intro/ or M-: (info
"(eintr)Top") RET
(for non programmers)
Emacs Lisp Manual
http://www.gnu.org/software/emacs/manual/elisp.html or M-: (info
"(elisp)Top") RET
Emacs Manual
http://www.gnu.org/software/emacs/manual/ or M-: (info "(emacs)Top") RET
For example, you could write:
(defun capitalize-randomly (start end)
(interactive "r")
(goto-char start)
(while (< (point) end)
(let ((ch (char-after (point))))
(delete-region (point) (1+ (point)))
(insert (format "%c" (if (zerop (random 2))
(upcase ch)
(downcase ch)))))))
So with M-x capitalize-randomly RET you can get something like:
> 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.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.