emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Karl Voit <devnull@Karl-Voit.at>
To: emacs-orgmode@gnu.org
Subject: Filter out agenda items using elisp
Date: Sun, 22 Jan 2017 12:09:24 +0100	[thread overview]
Message-ID: <2017-01-22T11-44-29@devnull.Karl-Voit.at> (raw)

Hi!

I want to write my own flexible narrow function for my agenda using
RegEx.  

I found org-agenda-filter-by-regexp() which seems a perfect hit for
my task. However, I need to call it with a universal prefix in order
to remove lines matching my RegEx:

(defun my-narrow-agenda ()
  "Getting rid of all org-agenda entries matching the RegEx"
  (interactive)
  (setq current-prefix-arg '(4))    ;; "add" prefix C-u
  (org-agenda-filter-by-regexp "\(WAITING\|:reward:\|:lp:\)")
  )

When I call the function when being in my agenda, I get asked for
entering the RegEx string to narrow the items as if I did not state
the prefix-arg nor the regex as parameters.


Then I took a look at org-agenda-filter-by-regexp() (see code
below), found a new best friend in trace-function(), and tried to
mimic the function call for org-agenda-filter-apply() when I do the
task manually/interactive:

(defun my-narrow-agenda ()
  (interactive)
  (org-agenda-filter-apply ("-NEXT.*:\\(@BWG\\|reward\\):" "+") regexp)
  )

This returns wrong number of arguments. But why? I used the exact
output of trace-function().


How can I accomplish my code?



The related code for org-agenda-filter-by-regexp is:

(defun org-agenda-filter-by-regexp (strip)
  "Filter agenda entries by a regular expression.
Regexp filters are cumulative.
With no prefix argument, keep entries matching the regexp.
With one prefix argument, filter out entries matching the regexp.
With two prefix arguments, remove the regexp filters."
  (interactive "P")
  (if (not (equal strip '(16)))
      (let ((flt (concat (if (equal strip '(4)) "-" "+")
             (read-from-minibuffer
              (if (equal strip '(4))
                  "Filter out entries matching regexp: "
                "Narrow to entries matching regexp: ")))))
    (push flt org-agenda-regexp-filter)
    (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
    (org-agenda-filter-show-all-re)
    (message "Regexp filter removed")))


-- 
get mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML into Org-mode:
       > get Memacs from https://github.com/novoid/Memacs <
Personal Information Management > http://Karl-Voit.at/tags/pim/
Emacs-related > http://Karl-Voit.at/tags/emacs/

                 reply	other threads:[~2017-01-22 11:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2017-01-22T11-44-29@devnull.Karl-Voit.at \
    --to=devnull@karl-voit.at \
    --cc=emacs-orgmode@gnu.org \
    --cc=news1142@Karl-Voit.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).