Ben Wing <ben(a)666.com> writes:
This proposal sounds great. Please implement if you can.
Sure.
While I was implementing this, I was bitten by
reset_decoding_stream bug. You need to apply my previous
two patches to make this work correctly.
Although set-buffer-process-coding-system seems designed to
be used with shell-mode, it doesn't work the way it does
before. Now it is equivalent to
comint-set-next-coding-system. It's resetted after one
command execution. You must use comint-set-coding-system
instead.
C-x RET c CODING-SYSTEM M-x shell works like FSF Emacs. If
explicitly specified, comint will reset to that
coding-system instead of automatic-conversion.
It seems there's no way to check whether given XEmacs is
compiled with file-coding. WIBNI it provides file-coding
feature?
1999-12-30 Yoshiki Hayashi <t90553(a)mail.ecc.u-tokyo.ac.jp>
* comint.el (comint-3-menubar-menu): Add menu for coding system.
(comint-3-menubar-menu-1): Ditto.
(comint-mode): Ditto. Add new local variable
comint-coding-system-for-read and comint-coding-system-for-write.
(comint-send-input): Reset coding system.
(comint-set-next-coding-system): New function.
(comint-set-coding-system): New function.
Index: comint.el
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs-packages/libs/xemacs-base/comint.el,v
retrieving revision 1.5
diff -u -r1.5 comint.el
--- comint.el 1999/07/23 08:45:16 1.5
+++ comint.el 1999/12/30 03:19:01
@@ -446,9 +446,17 @@
["Send EOF" comint-send-eof t]
)))
+;; When compiled with file-coding
+(when (boundp 'coding-system-for-read)
+ (defvar comint-3-menubar-menu nil)
+ (defconst comint-3-menubar-menu-1
+ '("Coding-System"
+ ["Next Command" comint-set-next-coding-system]
+ ["All Command" comint-set-coding-system]))
+ (defvar comint-coding-system-for-read)
+ (defvar comint-coding-system-for-write))
-
(defun comint-mode ()
"Major mode for interacting with an inferior interpreter.
Interpreter name is same as buffer name, sans the asterisks.
@@ -530,6 +538,15 @@
(make-local-variable 'comint-process-echoes)
(make-local-variable 'comint-file-name-chars)
(make-local-variable 'comint-file-name-quote-list)
+ ;; Set coding-system
+ ;; default to automatic-conversion
+ (when (boundp 'coding-system-for-read)
+ (make-local-variable 'comint-coding-system-for-read)
+ (make-local-variable 'comint-coding-system-for-write)
+ (setq comint-coding-system-for-read
+ (or coding-system-for-read 'automatic-conversion))
+ (setq comint-coding-system-for-write
+ (or coding-system-for-write 'automatic-conversion)))
(unless comint-1-menubar-menu
(easy-menu-define comint-1-menubar-menu nil ""
comint-1-menubar-menu-1))
@@ -544,6 +561,11 @@
(easy-menu-define comint-history-menubar-menu nil ""
comint-history-menubar-menu-1))
(easy-menu-add comint-history-menubar-menu)
+ (when (boundp 'coding-system-for-read)
+ (unless comint-3-menubar-menu
+ (easy-menu-define comint-3-menubar-menu nil ""
+ comint-3-menubar-menu-1))
+ (easy-menu-add comint-3-menubar-menu))
(run-hooks 'comint-mode-hook))
(if comint-mode-map
@@ -1358,8 +1380,15 @@
;; comint-send-input-hook?
(run-hook-with-args 'comint-output-filter-functions
(concat input "\n"))
- (comint-output-filter proc "")
- )))))
+ (comint-output-filter proc ""))
+ ;; Let output-filter run and reset coding-system
+ (when (fboundp 'set-process-coding-system)
+ (sit-for 1)
+ (set-process-coding-system
+ proc
+ comint-coding-system-for-read
+ comint-coding-system-for-write))))))
+
(defun comint-input-done ()
"Finalized comint-input-extent so nothing more is added."
;; Disable this for now. I'm not sure that font-lock doesn't do better
@@ -1732,6 +1761,40 @@
(defalias 'comint-send-string 'process-send-string)
(defalias 'comint-send-region 'process-send-region)
+
+
+;; Coding-system
+
+(when (boundp 'coding-system-for-read)
+ (defun comint-set-next-coding-system (input output)
+ "Set coding system for next command.
+INPUT is the coding system to be used to decode input from the process,
+OUTPUT is the coding system to be used to encode output to the process."
+ (interactive
+ "zCoding-system for process input: \nzCoding-system for process output:
")
+ (let ((proc (get-buffer-process (current-buffer))))
+ (if (null proc)
+ (error "no process")
+ (check-coding-system input)
+ (check-coding-system output)
+ (set-process-coding-system proc input output)))
+ (force-mode-line-update))
+
+ (defun comint-set-coding-system (input output)
+ "Set coding system for this session.
+INPUT is the coding system to be used to decode input from the process,
+OUTPUT is the coding system to be used to encode output to the process."
+ (interactive
+ "zCoding-system for process input: \nzCoding-system for process output:
")
+ (let ((proc (get-buffer-process (current-buffer))))
+ (if (null proc)
+ (error "no process")
+ (check-coding-system input)
+ (check-coding-system output)
+ (setq comint-coding-system-for-read input)
+ (setq comint-coding-system-for-write output)
+ (set-process-coding-system proc input output))
+ (force-mode-line-update))))
;; Random input hackage
--
Yoshiki Hayashi