annotate lisp/play/morse.el @ 112445:93fcbcb698b0

Improve configuration of makeinfo. * Makefile.in (MAKEINFO): Now controlled by `configure'. (MAKEINFO_OPTS): New variable. Use it where appropriate. (ENVADD): Updated.
author Werner Lemberg <wl@gnu.org>
date Sun, 23 Jan 2011 11:38:14 +0100
parents ef719132ddfa
children
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,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
4 ;; 2006, 2007, 2008, 2009, 2010, 2011 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
4eb58dc2c627 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;;; morse.el ends here