diff options
author | Yuchen Pei <id@ypei.org> | 2023-06-24 16:53:03 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-06-24 17:09:10 +1000 |
commit | ba77033a0c81952f5b9b8e140a17c4d12f4e9d05 (patch) | |
tree | ceb04536bff256d739d949d34634006a2d1bd8f9 /emacs | |
parent | 1753d0dfa0d6ddb413ac868dfa25011e5bfa8983 (diff) |
make C-k and M-k act like paredit
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/.emacs.d/init/ycp-editing.el | 4 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-editing.el | 36 |
2 files changed, 39 insertions, 1 deletions
diff --git a/emacs/.emacs.d/init/ycp-editing.el b/emacs/.emacs.d/init/ycp-editing.el index e9c7e4c..b9ed48b 100644 --- a/emacs/.emacs.d/init/ycp-editing.el +++ b/emacs/.emacs.d/init/ycp-editing.el @@ -40,7 +40,8 @@ (my-package my-editing (:delay 5) (my-keybind global-map - "M-k" #'my-kill-line-backward + "C-k" #'my-kill-forward + "M-k" #'my-kill-backward "M-w" #'my-copy-line-or-region "C-o" #'my-new-line-above-or-below "C-<" #'my-escape-url-dwim @@ -60,6 +61,7 @@ "C-M-y" #'my-yank-primary "C-a" #'my-beginning-of-line-or-indentation ) + (electric-pair-mode) ) (setq viper-mode nil) 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 |