From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Shahid Newsgroups: gmane.emacs.devel Subject: Re: Feedback on getting rid of `term-suppress-hard-newline' Date: Sun, 20 Jan 2019 19:14:04 -0500 Message-ID: <871s56sw98.fsf@gmail.com> References: <87efanc576.fsf@gmail.com> <87sgxsr8p0.fsf@gmail.com> NNTP-Posting-Host: ciao.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ciao.gmane.org 1548029655 157352 195.159.176.228 (21 Jan 2019 00:14:15 GMT) X-Complaints-To: usenet@ciao.gmane.org NNTP-Posting-Date: Mon, 21 Jan 2019 00:14:15 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 27.0.50 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 21 01:14:14 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1glNED-000esC-1P for ged-emacs-devel@m.gmane.org; Mon, 21 Jan 2019 01:14:13 +0100 Original-Received: from localhost ([127.0.0.1]:45879 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glNEL-0005j5-TG for ged-emacs-devel@m.gmane.org; Sun, 20 Jan 2019 19:14:21 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:44286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glNEC-0005h2-IJ for emacs-devel@gnu.org; Sun, 20 Jan 2019 19:14:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1glNEB-0005Y7-76 for emacs-devel@gnu.org; Sun, 20 Jan 2019 19:14:12 -0500 Original-Received: from mail-qt1-x82c.google.com ([2607:f8b0:4864:20::82c]:46217) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1glNEB-0005Xg-1H for emacs-devel@gnu.org; Sun, 20 Jan 2019 19:14:11 -0500 Original-Received: by mail-qt1-x82c.google.com with SMTP id y20so21524863qtm.13 for ; Sun, 20 Jan 2019 16:14:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:subject:message-id:in-reply-to:date :mime-version; bh=7tayZIoAsNpNPl3rhM0pQwMbIKZxXjgi1tP5hGLcOQg=; b=YEOwxADYXYzaJMF2kH2nKp1Y5/smLDPSNTsLzgIYI7y+nb4cDgpkZXOlMiWg6uADLu MFKKMfuIWeSG80IWDGIx/TUyDjDou5ClQMmj/xsxLnpSkQln8vPxXFJH48aUyIFkuxNQ SJI4XPBQmiHTGm9u8q5VA6O8tb+TtUcTMROGJjY3ZXI79HQwMDSPXJJ1kmPzERygkPDu RBZV4Iap1NKYq1BFmCBdkEQrZwcEKpGWIhcUQsJM6rZBtvKV23roJ27FbY4r1G2ty4o3 0UBTZMdfhuN8mkQMPRT1IqXndyM/WGx8CRwKZEDL7DNUwQo203jBD815Ss45trKEN5z4 4vMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:subject:message-id :in-reply-to:date:mime-version; bh=7tayZIoAsNpNPl3rhM0pQwMbIKZxXjgi1tP5hGLcOQg=; b=X3odnxJcVY9DvbmkSXGf758lRNC/n03dfpY7gDcm5uhm4BPLhh/cN578KCVUnuhWL9 3O9YypbUHEOvAyrwPYaY6+qR7JuxSr21LD/Iv6DY5SpwAfaO3EWfmrzJ7kgNtV6E/bmD kLAxyu8uB3Ula0HPJHUJh6HRlFme0w0x+H/7aSJ1TGMtJRu+K+WiYbUzjhwEIP9nRx1Z 7TTVxQz2As1B4h3lJJHTb+LtuqVNNtGRjbQx9I9DR5lj2+KC1YHsxFzKYZ139E6OuYko x6VFtr/Uy8+e6X/0LwsQ2idhUXocAPtp3s1ooWT8aiMYEgF+Ooqh8Ge8DN/SiDJfxu7A +vOA== X-Gm-Message-State: AJcUukfx2xWt0EEQ70zQCtbMw27n3HWWG+FHnE4DVAaYNJ4FNIdimKm3 R7y3v9lApjodVpsvkjXrWdG9Nn7Ylcs= X-Google-Smtp-Source: ALg8bN7Xs4+G9Wc8cxEwaN+BL7uBzpvJSpTBL25UhqFVxsPSTDh23BnzGGL48i0U0fLvHcqv1PkdcA== X-Received: by 2002:a0c:8382:: with SMTP id k2mr24632819qva.0.1548029649261; Sun, 20 Jan 2019 16:14:09 -0800 (PST) Original-Received: from amun (cpe-104-162-85-46.nyc.res.rr.com. [104.162.85.46]) by smtp.gmail.com with ESMTPSA id n71sm43296824qkl.72.2019.01.20.16.14.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Jan 2019 16:14:07 -0800 (PST) In-reply-to: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:232557 Archived-At: --=-=-= Content-Type: text/plain Sorry it took me a while to get back to you. I fixed most of the issues you mentioned but I had a few questions (see below). Stefan Monnier writes: >> ping > > FWIW, I think this makes a lot of sense, so please go ahead. > A few comments below, > > > Stefan > > >>> @@ -1106,6 +1106,7 @@ term-mode >>> (make-local-variable 'term-scroll-show-maximum-output) >>> (make-local-variable 'term-ptyp) >>> (make-local-variable 'term-exec-hook) >>> + (setq-local filter-buffer-substring-function 'term-filter-buffer-substring) > > Please use `add-function` to modify filter-buffer-substring-function. Done. > >>> + (put-text-property old-point (point) 'term-newline t))) > > I'd recommend you use a more explicit name which doesn't just state the > obvious "this is a newline in term mode". E.g. something like > `term-wrap-newline`. I changed the property name to 'term-line-wrap'. > >>> + (let (buffer-read-only) >>> + (delete-char 1)))) > > Never let-bind `buffer-read-only`: let-bind `inhibit-read-only` > instead. Done. I am curious to know why I shouldn't let-bind 'buffer-read-only' ? > >>> + ;; delete all fake newlines > > Please capitalize and punctuate your comments. Done. > >>> + (when (> len width) >>> + (goto-char (+ bol width)) > > Not sure how well term deals with wide chars (e.g. TAB or chinese > chars), but this code of yours clearly won't help. I think you > want to test current-column rather than `len` and then you want > move-to-column rather than advancing by N chars. I made the change in the attached patch. I don't have any fonts locally that are suitable for displaying Chinese characters so I couldn't test those. I tested with Arabic characters (e.g. 'C-x 8 RET ARABIC LIGATURE AKBAR ISOLATED FORM') and I don't think 'current-column' is reporting the right column number. In this case, it reports column count of 1 which isn't right. It does work though with tab characters. One more question, should I deprecate 'term-suppress-hard-newline' as part of this changeset ? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Adjust-line-wrapping-on-window-resize-and-killing-te.patch >From 8efc90d9a3a406dc795842bd86174da8e3944874 Mon Sep 17 00:00:00 2001 From: John Shahid Date: Sun, 20 Jan 2019 19:08:17 -0500 Subject: [PATCH] Adjust line wrapping on window resize and killing text * lisp/term.el (term-mode): Advice filter-buffer-substring-function to remove line wrapping from killed text. (term-reset-size): Add or remove line wrapping depending on the new terminal width. (term-emulate-terminal): (term-unwrap-line): --- lisp/term.el | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/lisp/term.el b/lisp/term.el index f49777f94c..1406b80fd5 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -1116,6 +1116,9 @@ term-mode (set (make-local-variable 'font-lock-defaults) '(nil t)) + (add-function :filter-return + (local 'filter-buffer-substring-function) + 'term--filter-buffer-substring) (add-function :filter-return (local 'window-adjust-process-window-size-function) (lambda (size) @@ -1132,9 +1135,32 @@ term-mode (setq term-input-ring (make-ring term-input-ring-size))) (term-update-mode-line)) +(defun term--insert-fake-newline (&optional count) + (let ((old-point (point))) + (term-insert-char ?\n count) + (put-text-property old-point (point) 'term-line-wrap t))) + +(defun term--remove-fake-newlines () + (goto-char (point-min)) + (while (setq fake-newline (next-single-property-change (point) + 'term-line-wrap)) + (goto-char fake-newline) + (let ((inhibit-read-only t)) + (delete-char 1)))) + +(defun term--filter-buffer-substring (content) + (with-temp-buffer + (insert content) + (term--remove-fake-newlines) + (buffer-string))) + (defun term-reset-size (height width) (when (or (/= height term-height) (/= width term-width)) + ;; Delete all newlines used for wrapping + (when (/= width term-width) + (save-excursion + (term--remove-fake-newlines))) (let ((point (point))) (setq term-height height) (setq term-width width) @@ -1147,7 +1173,19 @@ term-reset-size (setq term-start-line-column nil) (setq term-current-row nil) (setq term-current-column nil) - (goto-char point)))) + (goto-char point)) + (save-excursion + ;; Add newlines to wrap long lines that are currently displayed + (forward-line (- (term-current-row))) + (beginning-of-line) + (while (not (eobp)) + (let* ((eol (save-excursion (end-of-line) (current-column)))) + (when (> eol width) + (move-to-column width) + (let ((inhibit-read-only t)) + (term--insert-fake-newline))) + (unless (eobp) + (forward-char))))))) ;; Recursive routine used to check if any string in term-kill-echo-list ;; matches part of the buffer before point. @@ -2906,6 +2944,7 @@ term-emulate-terminal (delete-region (point) (line-end-position)) (term-down 1 t) (term-move-columns (- (term-current-column))) + (put-text-property (1- (point)) (point) 'term-line-wrap t) (setq decoded-substring (substring decoded-substring (- term-width old-column))) (setq old-column 0))) @@ -3719,7 +3758,10 @@ term-down ;; if the line above point wraps around, add a ?\n to undo the wrapping. ;; FIXME: Probably should be called more than it is. (defun term-unwrap-line () - (when (not (bolp)) (insert-before-markers ?\n))) + (when (not (bolp)) + (let ((old-point (point))) + (insert-before-markers ?\n) + (put-text-property old-point (point) 'term-line-wrap t)))) (defun term-erase-in-line (kind) (when (= kind 1) ;; erase left of point -- 2.20.1 --=-=-=--