*** empty log message ***
[bpt/emacs.git] / lisp / play / studly.el
1 ;;; studly.el --- StudlyCaps (tm)(r)(c)(xxx)
2
3 ;; Maintainer: FSF
4 ;; Keywords: games
5
6 ;;; This is in the public domain, since it was distributed
7 ;;; by its author without a copyright notice in 1986.
8
9 ;;; Code:
10
11 (defun studlify-region (begin end)
12 "Studlify-case the region"
13 (interactive "*r")
14 (save-excursion
15 (goto-char begin)
16 (setq begin (point))
17 (while (and (<= (point) end)
18 (not (looking-at "\\W*\\'")))
19 (forward-word 1)
20 (backward-word 1)
21 (setq begin (max (point) begin))
22 (forward-word 1)
23 (let ((offset 0)
24 (word-end (min (point) end))
25 c)
26 (goto-char begin)
27 (while (< (point) word-end)
28 (setq offset (+ offset (following-char)))
29 (forward-char 1))
30 (setq offset (+ offset (following-char)))
31 (goto-char begin)
32 (while (< (point) word-end)
33 (setq c (following-char))
34 (if (and (= (% (+ c offset) 4) 2)
35 (let ((ch (following-char)))
36 (or (and (>= ch ?a) (<= ch ?z))
37 (and (>= ch ?A) (<= ch ?Z)))))
38 (progn
39 (delete-char 1)
40 (insert (logxor c ? ))))
41 (forward-char 1))
42 (setq begin (point))))))
43
44 (defun studlify-word (count)
45 "Studlify-case the current word, or COUNT words if given an argument"
46 (interactive "*p")
47 (let ((begin (point)) end rb re)
48 (forward-word count)
49 (setq end (point))
50 (setq rb (min begin end) re (max begin end))
51 (studlify-region rb re)))
52
53 (defun studlify-buffer ()
54 "Studlify-case the current buffer"
55 (interactive "*")
56 (studlify-region (point-min) (point-max)))
57
58 ;;; studly.el ends here