Skip to content

Instantly share code, notes, and snippets.

@osmatsuda
Created July 14, 2017 04:31
Show Gist options
  • Save osmatsuda/4ee45880f6d45404c827f829fe0cfe2c to your computer and use it in GitHub Desktop.
Save osmatsuda/4ee45880f6d45404c827f829fe0cfe2c to your computer and use it in GitHub Desktop.
;; kill-word-camelcased
(defun kill-word-camelcased (arg)
"Kill characters forward until the end of a word even if
in a camelcased identifier. ARG is same as `kill-word`."
(interactive "p")
(let ((case-fold-search nil)
(start (point))
(bound (save-excursion (forward-word arg) (point)))
(succ (if (> arg 0) 1 -1))
current
found)
(when (not (= start bound))
(setq current start)
(while (not (= arg 0))
(forward-word succ)
(while (search-forward-regexp "[A-Z][a-z]"
(+ current succ)
t
(- succ))
(setq found t))
(when (and found (< succ 0))
(forward-char -2))
(setq current (point))
(setq arg (- arg succ)))
(kill-region start (point)))))
(defun backward-kill-word-camelcased (arg)
(interactive "p")
(kill-word-camelcased (- arg)))
(provide 'kill-word-camelcased)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment