forked from emacs-w3m/emacs-w3m
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
w3m-symbol.el
213 lines (188 loc) · 6.97 KB
/
w3m-symbol.el
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
;;; w3m-symbol.el --- Stuffs to replace symbols for emacs-w3m -*- lexical-binding: nil -*-
;; Copyright (C) 2002-2007, 2009, 2017, 2019
;; ARISAWA Akihiro <[email protected]>
;; Author: ARISAWA Akihiro <[email protected]>
;; Keywords: w3m, WWW, hypermedia, i18n
;; This file 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 file 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 GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;;; Code:
(defvar w3m-output-coding-system)
(defvar w3m-language)
(defvar w3m-use-symbol)
(declare-function w3m-mule-unicode-p "w3m")
(defgroup w3m-symbol nil
"Symbols for w3m"
:group 'w3m)
(defvar w3m-symbol-custom-type
'(list
:convert-widget w3m-widget-type-convert-widget
(let* ((w `(sexp :match (lambda (_widget value) (stringp value))
:size 4))
(a `(,@w :format "%v "))
(b `(,@w :format "%v\n"))
(c (list a a a a a a a b))
(d (list a a a a a b)))
`(:indent 4 :tag "Customized"
:value ,(if (equal w3m-language "Japanese")
w3m-Japanese-symbol
w3m-default-symbol)
,@c ,@c ,@c ,@c ,@d ,@d ,b ,b))))
(defcustom w3m-default-symbol
'("-+" " |" "--" " +" "-|" " |" "-+" ""
"--" " +" "--" "" "-+" "" "" ""
"-+" " |" "--" " +" "-|" " |" "-+" ""
"--" " +" "--" "" "-+" "" "" ""
" *" " +" " o" " #" " @" " -"
" =" " x" " %" " *" " o" " #"
" #"
"<=UpDn ")
"List of symbol string used by default."
:group 'w3m-symbol
:type w3m-symbol-custom-type)
(defcustom w3m-Chinese-BIG5-symbol
'("┼" "├" "┬" "┌" "┤" "│" "┐" ""
"┴" "└" "─" "" "┘" "" "" ""
"┼" "├" "┬" "┌" "┤" "│" "┐" ""
"┴" "└" "─" "" "┘" "" "" ""
"‧" "□" "☆" "○" "■" "★"
"◎" "●" "△" "●" "○" "□"
"●"
"《↑↓")
"List of symbol string, used in Chienese-BIG5 environment."
:group 'w3m-symbol
:type w3m-symbol-custom-type)
(defcustom w3m-Chinese-CNS-symbol
'("┼" "├" "┬" "┌" "┤" "│" "┐" ""
"┴" "└" "─" "" "┘" "" "" ""
"┼" "├" "┬" "┌" "┤" "│" "┐" ""
"┴" "└" "─" "" "┘" "" "" ""
"・" "□" "☆" "○" "■" "★"
"◎" "●" "△" "●" "○" "□"
"●"
"《↑↓")
"List of symbol string, used in Chienese-CNS environment."
:group 'w3m-symbol
:type w3m-symbol-custom-type)
(defcustom w3m-Chinese-GB-symbol
'("┼" "├" "┬" "┌" "┤" "│" "┐" ""
"┴" "└" "─" "" "┘" "" "" ""
"┼" "┠" "┯" "┏" "┨" "┃" "┓" ""
"┷" "┗" "━" "" "┛" "" "" ""
"・" "□" "☆" "○" "■" "★"
"◎" "●" "△" "●" "○" "□"
"●"
"《↑↓")
"List of symbol string, used in Chienese-GB environment."
:group 'w3m-symbol
:type w3m-symbol-custom-type)
(defcustom w3m-Japanese-symbol
'("┼" "├" "┬" "┌" "┤" "│" "┐" ""
"┴" "└" "─" "" "┘" "" "" ""
"┼" "┠" "┯" "┏" "┨" "┃" "┓" ""
"┷" "┗" "━" "" "┛" "" "" ""
"・" "□" "☆" "○" "■" "★"
"◎" "●" "△" "●" "○" "□"
"●"
"≪↑↓")
"List of symbol string, used in Japanese environment."
:group 'w3m-symbol
:type w3m-symbol-custom-type)
(defcustom w3m-Korean-symbol
'("┼" "├" "┬" "┌" "┤" "│" "┐" ""
"┴" "└" "─" "" "┘" "" "" ""
"┼" "┠" "┯" "┏" "┨" "┃" "┓" ""
"┷" "┗" "━" "" "┛" "" "" ""
"·" "□" "☆" "○" "■" "★"
"◎" "●" "△" "●" "○" "□"
"●"
"≪↑↓")
"List of symbol string, used in Korean environment."
:group 'w3m-symbol
:type w3m-symbol-custom-type)
(defcustom w3m-mule-unicode-symbol
(when (w3m-mule-unicode-p)
(append
(mapcar (lambda (p)
(if p
(char-to-string
(make-char (or (nth 2 p) 'mule-unicode-2500-33ff)
(car p) (cadr p)))
""))
'((32 92) (32 60) (32 76) (32 44) (32 68) (32 34) (32 48) nil
(32 84) (32 52) (32 32) nil (32 56) nil nil nil
(32 92) (32 64) (32 79) (32 47) (32 72) (32 35) (32 51) nil
(32 87) (32 55) (32 33) nil (32 59) nil nil nil
(115 34 mule-unicode-0100-24ff) (33 97) (34 102) (34 43) (33 96) (34 101)
(34 46) (34 47) (33 115) (34 47) (34 43) (33 97)
(34 47)))
(list (format "%c %c %c "
(make-char 'mule-unicode-0100-24ff 121 42)
(make-char 'mule-unicode-0100-24ff 118 113)
(make-char 'mule-unicode-0100-24ff 118 115)))))
"List of symbol string, using mule-unicode characters."
:group 'w3m-symbol
:type (if (w3m-mule-unicode-p)
w3m-symbol-custom-type
'(const :format "%{%t%}: %v")))
(defcustom w3m-symbol nil
"List of symbol string."
:group 'w3m-symbol
:type `(radio (const :format "Auto detect " nil)
(const :tag "Default" w3m-default-symbol)
(const :format "Chinese BIG5 " w3m-Chinese-BIG5-symbol)
(const :format "Chinese CNS " w3m-Chinese-CNS-symbol)
(const :tag "Chinese GB" w3m-Chinese-GB-symbol)
(const :format "Japanese " w3m-Japanese-symbol)
(const :format "Korean " w3m-Korean-symbol)
,(when w3m-mule-unicode-symbol
'(const :tag "Mule-Unicode" w3m-mule-unicode-symbol))
(variable :format "%t symbol: %v"
:value w3m-default-symbol)
,w3m-symbol-custom-type))
(defun w3m-use-symbol ()
(cond ((functionp w3m-use-symbol)
(funcall w3m-use-symbol))
(t w3m-use-symbol)))
(defvar current-language-environment)
(defun w3m-symbol ()
(cond (w3m-symbol
(if (symbolp w3m-symbol)
(symbol-value w3m-symbol)
w3m-symbol))
((and (eq w3m-output-coding-system 'utf-8)
w3m-mule-unicode-symbol))
((let ((lang (or w3m-language current-language-environment)))
(when (boundp (intern (format "w3m-%s-symbol" lang)))
(symbol-value (intern (format "w3m-%s-symbol" lang))))))
(t w3m-default-symbol)))
;;;###autoload
(defun w3m-replace-symbol ()
(when (w3m-use-symbol)
(let ((symbol-list (w3m-symbol)))
(save-excursion
(goto-char (point-min))
(while (re-search-forward "<_SYMBOL TYPE=\\([0-9]+\\)>" nil t)
(let ((symbol (nth (string-to-number (match-string 1)) symbol-list))
(start (point))
end symbol-cnt)
(search-forward "</_SYMBOL>" nil t)
(setq end (match-beginning 0)
symbol-cnt (/ (string-width (buffer-substring start end))
(string-width symbol)))
(goto-char start)
(delete-region start end)
(insert (apply 'concat (make-list symbol-cnt symbol)))))))))
(provide 'w3m-symbol)
;;; w3m-symbol.el ends here