From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: Agenda-like/query language project: org-agenda-ng/org-ql Date: Thu, 10 May 2018 16:41:27 -0500 Message-ID: <87sh6z2np4.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGtJo-0005Zm-7t for emacs-orgmode@gnu.org; Thu, 10 May 2018 17:41:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGtJl-0005gq-5R for emacs-orgmode@gnu.org; Thu, 10 May 2018 17:41:44 -0400 Received: from [195.159.176.226] (port=40666 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGtJk-0005ee-Uw for emacs-orgmode@gnu.org; Thu, 10 May 2018 17:41:41 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fGtHW-0008P2-V7 for emacs-orgmode@gnu.org; Thu, 10 May 2018 23:39:22 +0200 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: emacs-orgmode@gnu.org Hi all, I've made some improvements to my experimental "org-agenda-ng" project which might be interesting to some of you. It also works as a kind of "query language" for Org files, providing a lispy DSL to match/filter/select entries in Org files. It's on GitHub at: https://github.com/alphapapa/org-agenda-ng Note that the agenda-like view that it creates is largely compatible with agenda-related code, because it makes strings with the same text-properties as the canonical Org agenda view (not guaranteed to be comprehensive, it's a WIP, but it does most that I'm aware of). For example, org-super-agenda can group its views the same way it groups "real" Org agenda views. Here are some examples: #+BEGIN_SRC elisp ;; Show an agenda-like view of items in all agenda files with TODO and SOMEDAY keywords which are ;; tagged "computer" or "Emacs" and in the category "main": (org-agenda-ng org-agenda-files (and (todo "TODO" "SOMEDAY") (tags "computer" "Emacs") (category "main"))) ;; Show an agenda-like view of all habits: (org-agenda-ng org-agenda-files (habit)) ;; Show an agenda-like view similar to a "traditional" Org agenda: (org-agenda-ng "~/org/main.org" (or (habit) (date = today) (deadline <=) (scheduled <= today) (and (todo "DONE" "CANCELLED") (closed = today)))) ;; Return a list of Org entry elements which are not done, are tagged "Emacs", and have ;; priority B or higher: (org-ql org-agenda-files (and (not (done)) (tags "Emacs") (priority >= "B"))) ;; => ((headline (:raw-value "org-board" :begin 1220270 :end 1220403 ...)) ...) ;; Find the same entries as before, but return a list of heading positions: (org-ql "~/org/main.org" (and (not (done)) (tags "Emacs") (priority >= "B")) :action-fn (lambda (element) (org-element-property :begin element))) ;; => (44154 46469 56008 63965 100008 ...) ;; Or you can use mapcar around it to get the same result (API is WIP): (mapcar (lambda (element) (org-element-property :begin element)) (org-ql "~/org/main.org" (and (not (done)) (tags "Emacs") (priority >= "B")))) ;; => (44154 46469 56008 63965 100008 ...) #+END_SRC There are a few more ideas I have for improvements, but it has been whittled down to where I'm fairly happy with it. I will probably adjust the org-ql :action-fn so that users can directly control what function is used to return each matching result, instead of always using org-element-headline-parser as it currently does (which would improve performance when users don't need all the element properties). I may add some more matchers too, like for properties, regexps, etc. Performance is not quite on par with the traditional agenda code (which is more optimized, but also more complicated), but it's pretty good, and good enough to be useful, I think. And if Emacs ever gains a faster Elisp implementation, I think it would be fast enough in all cases. So my question is, would anyone find this generally useful? Should I consider polishing it up and releasing it as a package (in which case, it would probably be called something like org-ql rather than org-agenda-ng, and the agenda-like views would be ancillary)? Any questions, ideas, suggestions, and contributions are welcome. Thanks, Adam