From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] master 75d9a55: Fix bug 32543
Date: Tue, 18 Sep 2018 08:56:52 -0400 [thread overview]
Message-ID: <jwvbm8vas53.fsf-monnier+emacsdiffs@gnu.org> (raw)
In-Reply-To: <20180918123205.8BE9B204DF@vcs0.savannah.gnu.org> (Tino Calancha's message of "Tue, 18 Sep 2018 08:32:05 -0400 (EDT)")
> +(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
next parent reply other threads:[~2018-09-18 12:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20180918123203.24597.514@vcs0.savannah.gnu.org>
[not found] ` <20180918123205.8BE9B204DF@vcs0.savannah.gnu.org>
2018-09-18 12:56 ` Stefan Monnier [this message]
2018-09-18 17:37 ` [Emacs-diffs] master 75d9a55: Fix bug 32543 Tino Calancha
2018-09-18 21:11 ` Stefan Monnier
2018-09-18 22:03 ` Tino Calancha
2018-09-19 13:34 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvbm8vas53.fsf-monnier+emacsdiffs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=tino.calancha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).