puni icon indicating copy to clipboard operation
puni copied to clipboard

Feature request: make puni support org blocks

Open QiangF opened this issue 3 years ago • 3 comments

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 avatar Dec 30 '21 02:12 QiangF

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)))))))

QiangF avatar Dec 30 '21 02:12 QiangF

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

  • I'd like to avoid mode-specific logic in Puni.
  • All the user commands should be built on the puni-strict-forward/backward-sexp functions and avoid ad-hoc logic.

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?

AmaiKinono avatar Dec 30 '21 15:12 AmaiKinono

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

QiangF avatar Dec 31 '21 07:12 QiangF