From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#18135: bug#3735: shell-mode editing, movement, and command entry broken by prompt/output changes Date: Tue, 07 Dec 2021 17:57:34 +0100 Message-ID: <878rww4akh.fsf@miha-pc> References: <9A88C51B-AE7B-4FD8-9929-6F058AC23AE6@gmail.com> <87lf10138e.fsf_-_@gnus.org> <33D68609-31C2-465C-8718-667B5F51B50E@donhopkins.com> <87bl1v3u99.fsf@miha-pc> <8735n6svhn.fsf@gnus.org> Reply-To: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30972"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 3735@debbugs.gnu.org, dsb@smart.net, Chong Yidong , 18135@debbugs.gnu.org, Don Hopkins To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 07 17:53:12 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mudiI-0007kK-8H for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Dec 2021 17:53:10 +0100 Original-Received: from localhost ([::1]:50586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mudiH-00023L-7s for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Dec 2021 11:53:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mudiA-00022g-8C for bug-gnu-emacs@gnu.org; Tue, 07 Dec 2021 11:53:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mudiA-0001H7-0U for bug-gnu-emacs@gnu.org; Tue, 07 Dec 2021 11:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mudi9-0004uq-RI for bug-gnu-emacs@gnu.org; Tue, 07 Dec 2021 11:53:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Dec 2021 16:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18135 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 18135-submit@debbugs.gnu.org id=B18135.163889595618856 (code B ref 18135); Tue, 07 Dec 2021 16:53:01 +0000 Original-Received: (at 18135) by debbugs.gnu.org; 7 Dec 2021 16:52:36 +0000 Original-Received: from localhost ([127.0.0.1]:38498 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mudhj-0004u3-Pt for submit@debbugs.gnu.org; Tue, 07 Dec 2021 11:52:36 -0500 Original-Received: from kamnitnik.top ([209.250.245.214]:41346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mudhd-0004tp-V0; Tue, 07 Dec 2021 11:52:34 -0500 Original-Received: from localhost (BSN-77-156-43.static.siol.net [193.77.156.43]) by kamnitnik.top (Postfix) with ESMTPSA id DAAC39CAE9; Tue, 7 Dec 2021 16:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1638895949; bh=4K1d/FtctzFjWXpl5RWx8ViHPZIpkEu6M3mOuS8z+i8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=JY8C5iYfm1BtwmVdD/ygskyFeYd97dE8aAVn/V4Q49G1bi5Q1cbBs1IPMJGgkstfg bLNnLqT/nHNfgKQPj7TnEkMaZ0Ki3P06zwJn4985R9sMAVrKvBg/X4wgOCGERjHjoq qKS9Hgokoj7Y7dptq8FDt3IXEE69V31oOxdrHO4USkD/uLy52rYkBkGPgzCD2xFS6e lZPHd1U20UQkk3DaNx43KN/+kka1DO+NAJKLOwX9WUCKnRsFdq07fj+zhXq7/uIlaP Bo2FOzfHqe5u3mZ99h+vnLcu2tiw/9Qj4XXKgiwawCOXyZGeJZgiRSEu7hOuF+kr0I aTu+fLTpwdFHw== In-Reply-To: <8735n6svhn.fsf@gnus.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:221850 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > miha@kamnitnik.top writes: > >> Reproducer: >> >> - copy " -la" into kill ring >> - type "echo ls" into M-x shell >> - (Shell gives output line "ls".) >> - Go up to output line "ls" (C-p). >> - yank " -la" >> - press C-b >> - the line now "ls -la" with point after "l" >> - press RET >> >> Only " -la" is sent to the process instead of "ls -la" > > Thanks; with that I'm also able to reproduce the problem. > >> I am willing to write up a patch to fix this. I'm thinking of having >> comint-mode register a function in after-change-functions to mark text >> inserted in the 'output' field as 'output'. Would this be okay or are >> there any obvious flaws with this approach? > > I think that sounds like a promising approach, but I wonder whether > something could be done with rear-nonsticky here. `field' isn't > rear-sticky here for probably good reasons, but perhaps something > could be tweaked there? (I haven't actually tried, though.) Yeah I thought about that too. However, commands such as 'yank' or 'just-one-space' use insert rather than insert-and-inherit and thus always bypass inheritance of surrounding text properties regardless of it's stickiness. That is why I settled for using the 'insert-in-front-hooks' text property, patch attached. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Improve-yanking-in-the-middle-of-comint-process-outp.patch Content-Transfer-Encoding: quoted-printable From=207914fe85ba096f93d4b6817bc0d7b7976f3d316a Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Tue, 7 Dec 2021 16:59:39 +0100 Subject: [PATCH] Improve yanking in the middle of comint process output * lisp/comint.el (comint--unmark-string-as-output): New function to remove unwanted properties from text yanked from comint buffers. (comint-mode): Use it as a 'filter-buffer-substring-function'. (comint-output-filter): Set 'insert-in-front-hooks' text property on process output such that text yanked by the user in the middle of process output is marked as process output (Bug#3735). (comint--mark-as-output): New function. (comint--mark-yanked-as-output): New function. =2D-- lisp/comint.el | 54 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index 544f0b8b82..5f99f560cf 100644 =2D-- a/lisp/comint.el +++ b/lisp/comint.el @@ -730,6 +730,8 @@ comint-mode (or (file-remote-p default-directory) "")) (setq-local comint-accum-marker (make-marker)) (setq-local font-lock-defaults '(nil t)) + (add-function :filter-return (local 'filter-buffer-substring-function) + #'comint--unmark-string-as-output) (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) (add-hook 'isearch-mode-hook 'comint-history-isearch-setup nil t) (add-hook 'completion-at-point-functions 'comint-completion-at-point nil= t) @@ -1815,7 +1817,8 @@ comint-add-to-input-history (ring-insert comint-input-ring cmd))) =20 (defconst comint--prompt-rear-nonsticky =2D '(field inhibit-line-move-field-capture read-only font-lock-face) + '( field inhibit-line-move-field-capture read-only font-lock-face + insert-in-front-hooks) "Text properties we set on the prompt and don't want to leak past it.") =20 (defun comint-send-input (&optional no-newline artificial) @@ -2152,14 +2155,7 @@ comint-output-filter (goto-char (process-mark process)) ; In case a filter moved it. =20 (unless comint-use-prompt-regexp =2D (with-silent-modifications =2D (add-text-properties comint-last-output-start (point) =2D `(rear-nonsticky =2D ,comint--prompt-rear-nonsticky =2D front-sticky =2D (field inhibit-line-move-field-capture) =2D field output =2D inhibit-line-move-field-capture t)))) + (comint--mark-as-output comint-last-output-start (point))) =20 ;; Highlight the prompt, where we define `prompt' to mean ;; the most recent output that doesn't end with a newline. @@ -2191,6 +2187,46 @@ comint-output-filter ,comint--prompt-rear-nonsticky))) (goto-char saved-point))))))) =20 +(defun comint--mark-as-output (beg end) + (with-silent-modifications + (add-text-properties + beg end + `(rear-nonsticky + ,comint--prompt-rear-nonsticky + front-sticky + (field inhibit-line-move-field-capture) + field output + inhibit-line-move-field-capture t + ;; Text inserted by a user in the middle of process output + ;; should be marked as output. This is needed for commands + ;; such as `yank' or `just-one-space' which don't use + ;; `insert-and-inherit' and thus bypass default text property + ;; inheritance. + insert-in-front-hooks + (,#'comint--mark-as-output ,#'comint--mark-yanked-as-output))))) + +(defun comint--mark-yanked-as-output (beg end) + ;; `yank' removes the field text property from the text it inserts + ;; due to `yank-excluded-properties', so arrange for this text + ;; property to be reapplied in the `after-change-functions'. + (let (fun) + (setq + fun + (lambda (beg1 end1 _len1) + (remove-hook 'after-change-functions fun t) + (when (and (=3D beg beg1) + (=3D end end1)) + (comint--mark-as-output beg1 end1)))) + (add-hook 'after-change-functions fun nil t))) + +(defun comint--unmark-string-as-output (string) + (remove-list-of-text-properties + 0 (length string) + '( rear-nonsticky front-sticky field + inhibit-line-move-field-capture insert-in-front-hooks) + string) + string) + (defun comint-preinput-scroll-to-bottom () "Go to the end of buffer in all windows showing it. Movement occurs if point in the selected window is not after the process m= ark, =2D-=20 2.34.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmGvkn4THG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZP4cvD/4oG241wNooxZKczWYnWB8reznybd+0 8jYcI/Z+nx36LEB6FBXF/mIMjlZafAyEdgpuM4GXfKyMneHiJC3b9glKrrROefur YHkxlPQtfXHl5A79OpdAWyw1unc4wxfEchQ+wlK0ymNyxzSq3g/DB0TmO2EJg7Ob Qc9V3AdgHvXWJqOEnH+QQpqRjR/G3mY/3s61MDLrLp3PMhqCF0R6wgg5GB2zL5cp P5ZhhomyRujnrhsB9JLoeWxcx/YzL02tbe81gLKdZC1/fzH5wcudT+0BAPaFJmOL LkGHBIyFssk3U67u8PwXjgpw98CEZp33u0Q9nCFzHuLneDiyrP28fIplgE4awBc9 PEfwlaffQQhGVwiaa/VeFGqXOnnSBHRuL6aO7TksK1ogcsVNvZvXAJyz3iX5S8j9 pLi+g/7yZgsvDsCBvSXh2XThF5WrACU8znvKXpxDdGbQM8W+l0BuvHPjkEpyj9+R xp63tvx83K2ULqLUz33EMfnKd5oIsAx2vTrVWc9Tf9vdQK5ZWB0FwBzY+Oopkklp u7kXC69mVtTmZa4G6sX4a8k/x6VSwkL7qCuZFKXePw/6CldJ9P7Vn83gy2xcKSwF vQBVXZIvDJ1ixGkTrzMH5h+wugZinshowdTQCjYWSr1F2LSzpk8b6KcO2ZJYDVRo UXHPj3F2OtyZRg== =2PG1 -----END PGP SIGNATURE----- --==-=-=--