AmaiKinono / puni

Structured editing (soft deletion, expression navigating & manipulating) that supports many major modes out of the box.
GNU General Public License v3.0
398 stars 20 forks source link

Feature request: make puni support org blocks #14

Open QiangF opened 2 years ago

QiangF commented 2 years ago

To be specific, make puni-beginning-of-sexp and puni-end-of-sexp jump to cursor position designated with "|" in the following examples.

1. Greater Blocks

  #+BEGIN_NAME PARAMETERS
  |CONTENTS1
  CONTENTS2|
  #+END_NAME

2. Dynamic Blocks

  #+BEGIN: NAME PARAMETERS
  |CONTENTS1
  CONTENTS2|
  #+END:

3. Latex Environment

  \begin{equation*}
  |CONTENTS1
  CONTENTS2|
  \end{equation*}
QiangF commented 2 years ago

Someone have a function for this:

(defun my-org-babel-goto-block-corner (p)
  "Go to the beginning of the current block.
If called with a prefix, go to the end of the block"
  (interactive "P")
  (let* ((element (org-element-at-point)))
    (when (or (eq (org-element-type element) 'example-block)
              (eq (org-element-type element) 'src-block))
      (let ((begin (org-element-property :begin element))
            (end (org-element-property :end element)))
        ;; Ensure point is not on a blank line after the block.
        (beginning-of-line)
        (skip-chars-forward " \r\t\n" end)
        (when (< (point) end)
          (goto-char (if p end begin))
          (when p
            (skip-chars-backward " \r\t\n")
            (beginning-of-line)))))))
AmaiKinono commented 2 years ago

It is handy but it contradicts with Puni's design:

An alternative way is to advise puni-beginning/end-of-sexp to do things differently in org-mode. If you could find a way to do this, could you write it in the wiki?

QiangF commented 2 years ago

I find evil-matchit has support for different kind of matching pairs. Sadly it requires evil mode.