From ba77033a0c81952f5b9b8e140a17c4d12f4e9d05 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 24 Jun 2023 16:53:03 +1000 Subject: make C-k and M-k act like paredit --- emacs/.emacs.d/lisp/my/my-editing.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'emacs/.emacs.d/lisp/my/my-editing.el') diff --git a/emacs/.emacs.d/lisp/my/my-editing.el b/emacs/.emacs.d/lisp/my/my-editing.el index bd3ca83..a8fe822 100644 --- a/emacs/.emacs.d/lisp/my/my-editing.el +++ b/emacs/.emacs.d/lisp/my/my-editing.el @@ -336,5 +336,41 @@ Basically move the line up (goto-line line) (forward-char col))) +(defun my-kill-forward () + "Kill towards end of line, but not out of sexp." + (interactive) + (if (eolp) + (delete-char 1) + (let ((end) + (eol (save-excursion (end-of-line) (point)))) + (save-excursion + (skip-chars-forward " \t") + (while (not (or (eq end (point)) + (>= (point) eol))) + (setq end (point)) + (ignore-errors (forward-sexp)) + (skip-chars-forward " \t")) + (when (> (point) eol) (skip-chars-backward " \t")) + (setq end (point))) + (kill-region (point) end)))) + +(defun my-kill-backward () + "Kill towards beginning of line, but not out of sexp." + (interactive) + (if (bolp) + (delete-char -1) + (let ((beg) + (bol (save-excursion (beginning-of-line) (point)))) + (save-excursion + (skip-chars-backward " \t") + (while (not (or (eq beg (point)) + (<= (point) bol))) + (setq beg (point)) + (ignore-errors (backward-sexp)) + (skip-chars-backward " \t")) + (when (< (point) bol) (skip-chars-forward " \t")) + (setq beg (point))) + (kill-region beg (point))))) + (provide 'my-editing) ;;; my-editing.el ends here -- cgit v1.2.3