From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: mark parent element?
Date: Fri, 14 Mar 2014 18:11:39 +0100 [thread overview]
Message-ID: <877g7wpuwk.fsf@gmail.com> (raw)
In-Reply-To: CAN_Dec9jfG_i7mjuUHirvhfAJNuxateiQ2MrthC6t2QYcq5W8g@mail.gmail.com
Matt Price <moptop99@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
next prev parent reply other threads:[~2014-03-14 17:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-14 15:42 mark parent element? Matt Price
2014-03-14 17:11 ` Thorsten Jolitz [this message]
2014-03-14 17:57 ` Oleh
2014-03-14 18:11 ` Nicolas Goaziou
2014-03-15 2:06 ` Matt Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877g7wpuwk.fsf@gmail.com \
--to=tjolitz@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.