Initial Commit
[packages] / xemacs-packages / misc-games / studly.el
1 ;;; studly.el --- StudlyCaps (tm)(r)(c)(xxx)
2
3 ;; This is in the public domain, since it was distributed
4 ;; by its author without a copyright notice in 1986.
5
6 ;; Keywords: games
7
8 ;; This file is part of XEmacs.
9
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ;; 02111-1307, USA.
24
25 ;;; Synched up with: Not in FSF
26
27 ;;; Commentary:
28
29 ;; Functions to studlycapsify a region, word, or buffer.  Possibly the
30 ;; esoteric significance of studlycapsification escapes you; that is,
31 ;; you suffer from autostudlycapsifibogotification.  Too bad.
32
33 ;;; Code:
34
35 (defun studlify-region (begin end)
36   "Studlify-case the region"
37   (interactive "*r")
38   (save-excursion
39     (save-match-data
40       (goto-char begin)
41       (while (re-search-forward "\\w+" end t)
42         (let ((rnd (loop for pos from (match-beginning 0) to (match-end 0)
43                      sum (or (char-after pos) 0))))
44           (loop for pos from (match-beginning 0) to (1- (match-end 0)) do
45             (let ((c (char-after pos)))
46               (when (= (% (+ c rnd) 4) 2)
47                 (if (eq c (upcase c))
48                     (downcase-region pos (1+ pos))
49                   (upcase-region pos (1+ pos)))
50                 (incf pos)))))))))
51
52 (defun studlify-word (count)
53   "Studlify-case the current word, or COUNT words if given an argument"
54   (interactive "*p")
55   (let ((begin (point)) end rb re)
56     (forward-word count)
57     (setq end (point))
58     (setq rb (min begin end) re (max begin end))
59     (studlify-region rb re)))
60
61 (defun studlify-buffer ()
62   "Studlify-case the current buffer"
63   (interactive "*")
64   (studlify-region (point-min) (point-max)))
65
66 ;;; studly.el ends here