all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: Feedback on getting rid of `term-suppress-hard-newline'
Date: Thu, 21 Feb 2019 09:55:20 -0500	[thread overview]
Message-ID: <jwvtvgxb41h.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 87lg3d3g70.fsf@gmail.com

John Shahid <jvshahid@gmail.com> writes:
> Are there more changes to the previously attached patch in order to
> merge it into master ?

Oh, sorry, I dropped the ball.
Yes, it looks good, thank you very much.

Of course I couldn't resist making further comments, but feel free to
push it,


        Stefan


> +(make-obsolete-variable 'term-suppress-hard-newline nil
> +                        "term removes newlines used for wrapping on resize and when text is copied"
> +                        "27.1")

Please remove the third argument above (it should be the version).

> +  (add-function :filter-return
> +                (local 'filter-buffer-substring-function)
> +                'term--filter-buffer-substring)
                  ^
I'd put a # there.

> +(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)))

`count` is always nil, AFAICT, so you can just drop this argument.

> +(defun term--remove-fake-newlines ()
> +  (goto-char (point-min))
> +  (let (fake-newline)
> +    (while (setq fake-newline (next-single-property-change (point)
> +                                                           'term-line-wrap))
> +      (goto-char fake-newline)
> +      (let ((inhibit-read-only t))
> +        (delete-char 1)))))

I'd add a test (or an assertion) that (eq ?\n (char-after))), in case
the text-property ends up applied somewhere we didn't expect
(e.g. because it was inherited via insert-and-inherit).

> @@ -1147,7 +1177,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)))))))

I'd move this to a separate function.

More importantly, I don't quite understand why (- (term-current-row)))
should be the exactly correct number of lines to move back at the
beginning, so please add a comment explaining it (or if it's not exactly
right, the comment could explain why it's "right enough").

Also, I think you can simplify the loop by always calling
`move-to-column` and never `current-column`, as in the 100% untested
code below:

    (while (not (eobp))
      (move-to-column width)
      (if (eolp)
          (forward-char)
        (let ((inhibit-read-only t))
          (term--insert-fake-newline))))

> @@ -2895,20 +2937,20 @@ term-emulate-terminal
>                  (let ((old-column (term-horizontal-column))
>                        (old-point (point))
>                        columns)
> -                  (unless term-suppress-hard-newline
> -                    (while (> (+ (length decoded-substring) old-column)
> -                              term-width)
> -                      (insert (substring decoded-substring 0
> -                                         (- term-width old-column)))
> -                      ;; Since we've enough text to fill the whole line,
> -                      ;; delete previous text regardless of
> -                      ;; `term-insert-mode's value.
> -                      (delete-region (point) (line-end-position))
> -                      (term-down 1 t)
> -                      (term-move-columns (- (term-current-column)))
> -                      (setq decoded-substring
> -                            (substring decoded-substring (- term-width old-column)))
> -                      (setq old-column 0)))
> +                  (while (> (+ (length decoded-substring) old-column)
> +                            term-width)
> +                    (insert (substring decoded-substring 0
> +                                       (- term-width old-column)))
> +                    ;; Since we've enough text to fill the whole line,
> +                    ;; delete previous text regardless of
> +                    ;; `term-insert-mode's value.
> +                    (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))
>                    (insert decoded-substring)
>                    (setq term-current-column (current-column)
>                          columns (- term-current-column old-column))

I think I'd leave the term-suppress-hard-newline test in for now (that's
the point of marking is as obsolete).




  parent reply	other threads:[~2019-02-21 14:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12 12:14 Feedback on getting rid of `term-suppress-hard-newline' John Shahid
2019-01-16 14:14 ` John Shahid
2019-01-16 16:51   ` Stefan Monnier
2019-01-21  0:14     ` John Shahid
2019-01-21  3:04       ` Stefan Monnier
2019-01-21 20:32         ` John Shahid
2019-02-20 14:54           ` John Shahid
2019-02-21 14:55           ` Stefan Monnier [this message]
2019-02-24 18:00             ` John Shahid
     [not found]               ` <jwvh8cs6fzt.fsf-monnier+emacs@gnu.org>
     [not found]                 ` <87k1ho26vc.fsf@gmail.com>
     [not found]                   ` <87h8cr9is1.fsf@gmail.com>
2019-02-27 12:54                     ` Fwd: " John Shahid

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

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

  git send-email \
    --in-reply-to=jwvtvgxb41h.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.