2015-09-28 22:39:14 +00:00
|
|
|
;;; morse.el --- convert text to morse code and back
|
1995-11-25 05:42:30 +00:00
|
|
|
|
2017-01-01 03:14:01 +00:00
|
|
|
;; Copyright (C) 1995, 2001-2017 Free Software Foundation, Inc.
|
1995-11-25 05:42:30 +00:00
|
|
|
|
|
|
|
;; Author: Rick Farnbach <rick_farnbach@MENTORG.COM>
|
2000-10-08 17:37:14 +00:00
|
|
|
;; Keywords: games
|
1995-11-25 05:42:30 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1995-11-25 05:42:30 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:25:26 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1995-11-25 05:42:30 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 07:25:26 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1995-11-25 05:42:30 +00:00
|
|
|
|
2000-10-08 17:37:14 +00:00
|
|
|
;;; Commentary:
|
|
|
|
|
2004-02-19 19:36:36 +00:00
|
|
|
;; Converts text to Morse code and back with M-x morse-region and
|
2000-10-08 17:37:14 +00:00
|
|
|
;; M-x unmorse-region (though Morse code is no longer official :-().
|
|
|
|
|
2011-03-07 07:33:11 +00:00
|
|
|
;; Converts text to NATO phonetic alphabet and back with M-x
|
|
|
|
;; nato-region and M-x denato-region.
|
|
|
|
|
1995-11-25 05:42:30 +00:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(defvar morse-code '(("a" . ".-")
|
|
|
|
("b" . "-...")
|
|
|
|
("c" . "-.-.")
|
|
|
|
("d" . "-..")
|
|
|
|
("e" . ".")
|
|
|
|
("f" . "..-.")
|
|
|
|
("g" . "--.")
|
|
|
|
("h" . "....")
|
|
|
|
("i" . "..")
|
|
|
|
("j" . ".---")
|
|
|
|
("k" . "-.-")
|
|
|
|
("l" . ".-..")
|
|
|
|
("m" . "--")
|
|
|
|
("n" . "-.")
|
|
|
|
("o" . "---")
|
|
|
|
("p" . ".--.")
|
|
|
|
("q" . "--.-")
|
|
|
|
("r" . ".-.")
|
|
|
|
("s" . "...")
|
|
|
|
("t" . "-")
|
|
|
|
("u" . "..-")
|
|
|
|
("v" . "...-")
|
|
|
|
("w" . ".--")
|
|
|
|
("x" . "-..-")
|
|
|
|
("y" . "-.--")
|
|
|
|
("z" . "--..")
|
|
|
|
;; Punctuation
|
|
|
|
("=" . "-...-")
|
|
|
|
("?" . "..--..")
|
|
|
|
("/" . "-..-.")
|
|
|
|
("," . "--..--")
|
|
|
|
("." . ".-.-.-")
|
|
|
|
(":" . "---...")
|
|
|
|
("'" . ".----.")
|
|
|
|
("-" . "-....-")
|
|
|
|
("(" . "-.--.-")
|
|
|
|
(")" . "-.--.-")
|
|
|
|
;; Numbers
|
|
|
|
("0" . "-----")
|
|
|
|
("1" . ".----")
|
|
|
|
("2" . "..---")
|
|
|
|
("3" . "...--")
|
|
|
|
("4" . "....-")
|
|
|
|
("5" . ".....")
|
|
|
|
("6" . "-....")
|
|
|
|
("7" . "--...")
|
|
|
|
("8" . "---..")
|
2002-11-21 18:11:49 +00:00
|
|
|
("9" . "----.")
|
|
|
|
;; Non-ASCII
|
|
|
|
("Ä" . ".-.-")
|
2002-11-21 19:18:07 +00:00
|
|
|
("Æ" . ".-.-")
|
2002-11-21 18:11:49 +00:00
|
|
|
("Á" . ".--.-")
|
|
|
|
("Å" . ".--.-")
|
|
|
|
;; ligature character?? ("Ch" . "----")
|
|
|
|
("ß" . ".../...")
|
|
|
|
("É" . "..-..")
|
|
|
|
("Ñ" . "--.--")
|
|
|
|
("Ö" . "---.")
|
2002-11-21 19:18:07 +00:00
|
|
|
("Ø" . "---.")
|
2004-02-19 19:36:36 +00:00
|
|
|
("Ü" . "..--")
|
|
|
|
;; Recently standardized
|
|
|
|
("@" . ".--.-."))
|
1995-11-25 05:42:30 +00:00
|
|
|
"Morse code character set.")
|
|
|
|
|
2011-03-07 07:33:11 +00:00
|
|
|
(defvar nato-alphabet '(("a" . "Alfa")
|
|
|
|
("b" . "Bravo")
|
|
|
|
("c" . "Charlie")
|
|
|
|
("d" . "Delta")
|
|
|
|
("e" . "Echo")
|
|
|
|
("f" . "Foxtrot")
|
|
|
|
("g" . "Golf")
|
|
|
|
("h" . "Hotel")
|
|
|
|
("i" . "India")
|
|
|
|
("j" . "Juliett")
|
|
|
|
("k" . "Kilo")
|
|
|
|
("l" . "Lima")
|
|
|
|
("m" . "Mike")
|
|
|
|
("n" . "November")
|
|
|
|
("o" . "Oscar")
|
|
|
|
("p" . "Papa")
|
|
|
|
("q" . "Quebec")
|
|
|
|
("r" . "Romeo")
|
|
|
|
("s" . "Sierra")
|
|
|
|
("t" . "Tango")
|
|
|
|
("u" . "Uniform")
|
|
|
|
("v" . "Victor")
|
|
|
|
("w" . "Whiskey")
|
|
|
|
("x" . "Xray")
|
|
|
|
("y" . "Yankee")
|
|
|
|
("z" . "Zulu")
|
|
|
|
;; Numbers
|
|
|
|
("0" . "Zero")
|
|
|
|
("1" . "One")
|
|
|
|
("2" . "Two")
|
|
|
|
("3" . "Three")
|
|
|
|
("4" . "Four")
|
|
|
|
("5" . "Five")
|
|
|
|
("6" . "Six")
|
|
|
|
("7" . "Seven")
|
|
|
|
("8" . "Eight")
|
|
|
|
("9" . "Niner")
|
|
|
|
;; Punctuation is not part of standard
|
|
|
|
("=" . "Equals")
|
|
|
|
("?" . "Query")
|
|
|
|
("/" . "Slash")
|
|
|
|
("," . "Comma")
|
|
|
|
("." . "Stop")
|
|
|
|
(":" . "Colon")
|
|
|
|
("'" . "Apostrophe")
|
|
|
|
("-" . "Dash")
|
|
|
|
("(" . "Open")
|
|
|
|
(")" . "Close")
|
|
|
|
("@" . "At"))
|
|
|
|
"NATO phonetic alphabet.
|
Prefer directed to neutral quotes
Prefer directed to neutral quotes in docstings and diagnostics.
In docstrings, escape apostrophes that would otherwise be translated
to curved quotes using the newer, simpler rules.
* admin/unidata/unidata-gen.el (unidata-gen-table):
* lisp/align.el (align-region):
* lisp/allout.el (allout-mode, allout-solicit-alternate-bullet):
* lisp/bookmark.el (bookmark-default-annotation-text):
* lisp/calc/calc-aent.el (math-read-if, math-read-factor):
* lisp/calc/calc-lang.el (math-read-giac-subscr)
(math-read-math-subscr):
* lisp/calc/calc-misc.el (report-calc-bug):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-read-parse-table-part):
* lisp/cedet/ede/pmake.el (ede-proj-makefile-insert-dist-rules):
* lisp/cedet/semantic/complete.el (semantic-displayor-show-request):
* lisp/dabbrev.el (dabbrev-expand):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/elint.el (elint-get-top-forms):
* lisp/emacs-lisp/lisp-mnt.el (lm-verify):
* lisp/emulation/viper-cmd.el (viper-toggle-search-style):
* lisp/erc/erc-button.el (erc-nick-popup):
* lisp/erc/erc.el (erc-cmd-LOAD, erc-handle-login):
* lisp/eshell/em-dirs.el (eshell/cd):
* lisp/eshell/em-glob.el (eshell-glob-regexp):
* lisp/eshell/em-pred.el (eshell-parse-modifiers):
* lisp/eshell/esh-arg.el (eshell-parse-arguments):
* lisp/eshell/esh-opt.el (eshell-show-usage):
* lisp/files-x.el (modify-file-local-variable):
* lisp/filesets.el (filesets-add-buffer, filesets-remove-buffer)
(filesets-update-pre010505):
* lisp/find-cmd.el (find-generic, find-to-string):
* lisp/gnus/auth-source.el (auth-source-netrc-parse-entries):
* lisp/gnus/gnus-agent.el (gnus-agent-check-overview-buffer)
(gnus-agent-fetch-headers):
* lisp/gnus/gnus-int.el (gnus-start-news-server):
* lisp/gnus/gnus-registry.el:
(gnus-registry--split-fancy-with-parent-internal):
* lisp/gnus/gnus-score.el (gnus-summary-increase-score):
* lisp/gnus/gnus-start.el (gnus-convert-old-newsrc):
* lisp/gnus/gnus-topic.el (gnus-topic-rename):
* lisp/gnus/legacy-gnus-agent.el (gnus-agent-unlist-expire-days):
* lisp/gnus/nnmairix.el (nnmairix-widget-create-query):
* lisp/gnus/spam.el (spam-check-blackholes):
* lisp/mail/feedmail.el (feedmail-run-the-queue):
* lisp/mpc.el (mpc-playlist-rename):
* lisp/net/ange-ftp.el (ange-ftp-shell-command):
* lisp/net/mairix.el (mairix-widget-create-query):
* lisp/net/tramp-cache.el:
* lisp/obsolete/otodo-mode.el (todo-more-important-p):
* lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region):
* lisp/obsolete/pgg-pgp.el (pgg-pgp-process-region):
* lisp/obsolete/pgg-pgp5.el (pgg-pgp5-process-region):
* lisp/org/ob-core.el (org-babel-goto-named-src-block)
(org-babel-goto-named-result):
* lisp/org/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/org/ob-ref.el (org-babel-ref-resolve):
* lisp/org/org-agenda.el (org-agenda-prepare):
* lisp/org/org-bibtex.el (org-bibtex-fields):
* lisp/org/org-clock.el (org-clock-notify-once-if-expired)
(org-clock-resolve):
* lisp/org/org-feed.el (org-feed-parse-atom-entry):
* lisp/org/org-habit.el (org-habit-parse-todo):
* lisp/org/org-mouse.el (org-mouse-popup-global-menu)
(org-mouse-context-menu):
* lisp/org/org-table.el (org-table-edit-formulas):
* lisp/org/ox.el (org-export-async-start):
* lisp/play/dunnet.el (dun-score, dun-help, dun-endgame-question)
(dun-rooms, dun-endgame-questions):
* lisp/progmodes/ada-mode.el (ada-goto-matching-start):
* lisp/progmodes/ada-xref.el (ada-find-executable):
* lisp/progmodes/antlr-mode.el (antlr-options-alists):
* lisp/progmodes/flymake.el (flymake-parse-err-lines)
(flymake-start-syntax-check-process):
* lisp/progmodes/python.el (python-define-auxiliary-skeleton):
* lisp/progmodes/sql.el (sql-comint):
* lisp/progmodes/verilog-mode.el (verilog-load-file-at-point):
* lisp/server.el (server-get-auth-key):
* lisp/subr.el (version-to-list):
* lisp/textmodes/reftex-ref.el (reftex-label):
* lisp/textmodes/reftex-toc.el (reftex-toc-rename-label):
* lisp/vc/ediff-diff.el (ediff-same-contents):
* lisp/vc/vc-cvs.el (vc-cvs-mode-line-string):
* test/automated/tramp-tests.el (tramp-test33-asynchronous-requests):
Use directed rather than neutral quotes in diagnostics.
2015-08-25 06:39:33 +00:00
|
|
|
See “International Code of Signals” (INTERCO), United States
|
2011-03-07 07:33:11 +00:00
|
|
|
Edition, 1969 Edition (Revised 2003) available from National
|
2014-11-21 19:08:19 +00:00
|
|
|
Geospatial-Intelligence Agency at URL `http://www.nga.mil/'")
|
2011-03-07 07:33:11 +00:00
|
|
|
|
2000-10-08 17:37:14 +00:00
|
|
|
;;;###autoload
|
1995-11-25 05:42:30 +00:00
|
|
|
(defun morse-region (beg end)
|
|
|
|
"Convert all text in a given region to morse code."
|
2011-03-07 07:35:25 +00:00
|
|
|
(interactive "*r")
|
1995-11-25 05:42:30 +00:00
|
|
|
(if (integerp end)
|
|
|
|
(setq end (copy-marker end)))
|
|
|
|
(save-excursion
|
|
|
|
(let ((sep "")
|
|
|
|
str morse)
|
|
|
|
(goto-char beg)
|
|
|
|
(while (< (point) end)
|
|
|
|
(setq str (downcase (buffer-substring (point) (1+ (point)))))
|
|
|
|
(cond ((looking-at "\\s-+")
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(setq sep ""))
|
|
|
|
((setq morse (assoc str morse-code))
|
|
|
|
(delete-char 1)
|
|
|
|
(insert sep (cdr morse))
|
|
|
|
(setq sep "/"))
|
|
|
|
(t
|
|
|
|
(forward-char 1)
|
|
|
|
(setq sep "")))))))
|
|
|
|
|
2000-10-08 17:37:14 +00:00
|
|
|
;;;###autoload
|
1995-11-25 05:42:30 +00:00
|
|
|
(defun unmorse-region (beg end)
|
|
|
|
"Convert morse coded text in region to ordinary ASCII text."
|
2011-03-07 07:35:25 +00:00
|
|
|
(interactive "*r")
|
1995-11-25 05:42:30 +00:00
|
|
|
(if (integerp end)
|
|
|
|
(setq end (copy-marker end)))
|
|
|
|
(save-excursion
|
|
|
|
(let (str paren morse)
|
|
|
|
(goto-char beg)
|
|
|
|
(while (< (point) end)
|
|
|
|
(if (null (looking-at "[-.]+"))
|
|
|
|
(forward-char 1)
|
|
|
|
(setq str (buffer-substring (match-beginning 0) (match-end 0)))
|
|
|
|
(if (null (setq morse (rassoc str morse-code)))
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(replace-match
|
|
|
|
(if (string-equal "(" (car morse))
|
|
|
|
(if (setq paren (null paren)) "(" ")")
|
|
|
|
(car morse)) t)
|
|
|
|
(if (looking-at "/")
|
|
|
|
(delete-char 1))))))))
|
|
|
|
|
2011-03-07 07:33:11 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun nato-region (beg end)
|
|
|
|
"Convert all text in a given region to NATO phonetic alphabet."
|
|
|
|
;; Copied from morse-region. -- ashawley 2009-02-10
|
|
|
|
(interactive "*r")
|
|
|
|
(if (integerp end)
|
|
|
|
(setq end (copy-marker end)))
|
|
|
|
(save-excursion
|
|
|
|
(let ((sep "")
|
|
|
|
str nato)
|
|
|
|
(goto-char beg)
|
|
|
|
(while (< (point) end)
|
|
|
|
(setq str (downcase (buffer-substring (point) (1+ (point)))))
|
|
|
|
(cond ((looking-at "\\s-+")
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(setq sep ""))
|
|
|
|
((setq nato (assoc str nato-alphabet))
|
|
|
|
(delete-char 1)
|
|
|
|
(insert sep (cdr nato))
|
|
|
|
(setq sep "-"))
|
|
|
|
(t
|
|
|
|
(forward-char 1)
|
|
|
|
(setq sep "")))))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun denato-region (beg end)
|
|
|
|
"Convert NATO phonetic alphabet in region to ordinary ASCII text."
|
|
|
|
;; Copied from unmorse-region. -- ashawley 2009-02-10
|
|
|
|
(interactive "*r")
|
|
|
|
(if (integerp end)
|
|
|
|
(setq end (copy-marker end)))
|
|
|
|
(save-excursion
|
|
|
|
(let (str paren nato)
|
|
|
|
(goto-char beg)
|
|
|
|
(while (< (point) end)
|
|
|
|
(if (null (looking-at "[a-z]+"))
|
|
|
|
(forward-char 1)
|
|
|
|
(setq str (buffer-substring (match-beginning 0) (match-end 0)))
|
2011-04-07 03:27:15 +00:00
|
|
|
(if (null (setq nato (rassoc (capitalize str) nato-alphabet)))
|
2011-03-07 07:33:11 +00:00
|
|
|
(goto-char (match-end 0))
|
|
|
|
(replace-match
|
|
|
|
(if (string-equal "(" (car nato))
|
|
|
|
(if (setq paren (null paren)) "(" ")")
|
|
|
|
(car nato)) t)
|
|
|
|
(if (looking-at "-")
|
|
|
|
(delete-char 1))))))))
|
|
|
|
|
1995-11-25 05:42:30 +00:00
|
|
|
(provide 'morse)
|
|
|
|
|
|
|
|
;;; morse.el ends here
|