Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stig opened this issue May 7, 2019 · 2 comments
Open

Comments

@stig
Copy link
Contributor

stig commented May 7, 2019

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))))))
@zenspider
Copy link

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

@stig
Copy link
Contributor Author

stig commented Aug 15, 2020

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants