annotate lisp/w3/mule-sysdp.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents 9ee227acff29
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; mule-sysdp.el --- consolidate MULE-version dependencies in one file.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 William Perry
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
4
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Author: William Perry <wmperry@aventail.com>
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6 ;; Keywords: lisp, tools
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;; The purpose of this file is to eliminate the cruftiness that
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
9 ;; would otherwise be required of packages that want to run on multiple
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;; versions of Emacs with and without Mule support.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 (require 'cl)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 (defconst mule-sysdep-version (if (featurep 'mule)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ((string-match "XEmacs" emacs-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 'xemacs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ((and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 (boundp 'mule-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 (string-match "[0-9]+\\.[0-9]+"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 mule-version))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 (string-to-number (substring
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 mule-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 (match-beginning 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 (match-end 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 (t 2.3))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28 "What version of mule we are running under.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30 (defconst mule-retrieval-coding-system
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
32 (2.3 *euc-japan*)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
33 (2.4 'coding-system-euc-japan)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
34 (xemacs 'euc-japan)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
35 (otherwise nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
36 "Default retrieval coding system for packages that use this package.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
37
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
38 (defconst mule-no-coding-system
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 (2.4 'no-conversion)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 (2.3 *noconv*)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 (xemacs 'no-conversion)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 (otherwise nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 "Coding system that means no coding system should be used.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 (defun mule-detect-coding-version (st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
47 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
48 (2.3 (code-detect-region (point-min) (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
49 (2.4 (detect-coding-region (point-min) (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
50 (xemacs (detect-coding-region (point-min) (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
51 (otherwise nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 (defun mule-code-convert-region (st nd code)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
55 (2.3
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56 (setq mc-flag t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
57 (code-convert-region (point-min) (point-max) code *internal*)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
58 (set-file-coding-system code))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 (2.4
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60 (setq enable-multibyte-characters t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61 (if (eq code 'coding-system-automatic)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 (decode-coding-region st nd code)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 (set-buffer-file-coding-system code)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 (xemacs
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66 (decode-coding-region (point-min) (point-max) code)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 (set-file-coding-system code))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 (otherwise
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71 (defun mule-inhibit-code-conversion (proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 (if (process-buffer proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74 (set-buffer (process-buffer proc))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 (set 'mc-flag nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
76 (set 'enable-multibyte-characters nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
77 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
78 ((2.4 2.3)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
79 (set-process-coding-system proc mule-no-coding-system
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
80 mule-no-coding-system))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 (xemacs
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 (set-process-input-coding-system proc mule-no-coding-system)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
83 (set-process-input-coding-system proc mule-no-coding-system))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
84
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
85 (defun mule-write-region-no-coding-system (st nd file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
86 (let ((enable-multibyte-characters t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
87 (coding-system-for-write 'no-conversion)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
88 (file-coding-system mule-no-coding-system)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
89 (buffer-file-coding-system mule-no-coding-system)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
90 (mc-flag t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
91 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
92 (2.3 (write-region st nd file nil nil nil *noconv*))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
93 (otherwise
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
94 (write-region st nd file)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
95
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
96 (defun mule-encode-string (str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
97 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
98 (2.3
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
99 (code-convert-string str *internal* mule-retrieval-coding-system))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
100 ((2.4 xemacs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
101 (encode-coding-string str mule-retrieval-coding-system))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
102 (otherwise
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
103 str)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
104
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
105 (defun mule-decode-string (str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
106 (and str
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
107 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
108 ((2.4 xemacs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
109 (decode-coding-string str mule-retrieval-coding-system))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
110 (2.3
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
111 (code-convert-string str *internal* mule-retrieval-coding-system))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
112 (otherwise
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
113 str))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
114
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
115 (defun mule-truncate-string (str len &optional pad)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
116 "Truncate string STR so that string-width of STR is not greater than LEN.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
117 If width of the truncated string is less than LEN, and if a character PAD is
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
118 defined, add padding end of it."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
119 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
120 (2.4
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
121 (let ((cl (string-to-vector str)) (n 0) (sw 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
122 (if (<= (string-width str) len) str
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
123 (while (<= (setq sw (+ (char-width (aref cl n)) sw)) len)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
124 (setq n (1+ n)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
125 (string-match (make-string n ?.) str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
126 (setq str (substring str 0 (match-end 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
127 (if pad (concat str (make-string (- len (string-width str)) pad)) str)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
128 (2.3
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
129 (let ((cl (string-to-char-list str)) (n 0) (sw 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
130 (if (<= (string-width str) len) str
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
131 (while (<= (setq sw (+ (char-width (nth n cl)) sw)) len)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 (setq n (1+ n)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 (string-match (make-string n ?.) str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
134 (setq str (substring str 0 (match-end 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
135 (if pad (concat str (make-string (- len (string-width str)) pad)) str)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
136 (otherwise
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
137 (concat (if (> (length str) len) (substring str 0 len) str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
138 (if (or (null pad) (> (length str) len))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139 ""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 (make-string (- len (length str)) pad))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
141
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 (defun mule-make-iso-character (char)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 (if (<= char 127)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 char
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 (2.3 (make-character lc-ltn1 char))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 (2.4 (make-char charset-latin-iso8859-1 char))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 (xemacs char)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 (otherwise char))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 (case mule-sysdep-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 ((2.3 2.4 xemacs) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 (otherwise (fset 'string-width 'length)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 (and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 (boundp 'MULE)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 (not (featurep 'mule))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 (provide 'mule))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
160 (provide 'mule-sysdp)