emacs-humanities
[Top][All Lists]
Advanced

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

[emacs-humanities] How can I `upcase-word` for ALL words in the buffer w


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

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



 Sample code

#!/usr/bin/env python

# -*- coding: utf-8 -*-
'''.'''

# Include standard modules
import argparse

# Initiate the parser
parser = argparse.ArgumentParser()

parser.add_argument("-a", "--all", help="Run all arguments", action="store_true")
parser.add_argument("-f", "--foo", help="Foo", action="store_true")
parser.add_argument("-b", "--bar", help="Bar", action="store_true")

# Read arguments from the command line
args = parser.parse_args()


if not (args.all or args.bar):
    parser.error('No action requested, add -process or -upload')

if args.all:
    print("This is myprogram version 0.1")

if args.foo:
    print("Foooooooooo")

if args.bar:
    print("Baaaaaaaar")


reply via email to

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