From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] master 75d9a55: Fix bug 32543 Date: Tue, 18 Sep 2018 08:56:52 -0400 Message-ID: References: <20180918123203.24597.514@vcs0.savannah.gnu.org> <20180918123205.8BE9B204DF@vcs0.savannah.gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1537275302 27718 195.159.176.226 (18 Sep 2018 12:55:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 18 Sep 2018 12:55:02 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Tino Calancha Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 18 14:54:58 2018 Return-path: Envelope-to: ged-emacs-devel@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 1g2FWs-00075O-2K for ged-emacs-devel@m.gmane.org; Tue, 18 Sep 2018 14:54:58 +0200 Original-Received: from localhost ([::1]:40213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2FYy-0000vW-CN for ged-emacs-devel@m.gmane.org; Tue, 18 Sep 2018 08:57:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2FYs-0000uv-CE for emacs-devel@gnu.org; Tue, 18 Sep 2018 08:57:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2FYo-0007ym-CR for emacs-devel@gnu.org; Tue, 18 Sep 2018 08:57:02 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:38000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2FYn-0007se-Hu for emacs-devel@gnu.org; Tue, 18 Sep 2018 08:56:57 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w8ICurv1029635; Tue, 18 Sep 2018 08:56:53 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id EAB2E6A66C; Tue, 18 Sep 2018 08:56:52 -0400 (EDT) In-Reply-To: <20180918123205.8BE9B204DF@vcs0.savannah.gnu.org> (Tino Calancha's message of "Tue, 18 Sep 2018 08:32:05 -0400 (EDT)") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6376=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6376> : inlines <6883> : streams <1798807> : uri <2713022> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:229939 Archived-At: > +(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)))) I'm curious here: - Why use (point-at-bol) since we just moved to (point-min) and hence we know that (point-at-bol) == (point-min) == (point)? - why store this info in text-properties rather than in buffer-local variables? > + (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))) Here you could have used pcase-let: (pcase-let ((`(,region-start ,region-end ,orig-line ,buffer) (occur--parse-occur-buffer)) (regexp (car occur-revert-arguments))) > + (with-current-buffer buffer > + (when (wholenump orig-line) > + (goto-char 1) I'd recommend `point-min` instead of 1 here. > + (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)))))))))) `region` is the list which holds (among other things) `buffer`, so if we successfully entered (with-current-buffer buffer ...) I can't see how `region` could be nil. Stefan