0

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

(defun query-replace-region-or-from-top ()
  "If marked, query-replace for the region, else for the whole buffer (start from the 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))))

In addition, when I add (setq-default frame-background-mode 'dark) line in my .emacs file, I have following error message when I use query-replace-region-or-from-top function:

`Args out of range: #<buffer doo.py>, 0, 1`

What my be the reason of this error and how can I resolve it?


Debuggin result:

Debugger entered--Lisp error: (args-out-of-range #<buffer Driver.py> 0 1)
  buffer-substring-no-properties(0 1)
  perform-replace("DataStorage" "DataStorage" t nil nil nil nil nil nil nil nil)
  query-replace("DataStorage" "DataStorage" nil nil nil nil nil)
  funcall-interactively(query-replace "DataStorage" "DataStorage" nil nil nil nil nil)
  call-interactively(query-replace)
  (save-excursion (goto-char (point-min)) (call-interactively (quote query-replace)))
  (if (use-region-p) (call-interactively (quote query-replace)) (save-excursion (goto-char (point-min)) (call-interactively (quote query-replace))))
  (let ((orig-point (point))) (if (use-region-p) (call-interactively (quote query-replace)) (save-excursion (goto-char (point-min)) (call-interactively (quote query-replace)))) (message "Back to old point.") (goto-char
orig-point))
  (progn (let ((orig-point (point))) (if (use-region-p) (call-interactively (quote query-replace)) (save-excursion (goto-char (point-min)) (call-interactively (quote query-replace)))) (message "Back to old point.")
(goto-char orig-point)))
  query-replace-region-or-from-top()
  funcall-interactively(query-replace-region-or-from-top)
  call-interactively(query-replace-region-or-from-top nil nil)
  command-execute(query-replace-region-or-from-top)
alper
  • 1,238
  • 11
  • 30
  • 2
    In addition to the error message, you’ll need the back trace to find out _where_ the error happened. Run `M-x toggle-debug-on-error` then reproduce the problem again. – db48x Jun 24 '21 at 00:04
  • @db48x Please see my updated questions along with the debugging result, hope it helps. – alper Jun 24 '21 at 07:59
  • Does the problem occur when you start emacs from `emacs -Q`? – Tyler Jun 28 '21 at 14:27
  • No seems like it works . Than some other setting in my `.emacs` file may be the main cause of this problem. It is pretty difficult to find the reason in thousands line of `.emacs` code – alper Jun 29 '21 at 12:26
  • 1
    Yes, it is. But Emacs' commenting functions make it much easier to bisect your init to locate the problem https://emacs.stackexchange.com/questions/28429/how-do-i-troubleshoot-emacs-problems?r=SearchResults – Tyler Jun 29 '21 at 12:52
  • It was related to theme I was loading => `(load-theme 'dracula t)` // https://github.com/dracula/emacs – alper Jun 30 '21 at 00:41

1 Answers1

0

I am using dracula-theme (load-theme 'dracula t), which was the main cause of the error I was facing.

When I use query-replace-region-or-from-top function along with dracula-theme and (setq-default frame-background-mode 'dark) I was facing the error I mention on my question.

(defun query-replace-region-or-from-top () ... ;; function from my question
(load-theme 'dracula t)
(setq-default frame-background-mode 'dark)

First, I have removed (setq-default frame-background-mode 'dark) from my .init file. The reason, I wanted to use (setq-default frame-background-mode 'dark) was to make highlights clear to read. Due to dracula-theme it was so lights and during word seach font color gets white.


In order to achieve this, I have update settings for Isearch and Lazy Highlight using M-x customize-face.

enter image description here

enter image description here

Following lines are added into my customize.el file:

(custom-set-faces
 '(isearch ((t :background "#f1fa8c" :foreground "#282a36" :weight bold)))
 '(lazy-highlight ((t :background "#8be9fd" :foreground "#282a36" :weight bold)))))
alper
  • 1,238
  • 11
  • 30