Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4063212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:41:49+00:00 2026-05-20T15:41:49+00:00

I just asked a related question ( setq question ) but it’s distinctly different,

  • 0

I just asked a related question (setq question) but it’s distinctly different, so I decided to branch off with this question.

In my .emacs file, I define a key binding to the replace-string command:

(define-key global-map "\C-r" 'replace-string)

replace-string does basic search and replace. Assuming the first letter of the search string is lowercase, if the case-fold-search is nil then replace-string does case-sensitive search, otherwise it does case-insensitive search.

The problem is that case-fold-search controls the “case-sensitiveness” of both “search” (like the search-forward command) and “search and replace” (like the replace-string command).

The question is how do I make JUST the replace-string command (or anything C-r is bound to) case-sensitive, leaving the search-forward case-insensitive as it is by default.

Perhaps I would need to set case-fold-search to nil just for the replace-string command, but I’m not sure how to do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:41:50+00:00Added an answer on May 20, 2026 at 3:41 pm

    Put this in your .emacs:

    (defadvice replace-string (around turn-off-case-fold-search)
      (let ((case-fold-search nil))
        ad-do-it))
    
    (ad-activate 'replace-string)
    

    This does exactly what you said, set case-fold-search to nil just for replace-string.

    In fact this is almost exactly the example in the Emacs Lisp reference manual.

    Edit on 2021-11-02: as the link above indicates, defadvice is no longer the recommended way to implement this. The new recommended implementation would be

    (defun with-case-fold-search (orig-fun &rest args)
      (let ((case-fold-search t))
        (apply orig-fun args)))
    
    (advice-add 'replace-string :around #'with-case-fold-search)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just asked an SQL related question, and the first answer was: This is
I have question quite much related to this one I asked a while ago
I had recently asked a related question In C# how do I have a
I originally asked this question on programmers.stackexchange.com, because I figured the answers would be
I see that there are A LOT of related questions on this one, and
No offence intended, but let's not discuss that licensing schemes can be cracked (I
Ok, I asked the difference between Stackoverflow and bufferoverflow yesterday and almost getting voted
As you all know since it is one of the most asked topic on
I'm trying to understand the use cases for which implementing oAuth as a service
Background Info: I have two COM+ components on a remote server, based on .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.