emacs - 如何使用自定义函数在组织模式下仅删除一些标签

标签 emacs org-mode

有人可以帮我删除标题为 :event 的标签吗?或: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.

这是一个不包含 :event 的任务示例或: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 同步时,将被理解为相当于更常见的 completeddone 。字Reference上面的任务中是我选择用于日历上的事件的 Toodledo 待办事项状态,以及单词 Next Action我用它来处理有 future 截止日期的任务。

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

最佳答案

只要标题上有要点,以下内容就应该有效:

(when (search-forward-regexp ":event\\|event:" (line-end-position) t)
  (replace-match "")
  (when (and (looking-at ":$\\|: ") (looking-back " "))
     (delete-char 1)))

关于emacs - 如何使用自定义函数在组织模式下仅删除一些标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18168146/

相关文章:

emacs - 如何按名称导航到emacs中的erlang函数?

emacs - 将 Linum 模式配置为在空白模式下不显示空白符号?

emacs - 如何在 org-babel 的评估(导出)源 block 中导入/扩展 noweb refs?

emacs - 在组织模式下对标题的混合列表进行排序

sorting - 如何让 emacs 列出像 ls 这样的建议(沿列)

python - emacs:清除(删除)emacs 中的 python 结果控制台

html - 如何删除组织模式 html 导出中的页脚详细信息?

emacs - 通过键绑定(bind)重新归档到给定的子树

emacs - 在 emacs 中,*Help* 缓冲区中的 "hyperlink"是如何工作的?

emacs - 在 .emacs 文件外设置 emacs org-mode