Matt Price <mopto...@gmail.com> writes: > Hi, > > I'm trying to write a function that will mark the parent of the > current element. I think I understand how to do it but for some > reason I can get the mark to persist after the funciton is called. I > think it's really an elisp problem, not an org problem, but am hoping > someone can ehelp me. Here's what I have: > > (defun er/mark-org-parent-element () > "Marks an org parent element" > (interactive) > (let ((parent (plist-get (car (cdr (org-element-at-point))) :parent))) > (let ((parent-props (car (cdr parent)))) > ;; (print parent-props) > ;; (print (plist-get parent-props :begin)) > ;; (print (plist-get parent-props :end)) > (if (plist-get parent-props :begin) > (progn > (goto-char (plist-get parent-props :begin)) > (set-mark (point)) > (goto-char (plist-get parent-props :end)) > (exchange-point-and-mark) > ))) > ) > )
the set-mark doc give two hints in my eyes: ,----------------------------------------------------------------------- | set-mark is a compiled Lisp function in `simple.el'. | | (set-mark POS) | | Set this buffer's mark to POS. Don't use this function! | That is to say, don't use this function unless 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 stack. | This is why most applications should use `push-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. | Most editing commands should not alter the mark. | To remember a location for internal use in the Lisp program, | store it in a Lisp variable. Example: | | (let ((beg (point))) (forward-line 1) (delete-region beg (point))). `----------------------------------------------------------------------- 1. maybe try push-mark instead of set-mark? 2. maybe avoid marks completely if you just want make your program act on a region -- cheers, Thorsten