annotate lisp/code-cmds.el @ 958:4cbfb36b35e0

[xemacs-hg @ 2002-08-12 07:44:28 by youngs] 2002-08-11 John Paul Wallington <jpw@shootybangbang.com> * simple.el (join-line): New alias for `delete-indentation'.
author youngs
date Mon, 12 Aug 2002 07:44:28 +0000
parents 943eaba38521
children b531bf8658e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
1 ;;; code-cmds.el --- Commands for manipulating coding systems.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
2
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995,1999 Electrotechnical Laboratory, JAPAN.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
4 ;; Licensed to the Free Software Foundation.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
5 ;; Copyright (C) 2000 Free Software Foundation
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
6 ;; Copyright (C) 1997 MORIOKA Tomohiko
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
7 ;; Copyright (C) 2001, 2002 Ben Wing.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
8
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
9
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
11
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
15 ;; any later version.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
16
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
20 ;; General Public License for more details.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
21
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
25 ;; 02111-1307, USA.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
26
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
27 ;;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
28 ;; This code defines the keybindings and utility commands for the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
29 ;; user to manipulate coding systems.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
30 ;; This code used to be in mule-cmds.el which now only needs the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
31 ;; additional bindings/commands that are avaible on the real mule.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
32
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
33
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
34 ;;; Code:
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
35
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
36 ;;; Coding related key bindings and menus.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
37
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
38 (defvar coding-keymap (make-sparse-keymap "Coding+Mule")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
39 "Keymap for coding-system-specific and (when available) Mule commands.")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
40
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
41 ;; Keep "C-x C-m ..." for coding/mule specific commands.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
42 (define-key ctl-x-map "\C-m" coding-keymap)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
43
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
44 (define-key coding-keymap "f" 'set-buffer-file-coding-system)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
45 (define-key coding-keymap "F" 'set-default-buffer-file-coding-system) ; XEmacs
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
46 (define-key coding-keymap "t" 'set-terminal-coding-system)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
47 (define-key coding-keymap "p" 'set-buffer-process-coding-system)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
48 (define-key coding-keymap "c" 'universal-coding-system-argument)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
49 ;;(define-key coding-keymap "c" 'list-coding-system-briefly) ; XEmacs
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
50 (when-fboundp 'describe-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
51 (define-key coding-keymap "C" 'describe-coding-system)) ; XEmacs
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
52 (when-fboundp 'set-selection-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
53 (define-key coding-keymap "x" 'set-selection-coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
54 (define-key coding-keymap "X" 'set-next-selection-coding-system))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
55
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
56
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
57 (defun coding-system-change-eol-conversion (coding-system eol-type)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
58 "Return a coding system which differs from CODING-SYSTEM in eol conversion.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
59 The returned coding system converts end-of-line by EOL-TYPE
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
60 but text as the same way as CODING-SYSTEM.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
61 EOL-TYPE should be `lf', `crlf', `cr' or nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
62 If EOL-TYPE is nil, the returned coding system detects
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
63 how end-of-line is formatted automatically while decoding.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
64
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
65 EOL-TYPE can be specified by an symbol `unix', `dos' or `mac'.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
66 They means `lf', `crlf', and `cr' respectively."
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
67 (if (symbolp eol-type)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
68 (setq eol-type (cond ((or (eq eol-type 'unix)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
69 (eq eol-type 'lf))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
70 'eol-lf)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
71 ((or (eq eol-type 'dos)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
72 (eq eol-type 'crlf))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
73 'eol-crlf)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
74 ((or (eq eol-type 'mac)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
75 (eq eol-type 'cr))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
76 'eol-cr)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
77 (t eol-type))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
78 (let ((orig-eol-type (coding-system-eol-type coding-system)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
79 (if (null orig-eol-type)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
80 (if (not eol-type)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
81 coding-system
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
82 (coding-system-property coding-system eol-type))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
83 (let ((base (coding-system-base coding-system)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
84 (if (not eol-type)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
85 base
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
86 (if (eq eol-type orig-eol-type)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
87 coding-system
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
88 (setq orig-eol-type (coding-system-eol-type base))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
89 (if (null orig-eol-type)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
90 (coding-system-property base eol-type))))))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
91
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
92 ;; (defun coding-system-change-text-conversion (coding-system coding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
93 ;; "Return a coding system which differs from CODING-SYSTEM in text conversion.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
94 ;; The returned coding system converts text by CODING
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
95 ;; but end-of-line as the same way as CODING-SYSTEM.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
96 ;; If CODING is nil, the returned coding system detects
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
97 ;; how text is formatted automatically while decoding."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
98 ;; (if (not coding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
99 ;; (coding-system-base coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
100 ;; (let ((eol-type (coding-system-eol-type coding-system)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
101 ;; (coding-system-change-eol-conversion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
102 ;; coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
103 ;; (if (numberp eol-type) (aref [unix dos mac] eol-type))))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
104
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
105 (defun universal-coding-system-argument ()
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
106 "Execute an I/O command using the specified coding system."
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
107 (interactive)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
108 (let* ((default (and buffer-file-coding-system
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
109 (not (eq (coding-system-type buffer-file-coding-system)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
110 t))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
111 (coding-system-name buffer-file-coding-system)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
112 (coding-system
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
113 (read-coding-system
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
114 (if default
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
115 (format "Coding system for following command (default, %s): "
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
116 default)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
117 "Coding system for following command: ")
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
118 default))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
119 (keyseq (read-key-sequence
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
120 (format "Command to execute with %s:" coding-system)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
121 (cmd (key-binding keyseq)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
122 (let ((coding-system-for-read coding-system)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
123 (coding-system-for-write coding-system))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
124 (message "")
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
125 (call-interactively cmd))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
126
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
127 (defun set-default-output-coding-systems (coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
128 "Set default value for coding system output to CODING-SYSTEM.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
129 This sets the coding system of newly created buffers (the default value of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
130 `buffer-file-coding-system') and the default coding system for output to a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
131 subprocess (the CDR of `default-process-coding-system').
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
132
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
133 Other defaults are not changed; see `prefer-coding-system' for why."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
134 (check-coding-system coding-system)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
135 (set-default-buffer-file-coding-system coding-system)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
136 (setq default-process-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
137 (cons (car default-process-coding-system) coding-system)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
138
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
139 (defun prefer-coding-system (coding-system)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
140 "Add CODING-SYSTEM at the front of the priority list for automatic detection.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
141 This also sets the coding system of newly created buffers (the default
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
142 value of `buffer-file-coding-system') and the default coding system for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
143 output to a subprocess (the CDR of `default-process-coding-system').
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
144
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
145 If CODING-SYSTEM specifies a certain type of EOL conversion, the coding
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
146 systems set by this function will use that type of EOL conversion.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
147
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
148 This does not change the default coding system for converting file names
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
149 because that is dependent on the current locale; it's changed when
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
150 `set-language-environment' is called. It does not change
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
151 `terminal-coding-system' or `keyboard-coding-system'; they should get set
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
152 when the terminal is opened (and are typically an inherent property of the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
153 terminal), and don't change afterward. It does not change the default
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
154 coding system for reading files or input from a subprocess; they should
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
155 remain as `undecided' so that automatic detection is done."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
156 (interactive "zPrefer coding system: ")
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
157 (if (not (and coding-system (find-coding-system coding-system)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
158 (error "Invalid coding system `%s'" coding-system))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
159 (let ((coding-category (coding-system-category coding-system))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
160 (base (coding-system-base coding-system))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
161 (eol-type (coding-system-eol-type coding-system)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
162 (if (not coding-category)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
163 ;; CODING-SYSTEM is no-conversion or undecided.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
164 (error "Can't prefer the coding system `%s'" coding-system))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
165 (set-coding-category-system coding-category (or base coding-system))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
166 ;; (update-coding-systems-internal)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
167 (or (eq coding-category (car (coding-category-list)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
168 ;; We must change the order.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
169 (set-coding-priority-list (list coding-category)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
170 (if (and base (interactive-p))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
171 (message "Highest priority is set to %s (base of %s)"
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
172 base coding-system))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
173 ;; If they asked for specific EOL conversion, honor that.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
174 (if (memq eol-type '(lf crlf cr unix dos mac))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
175 (setq coding-system
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
176 (coding-system-change-eol-conversion base eol-type))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
177 (setq coding-system base))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
178 (set-default-output-coding-systems coding-system)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
179
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
180 ;; (defun find-coding-systems-region-subset-p (list1 list2)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
181 ;; "Return non-nil if all elements in LIST1 are included in LIST2.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
182 ;; Comparison done with EQ."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
183 ;; (catch 'tag
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
184 ;; (while list1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
185 ;; (or (memq (car list1) list2)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
186 ;; (throw 'tag nil))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
187 ;; (setq list1 (cdr list1)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
188 ;; t))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
189
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
190 ;; (defun find-coding-systems-region (from to)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
191 ;; "Return a list of proper coding systems to encode a text between FROM and TO.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
192 ;; All coding systems in the list can safely encode any multibyte characters
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
193 ;; in the text.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
194 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
195 ;; If the text contains no multibyte characters, return a list of a single
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
196 ;; element `undecided'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
197 ;; (find-coding-systems-for-charsets (find-charset-region from to)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
198
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
199 ;; (defun find-coding-systems-string (string)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
200 ;; "Return a list of proper coding systems to encode STRING.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
201 ;; All coding systems in the list can safely encode any multibyte characters
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
202 ;; in STRING.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
203 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
204 ;; If STRING contains no multibyte characters, return a list of a single
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
205 ;; element `undecided'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
206 ;; (find-coding-systems-for-charsets (find-charset-string string)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
207
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
208 ;; (defun find-coding-systems-for-charsets (charsets)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
209 ;; "Return a list of proper coding systems to encode characters of CHARSETS.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
210 ;; CHARSETS is a list of character sets."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
211 ;; (if (or (null charsets)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
212 ;; (and (= (length charsets) 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
213 ;; (eq 'ascii (car charsets))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
214 ;; '(undecided)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
215 ;; (setq charsets (delq 'composition charsets))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
216 ;; (let ((l (coding-system-list 'base-only))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
217 ;; (charset-preferred-codings
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
218 ;; (mapcar (function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
219 ;; (lambda (x)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
220 ;; (if (eq x 'unknown)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
221 ;; 'raw-text
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
222 ;; (get-charset-property x 'preferred-coding-system))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
223 ;; charsets))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
224 ;; (priorities (mapcar (function (lambda (x) (symbol-value x)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
225 ;; coding-category-list))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
226 ;; codings coding safe)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
227 ;; (if (memq 'unknown charsets)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
228 ;; ;; The region contains invalid multibyte characters.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
229 ;; (setq l '(raw-text)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
230 ;; (while l
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
231 ;; (setq coding (car l) l (cdr l))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
232 ;; (if (and (setq safe (coding-system-get coding 'safe-charsets))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
233 ;; (or (eq safe t)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
234 ;; (find-coding-systems-region-subset-p charsets safe)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
235 ;; ;; We put the higher priority to coding systems included
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
236 ;; ;; in CHARSET-PREFERRED-CODINGS, and within them, put the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
237 ;; ;; higher priority to coding systems which support smaller
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
238 ;; ;; number of charsets.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
239 ;; (let ((priority
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
240 ;; (+ (if (coding-system-get coding 'mime-charset) 4096 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
241 ;; (lsh (length (memq coding priorities)) 7)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
242 ;; (if (memq coding charset-preferred-codings) 64 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
243 ;; (if (> (coding-system-type coding) 0) 32 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
244 ;; (if (consp safe) (- 32 (length safe)) 0))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
245 ;; (setq codings (cons (cons priority coding) codings)))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
246 ;; (mapcar 'cdr
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
247 ;; (sort codings (function (lambda (x y) (> (car x) (car y))))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
248 ;; )))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
249
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
250 ;; (defun find-multibyte-characters (from to &optional maxcount excludes)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
251 ;; "Find multibyte characters in the region specified by FROM and TO.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
252 ;; If FROM is a string, find multibyte characters in the string.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
253 ;; The return value is an alist of the following format:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
254 ;; ((CHARSET COUNT CHAR ...) ...)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
255 ;; where
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
256 ;; CHARSET is a character set,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
257 ;; COUNT is a number of characters,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
258 ;; CHARs are found characters of the character set.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
259 ;; Optional 3rd arg MAXCOUNT limits how many CHARs are put in the above list.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
260 ;; Optional 4th arg EXCLUDE is a list of character sets to be ignored.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
261 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
262 ;; For invalid characters, CHARs are actually strings."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
263 ;; (let ((chars nil)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
264 ;; charset char)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
265 ;; (if (stringp from)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
266 ;; (let ((idx 0))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
267 ;; (while (setq idx (string-match "[^\000-\177]" from idx))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
268 ;; (setq char (aref from idx)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
269 ;; charset (char-charset char))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
270 ;; (if (eq charset 'unknown)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
271 ;; (setq char (match-string 0)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
272 ;; (if (or (eq charset 'unknown)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
273 ;; (not (or (eq excludes t) (memq charset excludes))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
274 ;; (let ((slot (assq charset chars)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
275 ;; (if slot
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
276 ;; (if (not (memq char (nthcdr 2 slot)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
277 ;; (let ((count (nth 1 slot)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
278 ;; (setcar (cdr slot) (1+ count))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
279 ;; (if (or (not maxcount) (< count maxcount))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
280 ;; (nconc slot (list char)))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
281 ;; (setq chars (cons (list charset 1 char) chars)))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
282 ;; (setq idx (1+ idx))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
283 ;; (save-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
284 ;; (goto-char from)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
285 ;; (while (re-search-forward "[^\000-\177]" to t)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
286 ;; (setq char (preceding-char)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
287 ;; charset (char-charset char))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
288 ;; (if (eq charset 'unknown)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
289 ;; (setq char (match-string 0)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
290 ;; (if (or (eq charset 'unknown)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
291 ;; (not (or (eq excludes t) (memq charset excludes))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
292 ;; (let ((slot (assq charset chars)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
293 ;; (if slot
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
294 ;; (if (not (member char (nthcdr 2 slot)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
295 ;; (let ((count (nth 1 slot)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
296 ;; (setcar (cdr slot) (1+ count))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
297 ;; (if (or (not maxcount) (< count maxcount))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
298 ;; (nconc slot (list char)))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
299 ;; (setq chars (cons (list charset 1 char) chars))))))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
300 ;; (nreverse chars)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
301
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
302 ;; (defvar last-coding-system-specified nil
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
303 ;; "Most recent coding system explicitly specified by the user when asked.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
304 ;; This variable is set whenever Emacs asks the user which coding system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
305 ;; to use in order to write a file. If you set it to nil explicitly,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
306 ;; then call `write-region', then afterward this variable will be non-nil
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
307 ;; only if the user was explicitly asked and specified a coding system.")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
308
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
309 ;; (defun select-safe-coding-system (from to &optional default-coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
310 ;; "Ask a user to select a safe coding system from candidates.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
311 ;; The candidates of coding systems which can safely encode a text
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
312 ;; between FROM and TO are shown in a popup window.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
313 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
314 ;; Optional arg DEFAULT-CODING-SYSTEM specifies a coding system to be
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
315 ;; checked at first. If omitted, buffer-file-coding-system of the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
316 ;; current buffer is used.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
317 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
318 ;; If the text can be encoded safely by DEFAULT-CODING-SYSTEM, it is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
319 ;; returned without any user interaction.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
320 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
321 ;; Kludgy feature: if FROM is a string, the string is the target text,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
322 ;; and TO is ignored."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
323 ;; (or default-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
324 ;; (setq default-coding-system buffer-file-coding-system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
325 ;; (let* ((charsets (if (stringp from) (find-charset-string from)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
326 ;; (find-charset-region from to)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
327 ;; (safe-coding-systems (find-coding-systems-for-charsets charsets)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
328 ;; (if (or (not enable-multibyte-characters)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
329 ;; (eq (car safe-coding-systems) 'undecided)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
330 ;; (eq default-coding-system 'no-conversion)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
331 ;; (and default-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
332 ;; (memq (coding-system-base default-coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
333 ;; safe-coding-systems)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
334 ;; default-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
335 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
336 ;; ;; At first, change each coding system to the corresponding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
337 ;; ;; mime-charset name if it is also a coding system.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
338 ;; (let ((l safe-coding-systems)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
339 ;; mime-charset)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
340 ;; (while l
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
341 ;; (setq mime-charset (coding-system-get (car l) 'mime-charset))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
342 ;; (if (and mime-charset (coding-system-p mime-charset))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
343 ;; (setcar l mime-charset))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
344 ;; (setq l (cdr l))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
345 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
346 ;; (let ((non-safe-chars (find-multibyte-characters
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
347 ;; from to 3
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
348 ;; (and default-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
349 ;; (coding-system-get default-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
350 ;; 'safe-charsets))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
351 ;; show-position overlays)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
352 ;; (save-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
353 ;; ;; Highlight characters that default-coding-system can't encode.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
354 ;; (when (integerp from)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
355 ;; (goto-char from)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
356 ;; (let ((found nil))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
357 ;; (while (and (not found)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
358 ;; (re-search-forward "[^\000-\177]" to t))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
359 ;; (setq found (assq (char-charset (preceding-char))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
360 ;; non-safe-chars))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
361 ;; (forward-line -1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
362 ;; (setq show-position (point))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
363 ;; (save-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
364 ;; (while (and (< (length overlays) 256)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
365 ;; (re-search-forward "[^\000-\177]" to t))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
366 ;; (let* ((char (preceding-char))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
367 ;; (charset (char-charset char)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
368 ;; (when (assq charset non-safe-chars)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
369 ;; (setq overlays (cons (make-overlay (1- (point)) (point))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
370 ;; overlays))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
371 ;; (overlay-put (car overlays) 'face 'highlight))))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
372 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
373 ;; ;; At last, ask a user to select a proper coding system.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
374 ;; (unwind-protect
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
375 ;; (save-window-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
376 ;; (when show-position
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
377 ;; ;; At first, be sure to show the current buffer.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
378 ;; (set-window-buffer (selected-window) (current-buffer))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
379 ;; (set-window-start (selected-window) show-position))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
380 ;; ;; Then, show a helpful message.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
381 ;; (with-output-to-temp-buffer "*Warning*"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
382 ;; (save-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
383 ;; (set-buffer standard-output)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
384 ;; (insert "The target text contains the following non ASCII character(s):\n")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
385 ;; (let ((len (length non-safe-chars))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
386 ;; (shown 0))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
387 ;; (while (and non-safe-chars (< shown 3))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
388 ;; (when (> (length (car non-safe-chars)) 2)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
389 ;; (setq shown (1+ shown))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
390 ;; (insert (format "%25s: " (car (car non-safe-chars))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
391 ;; (let ((l (nthcdr 2 (car non-safe-chars))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
392 ;; (while l
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
393 ;; (if (or (stringp (car l)) (char-valid-p (car l)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
394 ;; (insert (car l)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
395 ;; (setq l (cdr l))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
396 ;; (if (> (nth 1 (car non-safe-chars)) 3)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
397 ;; (insert "..."))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
398 ;; (insert "\n"))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
399 ;; (setq non-safe-chars (cdr non-safe-chars)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
400 ;; (if (< shown len)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
401 ;; (insert (format "%27s\n" "..."))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
402 ;; (insert (format "\
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
403 ;; These can't be encoded safely by the coding system %s.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
404 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
405 ;; Please select one from the following safe coding systems:\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
406 ;; default-coding-system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
407 ;; (let ((pos (point))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
408 ;; (fill-prefix " "))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
409 ;; (mapcar (function (lambda (x) (princ " ") (princ x)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
410 ;; safe-coding-systems)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
411 ;; (fill-region-as-paragraph pos (point)))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
412 ;;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
413 ;; ;; Read a coding system.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
414 ;; (let* ((safe-names (mapcar (lambda (x) (list (symbol-name x)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
415 ;; safe-coding-systems))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
416 ;; (name (completing-read
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
417 ;; (format "Select coding system (default %s): "
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
418 ;; (car safe-coding-systems))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
419 ;; safe-names nil t nil nil
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
420 ;; (car (car safe-names)))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
421 ;; (setq last-coding-system-specified (intern name))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
422 ;; (if (integerp (coding-system-eol-type default-coding-system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
423 ;; (setq last-coding-system-specified
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
424 ;; (coding-system-change-eol-conversion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
425 ;; last-coding-system-specified
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
426 ;; (coding-system-eol-type default-coding-system))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
427 ;; last-coding-system-specified))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
428 ;; (kill-buffer "*Warning*")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
429 ;; (while overlays
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
430 ;; (delete-overlay (car overlays))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
431 ;; (setq overlays (cdr overlays)))))))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
432
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
433 ;; (setq select-safe-coding-system-function 'select-safe-coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
434
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
435 ;; (defun select-message-coding-system ()
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
436 ;; "Return a coding system to encode the outgoing message of the current buffer.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
437 ;; It at first tries the first coding system found in these variables
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
438 ;; in this order:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
439 ;; (1) local value of `buffer-file-coding-system'
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
440 ;; (2) value of `sendmail-coding-system'
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
441 ;; (3) value of `default-buffer-file-coding-system'
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
442 ;; (4) value of `default-sendmail-coding-system'
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
443 ;; If the found coding system can't encode the current buffer,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
444 ;; or none of them are bound to a coding system,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
445 ;; it asks the user to select a proper coding system."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
446 ;; (let ((coding (or (and (local-variable-p 'buffer-file-coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
447 ;; buffer-file-coding-system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
448 ;; sendmail-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
449 ;; default-buffer-file-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
450 ;; default-sendmail-coding-system)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
451 ;; (if (eq coding 'no-conversion)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
452 ;; ;; We should never use no-conversion for outgoing mails.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
453 ;; (setq coding nil))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
454 ;; (if (fboundp select-safe-coding-system-function)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
455 ;; (funcall select-safe-coding-system-function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
456 ;; (point-min) (point-max) coding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
457 ;; coding)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
458
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
459 (provide 'code-cmds)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
460
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents:
diff changeset
461 ;;; code-cmds.el ends here