From cbc9d4691cb9dfce670f9ce07178d4d29e99a562 Mon Sep 17 00:00:00 2001 From: Zachary Kanfer Date: Mon, 14 Sep 2015 15:04:32 -0400 Subject: [PATCH] Add functions for capitalizing text intelligently. This patch adds three functions: upcase-dwim, downcase-dwim, and capitalize-dwim. These functions change the capitalization of text the way the user probably wants -- they act on the region if it's active, and on the next word if the region isn't. (capitalize-dwim, upcase-dwim, downcase-dwim): New functions. --- lisp/simple.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lisp/simple.el b/lisp/simple.el index f80faae..24732e1 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -8424,6 +8424,38 @@ contains the list of implementations currently supported for this command." command-name))))))) +;;; Functions for changing capitalization that Do What I Mean +(defun upcase-dwim (arg) + "Upcase words in the region, if active. If not, upcase word at point. +If the region is active, this function calls `upcase-region'. +Otherwise, it calls `upcase-word', with prefix argument passed to it +to upcase ARG words." + (interactive "*p") + (if (use-region-p) + (upcase-region (region-beginning) (region-end)) + (upcase-word arg))) + +(defun downcase-dwim (arg) + "Downcase words in the region, if active. If not, downcase word at point. +If the region is active, this function calls `downcase-region'. +Otherwise, it calls `downcase-word', with prefix argument passed to it +to downcase ARG words." + (interactive "*p") + (if (use-region-p) + (downcase-region (region-beginning) (region-end)) + (downcase-word arg))) + +(defun capitalize-dwim (arg) + "Capitalize words in the region, if active. If not, capitalize word at point. +If the region is active, this function calls `capitalize-region'. +Otherwise, it calls `capitalize-word', with prefix argument passed to it +to capitalize ARG words." + (interactive "*p") + (if (use-region-p) + (capitalize-region (region-beginning) (region-end)) + (capitalize-word arg))) + + (provide 'simple) -- 2.5.2