GNU bug report logs - #64632
Feature request: downcase-char, downcase-initials

Previous Next

Package: emacs;

Reported by: José Júnior <jjnilton <at> gmail.com>

Date: Fri, 14 Jul 2023 23:33:01 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: José Júnior <jjnilton <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64632 <at> debbugs.gnu.org
Subject: bug#64632: Feature request: downcase-char, downcase-initials
Date: Sat, 15 Jul 2023 11:13:40 -0300
[Message part 1 (text/plain, inline)]
In my case, it would be helpful for writing snippets. I missed these
functions when I was writing some snippets for some boilerplate code, where
in some situations `upcase-initials` was helpful, and so would be
`downcase-initials`. I'd guess a `downcase-initials-region` (like
`upcase-initials-region`) could be useful in certain cases, like fixing
function names in code, or even writing in general, but probably very
situational.

I understand equivalence alone wouldn't be enough to introduce new
commands, but it _feels_ that is missing something having one way but not
the other, especially when there's a `upcase-char` but not a
`downcase-char`.

And about `downcase-region` I don't think it would help in my case because
I needed to down case only the initial character of the word, and it's
interactive and requires an extra step (marking the region).

Anyway, I wrote these functions to fix my issue, maybe it can help someone
else:
(they probably could be better since I don't know Emacs Lisp well, but
worked for me)

```
(defun downcase-char (arg)
  "Downcasify ARG chars starting from point. Point doesn't move."
  (interactive "p")
  (save-excursion
    (downcase-region (point) (progn (forward-char arg) (point)))))

(defun downcase-initial (string)
  "Downcase initial character of the string."
  (concat (downcase (substring string 0 1)) (substring string 1)))

(defun downcase-initials (string)
  "Upcase the initial of each word in the string."
  (mapcar #'downcase-initial (split-string string "[^[:alpha:]]")))

(defun downcase-initials-region (beg end)
  "Upcase the initial of each word in the region."
  (interactive "r")
  (let ((region (buffer-substring-no-properties beg end)))
    (delete-region beg end)
    (insert (downcase region))))
```

On Sat, Jul 15, 2023 at 3:06 AM Eli Zaretskii <eliz <at> gnu.org> wrote:

> > From: José Júnior <jjnilton <at> gmail.com>
> > Date: Fri, 14 Jul 2023 20:31:42 -0300
> >
> > Hi, my suggestion is to add equivalent functions for `upcase-char` and
> `upcase-initials` but for
> > downcase (`downcase-char` and `downcase-initials`). When I first these
> functions, I expected to have
> > the downcase equivalent for each of them.
>
> Thanks.
>
> In which situations would such commands be useful?  We don't introduce
> commands just because they are equivalents of others.
>
> Anyway, we already have downcase-region, which you could use to
> downcase any range of characters, including a single character
> anywhere in a word.
>
[Message part 2 (text/html, inline)]

This bug report was last modified 1 year and 341 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.