all messages for Emacs-related lists mirrored at yhetil.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

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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.