unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Miles Bader <miles@lsi.nec.co.jp>
Cc: rms@gnu.org, monnier+gnu/emacs@rum.cs.yale.edu,
	Kai.Grossjohann@CS.Uni-Dortmund.DE, emacs-devel@gnu.org
Subject: Re: comint-carriage-motion causes severe problems.
Date: 19 Aug 2002 14:04:59 +0900	[thread overview]
Message-ID: <buoelcvqw04.fsf@mcspd15.ucom.lsi.nec.co.jp> (raw)
In-Reply-To: <200208180239.VAA02371@eel.dms.auburn.edu>

[-- Attachment #1: Type: text/plain, Size: 244 bytes --]

Luc Teirlinck <teirllm@dms.auburn.edu> 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:



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch to fix carriage motion problems in ielm --]
[-- Type: text/x-patch, Size: 6643 bytes --]

2002-08-19  Miles Bader  <miles@gnu.org>

	[original idea from Luc Teirlinck <teirllm@mail.auburn.edu>]
	* 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 <maa036@lancaster.ac.uk>
 ;; 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

[-- Attachment #3: Type: text/plain, Size: 70 bytes --]



-Miles
-- 
Saa, shall we dance?  (from a dance-class advertisement)

  parent reply	other threads:[~2002-08-19  5:04 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-02  0:35 comint-carriage-motion causes severe problems Luc Teirlinck
2002-07-02  1:32 ` Miles Bader
2002-07-02  8:33   ` Kai Großjohann
2002-07-02  8:46     ` Miles Bader
2002-07-02 15:34       ` Stefan Monnier
2002-07-02 16:18         ` Luc Teirlinck
2002-07-03 20:57           ` Richard Stallman
2002-07-03 21:11             ` Stefan Monnier
2002-07-04  1:18               ` Luc Teirlinck
2002-07-04 15:43                 ` Stefan Monnier
2002-07-04 16:56                   ` Luc Teirlinck
2002-07-04 17:04                     ` Stefan Monnier
2002-07-04 17:18                       ` Kai Großjohann
2002-07-04 17:31                       ` Luc Teirlinck
2002-07-04 18:21                       ` Miles Bader
2002-07-04  1:38               ` Luc Teirlinck
2002-07-04  3:49               ` Luc Teirlinck
     [not found]               ` <200207040337.WAA22499@eel.dms.auburn.edu>
     [not found]                 ` <200207041531.g64FVRp29714@rum.cs.yale.edu>
2002-07-04 16:07                   ` Luc Teirlinck
2002-07-04 18:24               ` Richard Stallman
2002-07-04 20:19                 ` Luc Teirlinck
2002-07-05 22:07                   ` Richard Stallman
2002-07-05  0:47                 ` Luc Teirlinck
2002-07-05 22:07                   ` Richard Stallman
2002-08-07  1:16                 ` Luc Teirlinck
2002-08-07 20:58                   ` Richard Stallman
2002-08-07 22:19                     ` Luc Teirlinck
2002-08-07 22:27                       ` Luc Teirlinck
2002-08-09  2:47                       ` Richard Stallman
2002-08-18  2:39                     ` Luc Teirlinck
2002-08-18  3:01                       ` Luc Teirlinck
2002-08-18  3:59                         ` Luc Teirlinck
2002-08-19  5:04                       ` Miles Bader [this message]
2002-07-02 17:08         ` Luc Teirlinck
2002-07-02 19:45   ` Richard Stallman
2002-07-03  0:02     ` Miles Bader
2002-07-03  0:06     ` Miles Bader
2002-07-04  7:07       ` Richard Stallman
2002-07-03  1:51     ` Luc Teirlinck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=buoelcvqw04.fsf@mcspd15.ucom.lsi.nec.co.jp \
    --to=miles@lsi.nec.co.jp \
    --cc=Kai.Grossjohann@CS.Uni-Dortmund.DE \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    --cc=monnier+gnu/emacs@rum.cs.yale.edu \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).