AmaiKinono / puni

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

two convenience functions for delete and splice #24

Closed bymoz089 closed 2 years ago

bymoz089 commented 2 years ago

I missed some convenience functions. Those functions delete some content of the current sexp before splicing. Maybe it is possible to include them (or better versions of them)?

(defun puni-splice-sexp-killing-backward ()
  "remove sexp content before point and splice."
  (interactive)
  (save-excursion
    (let ((pos (point)))
      (puni-beginning-of-sexp)
      (delete-region (point) pos)
      (puni-splice))))

(defun puni-splice-sexp-killing-forward ()
  "remove sexp content after point and splice."
  (interactive)
  (save-excursion
    (let ((pos (point)))
      (puni-end-of-sexp)
      (delete-region pos (point))
      (puni-splice))))
AmaiKinono commented 2 years ago

You can do it by:

I don't like to put such "composed" commands into Puni unless people really use them daily.

bymoz089 commented 2 years ago

Edited

Thanks for responding and for mentioning puni-kill-line! Now the body of above functions have only two lines. It's ok to define that on a private config.

Would you consider to make the kill argument of puni-soft-delete from puni-kill-line and puni-backward-kill-line a customizable option?
You did this already on other functions via the variable delete-active-region.


Note: following source code is just for documentation for future readers.

(defun my-puni-splice-sexp-killing-backward ()
  (interactive)
  (puni-backward-kill-line)
  (puni-splice))

For now I adviced puni-soft-delete to always operate with argument kill set to nil.

(defun my-puni-soft-delete-filter-kill-arg (orig-fun from to &optional strict-sexp style kill fail-action return-region)
  (funcall orig-fun from to strict-sexp style nil fail-action return-region))
(advice-add #'puni-soft-delete :around #'my-puni-soft-delete-filter-kill-arg)
AmaiKinono commented 2 years ago

Well, actually using puni-kill-line isn't a good idea. It can't deal with multi-line sexp:

(foo|
 bar)
;; what you want for puni-splice-sexp-killing-forward
foo|
;; what it actually does
foo|bar

Your original implementation is quite clean. Seems you don't like to define complex commands in private config? Here's a two-line version:

(defun puni-splice-sexp-killing-forward ()
  (interactive)
  (delete-region (point) (puni-end-of-list-around-point))
  (puni-splice))