#StackBounty: #frames #colors #replace frame-background-mode leads `Args out of range: #<buffer doo.py>, 0, 1` error

Bounty: 50

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))))
(bind-key* "M-%" 'query-replace-region-or-from-top)

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)


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.