1 ;;; morse.el --- convert text to morse code and back -*- coding: utf-8 -*-
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Rick Farnbach <rick_farnbach@MENTORG.COM>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Converts text to Morse code and back with M-x morse-region and
27 ;; M-x unmorse-region (though Morse code is no longer official :-().
31 (defvar morse-code
'(("a" .
".-")
84 ;; ligature character?? ("Ch" . "----")
91 ;; Recently standardized
93 "Morse code character set.")
96 (defun morse-region (beg end
)
97 "Convert all text in a given region to morse code."
100 (setq end
(copy-marker end
)))
105 (while (< (point) end
)
106 (setq str
(downcase (buffer-substring (point) (1+ (point)))))
107 (cond ((looking-at "\\s-+")
108 (goto-char (match-end 0))
110 ((setq morse
(assoc str morse-code
))
112 (insert sep
(cdr morse
))
119 (defun unmorse-region (beg end
)
120 "Convert morse coded text in region to ordinary ASCII text."
123 (setq end
(copy-marker end
)))
125 (let (str paren morse
)
127 (while (< (point) end
)
128 (if (null (looking-at "[-.]+"))
130 (setq str
(buffer-substring (match-beginning 0) (match-end 0)))
131 (if (null (setq morse
(rassoc str morse-code
)))
132 (goto-char (match-end 0))
134 (if (string-equal "(" (car morse
))
135 (if (setq paren
(null paren
)) "(" ")")
138 (delete-char 1))))))))
142 ;; arch-tag: 3331e6c1-9a9e-453f-abfd-163a9c3f93a6
143 ;;; morse.el ends here