doomemacs / doomemacs/core

The first call to `org-clock-in`/`org-resolve-clocks`/`org-files-list` on start loads all org-agenda-files in buffers

Open
#5,317 9 comments 4 reactions 0 assignees View on GitHub
:lang org re:perf
Dominant language
Emacs Lisp
Stars
22.7k
Forks
3.1k
Avg merge
10h 46m
Merged PRs (30d)
4

Description

### What did you expect to happen?

When starting Emacs, clocking into a task should not have an incidence on the list of buffers.

### What actually happened?

When I start Emacs and clock into a task, all the files listed in `org-agenda-files` are opened in buffers.
This happens systematically at the first call to `org-clock-in`. Subsequent calls (including after `doom/reload`) do not seem to trigger this behaviour.
`org-agenda-files` do get fully reloaded every few hours, but I have yet to determine what the context is.

### Describe your attempts to resolve the issue

I have managed to narrow the issue down to `org-files-list`.
Specifically:
- `org-clock-in` calls `org-resolve-clocks`
- `org-resolve-clocks` calls `org-files-list` (which is the only existing reference to `org-files-list`)
- `org-files-list` returns `org-agenda-files` list, plus all open Org files, according to the description

---

I have checked that this is the problem by running the following in the scratch buffer at start:

``` elisp
#+begin_src elisp
(dolist (file (org-files-list)))
#+end_src
```

This snippet does not return anything, but triggers all org files to be loaded into buffers.

---

I have not found any mention of this issue anywhere, which makes me think that either it's my config, or no one else is bothered by having all `org-agenda-files` in the buffer list.

---

The source code for `org-files-list`:
``` elisp
;; Defined in ~/.emacs.d/.local/straight/repos/org/lisp/org.el
(defun org-files-list ()
"Return `org-agenda-files' list, plus all open Org files.
This is useful for operations that need to scan all of a user's
open and agenda-wise Org files."
(let ((files (mapcar #'expand-file-name (org-agenda-files))))
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (and (derived-mode-p 'org-mode) (buffer-file-name))
(cl-pushnew (expand-file-name (buffer-file-name)) files
:test #'equal))))
files))
```

### Steps to reproduce

1. Start Emacs
2. Clock-in to a task

### System Information

https://pastebin.com/A5LJXHy6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.