unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: npostavs@users.sourceforge.net
Cc: emacs-devel@gnu.org, 21072@debbugs.gnu.org, monnier@iro.umontreal.ca
Subject: bug#21072: Brave new mark-defun (and a testing tool)
Date: Fri, 07 Apr 2017 10:25:08 +0200	[thread overview]
Message-ID: <871st4aal7.fsf@jane> (raw)
In-Reply-To: <87k272wh8x.fsf@users.sourceforge.net>

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 <mbork@mbork.pl> 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?
>
>>  \f
>> +** 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".
>>
>>  \f
>> +** 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





  reply	other threads:[~2017-04-07  8:25 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-08  6:01 Brave new mark-defun (and a testing tool) Marcin Borkowski
2017-02-12  7:09 ` John Wiegley
2017-02-12 10:10   ` Marcin Borkowski
2017-02-12 10:13     ` Marcin Borkowski
2017-02-12 21:29     ` John Wiegley
2017-02-13 11:00       ` Marcin Borkowski
2017-02-13 15:16         ` Dmitry Gutov
2017-02-13 15:58           ` Marcin Borkowski
2017-02-13 19:00           ` John Wiegley
2017-02-14 10:45             ` bug#21072: " Marcin Borkowski
2017-02-14 13:02               ` Dmitry Gutov
2017-02-14 19:06                 ` Marcin Borkowski
2017-02-14 19:25                   ` Stefan Monnier
2017-02-15  6:45                     ` Marcin Borkowski
2017-02-15  7:56                       ` Stefan Monnier
2017-02-15 19:18                         ` Marcin Borkowski
2017-02-15 19:27                           ` Stefan Monnier
2017-02-16  4:40                             ` Marcin Borkowski
2017-02-16 13:22                               ` Stefan Monnier
2017-02-17  8:54                                 ` Marcin Borkowski
2017-03-07 16:46                                   ` Eli Zaretskii
2017-03-29  6:34                                     ` Marcin Borkowski
2017-03-31 11:18                                       ` Marcin Borkowski
2017-04-02 22:56                                         ` npostavs
2017-04-07  8:25                                           ` Marcin Borkowski [this message]
2017-03-07 16:50                                   ` Dmitry Gutov
2017-03-07 16:53                                     ` Eli Zaretskii
2017-03-29  6:30                                       ` Marcin Borkowski
2017-03-29  6:30                                     ` Marcin Borkowski

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=871st4aal7.fsf@jane \
    --to=mbork@mbork.pl \
    --cc=21072@debbugs.gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=npostavs@users.sourceforge.net \
    /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).