For running code that should close all buffers that were opened, I use a
macro like this:
(defmacro with-no-new-buffers (&rest body)
"Run BODY, and kill any new buffers created.
Returns whatever BODY would return."
(let ((current-buffers (buffer-list)))
`(prog1
(progn
,@body)
(mapc (lambda (buf)
(unless (-contains? ',current-buffers buf)
(kill-buffer buf)))
(buffer-list)))))
For the other kinds of things you listed, check out
https://github.com/jkitchin/scimax/blob/master/scimax-notebook.org,
especially the nb-agenda function. It is more than you want, you can choose
a project, and then get an agenda for the org-files in that project.
Another example is at
https://github.com/jkitchin/scimax/blob/master/scimax-journal.el#L284 where
I get an agenda for journal entries in a date range. You can use this idea
generally, you let-bind the org-agenda-files variable to be the list you
want, and then call org-agenda.
These are a work in progress, but I use them pretty often.
You can restrict the agenda to a file, and even select search with
something like this:
(org-agenda nil "s" "<")
John
-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Mon, May 27, 2019 at 8:11 AM Christoph Groth <[email protected]>
wrote:
> Hello,
>
> I would like to expand my use of Org for notes, and to this end spread
> project-specific org files across my home directory (currently I'm using
> a central directory with one agenda file per year). For obvious
> reasons, I can't possibly include all these org files in
> org-agenda-files permanently and have them open in Emacs all the time.
>
> Instead, I'm thinking of a setup as follows: I'll reserve
> org-agenda-files for active projects only. But there will be many other
> org files (for projects that are finished or dormant, general notes,
> etc.), that I would like to be able to search as well.
>
> I saw that some people have solved this problem with a custom search
> solution, even using a database [1], but I think that for my purposes a
> simpler solution mostly using Org's built-in functionality will do. I'm
> also aware of org-agenda-text-search-extra-files, keeping all my extra
> files there is not satisfactory, because the search possibilities are
> limited (and otherwise it poses the same questions that I will ask
> further below).
>
> Instead, I imagine a custom Emacs command to launch an agenda with
> org-agenda-files that is temporarily set to a list of files that depends
> on the current context. For starters, this list could contain all the
> org files under the current directory:
>
> (split-string (shell-command-to-string "find `pwd`/* -name '*.org' -type
> f") "\n" t)
>
> This way, I could easily explore the org files that belong to specific
> subsets of my activities and interests. I could also search *all* my
> notes, when needed (for now the time this takes should not be a
> problem).
>
> I wonder if anyone has tried a similar setup and would be willing to
> share his experience and ideas. Specifically, I wonder about the
> following points:
>
> * Do you see any obvious problems with the above idea?
>
> * In Elisp, what is the best way to temporarily set org-agenda-files and
> later reset it back to the standard value?
>
> * How to automatically close unneeded org buffers that were opened for
> the temporarily agenda? The command org-agenda-exit is not
> satisfactory, because it also kills the buffers that one has just
> found due to the search, and also it's not automatic. Perhaps one
> could close the buffers immediately once the agenda view has been
> created?
>
> Thanks
> Christoph
>
> [1]
> https://kitchingroup.cheme.cmu.edu/blog/2017/01/03/Find-stuff-in-org-mode-anywhere/
>