From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: mark parent element? Date: Fri, 14 Mar 2014 18:11:39 +0100 Message-ID: <877g7wpuwk.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WOVdD-0007u1-TD for emacs-orgmode@gnu.org; Fri, 14 Mar 2014 13:10:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WOVd6-0003og-IV for emacs-orgmode@gnu.org; Fri, 14 Mar 2014 13:10:51 -0400 Received: from plane.gmane.org ([80.91.229.3]:59409) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WOVd6-0003oY-4g for emacs-orgmode@gnu.org; Fri, 14 Mar 2014 13:10:44 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WOVd3-0002K8-HE for emacs-orgmode@gnu.org; Fri, 14 Mar 2014 18:10:41 +0100 Received: from g231107118.adsl.alicedsl.de ([92.231.107.118]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 Mar 2014 18:10:41 +0100 Received: from tjolitz by g231107118.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 Mar 2014 18:10:41 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Matt Price 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