Skip to content

Commit

Permalink
lispy.el (lispy-backward-kill-word): add and bind to "M-DEL"
Browse files Browse the repository at this point in the history
* lispy.el (lispy-backward-kill-word): New function, bound to "M-DEL".

* lispy-test.el (lispy-backward-kill-word): Add test.

re purcell#40
  • Loading branch information
abo-abo committed Jan 23, 2015
1 parent a20f5c3 commit 25e765d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lispy-test.el
Expand Up @@ -1272,6 +1272,14 @@ Insert KEY if there's no command."
(should (string= (lispy-with "\"(require '|)\"" (kbd "M-d"))
"\"(require ')\"|")))

(ert-deftest lispy-backward-kill-word ()
(should (string= (lispy-with "(require 'cl)|" (kbd "M-DEL"))
"(require '|)"))
(should (string= (lispy-with "(eval-after-load \"foo\")|" (kbd "M-DEL"))
"(eval-after-load \"|\")"))
(should (string= (lispy-with "(eval-after-load \"|\")" (kbd "M-DEL"))
"(eval-after-| \"\")")))

(provide 'lispy-test)

;;; lispy-test.el ends here
18 changes: 18 additions & 0 deletions lispy.el
Expand Up @@ -812,6 +812,23 @@ Return nil if can't move."
(goto-char (1+ (cdr (lispy--bounds-string))))))
(kill-word 1)))))

(defun lispy-backward-kill-word (arg)
"Kill ARG words backward, keeping parens consistent."
(interactive "p")
(let (bnd)
(lispy-dotimes arg
(while (not (or (bobp)
(memq (char-syntax (char-before))
'(?w ?_))))
(backward-char 1))
(if (setq bnd (lispy--bounds-string))
(progn
(save-restriction
(narrow-to-region (1+ (car bnd)) (1- (cdr bnd)))
(backward-kill-word 1)
(widen)))
(backward-kill-word 1)))))

(defun lispy-yank ()
"Like regular `yank', but quotes body when called from \"|\"."
(interactive)
Expand Down Expand Up @@ -5278,6 +5295,7 @@ FUNC is obtained from (`lispy--insert-or-call' DEF PLIST)"
(define-key map (kbd "C-d") 'lispy-delete)
(define-key map (kbd "M-d") 'lispy-kill-word)
(define-key map (kbd "DEL") 'lispy-delete-backward)
(define-key map (kbd "M-DEL") 'lispy-backward-kill-word)
(define-key map (kbd "M-m") 'lispy-mark-symbol)
(define-key map (kbd "C-,") 'lispy-kill-at-point)
(define-key map (kbd "C-M-,") 'lispy-mark)
Expand Down

0 comments on commit 25e765d

Please sign in to comment.