Subject: bug#21501: new Emacs functions for capitalizing text intelligently

From: Zachary Kanfer <[email-masked]>
Date: Mon, 21 Sep 2015 14:52:01 -0400

Here's an updated patch with Eli's comments addressed. Now, these new
commands seem to have all the functionality of the existing *-region and
*-word commands.

Is the "dwim" acronym well known enough as "Do What I Mean" that that it
doesn't need to be included in the docstring? I can put it in if necessary,
but it's somewhat awkward.

I'm fine putting these commands in Emacs, and waiting to see if people like
them enough that it's worth changing the bindings. Is there any specific
user feedback or data we'd be looking for to know if we want to change the
bindings? Or is it more a concern of waiting to see if any bugs shake out?

On Sun, Sep 20, 2015 at 2:23 PM, Richard Stallman <[email-masked]> wrote:

> [[[ To any NSA and FBI agents reading my email: please consider    ]]]
> [[[ whether defending the US Constitution against all enemies,     ]]]
> [[[ foreign or domestic, requires you to follow Snowden's example. ]]]
>
>   > I'm tempted to bind M-u, M-l, and M-c to those new commands.
>
> Please let's try them privately first.  There is no need to be
> precipitous about this.  There is no hurry.
>
> --
> Dr Richard Stallman
> President, Free Software Foundation (gnu.org, fsf.org)
> Internet Hall-of-Famer (internethalloffame.org)
> Skype: No way! See stallman.org/skype.html.
>
>
From cbc9d4691cb9dfce670f9ce07178d4d29e99a562 Mon Sep 17 00:00:00 2001
From: Zachary Kanfer <[email-masked]>
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