From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.bugs,gmane.emacs.devel Subject: bug#21072: Brave new mark-defun (and a testing tool) Date: Fri, 07 Apr 2017 10:25:08 +0200 Message-ID: <871st4aal7.fsf@jane> References: <87o9ydrzkr.fsf@mbork.pl> <87mvdriuss.fsf@mbork.pl> <87bmu6icea.fsf@mbork.pl> <87wpctgieu.fsf@mbork.pl> <52e67f43-edcf-09e3-5fd6-6079763fd234@yandex.ru> <87tw7wh9sf.fsf@mbork.pl> <87k28sdka6.fsf@jane> <87efyze00g.fsf@jane> <87bmu2eoji.fsf@jane> <87wpcpw61w.fsf@jane> <83o9xdghmc.fsf@gnu.org> <87o9wkoald.fsf@jane> <87a881ofsu.fsf@jane> <87k272wh8x.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1491553523 12476 195.159.176.226 (7 Apr 2017 08:25:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 7 Apr 2017 08:25:23 +0000 (UTC) User-Agent: mu4e 0.9.19; emacs 26.0.50 Cc: emacs-devel@gnu.org, 21072@debbugs.gnu.org, monnier@iro.umontreal.ca To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 07 10:25:18 2017 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 1cwPCg-0001vT-4N for geb-bug-gnu-emacs@m.gmane.org; Fri, 07 Apr 2017 10:25:10 +0200 Original-Received: from localhost ([::1]:49494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwPCl-0004w5-S6 for geb-bug-gnu-emacs@m.gmane.org; Fri, 07 Apr 2017 04:25:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwPCZ-0004rl-IP for bug-gnu-emacs@gnu.org; Fri, 07 Apr 2017 04:25:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwPCY-0001S8-F1 for bug-gnu-emacs@gnu.org; Fri, 07 Apr 2017 04:25:03 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37505) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwPCY-0001S2-Bb for bug-gnu-emacs@gnu.org; Fri, 07 Apr 2017 04:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cwPCY-0006fy-3g for bug-gnu-emacs@gnu.org; Fri, 07 Apr 2017 04:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Marcin Borkowski Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 07 Apr 2017 08:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21072 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 21072-submit@debbugs.gnu.org id=B21072.149155349225643 (code B ref 21072); Fri, 07 Apr 2017 08:25:02 +0000 Original-Received: (at 21072) by debbugs.gnu.org; 7 Apr 2017 08:24:52 +0000 Original-Received: from localhost ([127.0.0.1]:35704 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwPCN-0006fX-P3 for submit@debbugs.gnu.org; Fri, 07 Apr 2017 04:24:51 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:49473) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwPCL-0006fM-AF for 21072@debbugs.gnu.org; Fri, 07 Apr 2017 04:24:50 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 29303E6BE5; Fri, 7 Apr 2017 10:24:47 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Hgg02NIDBpfc; Fri, 7 Apr 2017 10:24:42 +0200 (CEST) Original-Received: from localhost (apn-37-248-138-13.dynamic.gprs.plus.pl [37.248.138.13]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 4809CE6BD6; Fri, 7 Apr 2017 10:24:40 +0200 (CEST) In-reply-to: <87k272wh8x.fsf@users.sourceforge.net> 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:131327 gmane.emacs.devel:213736 Archived-At: Hey, and thanks for your feedback! My answers to particular points are below. On 2017-04-03, at 00:56, npostavs@users.sourceforge.net wrote: > Marcin Borkowski writes: > >> >> OK, I pushed the branch "fix-bug-21072". Can anyone confirm that it's >> ok and either merge it into master or tell me that I can do it? > >> >> +** New macro 'elisp-tests-with-temp-buffer' >> +which helps writing tests for functions that should change buffers in >> +specific ways or manipulate point or mark positions. >> + >> +--- > > I don't this should be documented in NEWS since the macro is being added > to a test file, so it's not part of Emacs' libraries. Also, the format > of the NEWS entry is wrong in the same way as the next one (see below). I deleted that from etc/NEWS. >> +With a prefix argument, it marks that many defuns or extends the >> +region by the appropriate number of defuns. With negative prefix >> +argument it marks defuns in the opposite direction and also changes >> +the direction of selecting for subsequent uses of @code{mark-defun}. > > This doesn't say what exactly happens with zero as argument. The code > seems to do something odd. Perhaps it should just be a user-error > instead? Or maybe just a nop. Good catch. I guess a no-op is fine. >> modified etc/NEWS >> @@ -363,6 +363,15 @@ words where first character is upper rather than title case, e.g., >> "DŽungla" instead of "Džungla". >> >> >> +** New behavior of 'mark-defun' implemented >> +Prefix argument selects that many (or that many more) defuns. >> +Negative prefix arg flips the direction of selection. Also, >> +'mark-defun' between defuns correctly selects N following defuns (or >> +-N previous for negative arguments). Finally, comments preceding the >> +defun are selected unless they are separated from the defun by a blank >> +line. >> + >> ++++ >> * Changes in Specialized Modes and Packages in Emacs 26.1 >> > > This entry should go before the page separator, and the "+++" should go > on the line just above the entry, not after it. That one I do not understand. This means that "+++" goes essentially _to the previous entry_, which doesn't seem to make sense (especially when viewing NEWS folded, which I assume everyone does, right?). >> +(defun beginning-of-defun-comments (&optional arg) > >> + (let (nbobp) >> + (while (progn >> + (setq nbobp (zerop (forward-line -1))) >> + (and (not (looking-at "^\\s-*$")) >> + (beginning-of-defun--in-emptyish-line-p) >> + nbobp))) >> + (when nbobp >> + (forward-line 1)))) > > > The looking-at call is redundant, right? Anyway, can't that all be Hm. Probably yes, although this seems to be not very well documented in `forward-comment's docs. > replaced by just > > (forward-comment (- (point))) > (unless (bolp) > (forward-line 1)) My tests say no. Consider these contents of a buffer: --8<---------------cut here---------------start------------->8--- ;; Comment at the bob (defun func (arg) "docstring" body) --8<---------------cut here---------------end--------------->8--- Put the point inside the defun and call mark-defun. Your version marks the comment at the beginning, mine doesn't. >> +(defun mark-defun (&optional arg) > >> + (let (nbobp) >> + (while (progn >> + (setq nbobp (zerop (forward-line -1))) >> + (and (looking-at "^\\s-*$") >> + nbobp))) >> + (when nbobp >> + (forward-line 1)))) > > I think this can be just > > (skip-chars-backward "[:space:]\n") > (unless (bolp) > (forward-line 1)) This OTOH does pass my tests, though I guess it would be clearer to replace (bolp) with (bobp) in the above code (if I understand correctly, in this situation they should be equivalent). WDYT? Thanks a lot, -- Marcin Borkowski