unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#21501: new Emacs functions for capitalizing text intelligently
@ 2015-09-17  4:32 Zachary Kanfer
  2015-09-19 20:27 ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Zachary Kanfer @ 2015-09-17  4:32 UTC (permalink / raw)
  To: 21501


[-- Attachment #1.1: Type: text/plain, Size: 1564 bytes --]

I'm submitting some additional -dwim functions to that change the
capitalization of text the way the user probably wants.

These work similarly to comment-dwim, or count-words: they act on the
region if and only if it's active (more specifically, if (use-region-p) is
true), and otherwise act on the word starting at point. Either way, they
use existing functions in Emacs: e.g. #'upcase-dwim delegates either to
#'upcase-region or #'upcase-word.

There are three functions: one for each of capitalizing text, upcasing
text, and lowercasing text. The docstrings are based on the docstring for
comment-dwim.

In my init file, I've changed the default mappings of M-u, M-l, and M-c to
these new functions, and would support changing Emacs's defaults to them.
However, I am led to believe that changing defaults isn't preferred, so
this patch doesn't contain any of that. Even without changing defaults, I
believe these functions are worth adding to Emacs.

The capitalization-related functions I'm using are all defined in C, so I
can't put these new functions alongside them. I put the changes in
simple.el, as that file's described as "A grab-bag of basic Emacs commands
not specifically related to some major mode or to file-handling.". I'm
happy to move the functions and create a new diff if there's a more
appropriate file for them to live in.

Changelog entry:

* simple.el: Add functions for capitalizing text intelligently.
(capitalize-dwim): New function.
(upcase-dwim): New function.
(downcase-dwim): New function.

The diff is attached.

-Zachary Kanfer

[-- Attachment #1.2: Type: text/html, Size: 1724 bytes --]

[-- Attachment #2: 0001-Add-functions-for-capitalizing-text-intelligently.patch --]
[-- Type: text/x-patch, Size: 1807 bytes --]

From ea4856434c1e5edf3e1d50958c908ec3e5b152b5 Mon Sep 17 00:00:00 2001
From: Zachary Kanfer <zkanfer@gmail.com>
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.
---
 lisp/simple.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lisp/simple.el b/lisp/simple.el
index f80faae..e2d4470 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8424,6 +8424,35 @@ contains the list of implementations currently supported for this command."
                            command-name)))))))
 
 \f
+;;; Functions relating to capitalization that Do What I Mean
+(defun upcase-dwim ()
+  "Call the upcase command you want (Do What I Mean).
+If the region is active, call `upcase-region'.  Otherwise call
+`upcase-word'."
+  (interactive "*")
+  (if (use-region-p)
+      (upcase-region (region-beginning) (region-end))
+    (upcase-word 1)))
+
+(defun downcase-dwim ()
+  "Call the downcase command you want (Do What I Mean).
+If the region is active, call `downcase-region'.  Otherwise call
+`downcase-word'."
+  (interactive "*")
+  (if (use-region-p)
+      (downcase-region (region-beginning) (region-end))
+    (downcase-word 1)))
+
+(defun capitalize-dwim ()
+  "Call the capitalize command you want (Do What I Mean).
+If the region is active, call `capitalize-region'.  Otherwise call
+`capitalize-word'."
+  (interactive "*")
+  (if (use-region-p)
+      (capitalize-region (region-beginning) (region-end))
+    (capitalize-word 1)))
+
+\f
 
 (provide 'simple)
 
-- 
2.5.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#21501: new Emacs functions for capitalizing text intelligently
  2015-09-17  4:32 bug#21501: new Emacs functions for capitalizing text intelligently Zachary Kanfer
@ 2015-09-19 20:27 ` Stefan Monnier
  2015-09-20  6:13   ` Zachary Kanfer
  2015-09-20 18:23   ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2015-09-19 20:27 UTC (permalink / raw)
  To: Zachary Kanfer; +Cc: 21501

> I'm submitting some additional -dwim functions to that change the
> capitalization of text the way the user probably wants.

Looks OK to me.

> Changelog entry:
> * simple.el: Add functions for capitalizing text intelligently.
> (capitalize-dwim): New function.
> (upcase-dwim): New function.
> (downcase-dwim): New function.

Thanks.  Please add that to the commit message.  More specifically, use
the first line above as the first line of the commit message, and add

   (capitalize-dwim, upcase-dwim, downcase-dwim): New functions.

at the end.

I'm tempted to bind M-u, M-l, and M-c to those new commands.

WDYT?


        Stefan





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#21501: new Emacs functions for capitalizing text intelligently
  2015-09-19 20:27 ` Stefan Monnier
@ 2015-09-20  6:13   ` Zachary Kanfer
  2015-09-20  6:46     ` Eli Zaretskii
  2015-09-20 18:23   ` Richard Stallman
  1 sibling, 1 reply; 7+ messages in thread
From: Zachary Kanfer @ 2015-09-20  6:13 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 21501


[-- Attachment #1.1: Type: text/plain, Size: 1318 bytes --]

Here's a changed patch. The first line is the first line of the changelog
entry without "simple.el"; it doesn't fit.

I'm in favor of changing M-u, M-l, and M-c to the new commands; I think
it's much improved behavior. The only time a user would have to do more
work to perform a capitalization action is if they've selected a region,
but want to act only on the next word. I would bet that's rare, and even
so, the user only has to press C-g before the capitalization. So if we're
ok changing default commands, I think changing M-u, M-l, and M-c is a win.

On Sat, Sep 19, 2015 at 4:27 PM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > I'm submitting some additional -dwim functions to that change the
> > capitalization of text the way the user probably wants.
>
> Looks OK to me.
>
> > Changelog entry:
> > * simple.el: Add functions for capitalizing text intelligently.
> > (capitalize-dwim): New function.
> > (upcase-dwim): New function.
> > (downcase-dwim): New function.
>
> Thanks.  Please add that to the commit message.  More specifically, use
> the first line above as the first line of the commit message, and add
>
>    (capitalize-dwim, upcase-dwim, downcase-dwim): New functions.
>
> at the end.
>
> I'm tempted to bind M-u, M-l, and M-c to those new commands.
>
> WDYT?
>
>
>         Stefan
>

[-- Attachment #1.2: Type: text/html, Size: 1850 bytes --]

[-- Attachment #2: 0002-Add-functions-for-capitalizing-text-intelligently.patch --]
[-- Type: text/x-patch, Size: 1870 bytes --]

From 70cc75c3e6ee2eb3c75d062ced5950ca36cb27d2 Mon Sep 17 00:00:00 2001
From: Zachary Kanfer <zkanfer@gmail.com>
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 | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lisp/simple.el b/lisp/simple.el
index f80faae..e2d4470 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8424,6 +8424,35 @@ contains the list of implementations currently supported for this command."
                            command-name)))))))
 
 \f
+;;; Functions relating to capitalization that Do What I Mean
+(defun upcase-dwim ()
+  "Call the upcase command you want (Do What I Mean).
+If the region is active, call `upcase-region'.  Otherwise call
+`upcase-word'."
+  (interactive "*")
+  (if (use-region-p)
+      (upcase-region (region-beginning) (region-end))
+    (upcase-word 1)))
+
+(defun downcase-dwim ()
+  "Call the downcase command you want (Do What I Mean).
+If the region is active, call `downcase-region'.  Otherwise call
+`downcase-word'."
+  (interactive "*")
+  (if (use-region-p)
+      (downcase-region (region-beginning) (region-end))
+    (downcase-word 1)))
+
+(defun capitalize-dwim ()
+  "Call the capitalize command you want (Do What I Mean).
+If the region is active, call `capitalize-region'.  Otherwise call
+`capitalize-word'."
+  (interactive "*")
+  (if (use-region-p)
+      (capitalize-region (region-beginning) (region-end))
+    (capitalize-word 1)))
+
+\f
 
 (provide 'simple)
 
-- 
2.5.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#21501: new Emacs functions for capitalizing text intelligently
  2015-09-20  6:13   ` Zachary Kanfer
@ 2015-09-20  6:46     ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2015-09-20  6:46 UTC (permalink / raw)
  To: Zachary Kanfer; +Cc: 21501

> From: Zachary Kanfer <zkanfer@gmail.com>
> Date: Sun, 20 Sep 2015 02:13:39 -0400
> Cc: 21501@debbugs.gnu.org
> 
> Here's a changed patch.

Thanks.  Allow me a couple of minor comments.

> I'm in favor of changing M-u, M-l, and M-c to the new commands; I think it's
> much improved behavior. The only time a user would have to do more work to
> perform a capitalization action is if they've selected a region, but want to
> act only on the next word. I would bet that's rare, and even so, the user only
> has to press C-g before the capitalization. So if we're ok changing default
> commands, I think changing M-u, M-l, and M-c is a win.

For us to be able to bind M-u etc. to these new commands, they need to
support the prefix argument to upcase-word etc.  The way you wrote
these new commands, that feature will be lost.

> +;;; Functions relating to capitalization that Do What I Mean
> +(defun upcase-dwim ()
> +  "Call the upcase command you want (Do What I Mean).
> +If the region is active, call `upcase-region'.  Otherwise call
> +`upcase-word'."

Every doc string should state the effect of the function/variable in
its first line, because some Help commands (like 'apropos') show only
the first line.  The above doc string (and the others in your patch)
don't do that; the effect is only clear if one reads the rest of the
doc string.

I suggest to change the doc strings like this:

  Upcase words in the region, if active; otherwise upcase word at point.
If the region is active, this function calls `upcase-region'.
Otherwise it calls `upcase-word'.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#21501: new Emacs functions for capitalizing text intelligently
  2015-09-19 20:27 ` Stefan Monnier
  2015-09-20  6:13   ` Zachary Kanfer
@ 2015-09-20 18:23   ` Richard Stallman
  2015-09-21 18:52     ` Zachary Kanfer
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2015-09-20 18:23 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: zkanfer, 21501

[[[ 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.






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#21501: new Emacs functions for capitalizing text intelligently
  2015-09-20 18:23   ` Richard Stallman
@ 2015-09-21 18:52     ` Zachary Kanfer
  2015-09-26  8:13       ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Zachary Kanfer @ 2015-09-21 18:52 UTC (permalink / raw)
  To: rms; +Cc: 21501


[-- Attachment #1.1: Type: text/plain, Size: 1297 bytes --]

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 <rms@gnu.org> 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.
>
>

[-- Attachment #1.2: Type: text/html, Size: 2097 bytes --]

[-- Attachment #2: 0003-Add-functions-for-capitalizing-text-intelligently.patch --]
[-- Type: text/x-patch, Size: 2188 bytes --]

From cbc9d4691cb9dfce670f9ce07178d4d29e99a562 Mon Sep 17 00:00:00 2001
From: Zachary Kanfer <zkanfer@gmail.com>
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)))))))
 
 \f
+;;; 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)))
+
+\f
 
 (provide 'simple)
 
-- 
2.5.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#21501: new Emacs functions for capitalizing text intelligently
  2015-09-21 18:52     ` Zachary Kanfer
@ 2015-09-26  8:13       ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2015-09-26  8:13 UTC (permalink / raw)
  To: Zachary Kanfer; +Cc: 21501-done

> From: Zachary Kanfer <zkanfer@gmail.com>
> Date: Mon, 21 Sep 2015 14:52:01 -0400
> Cc: 21501@debbugs.gnu.org
> 
> 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.

Thanks, I pushed them.

Note that with this contribution you've exhausted your limit of code
submissions that can be accepted without legal paperwork, so if you'd
like to continue your contribution (we hope you do), you will have to
do that paperwork.

Also, please in the future always include with your patches a log
message in the format described in CONTRIBUTE.

Thanks.





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-26  8:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-17  4:32 bug#21501: new Emacs functions for capitalizing text intelligently Zachary Kanfer
2015-09-19 20:27 ` Stefan Monnier
2015-09-20  6:13   ` Zachary Kanfer
2015-09-20  6:46     ` Eli Zaretskii
2015-09-20 18:23   ` Richard Stallman
2015-09-21 18:52     ` Zachary Kanfer
2015-09-26  8:13       ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).