all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 70579@debbugs.gnu.org, jimjoe@gmx.net
Subject: bug#70579: 30.0.50; gnus: Wrong unread count in the Group buffer
Date: Thu, 09 May 2024 23:23:37 -0700	[thread overview]
Message-ID: <87msoyqj6e.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87seyqqp5w.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Thu, 09 May 2024 21:14:19 -0700")

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

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>>> Ping!  Eric, can we make some progress here?
>>>
>>>> Cc: jimjoe@gmx.net
>>>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>>>> Date: Thu, 25 Apr 2024 21:34:45 -0700
>>>> 
>>>> James Thomas via "Bug reports for GNU Emacs, the Swiss army knife of
>>>> text editors" <bug-gnu-emacs@gnu.org> writes:
>>>> 
>>>> > - (Preferably starting with an empty drafts folder) Compose a message
>>>> >   and save it.
>>>> > - Open the drafts group, press e on the message and then kill the new
>>>> >   buffer; then (incidentally, if you now do '/ N' then this bug does not
>>>> >   arise) delete the message (B DEL)
>>>> > - Press q
>>>> > - The message count is wrong (but can be corrected with M-g)
>>>> >
>>>> > cf. In gnus.general (gnus-summary-goto-article "87y192lr8f.fsf@gmx.net")
>>
>> I've made some progress here -- the root of the problem seems to be
>> that, when we hit "e" in the draft summary buffer to resume editing a
>> draft, Gnus "jumps ahead" in message numbers. Basically what "editing"
>> actually means is that the old draft is deleted, and a new draft is
>> started, but the new draft has a article number that's the previous
>> draft's number + 2, and the "draft" group's active number is also
>> inflated (for instance (12 . 14) when it should be (12 . 13)). I was
>> also able to get it to jump three numbers in some cases.
>>
>>>>From this point, *any* normal usage will end up correcting the error:
>> using "C-c C-k" to kill the editing buffer (instead of "C-x k") or as
>> you noted any of the commands that lead to refreshing the unread count.
>> But if you don't use any of those commands, you'll see the inflated
>> active/unread count when you get back to the *Group* buffer (the "B DEL"
>> isn't necessary for the recipe, and in fact at that stage the message
>> under point has already been deleted).
>>
>> That's as far as I've gotten, and I'll keep working on why the article
>> number starts off inflated. But in the meantime, the solution is "don't
>> do that".
>
> Sorry, that sounded a bit unfriendly, when I was the one who asked you
> to submit the bug report! An hour or two of chasing Gnus function calls
> will do that to you...

Okay, I found two things, one the proximate cause of this bug, another
"probably wrong" adjacent issue.

The main problem is that `gnus-draft-setup' both calls `message-mode'
(which calls `message-set-auto-save-file-name'), and then directly calls
`message-set-auto-save-file-name' itself. Without getting into horrible
details, that functions shouldn't be called twice, because it generates
an extra numerical file name, which ends up inflating the active value
of the drafts group.

I've attached a patch that removes the second call. If you feel
comfortable applying and testing patches, I hope you'll try it. In my
experiments it fixes the problem.

The patch also semi-addresses the second issue. When saving a draft,
message-mode only buries the buffer, it doesn't delete it. If you go
back and start editing the draft, `gnus-draft-check-draft-articles' is
supposed to see if a there's already a buffer visiting the draft file,
and return you to that buffer instead of creating a new one. But it only
does that if the buffer is modified, which it isn't if you've
saved/buried the draft.

I don't see why that should mean that you need a whole new buffer for
editing the message, and the fact that there are now two "copies" of the
message buffer causes further problems with the inflating article
numbers (why I could sometimes see three or even four "jumps").

The patch removes the check for modification, and in my brief testing
behaves the way I would expect it to.

That whole part of the code is weird:

    (let ((buffers (buffer-list))
	  file buffs buff)
      (save-current-buffer
	(while (and articles
		    (not buff))
	  (setq file (nndraft-article-filename (pop articles))
		buffs buffers)
	  (while buffs
	    (set-buffer (setq buff (pop buffs)))
	    (if (and buffer-file-name
		     (equal (file-remote-p file)
			    (file-remote-p buffer-file-name))
		     (string-equal (file-truename buffer-file-name)
				   (file-truename file))
		     ; (buffer-modified-p)
                     )
		(setq buffs nil)
	      (setq buff nil)))))

That seems like a very long way of writing `find-buffer-visiting'. Maybe
the remote check should be carried over, but otherwise this seems very
replaceable.

Anyway, please let me know if you can check the patch.

Eric

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gnus-draft-fixes.diff --]
[-- Type: text/x-patch, Size: 928 bytes --]

diff --git a/lisp/gnus/gnus-draft.el b/lisp/gnus/gnus-draft.el
index 1fc2b33fffb..406ff705f3d 100644
--- a/lisp/gnus/gnus-draft.el
+++ b/lisp/gnus/gnus-draft.el
@@ -262,8 +262,7 @@ gnus-draft-setup
             (setq ga
                   (message-fetch-field gnus-draft-meta-information-header)))
           (insert mail-header-separator)
-          (forward-line 1)
-          (message-set-auto-save-file-name))))
+          (forward-line 1))))
     (gnus-backlog-remove-article group narticle)
     (when (and ga
                (ignore-errors (setq ga (car (read-from-string ga)))))
@@ -303,8 +302,7 @@ gnus-draft-check-draft-articles
 		     (equal (file-remote-p file)
 			    (file-remote-p buffer-file-name))
 		     (string-equal (file-truename buffer-file-name)
-				   (file-truename file))
-		     (buffer-modified-p))
+				   (file-truename file)))
 		(setq buffs nil)
 	      (setq buff nil)))))
       (when buff

  reply	other threads:[~2024-05-10  6:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26  3:32 bug#70579: 30.0.50; gnus: Wrong unread count in the Group buffer James Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-26  4:34 ` Eric Abrahamsen
2024-05-09  7:19   ` Eli Zaretskii
2024-05-10  4:00     ` Eric Abrahamsen
2024-05-10  4:14       ` Eric Abrahamsen
2024-05-10  6:23         ` Eric Abrahamsen [this message]
2024-05-10 11:01         ` James Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-10 11:58           ` James Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-10 12:37             ` James Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-10 15:49           ` Eric Abrahamsen

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=87msoyqj6e.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=70579@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=jimjoe@gmx.net \
    /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.