[parent not found: <mailman.13578.1353617204.855.help-gnu-emacs@gnu.org>]
* Re: Randomly capitalise letters
[not found] <mailman.13578.1353617204.855.help-gnu-emacs@gnu.org>
@ 2012-11-22 21:42 ` Pascal J. Bourguignon
2012-11-23 0:20 ` Johnny
2012-11-26 18:13 ` Sean McAfee
0 siblings, 2 replies; 11+ messages in thread
From: Pascal J. Bourguignon @ 2012-11-22 21:42 UTC (permalink / raw)
To: help-gnu-emacs
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 {}.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Randomly capitalise letters
2012-11-22 21:42 ` Pascal J. Bourguignon
@ 2012-11-23 0:20 ` Johnny
2012-11-26 18:13 ` Sean McAfee
1 sibling, 0 replies; 11+ messages in thread
From: Johnny @ 2012-11-23 0:20 UTC (permalink / raw)
To: Pascal J. Bourguignon; +Cc: help-gnu-emacs
"Pascal J. Bourguignon" <pjb@informatimago.com> 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.
>
> 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.
Thanks Pascal, I will check out the links to try to learn some lisp,
it's long overdue!
All the best,
--
Johnny
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Randomly capitalise letters
2012-11-22 21:42 ` Pascal J. Bourguignon
2012-11-23 0:20 ` Johnny
@ 2012-11-26 18:13 ` Sean McAfee
2012-11-27 2:30 ` Stefan Monnier
1 sibling, 1 reply; 11+ messages in thread
From: Sean McAfee @ 2012-11-26 18:13 UTC (permalink / raw)
To: help-gnu-emacs
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
> (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)))))))
It's worth noting that if you regularly use Emacs for producing random
numbers, you probably want to put "(random t)" in your .emacs file to
seed the random number generator. I once wrote some routines to
generate random events for an online game I was running, and it took a
little while for me to notice that the same events were regularly
occurring in the same order every morning.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Randomly capitalise letters
@ 2012-11-22 20:37 Johnny
2012-11-22 20:51 ` Johnny
0 siblings, 1 reply; 11+ messages in thread
From: Johnny @ 2012-11-22 20:37 UTC (permalink / raw)
To: help-gnu-emacs
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!
--
Johnny
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Randomly capitalise letters
2012-11-22 20:37 Johnny
@ 2012-11-22 20:51 ` Johnny
2012-11-22 21:32 ` Burton Samograd
0 siblings, 1 reply; 11+ messages in thread
From: Johnny @ 2012-11-22 20:51 UTC (permalink / raw)
To: help-gnu-emacs
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).
--
Johnny
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Randomly capitalise letters
2012-11-22 20:51 ` Johnny
@ 2012-11-22 21:32 ` Burton Samograd
2012-11-23 0:18 ` Johnny
2012-11-23 2:30 ` Stefan Monnier
0 siblings, 2 replies; 11+ messages in thread
From: Burton Samograd @ 2012-11-22 21:32 UTC (permalink / raw)
To: help-gnu-emacs
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))))
--
Burton Samograd
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Randomly capitalise letters
2012-11-22 21:32 ` Burton Samograd
@ 2012-11-23 0:18 ` Johnny
2012-11-23 2:30 ` Stefan Monnier
1 sibling, 0 replies; 11+ messages in thread
From: Johnny @ 2012-11-23 0:18 UTC (permalink / raw)
To: Burton Samograd; +Cc: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Randomly capitalise letters
2012-11-22 21:32 ` Burton Samograd
2012-11-23 0:18 ` Johnny
@ 2012-11-23 2:30 ` Stefan Monnier
2012-11-23 15:22 ` Burton Samograd
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2012-11-23 2:30 UTC (permalink / raw)
To: help-gnu-emacs
> (while (not (= start end))
> (if (= 0 (random downcase-factor))
> (upcase-region start (1+ start)))
> (incf start))))
You could speed it up with something like
(while (< start end)
(upcase-region start (1+ start))
(incf start (+ 1 (random downcase-factor))))
-- Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Randomly capitalise letters
2012-11-23 2:30 ` Stefan Monnier
@ 2012-11-23 15:22 ` Burton Samograd
0 siblings, 0 replies; 11+ messages in thread
From: Burton Samograd @ 2012-11-23 15:22 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (while (not (= start end))
>> (if (= 0 (random downcase-factor))
>> (upcase-region start (1+ start)))
>> (incf start))))
>
> You could speed it up with something like
>
> (while (< start end)
> (upcase-region start (1+ start))
> (incf start (+ 1 (random downcase-factor))))
Good idea in case you want to random-case 'War and Peace' :)
--
Burton Samograd
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-11-29 3:22 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.13892.1353983463.855.help-gnu-emacs@gnu.org>
2012-11-29 3:22 ` Randomly capitalise letters jidanni
[not found] <mailman.13578.1353617204.855.help-gnu-emacs@gnu.org>
2012-11-22 21:42 ` Pascal J. Bourguignon
2012-11-23 0:20 ` Johnny
2012-11-26 18:13 ` Sean McAfee
2012-11-27 2:30 ` Stefan Monnier
2012-11-22 20:37 Johnny
2012-11-22 20:51 ` Johnny
2012-11-22 21:32 ` Burton Samograd
2012-11-23 0:18 ` Johnny
2012-11-23 2:30 ` Stefan Monnier
2012-11-23 15:22 ` Burton Samograd
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.