1 ;;; morse.el --- Convert text to morse code and back.
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;; Author: Rick Farnbach <rick_farnbach@MENTORG.COM>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 (defvar morse-code
'(("a" .
".-")
74 "Morse code character set.")
76 (defun morse-region (beg end
)
77 "Convert all text in a given region to morse code."
80 (setq end
(copy-marker end
)))
85 (while (< (point) end
)
86 (setq str
(downcase (buffer-substring (point) (1+ (point)))))
87 (cond ((looking-at "\\s-+")
88 (goto-char (match-end 0))
90 ((setq morse
(assoc str morse-code
))
92 (insert sep
(cdr morse
))
98 (defun unmorse-region (beg end
)
99 "Convert morse coded text in region to ordinary ASCII text."
102 (setq end
(copy-marker end
)))
104 (let (str paren morse
)
106 (while (< (point) end
)
107 (if (null (looking-at "[-.]+"))
109 (setq str
(buffer-substring (match-beginning 0) (match-end 0)))
110 (if (null (setq morse
(rassoc str morse-code
)))
111 (goto-char (match-end 0))
113 (if (string-equal "(" (car morse
))
114 (if (setq paren
(null paren
)) "(" ")")
117 (delete-char 1))))))))
121 ;;; morse.el ends here