bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#64632: Feature request: downcase-char, downcase-initials


From: José Júnior
Subject: bug#64632: Feature request: downcase-char, downcase-initials
Date: Sat, 15 Jul 2023 11:13:40 -0300

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@gnu.org> wrote:
> From: José Júnior <jjnilton@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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]