0

I am using following answer to search and replace a word in the entire buffer:

(defun query-replace-region-or-from-top ()   
  (interactive)  
  (progn
    (let ((orig-point (point)))
      (if (use-region-p)
          (call-interactively 'query-replace)
        (save-excursion
          (goto-char (point-min))
          (call-interactively 'query-replace)))
      (message "Back to old point.")
      (goto-char orig-point))))

(global-set-key "\C-x\C-r" 'query-replace-region-or-from-top)```


When I apply query-replace-region-or-from-top, for example emacs into emacs_world it also changes EMACS into EMACS_WORLD.

How can I make query-replace-region-or-from-top case-sensitive?

NickD
  • 29,717
  • 3
  • 27
  • 44
alper
  • 1,370
  • 1
  • 13
  • 35

1 Answers1

3

You need to let-bind case-fold-search to nil:

(defun query-replace-region-or-from-top ()   
  (interactive)
  (let ((case-fold-search nil))  
    (progn
      ...
      (goto-char orig-point)))))

See the doc string for case-fold-search with C-h v case-fold-search:

case-fold-search is a variable defined in ‘src/buffer.c’.

Its value is t

Automatically becomes buffer-local when set. You can customize this variable. Probably introduced at or before Emacs version 18.

Non-nil if searches and matches should ignore case.

NickD
  • 29,717
  • 3
  • 27
  • 44