studly.el 1.8 KB

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