From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcin Borkowski Subject: Re: Is there a way to get all agenda TODOs programmatically? Date: Wed, 03 Jan 2018 10:31:41 +0100 Message-ID: <87vagjffuq.fsf@mbork.pl> References: <87376v36up.fsf@mbork.pl> <87a813rqdx.fsf@fastmail.fm> <87r2ue29j8.fsf@mbork.pl> <874lrasxu2.fsf@fastmail.fm> <877et5joln.fsf@mbork.pl> <87shbqv58k.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWfOz-0003gi-W9 for emacs-orgmode@gnu.org; Wed, 03 Jan 2018 04:32:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWfOw-0006TV-Rm for emacs-orgmode@gnu.org; Wed, 03 Jan 2018 04:32:01 -0500 Received: from mail.mojserwer.eu ([195.110.48.8]:56881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWfOw-0006OT-Jg for emacs-orgmode@gnu.org; Wed, 03 Jan 2018 04:31:58 -0500 In-reply-to: <87shbqv58k.fsf@alphapapa.net> 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: Adam Porter Cc: emacs-orgmode@gnu.org On 2018-01-01, at 00:37, Adam Porter wrote: > Marcin Borkowski writes: > >> Thanks again. I played around with this for some time, but there is one >> problem. The agenda has a lot of settings, and replicating them with >> org-map-entries turned out to be no fun. >> >> Is there a way to plug into the agenda generating functions somehow to >> get a Lisp list of agenda items? I'm pretty sure that can be done - >> org-super-agenda does something similar, after all - but I have no idea >> why. I could delve into agenda source myself, but is is quite hairy, so >> maybe someone knows that already? > > Hi Marcin, > > As you said, the agenda code is quite hairy--but it does work very well. > My meager attempt to begin reimplementing it in a more functional way > showed very poor performance by comparison; perhaps because I didn't do > it well, but I'm guessing also because of Emacs' function call overhead. > But for your project, perhaps the code would come in useful; feel free > to borrow anything that you like: > > https://github.com/alphapapa/org-agenda-ng > > As you mentioned, org-super-agenda simply uses the raw output of the > org-agenda commands by reading it from the agenda buffer. This works > well because each line in the agenda buffer is an item, and the text on > each line has Emacs text-properties that include most of the relevant > metadata (anything else can be retrieved by using a macro to eval code > at the item's marker--see org-super-agenda--when-with-marker-buffer, > which I should probably rename, haha). So getting a list of agenda > items could be as simple as running this in the agenda buffer: > > (split-string (buffer-substring (point-min) (point-max)) > "\n" 'omit-nulls) > > org-super-agenda does that by using advice to filter the return of > org-agenda-finalize-entries, which you could also do quite easily. > > So while the agenda code is relatively opaque, it's easier to use its > output than you might think. :) Let me know if I can help. (I haven't > been monitoring the list lately, so you might email me directly if > necessary.) Good luck! Hi Adam, and thanks for your answer. I never thought about analyzing agenda /output/ - that is quite clever! I still think it's a hack, and I really regret that Org does not offer a programmer a better API for agenda (and many other things) - there could be a lot of applications built on top of Org with that. I'll definitely try this solution some day (maybe even within a few days). Thanks and best, -- Marcin Borkowski