From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Temporarily setting agenda files list, cleaning up Date: Mon, 27 May 2019 08:46:04 -0400 Message-ID: References: <87v9xwf6iu.fsf@neron> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000002a3f440589ddef94" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:55450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVF1G-0001bU-14 for emacs-orgmode@gnu.org; Mon, 27 May 2019 08:46:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVF1E-0002yd-7d for emacs-orgmode@gnu.org; Mon, 27 May 2019 08:46:25 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:40753) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVF1C-0002oO-0G for emacs-orgmode@gnu.org; Mon, 27 May 2019 08:46:24 -0400 Received: by mail-wr1-x42a.google.com with SMTP id t4so8538957wrx.7 for ; Mon, 27 May 2019 05:46:18 -0700 (PDT) In-Reply-To: <87v9xwf6iu.fsf@neron> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Christoph Groth Cc: org-mode-email --0000000000002a3f440589ddef94 Content-Type: text/plain; charset="UTF-8" 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 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/ > --0000000000002a3f440589ddef94 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
For running code that should close all buffers that were o= pened, I use a macro like this:

(defmacro with-no-new-bu= ffers (&rest body)
=C2=A0 "Run BODY, and kill any new buffers c= reated.
Returns whatever BODY would return."
=C2=A0 (let ((curre= nt-buffers (buffer-list)))
=C2=A0 =C2=A0 `(prog1
(progn
=C2=A0= ,@body)
=C2=A0 =C2=A0 =C2=A0 =C2=A0(mapc (lambda (buf)
=C2=A0 =C2= =A0 =C2=A0 (unless (-contains? ',current-buffers buf)
(kill-buffe= r buf)))
=C2=A0 =C2=A0 (buffer-list)))))

For = the other kinds of things you listed, check out=C2=A0https://github.com= /jkitchin/scimax/blob/master/scimax-notebook.org, especially the nb-age= nda function. It is more than you want, you can choose a project, and then = get an agenda for the org-files in that project.=C2=A0=C2=A0

=
Another example is at=C2=A0https://github.com/jkitchin/sc= imax/blob/master/scimax-journal.el#L284=C2=A0where I get an agenda for = journal entries in a date range. You can use this idea generally, you let-b= ind the org-agenda-files variable to be the list you want, and then call or= g-agenda.=C2=A0

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" "<")
<= div>



=
John

------------------------= -----------
Professor John Kitchin=C2=A0
Doherty Hall A207F
Depart= ment of Chemical Engineering
Carnegie Mellon University
Pittsburgh, P= A 15213
412-268-7803


On Mon, May 27= , 2019 at 8:11 AM Christoph Groth <christoph@grothesque.org> 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 usin= g
a central directory with one agenda file per year).=C2=A0 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.=C2=A0 But there will be many oth= er
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.=C2= =A0 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.=C2=A0 For starters, this list could contain all the=
org files under the current directory:

(split-string (shell-command-to-string "find `pwd`/* -name '*.org&= #39; -type f") "\n" t)

This way, I could easily explore the org files that belong to specific
subsets of my activities and interests.=C2=A0 I could also search *all* my<= br> 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.=C2=A0 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 =C2=A0 later reset it back to the standard value?

* How to automatically close unneeded org buffers that were opened for
=C2=A0 the temporarily agenda?=C2=A0 The command org-agenda-exit is not
=C2=A0 satisfactory, because it also kills the buffers that one has just =C2=A0 found due to the search, and also it's not automatic.=C2=A0 Perh= aps one
=C2=A0 could close the buffers immediately once the agenda view has been =C2=A0 created?

Thanks
Christoph

[1] https://kitch= ingroup.cheme.cmu.edu/blog/2017/01/03/Find-stuff-in-org-mode-anywhere/<= br>
--0000000000002a3f440589ddef94--