emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Filter out agenda items using elisp
@ 2017-01-22 11:09 Karl Voit
  0 siblings, 0 replies; only message in thread
From: Karl Voit @ 2017-01-22 11:09 UTC (permalink / raw)
  To: emacs-orgmode

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/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-01-22 11:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-22 11:09 Filter out agenda items using elisp Karl Voit

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).