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 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 2, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; Converts text to Morse code and back with M-x morse-region and
29 ;; M-x unmorse-region (though Morse code is no longer official :-().
33 (defvar morse-code
'(("a" .
".-")
86 ;; ligature character?? ("Ch" . "----")
93 ;; Recently standardized
95 "Morse code character set.")
98 (defun morse-region (beg end
)
99 "Convert all text in a given region to morse code."
102 (setq end
(copy-marker end
)))
107 (while (< (point) end
)
108 (setq str
(downcase (buffer-substring (point) (1+ (point)))))
109 (cond ((looking-at "\\s-+")
110 (goto-char (match-end 0))
112 ((setq morse
(assoc str morse-code
))
114 (insert sep
(cdr morse
))
121 (defun unmorse-region (beg end
)
122 "Convert morse coded text in region to ordinary ASCII text."
125 (setq end
(copy-marker end
)))
127 (let (str paren morse
)
129 (while (< (point) end
)
130 (if (null (looking-at "[-.]+"))
132 (setq str
(buffer-substring (match-beginning 0) (match-end 0)))
133 (if (null (setq morse
(rassoc str morse-code
)))
134 (goto-char (match-end 0))
136 (if (string-equal "(" (car morse
))
137 (if (setq paren
(null paren
)) "(" ")")
140 (delete-char 1))))))))
144 ;;; arch-tag: 3331e6c1-9a9e-453f-abfd-163a9c3f93a6
145 ;;; morse.el ends here