]> code.delx.au - gnu-emacs/blob - lisp/play/studly.el
*** empty log message ***
[gnu-emacs] / lisp / play / studly.el
1 ;;; studly.el --- StudlyCaps (tm)(r)(c)(xxx)
2
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
10 ;; any later version.
11
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 (defun studlify-region (begin end)
22 "Studlify-case the region"
23 (interactive "*r")
24 (save-excursion
25 (goto-char begin)
26 (setq begin (point))
27 (while (and (<= (point) end)
28 (not (looking-at "\\W*\\'")))
29 (forward-word 1)
30 (backward-word 1)
31 (setq begin (max (point) begin))
32 (forward-word 1)
33 (let ((offset 0)
34 (word-end (min (point) end))
35 c)
36 (goto-char begin)
37 (while (< (point) word-end)
38 (setq offset (+ offset (following-char)))
39 (forward-char 1))
40 (setq offset (+ offset (following-char)))
41 (goto-char begin)
42 (while (< (point) word-end)
43 (setq c (following-char))
44 (if (and (= (% (+ c offset) 4) 2)
45 (let ((ch (following-char)))
46 (or (and (>= ch ?a) (<= ch ?z))
47 (and (>= ch ?A) (<= ch ?Z)))))
48 (progn
49 (delete-char 1)
50 (insert (logxor c ? ))))
51 (forward-char 1))
52 (setq begin (point))))))
53
54 (defun studlify-word (count)
55 "Studlify-case the current word, or COUNT words if given an argument"
56 (interactive "*p")
57 (let ((begin (point)) end rb re)
58 (forward-word count)
59 (setq end (point))
60 (setq rb (min begin end) re (max begin end))
61 (studlify-region rb re)))
62
63 (defun studlify-buffer ()
64 "Studlify-case the current buffer"
65 (interactive "*")
66 (studlify-region (point-min) (point-max)))
67
68 ;;; studly.el ends here