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