Fuco  committed 2084e3c

Add `my-capitalize-word`

  • Participants
  • Parent commits 668763b
  • Branches default

Comments (0)

Files changed (2)

File files/defuns-edit.el

 (require 'thingatpt)
+(require 's)
 (defun my-kill-whitespace (&optional forward)
   "Kill all the whitespace characters backwards until hitting
       (upcase-word arg))))))
+(defun my-capitalize-word (&optional arg)
+  "Capitalize the next ARG words and move over.
+With negative ARG capitalize previous ARG words but not move the point.
+Additionally, when looking at [ \\t]*$, capitalize backwards."
+  (interactive "p")
+  (when (and (looking-at-p "[ \t]*$") (> arg 0))
+    (setq arg (- arg)))
+  (let ((to-cap (delete-and-extract-region (progn
+                                             (when (sp-point-in-symbol)
+                                               (backward-word (- (cl-signum arg))))
+                                             (point))
+                                           (progn
+                                             (forward-word arg)
+                                             (point)))))
+    (insert (s-titleize to-cap))))
 ;; insert the text normally but keep the point fixed

File files/keys.el

 ;; up/downcase
 (bind-key "M-l" 'my-smart-downcase-word)
 (bind-key "M-u" 'my-smart-upcase-word)
+(bind-key "M-c" 'my-capitalize-word)
 ;;;;; multiple cursors
 (bind-key "C-c C-S-c" 'mc/edit-lines)