From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Miles Bader Newsgroups: gmane.emacs.devel Subject: Re: comint-carriage-motion causes severe problems. Date: 19 Aug 2002 14:04:59 +0900 Sender: emacs-devel-admin@gnu.org Message-ID: References: <200207020035.TAA19789@eel.dms.auburn.edu> <200207021534.g62FYao17897@rum.cs.yale.edu> <200207021618.LAA20219@eel.dms.auburn.edu> <200207032057.g63KvX604721@aztec.santafe.edu> <200207032111.g63LBAv25925@rum.cs.yale.edu> <200207041824.g64IO8i06426@aztec.santafe.edu> <200208070116.UAA01281@eel.dms.auburn.edu> <200208072058.g77KwUo03670@wijiji.santafe.edu> <200208180239.VAA02371@eel.dms.auburn.edu> Reply-To: Miles Bader NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1029733689 25945 127.0.0.1 (19 Aug 2002 05:08:09 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 19 Aug 2002 05:08:09 +0000 (UTC) Cc: rms@gnu.org, monnier+gnu/emacs@rum.cs.yale.edu, Kai.Grossjohann@CS.Uni-Dortmund.DE, emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17gelp-0006kH-00 for ; Mon, 19 Aug 2002 07:08:05 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17gfD5-00010p-00 for ; Mon, 19 Aug 2002 07:36:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17gemt-0004cn-00; Mon, 19 Aug 2002 01:09:11 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17gejS-0004VQ-00 for emacs-devel@gnu.org; Mon, 19 Aug 2002 01:05:38 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17gejO-0004Uq-00 for emacs-devel@gnu.org; Mon, 19 Aug 2002 01:05:37 -0400 Original-Received: from tyo202.gate.nec.co.jp ([210.143.35.52]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17gejN-0004Uh-00; Mon, 19 Aug 2002 01:05:34 -0400 Original-Received: from mailgate4.nec.co.jp ([10.7.69.193]) by TYO202.gate.nec.co.jp (8.11.6/3.7W01080315) with ESMTP id g7J55CM04802; Mon, 19 Aug 2002 14:05:12 +0900 (JST) Original-Received: from mailsv.nec.co.jp (mailgate51.nec.co.jp [10.7.69.190]) by mailgate4.nec.co.jp (8.11.6/3.7W-MAILGATE-NEC) with ESMTP id g7J55BI15635; Mon, 19 Aug 2002 14:05:11 +0900 (JST) Original-Received: from mcsss2.ucom.lsi.nec.co.jp ([10.30.114.133]) by mailsv.nec.co.jp (8.11.6/3.7W-MAILSV-NEC) with ESMTP id g7J555L05218; Mon, 19 Aug 2002 14:05:10 +0900 (JST) Original-Received: from mcspd15.ucom.lsi.nec.co.jp (mcspd15 [10.30.114.174]) by mcsss2.ucom.lsi.nec.co.jp (8.10.2+Sun/3.7Wlsi_mx_6.0) with ESMTP id g7J550s10880; Mon, 19 Aug 2002 14:05:00 +0900 (JST) Original-Received: by mcspd15.ucom.lsi.nec.co.jp (Postfix, from userid 31295) id AE9A036F2; Mon, 19 Aug 2002 14:04:59 +0900 (JST) Original-To: Luc Teirlinck System-Type: i686-pc-linux-gnu Blat: Foop In-Reply-To: <200208180239.VAA02371@eel.dms.auburn.edu> Original-Lines: 16 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:6641 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:6641 --=-=-= Luc Teirlinck writes: > Below are change logs and diffs for comint.el and ielm.el. I've made equivalent changes in CVS (basically the same changes you made, but some of the details are different). Here's the patch: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=p Content-Description: Patch to fix carriage motion problems in ielm 2002-08-19 Miles Bader [original idea from Luc Teirlinck ] * comint.el (comint-inhibit-carriage-motion): New variable. (comint-carriage-motion): Argument STRING removed. New arguments START and END; interpret characters between START and END rather than using special comint state. (comint-output-filter): Call `comint-carriage-motion'. (comint-output-filter-functions): Don't add `comint-carriage-motion'. * ielm.el (inferior-emacs-lisp-mode): Give `comint-inhibit-carriage-motion' a local value of t. Index: lisp/comint.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/comint.el,v retrieving revision 1.281 diff -u -r1.281 comint.el --- lisp/comint.el 8 Jul 2002 08:45:00 -0000 1.281 +++ lisp/comint.el 19 Aug 2002 05:00:08 -0000 @@ -1525,6 +1525,10 @@ You can use `add-hook' to add functions to this list either globally or locally.") +(defvar comint-inhibit-carriage-motion nil + "If nil, comint will interpret `carriage control' characters in output. +See `comint-carriage-motion' for details.") + ;; When non-nil, this is an overlay over the last recognized prompt in ;; the buffer; it is used when highlighting the prompt. (defvar comint-last-prompt-overlay nil) @@ -1539,43 +1543,38 @@ (overlay-end comint-last-prompt-overlay) (overlay-properties comint-last-prompt-overlay))))) -(defun comint-carriage-motion (string) - "Handle carriage control characters in comint output. +(defun comint-carriage-motion (start end) + "Interpret carriage control characters in the region from START to END. Translate carriage return/linefeed sequences to linefeeds. Make single carriage returns delete to the beginning of the line. -Make backspaces delete the previous character. - -This function should be in the list `comint-output-filter-functions'." - (save-match-data - ;; We first check to see if STRING contains any magic characters, to - ;; avoid overhead in the common case where it does not - (when (string-match "[\r\b]" string) - (let ((pmark (process-mark (get-buffer-process (current-buffer))))) - (save-excursion - (save-restriction - (widen) - (let ((inhibit-field-text-motion t) - (buffer-read-only nil)) - ;; CR LF -> LF - ;; Note that this won't work properly when the CR and LF - ;; are in different output chunks, but this is probably an - ;; exceedingly rare case (because they are generally - ;; written as a unit), and to delay interpretation of a - ;; trailing CR in a chunk would result in odd interactive - ;; behavior (and this case is probably far more common). - (goto-char comint-last-output-start) - (while (re-search-forward "\r$" pmark t) - (delete-char -1)) - ;; bare CR -> delete preceding line - (goto-char comint-last-output-start) - (while (search-forward "\r" pmark t) - (delete-region (point) (line-beginning-position))) - ;; BS -> delete preceding character - (goto-char comint-last-output-start) - (while (search-forward "\b" pmark t) - (delete-char -2))))))))) - -(add-hook 'comint-output-filter-functions 'comint-carriage-motion) +Make backspaces delete the previous character." + (save-excursion + ;; First do a quick check to see if there are any applicable + ;; characters, so we can avoid calling save-match-data and + ;; save-restriction if not. + (when (< (skip-chars-forward "^\b\r" end) (- end start)) + (save-match-data + (save-restriction + (widen) + (let ((inhibit-field-text-motion t) + (buffer-read-only nil)) + ;; CR LF -> LF + ;; Note that this won't work properly when the CR and LF + ;; are in different output chunks, but this is probably an + ;; exceedingly rare case (because they are generally + ;; written as a unit), and to delay interpretation of a + ;; trailing CR in a chunk would result in odd interactive + ;; behavior (and this case is probably far more common). + (while (re-search-forward "\r$" end t) + (delete-char -1)) + ;; bare CR -> delete preceding line + (goto-char start) + (while (search-forward "\r" end t) + (delete-region (point) (line-beginning-position))) + ;; BS -> delete preceding character + (goto-char start) + (while (search-forward "\b" end t) + (delete-char -2)))))))) ;; The purpose of using this filter for comint processes ;; is to keep comint-last-input-end from moving forward @@ -1660,7 +1659,12 @@ ;; Advance process-mark (set-marker (process-mark process) (point)) + (unless comint-inhibit-carriage-motion + ;; Interpret any carriage motion characters (newline, backspace) + (comint-carriage-motion comint-last-output-start (point))) + (run-hook-with-args 'comint-output-filter-functions string) + (goto-char (process-mark process)) ; in case a filter moved it (unless comint-use-prompt-regexp-instead-of-fields Index: lisp/ielm.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/ielm.el,v retrieving revision 1.26 diff -u -r1.26 ielm.el --- lisp/ielm.el 15 Jun 2002 14:17:24 -0000 1.26 +++ lisp/ielm.el 19 Aug 2002 05:00:08 -0000 @@ -1,6 +1,6 @@ ;;; ielm.el --- interaction mode for Emacs Lisp -;; Copyright (C) 1994 Free Software Foundation, Inc. +;; Copyright (C) 1994, 2002 Free Software Foundation, Inc. ;; Author: David Smith ;; Maintainer: FSF @@ -452,18 +452,24 @@ '(ielm-font-lock-keywords nil nil ((?: . "w") (?- . "w") (?* . "w")))) ;; A dummy process to keep comint happy. It will never get any input - (if (comint-check-proc (current-buffer)) nil + (unless (comint-check-proc (current-buffer)) ;; Was cat, but on non-Unix platforms that might not exist, so ;; use hexl instead, which is part of the Emacs distribution. (start-process "ielm" (current-buffer) "hexl") (process-kill-without-query (ielm-process)) (goto-char (point-max)) + + ;; Lisp output can include raw characters that confuse comint's + ;; carriage control code. + (set (make-local-variable 'comint-inhibit-carriage-motion) t) + ;; Add a silly header (insert ielm-header) (ielm-set-pm (point-max)) (comint-output-filter (ielm-process) ielm-prompt) (set-marker comint-last-input-start (ielm-pm)) (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)) + (run-hooks 'ielm-mode-hook)) (defun ielm-get-old-input nil --=-=-= -Miles -- Saa, shall we dance? (from a dance-class advertisement) --=-=-=--