From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Somelauw ." Subject: Re: Add contents-begin and contents-end to src-block in org-element.el Date: Wed, 27 Dec 2017 21:50:15 +0100 Message-ID: References: <87tvwggo9s.fsf@nicolasgoaziou.fr> <87o9mnfb0j.fsf@nicolasgoaziou.fr> <87po721lb5.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUIeZ-0002cn-51 for emacs-orgmode@gnu.org; Wed, 27 Dec 2017 15:50:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUIeY-0002O4-4V for emacs-orgmode@gnu.org; Wed, 27 Dec 2017 15:50:19 -0500 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:41901) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eUIeX-0002IO-Rl for emacs-orgmode@gnu.org; Wed, 27 Dec 2017 15:50:18 -0500 Received: by mail-wm0-x22c.google.com with SMTP id g75so41345585wme.0 for ; Wed, 27 Dec 2017 12:50:16 -0800 (PST) In-Reply-To: <87po721lb5.fsf@nicolasgoaziou.fr> 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" To: Nicolas Goaziou Cc: emacs-orgmode@gnu.org 2017-12-25 23:42 GMT+01:00 Nicolas Goaziou : > I suggest the following. > > For contents begin: > > (save-excursion > (goto-char (org-element-property :post-affiliated element)) > (line-beginning-position 2)) > > For contents end: > > (save-excursion > (goto-char (org-element-property :end element)) > (skip-chars-backward " \t\n") > (line-beginning-position)) > Thanks, your code works as long as the element at point is some kind of block element. I have identified the following block elements: - all elements that end with "-block - latex-export/environment - diary - drawer - export - fixed_width However, I'm trying to write something that works on all elements and I want my code to continue working even if new elements are added to org-mode. It would be ideal if elements had the following additional properties: - :value-begin - :value-end Unfortunately, they don't. I have come to the following hackish solution: #+BEGIN_SRC emacs-lisp (defun org-select-inner-element () "Select inner-element. Return begin and end of inner contents of org-element at point." (let* ((element (org-element-context))) ;; Element has a value (if-let ((value (org-element-property :value element))) ;; Try to return begin and end of :value property (let ((lines (remove "" (split-string value "[\n\r]")))) (list (save-excursion (goto-char (org-element-property :post-affiliated element)) (search-forward (first lines)) (match-beginning 0)) (save-excursion (goto-char (org-element-property :end element)) (search-backward (car (last lines))) (match-end 0)))) ;; Check if element has :contents-begin and contents-end (if (org-element-property :contents-begin element) (list (org-element-property :contents-begin element) (org-element-property :contents-end element)) ;; Otherwise select the whole element (list (org-element-property :begin element) (org-element-property :end element))) ))) #+END_SRC