swedish.el 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ;;; swedish.el --- miscellaneous functions for dealing with Swedish
  2. ;; Copyright (C) 1988, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Howard Gayle
  4. ;; Maintainer: FSF
  5. ;; Keywords: i18n
  6. ;; Obsolete-since: 22.1
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; Fixme: Is this actually used? if so, it should be in language,
  20. ;; possibly as a feature property of Swedish, probably defining a
  21. ;; `swascii' coding system.
  22. ;;; Code:
  23. ;; Written by Howard Gayle. See case-table.el for details.
  24. ;; See iso-swed.el for a description of the character set.
  25. (defvar mail-send-hook)
  26. (defvar news-group-hook-alist)
  27. (defvar news-inews-hook)
  28. (defvar swedish-re
  29. "[ \t\n]\\(och\\|att\\|en\\|{r\\|\\[R\\|p}\\|P\\]\\|som\\|det\\|av\\|den\\|f|r\\|F\\\\R\\)[ \t\n.,?!:;'\")}]"
  30. "Regular expression for common Swedish words.")
  31. (defvar swascii-to-8859-trans
  32. (let ((string (make-string 256 ? ))
  33. (i 0))
  34. (while (< i 256)
  35. (aset string i i)
  36. (setq i (1+ i)))
  37. (aset string ?\[ 196)
  38. (aset string ?\] 197)
  39. (aset string ?\\ 214)
  40. (aset string ?^ 220)
  41. (aset string ?\{ 228)
  42. (aset string ?\} 229)
  43. (aset string ?\` 233)
  44. (aset string ?\| 246)
  45. (aset string ?~ 252)
  46. string)
  47. "Trans table from SWASCII to 8859.")
  48. ; $ is not converted because it almost always means US
  49. ; dollars, not general currency sign. @ is not converted
  50. ; because it is more likely to be an at sign in a mail address
  51. ; than an E with acute accent.
  52. (defun swascii-to-8859-buffer ()
  53. "Convert characters in buffer from Swedish/Finnish-ascii to ISO 8859/1.
  54. Works even on read-only buffers. `$' and `@' are not converted."
  55. (interactive)
  56. (let ((buffer-read-only nil))
  57. (translate-region (point-min) (point-max) swascii-to-8859-trans)))
  58. (defun swascii-to-8859-buffer-maybe ()
  59. "Call swascii-to-8859-buffer if the buffer looks like Swedish-ascii.
  60. Leaves point just after the word that looks Swedish."
  61. (interactive)
  62. (let ((case-fold-search t))
  63. (if (re-search-forward swedish-re nil t)
  64. (swascii-to-8859-buffer))))
  65. (setq rmail-show-message-hook 'swascii-to-8859-buffer-maybe)
  66. (setq news-group-hook-alist
  67. (append '(("^swnet." . swascii-to-8859-buffer-maybe))
  68. (bound-and-true-p news-group-hook-alist)))
  69. (defvar 8859-to-swascii-trans
  70. (let ((string (make-string 256 ? ))
  71. (i 0))
  72. (while (< i 256)
  73. (aset string i i)
  74. (setq i (1+ i)))
  75. (aset string 164 ?$)
  76. (aset string 196 ?\[)
  77. (aset string 197 ?\])
  78. (aset string 201 ?@)
  79. (aset string 214 ?\\)
  80. (aset string 220 ?^)
  81. (aset string 228 ?\{)
  82. (aset string 229 ?\})
  83. (aset string 233 ?\`)
  84. (aset string 246 ?\|)
  85. (aset string 252 ?~)
  86. string)
  87. "8859 to SWASCII trans table.")
  88. (defun 8859-to-swascii-buffer ()
  89. "Convert characters in buffer from ISO 8859/1 to Swedish/Finnish-ascii."
  90. (interactive "*")
  91. (translate-region (point-min) (point-max) 8859-to-swascii-trans))
  92. (setq mail-send-hook '8859-to-swascii-buffer)
  93. (setq news-inews-hook '8859-to-swascii-buffer)
  94. ;; It's not clear what purpose is served by a separate
  95. ;; Swedish mode that differs from Text mode only in having
  96. ;; a separate abbrev table. Nothing says that the abbrevs you
  97. ;; define in Text mode have to be English!
  98. ;(defvar swedish-mode-abbrev-table nil
  99. ; "Abbrev table used while in swedish mode.")
  100. ;(define-abbrev-table 'swedish-mode-abbrev-table ())
  101. ;(defun swedish-mode ()
  102. ; "Major mode for editing Swedish text intended for humans to
  103. ;read. Special commands:\\{text-mode-map}
  104. ;Turning on swedish-mode calls the value of the variable
  105. ;text-mode-hook, if that value is non-nil."
  106. ; (interactive)
  107. ; (kill-all-local-variables)
  108. ; (use-local-map text-mode-map)
  109. ; (setq mode-name "Swedish")
  110. ; (setq major-mode 'swedish-mode)
  111. ; (setq local-abbrev-table swedish-mode-abbrev-table)
  112. ; (set-syntax-table text-mode-syntax-table)
  113. ; (run-mode-hooks 'text-mode-hook))
  114. ;(defun indented-swedish-mode ()
  115. ; "Major mode for editing indented Swedish text intended for
  116. ;humans to read.\\{indented-text-mode-map}
  117. ;Turning on indented-swedish-mode calls the value of the
  118. ;variable text-mode-hook, if that value is non-nil."
  119. ; (interactive)
  120. ; (kill-all-local-variables)
  121. ; (use-local-map text-mode-map)
  122. ; (define-abbrev-table 'swedish-mode-abbrev-table ())
  123. ; (setq local-abbrev-table swedish-mode-abbrev-table)
  124. ; (set-syntax-table text-mode-syntax-table)
  125. ; (make-local-variable 'indent-line-function)
  126. ; (setq indent-line-function 'indent-relative-maybe)
  127. ; (use-local-map indented-text-mode-map)
  128. ; (setq mode-name "Indented Swedish")
  129. ; (setq major-mode 'indented-swedish-mode)
  130. ; (run-mode-hooks 'text-mode-hook))
  131. (provide 'swedish)
  132. ;;; swedish.el ends here