Some fixes to follow coding conventions.
[bpt/emacs.git] / lisp / play / 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 ;; This file is part of GNU Emacs.
7
8 ;; Keywords: games
9
10 ;;; Commentary:
11
12 ;; Functions to studlycapsify a region, word, or buffer. Possibly the
13 ;; esoteric significance of studlycapsification escapes you; that is,
14 ;; you suffer from autostudlycapsifibogotification. Too bad.
15
16 ;;; Code:
17
18 ;;;###autoload
19 (defun studlify-region (begin end)
20 "Studlify-case the region"
21 (interactive "*r")
22 (save-excursion
23 (goto-char begin)
24 (setq begin (point))
25 (while (and (<= (point) end)
26 (not (looking-at "\\W*\\'")))
27 (forward-word 1)
28 (backward-word 1)
29 (setq begin (max (point) begin))
30 (forward-word 1)
31 (let ((offset 0)
32 (word-end (min (point) end))
33 c)
34 (goto-char begin)
35 (while (< (point) word-end)
36 (setq offset (+ offset (following-char)))
37 (forward-char 1))
38 (setq offset (+ offset (following-char)))
39 (goto-char begin)
40 (while (< (point) word-end)
41 (setq c (following-char))
42 (if (and (= (% (+ c offset) 4) 2)
43 (let ((ch (following-char)))
44 (or (and (>= ch ?a) (<= ch ?z))
45 (and (>= ch ?A) (<= ch ?Z)))))
46 (progn
47 (delete-char 1)
48 (insert (logxor c ? ))))
49 (forward-char 1))
50 (setq begin (point))))))
51
52 ;;;###autoload
53 (defun studlify-word (count)
54 "Studlify-case the current word, or COUNT words if given an argument"
55 (interactive "*p")
56 (let ((begin (point)) end rb re)
57 (forward-word count)
58 (setq end (point))
59 (setq rb (min begin end) re (max begin end))
60 (studlify-region rb re)))
61
62 (defun studlify-buffer ()
63 "Studlify-case the current buffer"
64 (interactive "*")
65 (studlify-region (point-min) (point-max)))
66
67 (provide 'studly)
68
69 ;;; studly.el ends here