emacs-humanities
[Top][All Lists]
Advanced

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

Re: [emacs-humanities] How can I `upcase-word` for ALL words in the buff


From: David Hedlund
Subject: Re: [emacs-humanities] How can I `upcase-word` for ALL words in the buffer without typing the word twice?
Date: Mon, 10 Apr 2023 07:55:25 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1


On 2023-04-05 06:47, Marcin Borkowski wrote:
On 2023-04-04, at 21:50, David Hedlund<public@beloved.name>  wrote:

I'm constantly running into this situation because when I'm copying
code, pylint is giving me the message: Constant name "parser" doesn't
conform to UPPER_CASE naming style (python-pylint)

In the sample code section below, I'm trying to replace "parser", and
"args", with "PARSER", and "ARGS", respectively.

Normally I'd use.

M-x RET replace-string RET parser RET PARSER

M-x RET replace-string RET args RET ARGS

However, I don't like the idea of typing the word twice (lowercase,
then uppercase), because

* it's time-consuming

* here's a risk that I make a typo.


This is only useful for the selected word:

M-x RET upcase-word RET


To illustrate, I'd like to run something like this to replace "parser"
with "PARSER" in the whole buffer:

M-x RET replace-string-TO-upcase-word RET parser
You already got two excellent answers, but let me mention that writing
a simple Elisp function to find one of a set of specific words and
upcase it (or prompt for a word and upcase that word in the whole buffer
or region) should be pretty simple.  (I might even show you how to write
it if you want -- but first a question: is the set of words you need to
upcase predetermined or do you want to provide a word every time?)


I switched from upcase to downcase, because pylint stopped to complain about lowercase words after my distro upgrade, so I need to replace uppercase words with lowercase words instead.

However, I wish it to be predetermined by placing the cursor on a word, any place on the word to make it convenient. I think this will satisfy my need:

* Place the cursor at the beginning of the word: C-left RET

* Select the whole word: C-SPC C-right RET

* Copy the word: M-w RET

* Go to the beginning of the buffer: M-< RET

* Replace the word with downcase

M-x replace-regexp RET
Shift-Insert RET
\,(downcase \&) RET

or

M-x replace-regexp RET
Shift-Insert RET
M-p RET
M-l RET


Also, I wish case sensitivity for the ("parser" should not replace "Parser" for example), like case-fold-search. I've read that case-replace can be set to nil, and then back to true, but I don't know how to do this.


I'd be very happy if you would like to help me to write a function for this.


Kind regards


Best,



reply via email to

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