From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#70820: [PATCH] Editable grep buffers Date: Sat, 31 Aug 2024 10:54:44 +0300 Message-ID: <86y14dcekb.fsf@gnu.org> References: <87seytlhcq.fsf@gmail.com> <86pltxa40q.fsf@gnu.org> <87jzk5kmwk.fsf@gmail.com> <86ikzoa51h.fsf@gnu.org> <878r0klcp1.fsf@gmail.com> <864jb89zwq.fsf@gnu.org> <87wmo3jmws.fsf@gmail.com> <87fruny6xe.fsf@gmail.com> <86le47eafb.fsf@gnu.org> <86pltjceft.fsf@gnu.org> <86ikzbcces.fsf@gnu.org> <87le1lj4pv.fsf@gmail.com> <87bk1vzuw1.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22608"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70820@debbugs.gnu.org, monnier@iro.umontreal.ca To: Visuwesh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 31 09:55:16 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1skIx1-0005jn-Kk for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 31 Aug 2024 09:55:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1skIws-0008Pd-Ff; Sat, 31 Aug 2024 03:55:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1skIwq-0008P5-Uw for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 03:55:04 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1skIwq-0003eq-Le for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 03:55:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-version:References:In-Reply-To:From:Date:To:Subject; bh=Opf4SWkmxcyVyXP8wq5YOG+NXrQpv+sE72cg29EBN7g=; b=p7cyAYSV7PNs2kRglVBr7YyySgxv988nwjUF89o52RZ4TWq3DgbcyRSA/qrfrbFDwAvbWhbM6Mum80ultRg3eUf4xA+fvwL6ax7tUCpUBz3j2FkcWccEmkBO2+LOSa7wYzmK2sM9N8gGXW6JS6cy32SZt0M5ON8kn2X7+OpsodPXrK6GzaEdRVC4SQktcwxNRvS5h3uyAr006AMxLR+jHeFGhj4xRBASgxY8qW4hhtk5OifRKCxqoGUUI2IB35bpZi67Rqoi16cerWs9kEuyuzP2HsDVEZA+8Gkf81icJ7ry4bP8a3M+2SpzBvTGroVzotKhoSUNgvB2hfPaDa8jJg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1skIxm-00061J-A5 for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 03:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 31 Aug 2024 07:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70820 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70820-submit@debbugs.gnu.org id=B70820.172509095323122 (code B ref 70820); Sat, 31 Aug 2024 07:56:02 +0000 Original-Received: (at 70820) by debbugs.gnu.org; 31 Aug 2024 07:55:53 +0000 Original-Received: from localhost ([127.0.0.1]:53823 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skIxc-00060s-HV for submit@debbugs.gnu.org; Sat, 31 Aug 2024 03:55:52 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:48244) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skIxa-00060Z-Lz for 70820@debbugs.gnu.org; Sat, 31 Aug 2024 03:55:51 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1skIwY-0003MM-Uq; Sat, 31 Aug 2024 03:54:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=Opf4SWkmxcyVyXP8wq5YOG+NXrQpv+sE72cg29EBN7g=; b=hNsioBND6rTs5lHqyzm+ cAbI7hN124WLrY0f7YU9O7uNZPc57xpxsgdNHr2338CeE/jMNjGz1FuAbH5rM473fqmcjbYKeimLS CBJ5JegxyCht4fVvGTvTJD43TNRFyLDBx4v8WhMpARiqCtTvMFuX3HbDWNJvJlfC3a7/1x9wtJVDX arRPoAT+cVinY5QBUPkXazTdPrK4MQG+z+K5MAPM06YeU9L7Q1ANm+6sjY4A2cOQxdCuqJl9lHDhd 6xXYi1MkvNEmFv0iHo0rQLqHvVM3vqjkvXnx5mxb/kcWQSvVeQC4wTWmhzayW8udoZ2l29CAPrw1Q E8gcAyLSOYSFng==; In-Reply-To: <87bk1vzuw1.fsf@gmail.com> (message from Visuwesh on Wed, 14 Aug 2024 08:13:42 +0530) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:290975 Archived-At: Ping! Can we make progress with this issue? I think there were no objections to your proposal. > From: Visuwesh > Cc: Eli Zaretskii , 70820@debbugs.gnu.org > Date: Wed, 14 Aug 2024 08:13:42 +0530 > > [செவ்வாய் ஆகஸ்ட் 13, 2024] Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" wrote: > > >> +(defun compilation--update-markers (loc marker screen-columns first-column) > >> + "Update markers in LOC, and set MARKER to location pointed by LOC. > >> +SCREEN-COLUMNS and FIRST-COLUMN are the value of > >> +`compilation-error-screen-columns' and `compilation-first-column' to use > >> +if they are not set buffer-locally in the target buffer." > >> + (with-current-buffer > >> + (if (bufferp (caar (compilation--loc->file-struct loc))) > >> + (caar (compilation--loc->file-struct loc)) > >> + (apply #'compilation-find-file > >> + marker > >> + (caar (compilation--loc->file-struct loc)) > >> + (cadr (car (compilation--loc->file-struct loc))) > >> + (compilation--file-struct->formats > >> + (compilation--loc->file-struct loc)))) > >> + (let ((screen-columns > >> + ;; Obey the compilation-error-screen-columns of the target > >> + ;; buffer if its major mode set it buffer-locally. > >> + (if (local-variable-p 'compilation-error-screen-columns) > >> + compilation-error-screen-columns screen-columns)) > >> + (compilation-first-column > >> + (if (local-variable-p 'compilation-first-column) > >> + compilation-first-column first-column)) > >> + (last 1)) > >> + (save-restriction > >> + (widen) > >> + (goto-char (point-min)) > >> + ;; Treat file's found lines in forward order, 1 by 1. > >> + (dolist (line (reverse (cddr (compilation--loc->file-struct loc)))) > >> + (when (car line) ; else this is a filename without a line# > >> + (compilation-beginning-of-line (- (car line) last -1)) > >> + (setq last (car line))) > >> + ;; Treat line's found columns and store/update a marker for each. > >> + (dolist (col (cdr line)) > >> + (if (compilation--loc->col col) > >> + (if (eq (compilation--loc->col col) -1) > >> + ;; Special case for range end. > >> + (end-of-line) > >> + (compilation-move-to-column (compilation--loc->col col) > >> + screen-columns)) > >> + (beginning-of-line) > >> + (skip-chars-forward " \t")) > >> + (if (compilation--loc->marker col) > >> + (set-marker (compilation--loc->marker col) (point)) > >> + (setf (compilation--loc->marker col) (point-marker))) > >> + ;; (setf (compilation--loc->timestamp col) timestamp) > >> + )))))) > > > > Are there any changes in this code, or is it "verbatim" the code > > extracted from `compilation-next-error-function`? > > It is extracted verbatim from compilation-next-error-function. > > >> +(defvar grep-edit-mode-hook nil > >> + "Hooks run when changing to Grep-Edit mode.") > > > > It's just "Hook" because `grep-edit-mode-hook` is a hook. Hooks contain > > functions, so when you run a hook, the corresponding functions are called. > > Ah, I was under the impression that the functions were also referred to > as hooks. I will correct them in a future patch. > > >> +(defun grep-edit-mode () > >> + "Major mode for editing *grep* buffers. > >> +In this mode, changes to the *grep* buffer are applied to the > >> +originating files. > >> +\\ > >> +Type \\[grep-edit-save-changes] to exit Grep-Edit mode, return to Grep > >> +mode. > >> + > >> +The only editable texts in a Grep-Edit buffer are the match results." > >> + (interactive) > >> + (error "This mode can be enabled only by `grep-change-to-grep-edit-mode'")) > >> +(put 'grep-edit-mode 'mode-class 'special) > >> + > >> +(defun grep-change-to-grep-edit-mode () > >> + "Switch to `grep-edit-mode' to edit *grep* buffer." > >> + (interactive) > >> + (unless (derived-mode-p 'grep-mode) > >> + (error "Not a Grep buffer")) > >> + (when (get-buffer-process (current-buffer)) > >> + (error "Cannot switch when grep is running")) > >> + (use-local-map grep-edit-mode-map) > >> + (grep-edit--prepare-buffer) > >> + (setq buffer-read-only nil) > >> + (setq major-mode 'grep-edit-mode) > >> + (setq mode-name "Grep-Edit") > >> + (buffer-enable-undo) > >> + (set-buffer-modified-p nil) > >> + (setq buffer-undo-list nil) > >> + (add-hook 'after-change-functions #'occur-after-change-function nil t) > >> + (run-mode-hooks 'grep-edit-mode-hook) > >> + (message "Editing: \\[grep-edit-save-changes] to return to Grep mode")) > > > > I'm tempted to say you should use `major-mode-suspend/resume` (which > > would avoid the duplication of parts of `grep-mode` in > > `grep-edit-save-changes`), but I guess this might re-introduce the > > problem with buffer-local variables. > > Yes, unfortunately it will re-introduce the problem with buffer-local > variables. > > If everyone is okay with the current patch, I can get to writing the > NEWS entry and updating the manual. Thanks. >