File: w3m-ucs.el

package info (click to toggle)
w3m-el-snapshot 1.4.483%2B0.20120614-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,640 kB
  • sloc: lisp: 43,970; sh: 472; makefile: 391
file content (109 lines) | stat: -rw-r--r-- 3,625 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
;;; w3m-ucs.el --- CCL programs to process Unicode.

;; Copyright (C) 2001, 2005, 2007 TSUCHIYA Masatoshi <tsuchiya@namazu.org>

;; Authors: TSUCHIYA Masatoshi <tsuchiya@namazu.org>,
;;          ARISAWA Akihiro <ari@mbf.sphere.ne.jp>
;; Keywords: w3m, WWW, hypermedia

;; This file is a part of emacs-w3m.

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This program 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
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; This file contains CCL codes to handle UCS characters in emacs-w3m.
;; For more detail about emacs-w3m, see:
;;
;;    http://emacs-w3m.namazu.org/

;; This module requires `Mule-UCS' package.  It can be downloaded from:
;;
;;    ftp://ftp.m17n.org/pub/mule/Mule-UCS/

;;; Code:

;; Enable XEmacs 21.5-Mule to compile this module anyway.
(eval-when-compile
  (if (featurep 'xemacs)
      (let ((mucs-ignore-version-incompatibilities t))
	(defvar font-ccl-encoder-alist nil)
	(require 'un-define))))

(require 'un-define)
(require 'w3m-ccl)

(eval-and-compile
  (autoload 'w3m-make-ccl-coding-system "w3m"))

(defun w3m-ucs-to-char (codepoint)
  (condition-case nil
      (or (ucs-to-char codepoint) ?~)
    (error ?~)))

(eval-and-compile
  (defconst w3m-ccl-get-ucs-codepoint-with-mule-ucs
    '(;; (1) Convert a set of r1 (charset-id) and r0 (codepoint) to a
      ;; character in Emacs internal representation.
      (if (r0 > 255)
	  ((r4 = (r0 & 127))
	   (r0 = (((r0 >> 7) * 96) + r4))
	   (r0 |= (r1 << 16)))
	((r0 |= (r1 << 16))))
      ;; (2) Convert a character in Emacs to a UCS codepoint.
      (call emacs-char-to-ucs-codepoint-conversion)
      (if (r0 <= 0)
	  (write-repeat ?~)))		; unknown character.
    "CCL program to convert multibyte char to ucs with Mule-UCS."))

(define-ccl-program w3m-euc-japan-mule-ucs-encoder
  `(4
    (loop
     ,@w3m-ccl-write-euc-japan-character
     ,@w3m-ccl-get-ucs-codepoint-with-mule-ucs
     ,@w3m-ccl-generate-ncr)))

(w3m-make-ccl-coding-system
 'w3m-euc-japan-mule-ucs ?E
 "ISO 2022 based EUC encoding for Japanese with w3m internal characters.
A character that can not be encoded with `euc-japan' is converted to a
UCS codepoint with Mule-UCS, and the codepoint is represented as a
string which represents the character in Numeric Character
References (NCR).
  (generated by `w3m')"
 'w3m-euc-japan-decoder
 'w3m-euc-japan-mule-ucs-encoder)

(define-ccl-program w3m-iso-latin-1-mule-ucs-encoder
  `(4
    (loop
     ,@w3m-ccl-write-iso-latin-1-character
     ,@w3m-ccl-get-ucs-codepoint-with-mule-ucs
     ,@w3m-ccl-generate-ncr)))

(w3m-make-ccl-coding-system
 'w3m-iso-latin-1-mule-ucs ?1
 "ISO 2022 based 8-bit encoding for Latin-1 with w3m internal characters.
A character that can not be encoded with `iso-latin-1' is converted to
a UCS codepoint with Mule-UCS, and the codepoint is represented as a
string which represents the character in Numeric Character
References (NCR).
  (generated by `w3m')"
 'w3m-iso-latin-1-decoder
 'w3m-iso-latin-1-mule-ucs-encoder)

(provide 'w3m-ucs)
;;; w3m-ucs.el ends here.