From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#32543: 26.1; list-matching-lines-jump-to-current breaks revert-buffer in occur-mode Date: Thu, 06 Sep 2018 19:55:41 +0900 Message-ID: <87h8j2ao9e.fsf@calancha-pc.dy.bbexcite.jp> References: <84223559-4256-4BC9-A603-4D6C11A8EF06@gmail.com> <87d0tw96l7.fsf@mail.linkov.net> <87o9deahfc.fsf@calancha-pc.dy.bbexcite.jp> <87ftyqryp2.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1536231248 13345 195.159.176.226 (6 Sep 2018 10:54:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 6 Sep 2018 10:54:08 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 32543@debbugs.gnu.org, Andrey Kolomoets To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 06 12:54:03 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxrvH-0003L3-9q for geb-bug-gnu-emacs@m.gmane.org; Thu, 06 Sep 2018 12:54:03 +0200 Original-Received: from localhost ([::1]:60771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxrxN-0001pl-R0 for geb-bug-gnu-emacs@m.gmane.org; Thu, 06 Sep 2018 06:56:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxrxH-0001n5-0p for bug-gnu-emacs@gnu.org; Thu, 06 Sep 2018 06:56:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxrxC-00064I-Sy for bug-gnu-emacs@gnu.org; Thu, 06 Sep 2018 06:56:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxrxC-00063J-N0 for bug-gnu-emacs@gnu.org; Thu, 06 Sep 2018 06:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fxrxC-0008BE-EU for bug-gnu-emacs@gnu.org; Thu, 06 Sep 2018 06:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 06 Sep 2018 10:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32543 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32543-submit@debbugs.gnu.org id=B32543.153623135631432 (code B ref 32543); Thu, 06 Sep 2018 10:56:02 +0000 Original-Received: (at 32543) by debbugs.gnu.org; 6 Sep 2018 10:55:56 +0000 Original-Received: from localhost ([127.0.0.1]:47712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxrx5-0008Au-SD for submit@debbugs.gnu.org; Thu, 06 Sep 2018 06:55:56 -0400 Original-Received: from mail-wr1-f66.google.com ([209.85.221.66]:39273) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxrx2-0008Ab-O1 for 32543@debbugs.gnu.org; Thu, 06 Sep 2018 06:55:54 -0400 Original-Received: by mail-wr1-f66.google.com with SMTP id s14-v6so1915710wrw.6 for <32543@debbugs.gnu.org>; Thu, 06 Sep 2018 03:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=EgbvUfa8jl4xzXYxEG/zYkB6hFyAhogB5fUWpKYzkGo=; b=WebSsw5IKNcE3jrsr3QBZ98rHci6iC60vxXcpA342PlVDJDhCrhxGARMQPW6O8L9Dp oaU1x5I0zpnHQ7SdkMfGfwE6i+Jr/oi61T3cldC44TESwL+c1r9cYtiscjEUW6/G/4ZC +dj/pGIdSFvTU5WJBILlzbyC/+MLg76qbOihNBFt7fzr4iEo0RzZyQN3uBqqMAKRUWSR QSX9vcwJZw8UiSzcbOu1jkiyr7NDzRH69/twK3fVkveYVkL1cHaMegZa8uGtAa5YlLiP cUVsdSF7qB0hMYFfaKUcv5QYlhkcu/j2BOvLD3ww+EBlaZEJuzVlk9SEuefOCPPrpE67 AFqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=EgbvUfa8jl4xzXYxEG/zYkB6hFyAhogB5fUWpKYzkGo=; b=A9892u0CuaieXY7N4di3Ph2uC0P0+2XoWrU5qDjq/U/zJ/U8Npz6UrS2cZ1Y3iIKIw fhsl7X7VnXlmEu7OevzAeW6iI/QWq47VKjxAsDBpr07nUyCkSh8uKn1IjvQxdGkiBq4j r/GNPXETpHh91SXZjy2CWi++Ap2U9v5AV3RFnydVWF5WuX55QPqvmsxvuFVayAMv52Z1 ynbptzc8yHektWdzvV5aTmCSyZT25/EsK8YgS+PEKI1GnC5DCsPCISVB4rhI+VHKf+Ol MumVfTSjhTc7+udpPiIaDLkIquSBrYlUkfzjiZ85TnDC0vshO5AjcwNDnnSsfUJnxQrO KLqw== X-Gm-Message-State: APzg51DDYYLcVxST4IWkVC+DMNpRbqGTg7ws3xlZRyd1jyIFMdDnpS8+ mYH8aIO1nl2JlAqNl8uICVU= X-Google-Smtp-Source: ANB0VdYaIEfrYpiIa9rUa//OXzpGT5+2AXFu/oHtI+o3YzDVt9wG9SrObfJ5+WcUIw6cQX0TwTo60g== X-Received: by 2002:adf:92c2:: with SMTP id 60-v6mr1860946wrn.153.1536231346927; Thu, 06 Sep 2018 03:55:46 -0700 (PDT) Original-Received: from calancha-pc.dy.bbexcite.jp ([213.99.246.133]) by smtp.gmail.com with ESMTPSA id 34-v6sm3980391wra.20.2018.09.06.03.55.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 03:55:46 -0700 (PDT) In-Reply-To: <87ftyqryp2.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 04 Sep 2018 01:41:29 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:150078 Archived-At: Juri Linkov writes: >> + (let* ((region (occur--parse-occur-buffer)) >> + (region-start (car region)) >> + (region-end (cadr region)) >> + (orig-line (caddr region)) >> + (buffer (cadddr region)) > > Better to use (nth 1), (nth 2), (nth 3), ... Yeah, it reads better. Here is the updated patch: --8<-----------------------------cut here---------------start------------->8--- commit 88588f772a82397e8c60e0e066507b3d67b72848 Author: Tino Calancha Date: Thu Sep 6 19:48:18 2018 +0900 Fix bug 32543 Store the region and orig line into the *Occur* header line. Retrieve this information in `occur-revert-function'. * lisp/replace.el (occur--parse-occur-buffer): New defun. (occur-revert-function): Use it. (occur-engine): Store region and original position as text properties into the *Occur* header line. * lisp/replace.el (occur-engine): Add sensible default values for (occur--orig-line and nlines. diff --git a/lisp/replace.el b/lisp/replace.el index 20b868a765..093993a3b6 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -1206,9 +1206,38 @@ occur-after-change-function (move-to-column col))))))) +(defun occur--parse-occur-buffer() + "Retrieve a list of the form (BEG END ORIG-LINE BUFFER). +BEG and END define the region. +ORIG-LINE and BUFFER are the line and the buffer from which +the user called `occur'." + (save-excursion + (goto-char (point-min)) + (let ((buffer (get-text-property (point-at-bol) 'occur-title)) + (beg-pos (get-text-property (point-at-bol) 'region-start)) + (end-pos (get-text-property (point-at-bol) 'region-end)) + (orig-line (get-text-property (point-at-bol) 'current-line)) + beg-line end-line) + (list beg-pos end-pos orig-line buffer)))) + (defun occur-revert-function (_ignore1 _ignore2) "Handle `revert-buffer' for Occur mode buffers." - (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))) + (if (cdr (nth 2 occur-revert-arguments)) ; multi-occur + (apply 'occur-1 (append occur-revert-arguments (list (buffer-name)))) + (let* ((region (occur--parse-occur-buffer)) + (region-start (nth 0 region)) + (region-end (nth 1 region)) + (orig-line (nth 2 region)) + (buffer (nth 3 region)) + (regexp (car occur-revert-arguments))) + (with-current-buffer buffer + (when (wholenump orig-line) + (goto-char 1) + (forward-line (1- orig-line))) + (save-excursion + (if region + (occur regexp nil (list (cons region-start region-end))) + (apply 'occur-1 (append occur-revert-arguments (list (buffer-name)))))))))) (defun occur-mode-find-occurrence () (let ((pos (get-text-property (point) 'occur-target))) @@ -1651,7 +1680,7 @@ occur-engine (matches 0) ;; count of matches (curr-line ;; line count (or occur--region-start-line 1)) - (orig-line occur--orig-line) + (orig-line (or occur--orig-line 1)) (orig-line-shown-p) (prev-line nil) ;; line number of prev match endpt (prev-after-lines nil) ;; context lines of prev match @@ -1701,6 +1730,8 @@ occur-engine (setq matches (1+ matches))) (when (and list-matching-lines-jump-to-current-line (not multi-occur-p)) + (or orig-line (setq orig-line 1)) + (or nlines (setq nlines (line-number-at-pos (point-max)))) (when (= curr-line orig-line) (add-face-text-property 0 len list-matching-lines-current-line-face nil curstring) @@ -1859,7 +1890,9 @@ occur-engine "")) 'read-only t)) (setq end (point)) - (add-text-properties beg end `(occur-title ,buf)) + (add-text-properties beg end `(occur-title ,buf current-line ,orig-line + region-start ,occur--region-start + region-end ,occur--region-end)) (when title-face (add-face-text-property beg end title-face)) (goto-char (if (and list-matching-lines-jump-to-current-line --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2018-09-06 Repository revision: bca35315e16cb53415649e5c0ac2ec0cc1368679