mhayashi1120 / Emacs-wgrep

Writable grep buffer and apply the changes to files
GNU General Public License v3.0
612 stars 43 forks source link

wgrep-set-readonly-area should consider some backends do not has wgrep-header #79

Closed jixiuf closed 8 months ago

jixiuf commented 3 years ago

I am trying to make embark-occur support wgrep ,see https://github.com/oantolin/embark/issues/47#issuecomment-748494661

without this pull request, I would got

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  put-text-property(666 nil read-only t)
  (while (setq start (next-single-property-change pos 'wgrep-line-filename)) (setq end (next-single-property-change start 'wgrep-line-filename)) (put-text-property start end 'read-only state) (put-text-property (1- end) end 'rear-nonsticky t) (if (eq (char-before start) 10) (progn (put-text-property (1- start) start 'read-only state))) (setq pos end))
  (save-excursion (setq pos (point-min)) (while (setq start (next-single-property-change pos 'wgrep-line-filename)) (setq end (next-single-property-change start 'wgrep-line-filename)) (put-text-property start end 'read-only state) (put-text-property (1- end) end 'rear-nonsticky t) (if (eq (char-before start) 10) (progn (put-text-property (1- start) start 'read-only state))) (setq pos end)) (setq pos (point-min)) (while (setq start (next-single-property-change pos 'wgrep-ignore)) (setq end (next-single-property-change start 'wgrep-ignore)) (put-text-property start end 'read-only state) (if (eq (char-before start) 10) (progn (put-text-property (1- start) start 'read-only state))) (setq pos end)) (let ((footer (or (next-single-property-change (point-min) 'wgrep-footer) (point-max)))) (if (eq (char-before footer) 10) (progn (put-text-property (1- footer) footer 'read-only state)))))
  (let ((inhibit-read-only t) (wgrep-inhibit-modification-hook t) pos start end) (save-excursion (setq pos (point-min)) (while (setq start (next-single-property-change pos 'wgrep-line-filename)) (setq end (next-single-property-change start 'wgrep-line-filename)) (put-text-property start end 'read-only state) (put-text-property (1- end) end 'rear-nonsticky t) (if (eq (char-before start) 10) (progn (put-text-property (1- start) start 'read-only state))) (setq pos end)) (setq pos (point-min)) (while (setq start (next-single-property-change pos 'wgrep-ignore)) (setq end (next-single-property-change start 'wgrep-ignore)) (put-text-property start end 'read-only state) (if (eq (char-before start) 10) (progn (put-text-property (1- start) start 'read-only state))) (setq pos end)) (let ((footer (or (next-single-property-change (point-min) 'wgrep-footer) (point-max)))) (if (eq (char-before footer) 10) (progn (put-text-property (1- footer) footer 'read-only state))))) (setq wgrep-readonly-state state))
  wgrep-set-readonly-area(t)
  wgrep-change-to-wgrep-mode()
  (progn (wgrep-change-to-wgrep-mode))
  (if (derived-mode-p 'ivy-occur-mode 'rg-mode 'grep-mode 'embark-occur-mode 'ivy-occur-grep-mode 'helm-grep-mode) (progn (wgrep-change-to-wgrep-mode)))
  enable-wgrep-when-entry-insert()
  run-hooks(evil-insert-state-entry-hook)
  (let ((evil-state 'insert)) (evil-normalize-keymaps) (if 't (activate-input-method evil-input-method) (if deactivate-current-input-method-function (deactivate-input-method))) (if evil-no-display nil (evil-refresh-cursor 'insert) (evil-refresh-mode-line 'insert) (if (called-interactively-p 'any) (progn (redisplay)))) (cond ((evil-insert-state-p) (add-hook 'post-command-hook #'evil-maybe-remove-spaces) (add-hook 'pre-command-hook #'evil-insert-repeat-hook) (setq evil-maybe-remove-spaces t) (if (eq evil-want-fine-undo t) nil (evil-start-undo-step))) (t (remove-hook 'post-command-hook #'evil-maybe-remove-spaces) (remove-hook 'pre-command-hook #'evil-insert-repeat-hook) (evil-maybe-remove-spaces t) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker 94 nil t) (if (eq evil-want-fine-undo t) nil (evil-end-undo-step)) (if (or (evil-normal-state-p evil-next-state) (evil-motion-state-p evil-next-state)) (progn (evil-move-cursor-back (and (eolp) (not evil-move-beyond-eol))))))) (run-hooks 'evil-insert-state-entry-hook) (if (and evil-echo-state arg (not evil-no-display) evil-insert-state-message) (progn (if (functionp evil-insert-state-message) (funcall evil-insert-state-message) (evil-echo "%s" evil-insert-state-message)))))
  (let ((evil-next-state 'insert) input-method-activate-hook input-method-deactivate-hook) (evil-change-state nil) (setq evil-state 'insert) (progn (let* ((p (if (and #'equal (not ...)) (assoc 'insert evil-previous-state-alist #'equal) (assq 'insert evil-previous-state-alist))) (v evil-previous-state)) (progn (if p (setcdr p v) (setq evil-previous-state-alist (cons (setq p ...) evil-previous-state-alist))) v)) evil-previous-state-alist) (let ((evil-state 'insert)) (evil-normalize-keymaps) (if 't (activate-input-method evil-input-method) (if deactivate-current-input-method-function (deactivate-input-method))) (if evil-no-display nil (evil-refresh-cursor 'insert) (evil-refresh-mode-line 'insert) (if (called-interactively-p 'any) (progn (redisplay)))) (cond ((evil-insert-state-p) (add-hook 'post-command-hook #'evil-maybe-remove-spaces) (add-hook 'pre-command-hook #'evil-insert-repeat-hook) (setq evil-maybe-remove-spaces t) (if (eq evil-want-fine-undo t) nil (evil-start-undo-step))) (t (remove-hook 'post-command-hook #'evil-maybe-remove-spaces) (remove-hook 'pre-command-hook #'evil-insert-repeat-hook) (evil-maybe-remove-spaces t) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker 94 nil t) (if (eq evil-want-fine-undo t) nil (evil-end-undo-step)) (if (or (evil-normal-state-p evil-next-state) (evil-motion-state-p evil-next-state)) (progn (evil-move-cursor-back (and ... ...)))))) (run-hooks 'evil-insert-state-entry-hook) (if (and evil-echo-state arg (not evil-no-display) evil-insert-state-message) (progn (if (functionp evil-insert-state-message) (funcall evil-insert-state-message) (evil-echo "%s" evil-insert-state-message))))))
  (cond ((and (numberp arg) (< arg 1)) (setq evil-previous-state evil-state evil-state nil) (let ((evil-state 'insert)) (run-hooks 'evil-insert-state-exit-hook) (setq evil-state nil) (evil-normalize-keymaps) (cond ((evil-insert-state-p) (add-hook 'post-command-hook #'evil-maybe-remove-spaces) (add-hook 'pre-command-hook #'evil-insert-repeat-hook) (setq evil-maybe-remove-spaces t) (if (eq evil-want-fine-undo t) nil (evil-start-undo-step))) (t (remove-hook 'post-command-hook #'evil-maybe-remove-spaces) (remove-hook 'pre-command-hook #'evil-insert-repeat-hook) (evil-maybe-remove-spaces t) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker 94 nil t) (if (eq evil-want-fine-undo t) nil (evil-end-undo-step)) (if (or (evil-normal-state-p evil-next-state) (evil-motion-state-p evil-next-state)) (progn (evil-move-cursor-back ...))))))) (t (if evil-local-mode nil (evil-local-mode 1)) (let ((evil-next-state 'insert) input-method-activate-hook input-method-deactivate-hook) (evil-change-state nil) (setq evil-state 'insert) (progn (let* ((p (if ... ... ...)) (v evil-previous-state)) (progn (if p (setcdr p v) (setq evil-previous-state-alist ...)) v)) evil-previous-state-alist) (let ((evil-state 'insert)) (evil-normalize-keymaps) (if 't (activate-input-method evil-input-method) (if deactivate-current-input-method-function (deactivate-input-method))) (if evil-no-display nil (evil-refresh-cursor 'insert) (evil-refresh-mode-line 'insert) (if (called-interactively-p 'any) (progn (redisplay)))) (cond ((evil-insert-state-p) (add-hook 'post-command-hook #'evil-maybe-remove-spaces) (add-hook 'pre-command-hook #'evil-insert-repeat-hook) (setq evil-maybe-remove-spaces t) (if (eq evil-want-fine-undo t) nil (evil-start-undo-step))) (t (remove-hook 'post-command-hook #'evil-maybe-remove-spaces) (remove-hook 'pre-command-hook #'evil-insert-repeat-hook) (evil-maybe-remove-spaces t) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker 94 nil t) (if (eq evil-want-fine-undo t) nil (evil-end-undo-step)) (if (or ... ...) (progn ...)))) (run-hooks 'evil-insert-state-entry-hook) (if (and evil-echo-state arg (not evil-no-display) evil-insert-state-message) (progn (if (functionp evil-insert-state-message) (funcall evil-insert-state-message) (evil-echo "%s" evil-insert-state-message))))))))
  evil-insert-state(1)
  (if (and (called-interactively-p 'any) (evil-visual-state-p)) (cond ((eq (evil-visual-type) 'line) (evil-visual-rotate 'upper-left) (evil-insert-line count vcount)) ((eq (evil-visual-type) 'block) (let ((column (min (evil-column evil-visual-beginning) (evil-column evil-visual-end)))) (evil-visual-rotate 'upper-left) (move-to-column column t) (evil-insert count vcount skip-empty-lines))) (t (evil-visual-rotate 'upper-left) (evil-insert count vcount skip-empty-lines))) (setq evil-insert-count count evil-insert-lines nil evil-insert-vcount (and vcount (> vcount 1) (list (line-number-at-pos) (current-column) vcount)) evil-insert-skip-empty-lines skip-empty-lines) (evil-insert-state 1))
  evil-insert(1 nil nil)
  funcall-interactively(evil-insert 1 nil nil)
  command-execute(evil-insert)