Emacs-wgrep icon indicating copy to clipboard operation
Emacs-wgrep copied to clipboard

wgrep-ag not working for grouped results - if there is only one group

Open stig opened this issue 5 years ago • 2 comments

I can't edit the results when there is only one result group. I get the error Text is read-only. Furthermore, when hitting C-c C-p a second time and attemptinging to delete a whole line is: wgrep-mark-deletion: Not a grep result.

If I copy the file with the matches to another file and re-run I can edit the results, and wgrep-ag works as normal.

Another work-around is to turn off grouped results.


Edit:

After a little more investigating I think the problem is with the wgrep-ag-prepare-header/footer function. I am reasonably certain that the the issue is this line: (re-search-backward result-line-regexp nil t) -- because that matches the File: line, it effectively marks the entire last group as part of the footer. I haven't been able to fix it yet, however.

Edit2:

I've submit a fix in #61, but I read in the repo owner's profile that they don't have time to maintain their modules. Thus you may want to work around this issue locally, as I'm doing. Here's how I'm doing that:


;; This fixes the last group not being editable until it's fixed
;; upstream, cf https://github.com/mhayashi1120/Emacs-wgrep/pull/61
(eval-after-load "wgrep-ag"
  '(defun wgrep-ag-prepare-header/footer ()
     (save-excursion
       (goto-char (point-min))
       ;; Look for the first useful result line.
       (if (re-search-forward (concat wgrep-ag-grouped-result-file-regexp
				      "\\|"
				      wgrep-ag-ungrouped-result-regexp))
	   (add-text-properties (point-min) (line-beginning-position)
				'(read-only t wgrep-header t))
	 ;; No results in this buffer, let's mark the whole thing as
	 ;; header.
	 (add-text-properties (point-min) (point-max)
			      '(read-only t wgrep-header t)))

       ;; OK, header dealt with. Now let's try find the footer.
       (goto-char (point-max))
       (re-search-backward "^\\(?:-[^:]+?:[[:digit:]]+:[[:digit:]]+:\\)" nil t)
       ;; Point is now at the beginning of the result nearest the end
       ;; of the buffer, AKA the last result.  Move to the start of
       ;; the line after the last result, and mark everything from
       ;; that line forward as wgrep-footer.  If we can't move to the
       ;; line after the last line then there apparently is no
       ;; footer.
       (when (zerop (forward-line 1))
	 (add-text-properties (point) (point-max)
			      '(read-only t wgrep-footer t))))))

stig avatar May 07 '19 09:05 stig

#61 was merged, but maybe not released? I still have "last group" problems.

zenspider avatar Aug 03 '20 22:08 zenspider

@zenspider I think that is the case, yes. If you use package.el, it may work if you pin to unstable MELPA? Personally I use straight.el and use this recipe to get the latest and greatest:

(use-package wgrep
  :straight (wgrep :type git
                   :host github
                   :repo "mhayashi1120/Emacs-wgrep"))

@mhayashi1120 any chance of creating a 2.3.3 tag to pick up that bugfix?

stig avatar Aug 15 '20 17:08 stig