[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Add contents-begin and contents-end to src-block in org-element.
Re: [O] Add contents-begin and contents-end to src-block in org-element.el
Wed, 27 Dec 2017 21:50:15 +0100
2017-12-25 23:42 GMT+01:00 Nicolas Goaziou <address@hidden>:
> I suggest the following.
> For contents begin:
> (goto-char (org-element-property :post-affiliated element))
> (line-beginning-position 2))
> For contents end:
> (goto-char (org-element-property :end element))
> (skip-chars-backward " \t\n")
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
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
It would be ideal if elements had the following additional properties:
Unfortunately, they don't.
I have come to the following hackish solution:
(defun org-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]"))))
(goto-char (org-element-property :post-affiliated element))
(search-forward (first lines))
(goto-char (org-element-property :end element))
(search-backward (car (last lines)))
;; 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)))