emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Silently remove lockfiles from org-agenda-files
@ 2024-01-19  6:27 Joseph Turner
  2024-01-19 13:19 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph Turner @ 2024-01-19  6:27 UTC (permalink / raw)
  To: Org Mode Mailing List

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

My configuration contains the equivalent of

(setopt org-agenda-files
       (directory-files-recursively "~/.local/share/org/todo" ".org$"))

My Emacs setup broke today due to the presence of a lockfile inside
"~/.local/share/org/todo".  I use EXWM, and I show org-agenda on startup:

(add-hook 'after-init-hook
            (lambda () (org-agenda nil "t")))
(setq initial-buffer-choice (lambda () (get-buffer "*Org Agenda*")))

org-agenda-files contained a non-existent file, so org-check-agenda-file
attempted to prompt me.  For some reason (maybe EXWM didn't fully load),
Emacs simply hung without prompting, leaving me with a black screen.

The attached patch silently removes lockfiles from org-agenda-files.

Thanks!

Joseph

P.S.

I'm not sure how the lockfile ended up there.  Maybe I killed Emacs with
SIGKILL while one of my agenda files was open and modified in a buffer,
and so the lockfile was not deleted?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org.el-org-check-agenda-file-Silently-exclude-l.patch --]
[-- Type: text/x-diff, Size: 1052 bytes --]

From e69e69a03c215704d83f8388370f0db2bc93891d Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
Date: Thu, 18 Jan 2024 22:24:10 -0800
Subject: [PATCH] * lisp/org.el (org-check-agenda-file): Silently exclude
 lockfiles

---
 lisp/org.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 8929a7217..f48a8ff46 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15563,8 +15563,12 @@ (defun org-file-menu-entry (file)
   (vector file (list 'find-file file) t))
 
 (defun org-check-agenda-file (file)
-  "Make sure FILE exists.  If not, ask user what to do."
+  "Make sure FILE exists.  If not, ask user what to do.
+Automatically exclude lockfiles."
   (unless (file-exists-p file)
+    (when (string-match-p (rx bos ".#") file) ; Exclude lockfiles
+      (org-remove-file file)
+      (throw 'nextfile t))
     (message "Non-existent agenda file %s.  [R]emove from list or [A]bort?"
 	     (abbreviate-file-name file))
     (let ((r (downcase (read-char-exclusive))))
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Silently remove lockfiles from org-agenda-files
  2024-01-19  6:27 [PATCH] Silently remove lockfiles from org-agenda-files Joseph Turner
@ 2024-01-19 13:19 ` Ihor Radchenko
  2024-01-31 21:51   ` Joseph Turner
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2024-01-19 13:19 UTC (permalink / raw)
  To: Joseph Turner; +Cc: Org Mode Mailing List

Joseph Turner <joseph@breatheoutbreathe.in> writes:

> My Emacs setup broke today due to the presence of a lockfile inside
> "~/.local/share/org/todo".  I use EXWM, and I show org-agenda on startup:
>
> (add-hook 'after-init-hook
>             (lambda () (org-agenda nil "t")))
> (setq initial-buffer-choice (lambda () (get-buffer "*Org Agenda*")))
>
> org-agenda-files contained a non-existent file, so org-check-agenda-file
> attempted to prompt me.  For some reason (maybe EXWM didn't fully load),
> Emacs simply hung without prompting, leaving me with a black screen.

You may consider reporting the hang to Emacs or EXWM bug tracker.

> My configuration contains the equivalent of
>
> (setopt org-agenda-files
>        (directory-files-recursively "~/.local/share/org/todo" ".org$"))

I'd recommend using a different approach - use org-agenda-file-regexp
instead of ".org$"; or use #'file-directory-p as predicate - Org mode
then select Org files inside all the listed directories by itself.

> The attached patch silently removes lockfiles from org-agenda-files.

> -  "Make sure FILE exists.  If not, ask user what to do."
> +  "Make sure FILE exists.  If not, ask user what to do.
> +Automatically exclude lockfiles."
>    (unless (file-exists-p file)
> +    (when (string-match-p (rx bos ".#") file) ; Exclude lockfiles
> +      (org-remove-file file)
> +      (throw 'nextfile t))

I feel slightly reluctant about this patch:

1. You are only working around the actual problem with agenda file being
   deleted from disk while Emacs is loading. So, the patch is not
   solving a real Org mode problem - Org mode prompting about
   non-existing file is not wrong; your bug has nothing to do with Org
   mode itself.

2. In theory, there might be users with actual Org files starting from
   ".#" for whatever reason. The probability is not high, but if users
   choose to set org-agenda-files directly, file-by-file, that's a
   choice we should better respect in order to not create a blocker.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Silently remove lockfiles from org-agenda-files
  2024-01-19 13:19 ` Ihor Radchenko
@ 2024-01-31 21:51   ` Joseph Turner
  2024-02-01 11:47     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph Turner @ 2024-01-31 21:51 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode Mailing List

Hi Ihor,

Ihor Radchenko <yantar92@posteo.net> writes:

> Joseph Turner <joseph@breatheoutbreathe.in> writes:
>
>> My Emacs setup broke today due to the presence of a lockfile inside
>> "~/.local/share/org/todo".  I use EXWM, and I show org-agenda on startup:
>>
>> (add-hook 'after-init-hook
>>             (lambda () (org-agenda nil "t")))
>> (setq initial-buffer-choice (lambda () (get-buffer "*Org Agenda*")))
>>
>> org-agenda-files contained a non-existent file, so org-check-agenda-file
>> attempted to prompt me.  For some reason (maybe EXWM didn't fully load),
>> Emacs simply hung without prompting, leaving me with a black screen.
>
> You may consider reporting the hang to Emacs or EXWM bug tracker.

>> My configuration contains the equivalent of
>>
>> (setopt org-agenda-files
>>        (directory-files-recursively "~/.local/share/org/todo" ".org$"))
>
> I'd recommend using a different approach - use org-agenda-file-regexp
> instead of ".org$"; or use #'file-directory-p as predicate - Org mode
> then select Org files inside all the listed directories by itself.

Good to know about org-agenda-file-regexp.

>> The attached patch silently removes lockfiles from org-agenda-files.
>
>> -  "Make sure FILE exists.  If not, ask user what to do."
>> +  "Make sure FILE exists.  If not, ask user what to do.
>> +Automatically exclude lockfiles."
>>    (unless (file-exists-p file)
>> +    (when (string-match-p (rx bos ".#") file) ; Exclude lockfiles
>> +      (org-remove-file file)
>> +      (throw 'nextfile t))
>
> I feel slightly reluctant about this patch:
>
> 1. You are only working around the actual problem with agenda file being
>    deleted from disk while Emacs is loading. So, the patch is not
>    solving a real Org mode problem - Org mode prompting about
>    non-existing file is not wrong; your bug has nothing to do with Org
>    mode itself.
>
> 2. In theory, there might be users with actual Org files starting from
>    ".#" for whatever reason. The probability is not high, but if users
>    choose to set org-agenda-files directly, file-by-file, that's a
>    choice we should better respect in order to not create a blocker.

Yes, I think you're right.  Thanks for your caution :)

Joseph


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Silently remove lockfiles from org-agenda-files
  2024-01-31 21:51   ` Joseph Turner
@ 2024-02-01 11:47     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2024-02-01 11:47 UTC (permalink / raw)
  To: Joseph Turner; +Cc: Org Mode Mailing List

Joseph Turner <joseph@breatheoutbreathe.in> writes:

>> I feel slightly reluctant about this patch:
>> ...
>
> Yes, I think you're right.  Thanks for your caution :)

Closing.
Canceled.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-01 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19  6:27 [PATCH] Silently remove lockfiles from org-agenda-files Joseph Turner
2024-01-19 13:19 ` Ihor Radchenko
2024-01-31 21:51   ` Joseph Turner
2024-02-01 11:47     ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).