From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#66395: 28.2; Todo-mode locks up when trying to edit an entry Date: Sun, 05 Nov 2023 23:00:36 +0100 Message-ID: <87h6lzx3ln.fsf@gmx.net> References: <871qe6ntf4.fsf@ndegruchy-wlt> <877cnyazsd.fsf@gmx.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19623"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Christos Ballas , LdBeth , 66395@debbugs.gnu.org, 55284@debbugs.gnu.org To: "Nathan R. DeGruchy" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 05 23:01:56 2023 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 1qzlBq-0004qS-J5 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Nov 2023 23:01:54 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzlBP-0007Ya-Sd; Sun, 05 Nov 2023 17:01:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qzlBN-0007Xc-MZ for bug-gnu-emacs@gnu.org; Sun, 05 Nov 2023 17:01:25 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzlBN-00044h-E6 for bug-gnu-emacs@gnu.org; Sun, 05 Nov 2023 17:01:25 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qzlBy-0000Cl-2b for bug-gnu-emacs@gnu.org; Sun, 05 Nov 2023 17:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Nov 2023 22:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66395 X-GNU-PR-Package: emacs Original-Received: via spool by 66395-submit@debbugs.gnu.org id=B66395.1699221697719 (code B ref 66395); Sun, 05 Nov 2023 22:02:02 +0000 Original-Received: (at 66395) by debbugs.gnu.org; 5 Nov 2023 22:01:37 +0000 Original-Received: from localhost ([127.0.0.1]:38294 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzlBY-0000BV-1f for submit@debbugs.gnu.org; Sun, 05 Nov 2023 17:01:36 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]:48001) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzlBU-0000B8-TH; Sun, 05 Nov 2023 17:01:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1699221638; x=1699826438; i=stephen.berman@gmx.net; bh=ftVieOPsmcvIWM4Ty8kVuOI+hF3TGSQXNob8dhcduAw=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References: Date; b=PcwVo/sXLhdcJue1mJpzIEg1YsqtgJ38ZmiRhhPcy/+dC5wSmOLxAyKrudgPzQJ8 k3Tmh8O5AuKgaygSq3gL5LE6oNSxUsKO5NfiecoDXUuxTPH21CUhyj8Ekd7dPB/Ug obKzTOS58rd0PMpM5XgIqD5tjMoLtpFhnFFi7VTUd6xK00whuJ5hlRKp8UTl9SMra qMbHecmmh9bX0h3bsaQiXRGekuK1pybVLZGHrmzlKhZpxVqWkYJr1slUCn6sy/6/p ECsdl8yKfxdJ+zQnzkQLtx2OJ21qaUEUabDFfoKt1LNRfmXzwChUoLmk4PL5YeXcC ltuFXImo4ELjMsRguA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs2 ([94.134.196.221]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MTRMi-1qpyd002MG-00TopJ; Sun, 05 Nov 2023 23:00:38 +0100 In-Reply-To: <877cnyazsd.fsf@gmx.net> (Stephen Berman's message of "Sat, 07 Oct 2023 23:27:46 +0200") X-Provags-ID: V03:K1:9wkQes1T0GENn81ekUJ9z2FgNFct8Xv3CR39dXTIrTga42Gc5YF LUHFHdN4iJisjOdkav9+zXuE6zarBPq9wl+3jqJBVeSbxmxGn597NA6Hsk4/+lNTx0EvmB+ Yanb/OuB7QxV351WOG5qfBygoV55prc6M9bDudeXoZVEcpjAmbXozH9VXFZJrsOqbSA5Q/3 LYYC5Z5T/NgkzfSmfTPxQ== UI-OutboundReport: notjunk:1;M01:P0:Tp/Mp4vwwjU=;7F69ybX7gbgCpifRT1E43hFsIPB 9XxZ1BzIIiVJDFelJJ+U+qEUbD8oPowy1Dc7bRqdlVyxVc3hWGRPMlirl1vW0a8mVGNR5hR7Q whS4lvcfUfSdZ0ToMR7n8iejS4HlK9MtuyhO04tfTlo5b5aHXQi1IgqOMwfBT7QS79Yg7597V 4LfbfF6IKTgwo4DhV1Ad08M2dJEyKCuOpR108IlWkECqUhWss4pXthphuJhCXWssx7v33pULe 8Sf+lir0sbbGjR+kDbxPPAoHVeYIfOIkJ9OL2zfvRNbfM+xuLCjtxOcKfU0hQNmPG2CTrMwbA yMrGrdMa8ZL1TrFbJgwG5mXL1b1X88V/exhF+G9MgLM+nAlzl0FbhNCGb6T2DdzPFuKuPypaH NIiUtewumQozfCo3CA/5xlbD7ek+T9L80ViIU+5d8D0v43O7jufMdUxIx7PuF0Y4TZaJy6Xsx Hh9RYJbth94JmQyEJUWqy2Fha/2zfgnZpg8SCAnRjYloImtkAgUtpIRMIolrPoO1aQ24/JIf5 OqZPWQrwXFq3ysIEkM+0GmR9d03d7KiRU5sgcW3v2dzMtARbT0sh8y5Ug/6DeXZQMjG9upqmL aWFF4HvEU4tfAKOe7nYDpfSUIqFMnbGPZ5OTsVbJTbQVle9SBeZF2RfA8rPxrCO8VQYPS3Vr2 JyVBq5Ikv/cS4jVgnWwB5T0KxDLEP0BV/HQAwsDqBls5aMbd5LfT7cvViNfTDvi0/s/bLIutR Ua7Wdou+AugbAZXXSydnmrmQznTds34TIY3jTlkcHoIUBQ2YxbBx3bACpuGcjtqwHBbq8W30 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273844 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable merge 55284 66395 thanks On Sat, 07 Oct 2023 23:27:46 +0200 Stephen Berman = wrote: > On Sat, 7 Oct 2023 19:06:55 +0000 "Nathan R. DeGruchy" wrote: > >> I am trying to explore using 'todo-mode' as a todo list and while I can >> see and create entries in todo-mode using the normal functions, trying >> to edit an item seems to cause emacs to soft-lock. I can reproduce this >> in a config-less emacs via `emacs -Q`. >> >> Basically, I have a todo-file at $HOME/.config/emacs/todo/tasks.todo, >> this was created when using `todo-show` initially. The contents are not >> very complex: >> >> (("Emacs" . [1 0 0 0]) ("Home" . [1 0 0 0])) >> --=3D=3D-- Emacs >> [2023-10-07] Learn Todo Mode >> >> =3D=3D--=3D=3D DONE >> --=3D=3D-- Home >> [2023-10-07] Get new wiper blades >> >> =3D=3D--=3D=3D DONE >> >> When on either of the items, if I hit 'e' to edit them, it causes emacs >> to lock up, specifically around `todo-done-item-p()`. I found this out >> by enabling `toggle-debug-on-quit`, reproducing the error, and the >> C-g'ing out of the loop/lockup. I also tried to trace through the >> todo-edit-item with edebug-defun. Stepping through, it seems to reach >> the same predicate function and ... stop. >> >> I'm not sure where to go from here. > > On Sat, 07 Oct 2023 14:37:00 -0500 LdBeth wrote: > >> As we have discussed on IRC, the nonstandard timestamp format is the ca= use. > > Yes. This is a duplicate of bug#55284. At the time that bug was > reported, I didn't have time to try fixing it (being the todo-mode > maintainer), and later, unfortunately, I forgot about it. I'll try to > look into it soon, but, as I noted in that bug thread, I think it's not > easy to fix. One issue is that todo-mode basically employs the same > handling of date formats as diary-lib.el, and the ISO date style causes > problems there too, see bug#55286. I've finally attended to this bug. The problem is due to using a faulty regular expression for matching todo date headers in the ISO format. There was a related bug report years ago about a diary display problem with the ISO format (bug#8583), and the fix for that (whose author conceded it was "ugly") points the way to a fix for todo-mode, see the attached patch (which I have to concede is even uglier and more complicated than the fix for bug#8583, but I couldn't find a better way). (I actually had been aware of the diary bug and the fix, but didn't try to apply it to todo-mode back then; I don't remember exactly why but I guess because I concluded it was not straightforward to adapt the fix to todo-mode and since I didn't use the ISO format myself I lacked motivation, also because there had been no todo-mode bug reports about it -- until bug#55286 (and now the current bug), but by then I had forgotten about bug#8583.) >> The hang is cause by the while loop `todo-item-start' not properly hand= le fail >> case, however. >> >> This patch would at least fix the hang. >> >> --- >> LdBeth >> >> --- todo-mode.el.old 2023-10-07 14:28:59.000000000 -0500 >> +++ todo-mode.el 2023-10-07 14:30:20.000000000 -0500 >> @@ -5242,8 +5242,8 @@ >> ;; Buffer is widened. >> (looking-at (regexp-quote todo-category-beg))) >> (goto-char (line-beginning-position)) >> - (while (not (looking-at todo-item-start)) >> - (forward-line -1)) >> + (while (and (not (looking-at todo-item-start)) >> + (=3D (forward-line -1) 0))) >> (point))) >> >> (defun todo-item-end () > > Thanks. Even though this doesn't eliminate other problems with using > the ISO date style in todo-mode (or in the Emacs Diary), since it does > prevent the infinite loop here, it may be a good stopgap. With the attached patch I think this stopgap should be unnecessary: the while-loop should no longer fail when the ISO date format is used (barring any bugs in the patch, and if there are, it should fail so they can be found and fixed). However, using the ISO date format in todo-mode does necessitate additional changes, in the code for editing todo item headers, which the attached patch also includes. Although with this patch todo-mode now supports the ISO date format, there remains a problem. Todo mode (like the Emacs Diary) uses the date format specified by calendar-date-display-form, which is a user option that has three default styles (American, European and ISO), which you can change by customizing `calendar-date-style' or by executing `calendar-set-date-style'. But if you change it, that breaks using todo-mode with any existing todo file that was created using a different date format, in the same way that trying to use the ISO format with todo-mode fails without the attached patch (i.e., the current bug). (As noted above with reference to bug#55286, the diary is subject to similar breakage.) After I came up with the attached patch to support the ISO date format in todo-mode, I started tackling the issue of changing the date format, and I now have what I think is a viable solution. However, to implement it I've had to make extensive changes in the todo-mode code, and also to part of the internal structure of todo files (but not to the UI), and I'm still testing these changes. They include essentially the changes in the attached patch (though partly in a more general form). Therefore, what I'd like to do first is install this patch, after waiting several days for any feedback. I'll open a new bug to post and discuss the more extensive changes I'd like to make. Steve Berman --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Description: Todo mode support for ISO date format Content-Transfer-Encoding: quoted-printable diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 093ea0e22b6..5354a65799d 100644 =2D-- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -189,20 +189,53 @@ todo-month-abbrev-array "Array of abbreviated month names, in order. The final element is \"*\", indicating an unspecified month.") +(defconst todo--date-pattern-groups + (pcase calendar-date-style + ('american '((monthname . "6") (month . "7") (day . "8") (year = . "9"))) + ('european '((day . "6") (monthname . "7") (month . "8") (year = . "9"))) + ('iso '((year . "6") (monthname . "7") (month . "8") (day . "9"= )))) + "Alist for grouping date components in `todo-date-pattern'.") + (defconst todo-date-pattern - (let ((dayname (diary-name-pattern calendar-day-name-array nil t))) - (concat "\\(?4:\\(?5:" dayname "\\)\\|" - (calendar-dlet - ((dayname) - (monthname (format "\\(?6:%s\\)" (diary-name-pattern - todo-month-name-array - todo-month-abbrev-array))) - (month "\\(?7:[0-9]+\\|\\*\\)") - (day "\\(?8:[0-9]+\\|\\*\\)") - (year "-?\\(?9:[0-9]+\\|\\*\\)")) - (mapconcat #'eval calendar-date-display-form)) - "\\)")) - "Regular expression matching a todo item date header.") + (let* ((dayname (diary-name-pattern calendar-day-name-array nil t)) + (d (concat "\\(?" (alist-get 'day todo--date-pattern-groups) + ":[0-9]+\\|\\*\\)")) + (mn (format (concat "\\(?" (alist-get 'monthname + todo--date-pattern-groups) + ":%s\\)") + (diary-name-pattern todo-month-name-array + todo-month-abbrev-array))) + (m (concat "\\(?" (alist-get 'month todo--date-pattern-groups) + ":[0-9]+\\|\\*\\)")) + (y (concat "\\(?" (alist-get 'year todo--date-pattern-groups) + ":[0-9]+\\|\\*\\)")) + (dd "1111111") + (mm "2222222") + (yy "3333333") + (s (concat "\\(?4:\\(?5:" dayname "\\)\\|" + (calendar-dlet + ((dayname) + (monthname mn) + (year yy) + (month mm) + (day dd)) + (mapconcat #'eval calendar-date-display-form)) + "\\)"))) + ;; The default value of calendar-iso-date-display-form calls + ;; `string-to-number' on the values of `month' and `day', so we + ;; gave them placeholder values above and now replace these with + ;; the necessary regexps with appropriately numbered groups, because + ;; `todo-edit-item--header' uses these groups. + (when (string-match dd s nil t) + (setq s (string-replace dd d s))) + (when (string-match mm s nil t) + (setq s (string-replace mm m s))) + (when (string-match yy s nil t) + (setq s (string-replace yy y s))) + s) + "Regular expression matching a todo item date header. +The value of `calendar-date-display-form' determines the form of +the date header.") ;; By itself this matches anything, because of the `?'; however, it's onl= y ;; used in the context of `todo-date-pattern' (but Emacs Lisp lacks @@ -2349,11 +2382,19 @@ todo-edit-item--header (regexp-quote todo-nondiary-end) "?") (line-end-position) t) (let* ((otime (match-string-no-properties 2)) - (odayname (match-string-no-properties 5)) - (omonthname (match-string-no-properties 6)) - (omonth (match-string-no-properties 7)) - (oday (match-string-no-properties 8)) - (oyear (match-string-no-properties 9)) + (odayname (match-string-no-properties 5)) + (mngroup (string-to-number + (alist-get 'monthname todo--date-pattern-group= s))) + (omonthname (match-string-no-properties mngroup)) + (mgroup (string-to-number + (alist-get 'month todo--date-pattern-groups))) + (omonth (match-string-no-properties mgroup)) + (dgroup (string-to-number + (alist-get 'day todo--date-pattern-groups))) + (oday (match-string-no-properties dgroup)) + (ygroup (string-to-number + (alist-get 'year todo--date-pattern-groups))) + (oyear (match-string-no-properties ygroup)) (tmn-array todo-month-name-array) (mlist (append tmn-array nil)) (tma-array todo-month-abbrev-array) @@ -2399,11 +2440,23 @@ todo-edit-item--header ((eq what 'month) (setf day oday year oyear - (if (memq 'month calendar-date-display-form) + ;; With default ISO style, 'month is in a + ;; sublist of c-d-d-f, so we flatten it. + (if (memq 'month (flatten-tree + calendar-date-display-form)) month monthname) (cond ((not current-prefix-arg) - (todo-read-date 'month)) + (let ((nmonth (todo-read-date 'month))) + ;; If old month is given as a number, + ;; have to convert new month name to + ;; the corresponding number. + (when omonth + (setq nmonth + (number-to-string + (1+ (seq-position tma-array + nmonth))))) + nmonth)) ((or (string=3D omonth "*") (=3D mm 13)) (user-error "Cannot increment *")) (t --=-=-=--