2

任何人都可以帮我删除标题为:eventor的标签:event:,它可能会或可能不会出现在被标记为已完成的特定待办事项中。

如果不存在其他标签,则要删除的表单是:event:. 如果右侧附加了一个附加标签,那么要删除的表单是:event——因为连接到另一个标签的冒号需要保留——例如,:smith_john: 我想对所有待办事项使用这个功能,即使有些待办事项将包含event标签。

这有点棘手,因为正常的搜索和替换不仅限于待办事项列表中的这一特定任务。我知道与状态更改有关的标签删除功能,但我更愿意使用我自己的删除功能。

这是:event附加到另一个标签的示例:

** Reference [#A] smith @ meeting; 08/09/2013; 8:30 a.m. :event:smith_john:
   DEADLINE: <2013-08-09 Fri 08:30 >  SCHEDULED: <2013-08-09 Fri >
   :PROPERTIES:
   :ToodledoID: 335265357
   :ToodledoFolder: EVENTS
   :Hash: 4a6b6cc7fbefa9b7695b12247bf84d15
   :END:
   These are some notes relating to the client named John Smith.

这是一个不包含:eventor:event:标记的任务示例。尽管如此,该none功能应该能够像上面的任务一样将其关闭。

** Next Action [#D] 0 @ kid's birthday -- 07/18/1993 :lawlist:
   DEADLINE: <2014-07-18 Fri >
   :PROPERTIES:
   :ToodledoID: 332902470
   :ToodledoFolder: TASKS
   :Hash: e7cf177f187d47c8fa8ca882f2725305
   :END:
   These are some notes relating to a task without an event tag.

以下是我用来将待办事项标记为 的函数None,当与 Toodledo 同步时,将被理解为等同于通常称为completedor的函数done。上面任务中的单词Reference是我选择用于我日历上​​的事件的 Toodledo 待办状态,这个词Next Action是我用于具有未来截止日期的任务的单词。

(defun none (&optional default-heading)
(interactive)
  (let ((lawlist-item default-heading)
          result)
      (unless lawlist-item
        (condition-case nil
            (progn 
              (org-back-to-heading t)
              (setq lawlist-item (elt (org-heading-components) 4)))
          )
       )
  (org-todo "None")
  (org-priority ?E)
  (org-schedule 'remove)
  (org-deadline 'remove)
  (org-set-property "ToodledoFolder" "DONE")
  (setq org-archive-save-context-info nil)
  (setq org-archive-location "/Users/HOME/.0.data/*TODO*::* DONE")
  (org-archive-subtree)
  (goto-char (point-min))
  (re-search-forward "^\* DONE" nil t)
     (condition-case err
         (progn
           (org-sort-entries t ?a)
           (lawlist-org-cleanup) ) ;; a custom pagination function.
       (error nil))
  (re-search-forward lawlist-item nil t)
  (beginning-of-visual-line) 
  (org-cycle-hide-drawers 'all)
  ))

编辑:以下是上述函数中使用的清理none函数,以防万一有人对以这种方式关闭特定待办事项的完整解决方案感兴趣:

(defun delete-trailing-blank-lines-at-end-of-file ()
       "Deletes all blank lines at the end of the file, even the last one"
       (interactive)
       (save-excursion
         (save-restriction
           (widen)
           (goto-char (point-max))
           (delete-blank-lines)
           (let ((trailnewlines (abs (skip-chars-backward "\n\t"))))
             (if (> trailnewlines 0)
                 (progn
                   (delete-char trailnewlines)))))))

(defun lawlist-org-cleanup ()
(interactive)
(save-excursion 
(replace-regexp "\n+\\*\\* " "\n\n** " nil (point-min) (point-max))
(replace-regexp "\n+\\* " "\n\n\n* " nil (point-min) (point-max))
(replace-regexp "\n\t\s*" "\n   " nil (point-min) (point-max)) )
(delete-trailing-blank-lines-at-end-of-file) )
4

4 回答 4

2

只要标题出现在标题上,以下内容就应该起作用:

(when (search-forward-regexp ":event\\|event:" (line-end-position) t)
  (replace-match "")
  (when (and (looking-at ":$\\|: ") (looking-back " "))
     (delete-char 1)))
于 2013-08-11T11:02:01.707 回答
1

您可能对以下内容感兴趣:

;; remove redundant tags of headlines (from David Maus)
(defun leuven--org-remove-redundant-tags ()
  "Remove redundant tags of headlines in current buffer.
A tag is considered redundant if it is local to a headline and inherited by
a parent headline."
  (interactive)
  (when (eq major-mode 'org-mode)
    (save-excursion
      (org-map-entries
       '(lambda ()
          (let ((alltags (split-string
                          (or (org-entry-get (point) "ALLTAGS") "")
                          ":"))
                local inherited tag)
            (dolist (tag alltags)
              (if (get-text-property 0 'inherited tag)
                  (push tag inherited) (push tag local)))
            (dolist (tag local)
              (if (member tag inherited) (org-toggle-tag tag 'off)))))
       t nil))))
于 2013-08-12T08:09:09.953 回答
1

如果您只想在状态更改为DONE(或等效)时删除标签,您可以使用以下内容:

(defun zin/org-remove-tag (tag)
    "Removes `TAG' from current list of tags if present when todo
state is DONE."
  (when (org-entry-is-done-p)
    (org-toggle-tag tag 'off)))

(defun zin/remove-event ()
   "Removes `event' from list of tags when state is set to done."
  (zin/org-remove-tag "event"))

(add-hook 'org-after-todo-state-change-hook 'zin/remove-event)

(org-entry-is-done-p)将返回DONE标题的状态,如果未标记为已完成,则返回 NIL。 org-toggle-tag将切换标签的当前状态,或者设置为'onor'off如果提供了可选参数(在这种情况下'off)。

第一个函数对于任何给定的标签都是通用的,而第二个函数是特定于您想要的“事件”标签的。

或者,您可以使用以下内容作为您的钩子:

(add-hook 'org-after-todo-state-change-hook '(lambda ()
                                               (zin/org-remove-tag "event")))
于 2013-08-13T12:57:16.663 回答
0

虽然接受的答案效果很好,但以下代码片段使用org-mode函数来完成相同的结果——org-set-tags-to可以使用字符串或列表作为其可选参数;并且,没有参数会删除所有标签。

(let (tags)
  (save-excursion
    (org-back-to-heading t)
    (setq tags (org-element-property :tags (org-element-at-point))))
  (when (and tags (member "event" tags))
    (setq tags (delete "event" tags))
    (org-set-tags-to tags)))
于 2015-01-28T21:19:11.113 回答