1

有人可以给我一个设置标记的函数示例,然后做一些在缓冲区其他地方设置附加标记的操作,然后返回到函数开头标记的原始位置。

transient-mark-mode默认启用。我尝试设置标记,(activate-mark)然后(deactivate-mark)将标记推入mark-ring,然后我的函数在缓冲区中移动,存档待办事项并执行一些组织工作并暂停 a 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)
  ))
4

2 回答 2

2

这也可能会有所帮助:您可能不想在Lisp代码中设置标记。

这就是 Elisp 手册所说的set-mark

 -- Function: set-mark position

 This function sets the mark to POSITION, and activates the mark.
 The old value of the mark is _not_ pushed onto the mark ring.

 *Please note:* Use this function only if you want the user to see
 that the mark has moved, and you want the previous mark position to
 be lost.  Normally, when a new mark is set, the old one should go
 on the `mark-ring'.  For this reason, most applications should use
 `push-mark' and `pop-mark', not `set-mark'.

 Novice Emacs Lisp programmers often try to use the mark for the
 wrong purposes.  The mark saves a location for the user's
 convenience.  An editing command should not alter the mark unless
 altering the mark is part of the user-level functionality of the
 command.  (And, in that case, this effect should be documented.)
 To remember a location for internal use in the Lisp program, store
 it in a Lisp variable.  For example:

      (let ((beg (point)))
        (forward-line 1)
        (delete-region beg (point))).

这就是两者的文档字符串并对此进行了set-mark-command说明push-mark

Novice Emacs Lisp programmers often try to use the mark for the wrong
purposes.  See the documentation of `set-mark' for more information.
于 2013-08-17T23:26:55.163 回答
1

这听起来像是save-excursion您正在寻找的东西——它将您的位置(连同其他信息)保存在缓冲区中,执行主体,然后返回到原始位置。

于 2013-08-17T22:47:11.847 回答