simpson@math.psu.edu (Stephen G. Simpson) (02/16/91)
The information below was posted on the Chinese Computing Network (ccnet-l@uga.uga.edu) and is also available for anonymous ftp at cs.purdue.edu in pub/ygz/cxemacs. The Emacs Lisp code below leaves a lot of room for improvement. If you make any progress, please send your code to me (simpson@math.psu.edu), Mark Leisher (mleisher@nmsu.edu), and Yongguang Zhang (ygz@cs.purdue.edu). --------------- beginning of cxemacs document --------------- CHINESE EMACS !!!!! Here is a way to make Emacs work under CXterm. You will then be able to use Emacs to edit Chinese files. (For those who don't know, Emacs is GNU Emacs, the widely used customizable text editor. CXterm is a Chinese-capable X-Window terminal program, based on MIT X11R4 XTerm. CXterm uses the standard GuoBiao coding of Chinese characters, where each Chinese character is represented by two 8-bit bytes. CXterm is available for anonymous FTP at cs.purdue.edu, directory pub/ygz.) FIRST, get the source code for GNU Emacs, version 18.55. (The patch below may also work for version 18.56 and above. It will become obsolete when version 19 arrives.) SECOND, apply Ken Cline's 8-bit patch (at the end of this message) to the Emacs source code. Then compile and install Emacs, following the instructions provided with the source code. THIRD, put the following lines of Emacs Lisp code into your Emacs startup file, normally .emacs. (Alternatively, you can save this as an autoloaded cxterm-mode.el file.) ---------------- Emacs Lisp code ------------------------- ;; set up keymap for 8-bit characters (setq insert-meta-map (make-keymap)) (setq num 0) (while (< num 128) (define-key insert-meta-map (char-to-string num) (concat "\C-Q" (char-to-string (+ 128 num)))) (setq num (+ num 1))) ;; interactive commands for CXterm mode ;; -- should be improved to take arguments, etc. (defun cxterm-forward-char () "CXterm version of forward-char" (interactive) (forward-char (if (> (char-after (point)) 128) 2 1))) (defun cxterm-backward-char () "CXterm version of backward-char" (interactive) (backward-char (if (> (char-after (- (point) 1)) 128) 2 1))) (defun cxterm-delete-char () "CXterm version of delete-char" (interactive) (delete-char (if (> (char-after (point)) 128) 2 1))) (defun cxterm-backward-delete-char-untabify () "CXterm version of backward-delete-char-untabify" (interactive) (backward-delete-char-untabify (if (> (char-after (- (point) 1)) 128) 2 1))) ;; CXterm mode -- should be a minor mode toggle (defun cxterm-mode-on () "Put the current buffer into CXterm mode, for editing Chinese files inside CXterm." (interactive) (setq ctl-arrow 2) (local-set-key (char-to-string 28) insert-meta-map) (local-set-key "\C-f" 'cxterm-forward-char) (local-set-key "\C-b" 'cxterm-backward-char) (local-set-key "\C-d" 'cxterm-delete-char) (local-set-key "\177" 'cxterm-backward-delete-char-untabify) ;; Unfortunately, the next two variables are global, ;; so the Meta key will be disabled in 7-bit buffers. (setq meta-prefix-char 28) (setq meta-flag t)) ------------- end of Emacs Lisp code ---------------------- FOURTH, open a CXterm window and run Emacs inside it. (If your Emacs was compiled with X-Window support, you will need to run Emacs using -t `tty` as the first command line option. This option tells Emacs to run in the current window, rather than opening up its own window.) FIFTH, get into an Emacs editing buffer, and type "ESC x cxterm-mode-on" (without the quotation marks or spaces, and followed by a carriage return). This will put the buffer into Chinese mode. You can now use this buffer to display and edit files containing a mixture of Chinese and plain ASCII. Chinese characters are entered as usual using any of the input methods provided by CXterm. You should be able to delete and move text using familiar Emacs keys and commands. The only difference you will notice is that your Meta key (if you have one) will not work correctly. However, the ESC key will work, so you can still use Meta key commands. (For instance, instead of Meta-v you will type ESC v.) If the screen display becomes confused, type Control-L to refresh it. Enjoy !!!! I would like to thank Mark Leisher for giving me Ken Cline's patch, and Yongguang Zhang for writing the interactive CXterm mode commands. Stephen G. Simpson simpson@math.psu.edu Department of Mathematics t20@psuvm.bitnet Pennsylvania State University +1 814 863-0775 University Park, PA 16802 ------------------- Ken Cline's 8-bit patch ---------------- From: cline@PROOF.ERGO.CS.CMU.EDU (Kenneth Cline) Newsgroups: comp.emacs Subject: Re: Character display Message-ID: <7230@pt.cs.cmu.edu> Date: 6 Dec 89 19:19:17 GMT Distribution: gnu Organization: Carnegie-Mellon University, CS/RI Incorporating the diffs for buffer.c, indent.c and xdisp.c below will cause emacs to display 255 character fonts (newline is special) in buffers with local variable ctl-arrow set to any value other than T or NIL. This change will be obsolete when version 19 is released, but it is nonetheless useful for the time being. It has been pointed out that answering questions about the availability of version 19 takes time away from writing the code, so please be patient. *** /tmp/,RCSt1a14606 Thu Dec 7 22:01:03 1989 --- buffer.c Thu Dec 7 21:00:44 1989 *************** *** 1297,1305 **** Automatically becomes local when set in any fashion."); DEFVAR_PER_BUFFER ("ctl-arrow", &bf_cur->ctl_arrow, ! "*Non-nil means display control chars with uparrow.\n\ Nil means use backslash and octal digits.\n\ ! Automatically becomes local when set in any fashion."); DEFVAR_PER_BUFFER ("truncate-lines", &bf_cur->truncate_lines, "*Non-nil means do not display continuation lines;\n\ --- 1297,1308 ---- Automatically becomes local when set in any fashion."); DEFVAR_PER_BUFFER ("ctl-arrow", &bf_cur->ctl_arrow, ! "*t means display control chars with uparrow.\n\ Nil means use backslash and octal digits.\n\ ! Otherwise assume that control and meta chars are printable.\n\ ! Automatically becomes local when set in any fashion.\n\ ! \n\ ! This is an Ergo local feature."); DEFVAR_PER_BUFFER ("truncate-lines", &bf_cur->truncate_lines, "*Non-nil means do not display continuation lines;\n\ *** /tmp/,RCSt1a28312 Wed Jan 31 20:57:35 1990 --- indent.c Wed Dec 27 10:56:26 1989 *************** *** 67,73 **** register int tab_seen; register int post_tab; register int tab_width = XINT (bf_cur->tab_width); ! int ctl_arrow = !NULL (bf_cur->ctl_arrow); if (point == last_known_column_point && bf_modified == last_known_column_modified) --- 67,74 ---- register int tab_seen; register int post_tab; register int tab_width = XINT (bf_cur->tab_width); ! int ctl_arrow = (!NULL (bf_cur->ctl_arrow)) ! + (EQ (bf_cur->ctl_arrow, Qt)); if (point == last_known_column_point && bf_modified == last_known_column_modified) *************** *** 109,115 **** tab_seen = 1; } else ! col += (ctl_arrow && c < 0200) ? 2 : 4; } if (tab_seen) --- 110,117 ---- tab_seen = 1; } else ! col += (ctl_arrow == 1 && c >= 0177) ? 1 : ! (ctl_arrow && c < 0200) ? 2 : 4; } if (tab_seen) *************** *** 231,237 **** register int goal; register int end = NumCharacters; register int tab_width = XINT (bf_cur->tab_width); ! register int ctl_arrow = !NULL (bf_cur->ctl_arrow); Lisp_Object val; --- 233,240 ---- register int goal; register int end = NumCharacters; register int tab_width = XINT (bf_cur->tab_width); ! register int ctl_arrow = (!NULL (bf_cur->ctl_arrow)) ! + (EQ (bf_cur->ctl_arrow, Qt)); Lisp_Object val; *************** *** 258,263 **** --- 261,268 ---- col += tab_width - 1; col = col / tab_width * tab_width; } + else if (ctl_arrow == 1 && c >= 040) + continue; else if (ctl_arrow && (c < 040 || c == 0177)) col++; else if (c < 040 || c >= 0177) *************** *** 306,312 **** register int pos; register int c; register int tab_width = XFASTINT (bf_cur->tab_width); ! register int ctl_arrow = !NULL (bf_cur->ctl_arrow); int selective = XTYPE (bf_cur->selective_display) == Lisp_Int ? XINT (bf_cur->selective_display) --- 311,318 ---- register int pos; register int c; register int tab_width = XFASTINT (bf_cur->tab_width); ! register int ctl_arrow = (!NULL (bf_cur->ctl_arrow)) ! + (EQ (bf_cur->ctl_arrow, Qt)); int selective = XTYPE (bf_cur->selective_display) == Lisp_Int ? XINT (bf_cur->selective_display) *************** *** 370,376 **** } } else ! cpos += (ctl_arrow && c < 0200) ? 2 : 4; if (HPOS (cpos) >= width && (HPOS (cpos) > width --- 376,382 ---- } } else ! cpos += (ctl_arrow == 1 && c >= 040 ) ? 1 : (ctl_arrow && c < 0200) ? 2 : 4; if (HPOS (cpos) >= width && (HPOS (cpos) > width *** /tmp/,RCSt1a28325 Wed Jan 31 20:58:19 1990 --- xdisp.c Wed Dec 27 10:56:23 1989 *************** *** 1203,1209 **** register char *p1prev; register struct display_line *line; int tab_width = XINT (bf_cur->tab_width); ! int ctl_arrow = !NULL (bf_cur->ctl_arrow); int width = XFASTINT (w->width) - 1 - (XFASTINT (w->width) + XFASTINT (w->left) != screen_width); struct position val; --- 1203,1210 ---- register char *p1prev; register struct display_line *line; int tab_width = XINT (bf_cur->tab_width); ! int ctl_arrow = (!NULL (bf_cur->ctl_arrow)) ! + (EQ (bf_cur->ctl_arrow, Qt)); int width = XFASTINT (w->width) - 1 - (XFASTINT (w->width) + XFASTINT (w->left) != screen_width); struct position val; *************** *** 1319,1324 **** --- 1320,1331 ---- } break; } + else if (ctl_arrow == 1 && c >= 040) + { + if (p1 >= startp) + *p1 = c; + p1++; + } else if (c < 0200 && ctl_arrow) { if (p1 >= startp) *************** *** 1917,1922 **** --- 1924,1935 ---- p1++; } while ((p1 - start + hscroll - (hscroll > 0)) % tab_width); + } + else if (buffer_defaults.ctl_arrow == 1 && c >= 040) + { + if (p1 >= start) + *p1 = c; + p1++; } else if (c < 0200 && buffer_defaults.ctl_arrow) { --------------- end of Ken Cline's 8-bit patch ------------- --------------- end of cxemacs document -------------------- -- Stephen G. Simpson simpson@math.psu.edu Department of Mathematics t20@psuvm.bitnet Pennsylvania State University +1 814 863-0775 University Park, PA 16802