【发布时间】:2014-11-23 11:46:46
【问题描述】:
谁能给我一个函数的例子,它会设置一个标记,然后做一些事情,在缓冲区的其他地方设置额外的标记,然后返回到函数开头标记的原始位置。
transient-mark-mode 默认启用。我尝试使用(activate-mark) 设置标记,然后使用(deactivate-mark) 将标记推入mark-ring,然后我的函数在缓冲区中移动,归档待办事项并执行一些组织工作并暂停read-event(在新的待办事项存档的位置)让我看到一切都正确完成,然后我使用(set-mark-command t)回到一切开始的地方。但是,(set-mark-command t) 并没有让我回到函数开头的原始标记。相反,(set-mark-command t) 将我带到了另一个标记,该标记是在函数运行时无意中设置的。
(defun none (&optional default-heading)
(interactive)
(beginning-of-visual-line)
(activate-mark)
(deactivate-mark)
(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)))
)
)
(when (search-forward-regexp ":event\\|event:" (line-end-position) t)
(replace-match "")
(when (and (looking-at ":$\\|: ") (looking-back " "))
(delete-char 1)))
(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) )
(error nil))
(re-search-forward lawlist-item nil t)
(message (format "%s -- Finished!" lawlist-item))
(beginning-of-visual-line)
(org-cycle-hide-drawers 'all)
(read-event)
(set-mark-command t)
))
【问题讨论】:
-
save-excursion是你想要的吗?此处的文档:gnu.org/software/emacs/manual/html_node/elisp/Excursions.html -
谢谢。今晚我会阅读保存游览,看看这是否有助于我在缓冲区中定义一个位置,做一些不相关的事情,然后回到原来的位置。