annotate lisp/play/morse.el @ 100336:d53183123ad7

* font.c (Ffont_spec): Move usage to end of docstring.
author Juanma Barranquero <lekktu@gmail.com>
date Wed, 10 Dec 2008 19:25:26 +0000
parents 949bd6ad1ba4
children a9dc0e7c3f2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48494
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
1 ;;; morse.el --- convert text to morse code and back -*- coding: utf-8 -*-
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
74509
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68634
diff changeset
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005,
79716
54006a859bcc Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78227
diff changeset
4 ;; 2006, 2007, 2008 Free Software Foundation, Inc.
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: Rick Farnbach <rick_farnbach@MENTORG.COM>
32298
f3d3118f2946 (morse-region, unmorse-region): Add autoload
Dave Love <fx@gnu.org>
parents: 14169
diff changeset
7 ;; Keywords: games
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
32298
f3d3118f2946 (morse-region, unmorse-region): Add autoload
Dave Love <fx@gnu.org>
parents: 14169
diff changeset
24 ;;; Commentary:
f3d3118f2946 (morse-region, unmorse-region): Add autoload
Dave Love <fx@gnu.org>
parents: 14169
diff changeset
25
54081
58125578390a Fix typo.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
26 ;; Converts text to Morse code and back with M-x morse-region and
32298
f3d3118f2946 (morse-region, unmorse-region): Add autoload
Dave Love <fx@gnu.org>
parents: 14169
diff changeset
27 ;; M-x unmorse-region (though Morse code is no longer official :-().
f3d3118f2946 (morse-region, unmorse-region): Add autoload
Dave Love <fx@gnu.org>
parents: 14169
diff changeset
28
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; Code:
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (defvar morse-code '(("a" . ".-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ("b" . "-...")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ("c" . "-.-.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ("d" . "-..")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ("e" . ".")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ("f" . "..-.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ("g" . "--.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ("h" . "....")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ("i" . "..")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ("j" . ".---")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ("k" . "-.-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ("l" . ".-..")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ("m" . "--")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ("n" . "-.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ("o" . "---")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ("p" . ".--.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ("q" . "--.-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ("r" . ".-.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ("s" . "...")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ("t" . "-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ("u" . "..-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ("v" . "...-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ("w" . ".--")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ("x" . "-..-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ("y" . "-.--")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ("z" . "--..")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; Punctuation
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ("=" . "-...-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ("?" . "..--..")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ("/" . "-..-.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ("," . "--..--")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ("." . ".-.-.-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (":" . "---...")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ("'" . ".----.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ("-" . "-....-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ("(" . "-.--.-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (")" . "-.--.-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; Numbers
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ("0" . "-----")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ("1" . ".----")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ("2" . "..---")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ("3" . "...--")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ("4" . "....-")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ("5" . ".....")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ("6" . "-....")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ("7" . "--...")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ("8" . "---..")
48494
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
78 ("9" . "----.")
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
79 ;; Non-ASCII
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
80 ("Ä" . ".-.-")
48496
07981d5d6992 (morse-code): Add Norwegian non-ASCII characters.
Simon Josefsson <jas@extundo.com>
parents: 48494
diff changeset
81 ("Æ" . ".-.-")
48494
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
82 ("Á" . ".--.-")
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
83 ("Å" . ".--.-")
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
84 ;; ligature character?? ("Ch" . "----")
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
85 ("ß" . ".../...")
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
86 ("É" . "..-..")
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
87 ("Ñ" . "--.--")
f07e2528571d (morse-code): Add non-ASCII characters, according
Simon Josefsson <jas@extundo.com>
parents: 38425
diff changeset
88 ("Ö" . "---.")
48496
07981d5d6992 (morse-code): Add Norwegian non-ASCII characters.
Simon Josefsson <jas@extundo.com>
parents: 48494
diff changeset
89 ("Ø" . "---.")
54081
58125578390a Fix typo.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
90 ("Ü" . "..--")
58125578390a Fix typo.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
91 ;; Recently standardized
58125578390a Fix typo.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
92 ("@" . ".--.-."))
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 "Morse code character set.")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
32298
f3d3118f2946 (morse-region, unmorse-region): Add autoload
Dave Love <fx@gnu.org>
parents: 14169
diff changeset
95 ;;;###autoload
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (defun morse-region (beg end)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 "Convert all text in a given region to morse code."
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (interactive "r")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (if (integerp end)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (setq end (copy-marker end)))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (save-excursion
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (let ((sep "")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 str morse)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (goto-char beg)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (while (< (point) end)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (setq str (downcase (buffer-substring (point) (1+ (point)))))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (cond ((looking-at "\\s-+")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (goto-char (match-end 0))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (setq sep ""))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ((setq morse (assoc str morse-code))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (delete-char 1)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (insert sep (cdr morse))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (setq sep "/"))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (t
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (forward-char 1)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (setq sep "")))))))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
32298
f3d3118f2946 (morse-region, unmorse-region): Add autoload
Dave Love <fx@gnu.org>
parents: 14169
diff changeset
118 ;;;###autoload
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defun unmorse-region (beg end)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "Convert morse coded text in region to ordinary ASCII text."
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (interactive "r")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (if (integerp end)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (setq end (copy-marker end)))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (save-excursion
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (let (str paren morse)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (goto-char beg)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (while (< (point) end)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (if (null (looking-at "[-.]+"))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (forward-char 1)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (setq str (buffer-substring (match-beginning 0) (match-end 0)))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (if (null (setq morse (rassoc str morse-code)))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (goto-char (match-end 0))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (replace-match
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (if (string-equal "(" (car morse))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (if (setq paren (null paren)) "(" ")")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (car morse)) t)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (if (looking-at "/")
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (delete-char 1))))))))
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (provide 'morse)
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79716
diff changeset
142 ;; arch-tag: 3331e6c1-9a9e-453f-abfd-163a9c3f93a6
13651
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;;; morse.el ends here