1

誰かがマークを設定する関数の例を教えてください。その後、バッファ内の他の場所に追加のマークを設定するいくつかのことを行い、関数の最初にマークされた元の位置に戻ります。

transient-mark-modeデフォルトで有効になっています。でマークを設定してから、マークを にプッシュしてみました。(activate-mark)次に、関数がバッファ内を移動して、todo をアーカイブし、 (todo がアーカイブされた新しい場所で) のためにいくつかの組織的な作業と一時停止を実行して、それを確認できるようにします。すべてが正しく行われ、その後、すべてが始まった場所に戻っていました。ただし、関数の開始時に元のマークに戻すことはできませんでした。代わりに、関数の実行中に誤って別の場所に設定された別のマークに移動しました。(deactivate-mark)mark-ringread-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 に答える