annotate lisp/play/studly.el @ 157:01ad7ec29c98

Initial revision
author Jim Blandy <jimb@redhat.com>
date Sat, 05 Jan 1991 15:12:15 +0000
parents 9b11cd9e3ba8
children fec3f9a1e3e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;;; StudlyCaps (tm)(r)(c)(xxx)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 (defun studlify-region (begin end)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 "Studlify-case the region"
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 (interactive "*r")
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 (save-excursion
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 (goto-char begin)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 (setq begin (point))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 (while (and (<= (point) end)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 (not (looking-at "\\W*\\'")))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 (forward-word 1)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 (backward-word 1)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 (setq begin (max (point) begin))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 (forward-word 1)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 (let ((offset 0)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 (word-end (min (point) end))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 c)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 (goto-char begin)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 (while (< (point) word-end)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 (setq offset (+ offset (following-char)))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 (forward-char 1))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 (setq offset (+ offset (following-char)))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 (goto-char begin)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 (while (< (point) word-end)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 (setq c (following-char))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 (if (and (= (% (+ c offset) 4) 2)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 (let ((ch (following-char)))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 (or (and (>= ch ?a) (<= ch ?z))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 (and (>= ch ?A) (<= ch ?Z)))))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 (progn
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 (delete-char 1)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 (insert (logxor c ? ))))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 (forward-char 1))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 (setq begin (point))))))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 (defun studlify-word (count)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 "Studlify-case the current word, or COUNT words if given an argument"
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 (interactive "*p")
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 (let ((begin (point)) end rb re)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 (forward-word count)
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (setq end (point))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 (setq rb (min begin end) re (max begin end))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (studlify-region rb re)))
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 (defun studlify-buffer ()
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 "Studlify-case the current buffer"
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (interactive "*")
9b11cd9e3ba8 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 (studlify-region (point-min) (point-max)))