简体   繁体   English

通过议程编写和调用函数(组织模式)

[英]Write and call function from agenda (org-mode)

(I don't know lisp, so I suspect this is really simple.) (我不懂lisp,所以我怀疑这真的很简单。)

I want to write a function to simplify my org-mode and GTD setup. 我想编写一个函数来简化我的组织模式和GTD设置。

I've based my org-mode setup on the write up here: http://doc.norang.ca/org-mode.html#CustomAgendaViewSetup 我的组织模式设置基于以下内容: http : //doc.norang.ca/org-mode.html#CustomAgendaViewSetup

I want to use the "NEXT" setup (see below) for multiple tags - I can just simply cut and paste the same code over and over, but it would be so much cleaner to write a function, so rather than having this: 我想对多个标签使用“ NEXT”设置(见下文)-我可以简单地一遍又一遍地剪切和粘贴相同的代码,但是编写一个函数会更加干净,而不是拥有这个:

            (tags-todo "-WAITING-CANCELLED/!NEXT"
                       ((org-agenda-overriding-header "Next Tasks")
                        (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
                        (org-agenda-todo-ignore-scheduled 'future)
                        (org-agenda-todo-ignore-deadlines 'future)
                        (org-tags-match-list-sublevels t)
                        (org-agenda-sorting-strategy
                         '(todo-state-down effort-up category-keep))))

I'd prefer something like: 我更喜欢这样的东西:

            (MyFunction "@work")
            (MyFunction "@computer")

Where the argument to the function changes the filtering in the above code block to something like: 该函数的参数将上述代码块中的过滤更改为:

            (tags-todo "-WAITING-CANCELLED+<XXX>/!NEXT"

ie

            (tags-todo "-WAITING-CANCELLED+@work/!NEXT"

Can someone help by pointing me in the right direction? 有人可以帮我指出正确的方向吗?

The following should do the trick (it also includes a variable to test for whether to use + or - before the tag, defaulting to - ). 以下应该可以解决问题(它还包含一个变量,用于测试在标记之前使用+还是- ,默认为- )。

(defun zin/agenda-test (tag &optional signp)
  "Simplify agenda coding, only require TAG to create new block.

SIGNP determines whether to use `+' or `-' when adding the tag.
Defaulting to `-'."
  (let ((sign (if signp "+" "-")))
    `(tags-todo ,(format "-WAITING-CANCELLED%s%s/!NEXT" sign tag)
        ((org-agenda-overriding-header "Next Tasks")
         (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
         (org-agenda-todo-ignore-scheduled 'future)
         (org-agenda-todo-ignore-deadlines 'future)
         (org-tags-match-list-sublevels t)
         (org-agenda-sorting-strategy
          '(todo-state-down effort-up category-keep))))))

(setq org-agenda-custom-commands `(("t" "Test"
                                (,(zin/agenda-test "@tag")
                                 ,(zin/agenda-test "@test" '+)))))

You have to make sure that org-agenda-custom-commands uses the backquote syntax ( ` ) instead of (quote ...) , otherwise the commands will not expand properly. 您必须确保org-agenda-custom-commands使用反引号语法( ` )而不是(quote ...) ,否则命令将无法正确扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM