annotate lisp/games/studly.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; studly.el --- StudlyCaps (tm)(r)(c)(xxx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; This is in the public domain, since it was distributed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; by its author without a copyright notice in 1986.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: games
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Functions to studlycapsify a region, word, or buffer. Possibly the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; esoteric significance of studlycapsification escapes you; that is,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; you suffer from autostudlycapsifibogotification. Too bad.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 (defun studlify-region (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 "Studlify-case the region"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 (interactive "*r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 (setq begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 (while (and (<= (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (not (looking-at "\\W*\\'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 (backward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (setq begin (max (point) begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (let ((offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (word-end (min (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (while (< (point) word-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (setq offset (+ offset (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (setq offset (+ offset (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (while (< (point) word-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (setq c (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (if (and (= (% (+ c offset) 4) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (let ((ch (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (or (and (>= ch ?a) (<= ch ?z))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (and (>= ch ?A) (<= ch ?Z)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (insert (logxor c ? ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (setq begin (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defun studlify-word (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "Studlify-case the current word, or COUNT words if given an argument"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (let ((begin (point)) end rb re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (forward-word count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq rb (min begin end) re (max begin end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (studlify-region rb re)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defun studlify-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "Studlify-case the current buffer"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (studlify-region (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; studly.el ends here