0

In the following interesting config https://www.gtrun.org/post/config/#alphapapa-unpackaged-dot-el-a-collection-of-useful-emacs-lisp-code-that-isn-t-substantial-enough-to-be-packaged I found the command (unpackaged/org-return-dwim). It works when the cursor is on the heading, so that the cursor moves to the end headings content. I would like to make this command work in the heading itself, I managed to do it for two different cases for my custom paste in heading command:

a) When the cursor is on the heading

b) When the cursor is below the heading

Following code is used:

(evil-define-operator paste-in-prev-heading (beg end type register count yank-handler)
  "Delete preceding line(s)."
  :motion nil
  (interactive "<R><x><c><y>")
;; If count is nil or not a number
        (cond
          ((not (numberp count))
           (setq count 1) ) )

(org-previous-visible-heading count)
(unpackaged/org-return-dwim)
(evil-paste-before 1) )

(evil-define-operator paste-in-next-heading (beg end type register count yank-handler)
  "Delete preceding line(s)."
  :motion nil
  (interactive "<R><x><c><y>")

(unpackaged/org-return-dwim )
(evil-paste-after 1)
)

My question is, how can I combine the two cases into one? I need to somehow notice whether the cursor is on the heading or not in order to select either command made for the cursor on the heading or the command made for the cursor under the heading. Many thanks in advance.

1 Answer 1

1

You can use org-at-heading-p to determine whether you are currently on a heading or not. Perhaps better however, you can use org-back-to-heading unconditionally: then you are guaranteed to be at the beginning of the heading - that assumes that unpackaged/org-return-dwim does what you expect from there; if not, you might want to also do org-end-of-line to make sure that you are in a context where unpackaged/org-return-dwim will do the "right" thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.