l...@phdk.org writes: > 1. `org-indent-line' indents the end tag of some blocks to match the > begin tag, but doesn't do so with src blocks, among others. > > MRE: With the pointer before =#+end_src= in the following, do `M-x > org-indent-line' > #+begin_src fundamental > foo > #+end_src > Expected: line is indented by 2 > Actual: line is indented by 4 > > I thought it was a bit weird since the code for calculating the src > block content indent does handle it if the block itself is indented, and > it worked fine for other block types. It seems this is because src > blocks (+ export, example, et al) aren't greater elements and don't > have a `contents-end' property.
Not just src-blocks, I think. Also other kinds of verbatim blocks: example blocks, latex environments, and comment blocks. Note that indenting region does indent #+end_... tag. > I was looking at fixing it for all cases but realized it would require > messing with the element parsers which I'm honestly really not looking > to get into, but I've attached a draft patch that works for src > blocks. It's a pretty theoretical problem, but if you think it's worth > fixing and that the patch makes sense I'd be happy to clean it up and > add a test. Yes, I do think that it is worth fixing. > - ;; POS is after contents in a greater element. Indent like > - ;; the beginning of the element. > - ((and (memq type org-element-greater-elements) > - (let ((cend (org-element-contents-end element))) > + ;; POS is after contents in a greater element or src-block. > + ;; Indent like the beginning of the element. > + ((and (or (memq type org-element-greater-elements) > + (org-element-type-p element 'src-block)) > + (let ((cend (or (org-element-contents-end element) > + (org-with-wide-buffer > + (goto-char (org-element-end element)) > + (skip-chars-backward " \r\t\n") > + (line-beginning-position))))) Looks reasonable, other than that the same should probably be done for other kinds of verbatim blocks. In the future, there will be :value-being/:value-end property to avoid the skip-chars-backwad dance, but not yet. See https://git.sr.ht/~yantar92/org-mode/commit/f8e2eeae21e99492cb -- Ihor Radchenko // yantar92, Org mode maintainer, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>