Last active
February 23, 2016 06:43
-
-
Save CarlOlson/a4ae96fdb92914e98dc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;; | |
;;; delete-word.el ;;; | |
;;;;;;;;;;;;;;;;;;;;;; | |
(global-set-key (kbd "C-S-d") #'delete-forward-word) | |
(global-set-key (kbd "C-S-h") #'delete-backward-word) | |
(defun delete-forward-word (point) | |
"Deletes forwards by words. Similar to `delete-forward-char' | |
and `delete-backward-word', but doesn't stop at any punctuation." | |
(interactive "d") | |
(when (re-search-forward "[ \t]+\\|.$" nil t) | |
(delete-region point (point)))) | |
(defun delete-backward-word (point) | |
"Deletes backwards by words. Stops at some common delimiter in | |
Lisp and other languages. Similar to `delete-backward-char'." | |
(interactive "d") | |
(let ((regexp (rx (or (none-then-some " \t\n") | |
(none-then-some ?-) | |
(none-then-some ?.) | |
(and (not (any " \t\n")) | |
(zero-or-more (any " \t\n")) | |
(syntax open-parenthesis)))))) | |
(cond | |
((re-search-backward regexp nil t) | |
(forward-char) | |
(delete-region point (point))) | |
(t (delete-region point (point-min)))))) | |
(autoload #'rx "rx") | |
(eval-after-load 'rx | |
'(add-to-list 'rx-constituents | |
'(none-then-some . (rx-none-then-some 1 1)))) | |
(defun rx-none-then-some (form) | |
"Useful to match backwards, turns into the expression: | |
(and (not x) (one-or-more x))" | |
(rx-check form) | |
(if (or (symbolp (cadr form)) | |
(characterp (cadr form)) | |
(stringp (cadr form))) | |
(setq form (cons 'any (cdr form))) | |
(setq form (cadr form))) | |
(rx-check-not form) | |
(concat (rx-to-string `(not ,form)) | |
(rx-to-string form) | |
"+")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment