all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: Jean Louis <bugs@gnu.support>
Cc: 37179@debbugs.gnu.org
Subject: bug#37179: 27.0.50; tabulated-list-mode creates obsolete empty line on the end
Date: Sun, 18 Oct 2020 16:56:13 -0700	[thread overview]
Message-ID: <CADwFkmkumy1LdL6xrF0fpJrPvWi3j0qWOOK9Dt9DGsWDY0C82w@mail.gmail.com> (raw)
In-Reply-To: <86a7bxy52a.fsf@protected.rcdrun.com> (Jean Louis's message of "Sun, 25 Aug 2019 11:20:29 +0200")

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

Jean Louis <bugs@gnu.support> writes:

> Here is sample demonstration:
>
> (define-derived-mode my-mode tabulated-list-mode "My Mode" "My mode"
>   (setq tabulated-list-format [("ID" 5 t . (:right-align t))
>                                ("Hyperlink" 30 t)
>                                ("Type" 10 t)])
>   (setq tabulated-list-padding 1)
>   (setq tabulated-list-sort-key (cons "ID" nil))
>   (tabulated-list-init-header))
>
> (defun my-set-list (&optional parent)
>   (interactive)
>   (let ((buffer "*Hyperspace*"))
>     (pop-to-buffer buffer nil)
>     (read-only-mode 0)
>     (erase-buffer)
>     (read-only-mode 1)
>     (my-mode)
>     (hl-line-mode)
>     (setq tabulated-list-entries (list
> 				  (list "1" ["1" "Link 1" "Type"])
> 				  (list "2" ["2" "Link 2" "Type"])))
>     (tabulated-list-print t)))
>
> When it is defined the M-x my-set-list allows me to go after the last
> line. Yet that is not logical, and empty line shall not be displayed, as
> it does not exist in the tabulated-list-entries variable.
>
> Video demonstration 1MB:
> https://gnu.support/images/2019/08/2019-08-25/2019-08-25-11:15:46.ogv

I tend to agree; there doesn't seem to be any point to go to a line
after the last entry.

But this issue is not unique to tabulated-list-mode, and in fact crops
up in all kinds of places in Emacs.  IME, the usual solution is to just
leave the final newline, and maybe there are good reasons for that.  See
Dired for example, or Gnus.

As an experiment, I came up with the attached patch that removes the
final newline in `tabulated-list-mode'.  As expected, it is not without
issues: `end-of-buffer' leaves point at the end of last line.  If that
line is very long, we can end up scrolled far to the right, which is
rather unsettling.  Another thing that may or may not be problematic (I
didn't test it) is if we have commands that operate on regions of lines.

So I'm not exactly sure what to do here.  Perhaps we should just leave
it alone...  Or maybe there is some smart solution just waiting to be
discovered.

Does anyone else have any comments?

[-- Attachment #2: 37179.diff --]
[-- Type: text/x-diff, Size: 625 bytes --]

diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el
index 2f7899ec51..7079eaad03 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -480,6 +480,11 @@ tabulated-list-print
               (forward-line 1)
               (delete-region old (point))))))
       (setq entries (cdr entries)))
+    ;; Remove empty last line.
+    (save-excursion
+      (let ((inhibit-read-only t))
+        (goto-char (point-max))
+        (delete-char -1)))
     (set-buffer-modified-p nil)
     ;; If REMEMBER-POS was specified, move to the "old" location.
     (if saved-pt

  reply	other threads:[~2020-10-18 23:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-25  9:20 bug#37179: 27.0.50; tabulated-list-mode creates obsolete empty line on the end Jean Louis
2020-10-18 23:56 ` Stefan Kangas [this message]
2020-10-19  6:41   ` Jean Louis
2020-10-19  8:57     ` Stefan Kangas
2020-10-19 16:05     ` Drew Adams
2020-10-19  8:54   ` Lars Ingebrigtsen

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=CADwFkmkumy1LdL6xrF0fpJrPvWi3j0qWOOK9Dt9DGsWDY0C82w@mail.gmail.com \
    --to=stefan@marxist.se \
    --cc=37179@debbugs.gnu.org \
    --cc=bugs@gnu.support \
    /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.