From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.bugs Subject: bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp Date: Thu, 09 Jun 2016 13:56:25 +0200 Message-ID: <8737omh8yk.fsf@amu.edu.pl> References: <55A74B3C.8030608@gmail.com> <87k2jm2bay.fsf@amu.edu.pl> <83r3dln1ez.fsf@gnu.org> <87y47tzn0v.fsf@mbork.pl> <83lh3tmyzv.fsf@gnu.org> <87twihzhni.fsf@mbork.pl> <83fuu1mu25.fsf@gnu.org> <87eg9jynn0.fsf@mbork.pl> <83h9edkhjs.fsf@gnu.org> <874mabe5h6.fsf@mbork.pl> <83twibfil2.fsf@gnu.org> <87y47mcywp.fsf@mbork.pl> <83a8k2fjpi.fsf@gnu.org> <87y46kb11o.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1465473446 28580 80.91.229.3 (9 Jun 2016 11:57:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 9 Jun 2016 11:57:26 +0000 (UTC) Cc: rfflrccrd@gmail.com, 21072@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 09 13:57:15 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bAyaI-0006E1-MQ for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Jun 2016 13:57:15 +0200 Original-Received: from localhost ([::1]:33923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAyaH-00081Y-UJ for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Jun 2016 07:57:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAyaB-00081S-Pt for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2016 07:57:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAya6-0007yJ-8E for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2016 07:57:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49276) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAya6-0007yF-4u for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2016 07:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bAya5-0000lj-NT for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2016 07:57:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Marcin Borkowski Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 Jun 2016 11:57:01 +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.14654733962923 (code B ref 21072); Thu, 09 Jun 2016 11:57:01 +0000 Original-Received: (at 21072) by debbugs.gnu.org; 9 Jun 2016 11:56:36 +0000 Original-Received: from localhost ([127.0.0.1]:33380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bAyZf-0000l5-QS for submit@debbugs.gnu.org; Thu, 09 Jun 2016 07:56:36 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:55737) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bAyZc-0000ku-1v for 21072@debbugs.gnu.org; Thu, 09 Jun 2016 07:56:34 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 7843FBF46BF; Thu, 9 Jun 2016 13:56:30 +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 rKliI6LzhFLW; Thu, 9 Jun 2016 13:56:28 +0200 (CEST) Original-Received: from localhost (unknown [150.254.81.11]) by mail.mojserwer.eu (Postfix) with ESMTPSA id C66E6BF46B9; Thu, 9 Jun 2016 13:56:27 +0200 (CEST) User-agent: mu4e 0.9.16; emacs 25.1.50.3 In-reply-to: <87y46kb11o.fsf@mbork.pl> 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:119323 Archived-At: Hi everyone, it's me again. I looked at the tests of `mark-defun' for Python, and they did shed some light on the weird implementation. In short, `mark-defun' first jumps to the beginning and the to the end of the current defun, checks whether the point is now before or after the initial position, and if before, back up and jump to the end first and to the beginning next. This might actually happen, since e.g. in Python, when point is on a "def" beginning a function definition, `beginning-of-defun' goes to the start of the _preceding_ defun. In fact, I think this is a bug in beginning-of-defun (or more precisely, its Python version), and consequently I think the weird code in `mark-defun' is a workaround for a deeper bug. I can now do one of a few things. (Not ATM, I'll have to take my time.) 1. Fix the docs so that #21072 is no longer a bug (i.e., change the docs so that there's no discrepancy between them and code). 2a. Just fix the problem reported in #21072, hoping that it doesn't break anything else. 2b. Write a few tests for `mark-defun',_then_ fix the problem, and check whether these tests pass. Of course, all these tests would be for Elisp (and maybe for C and/or JavaScript). 3. Try to come up with a better `mark-defun', still given the limitations of `beginning-of-defun', e.g., make `mark-defun' use the numeric prefix argument in a reasonable way (i.e., what Drew proposed). 4. Report a bug in `beginning-of-defun', and hope someone (probably not me, I do not know enough about ppss now and do not have time to learn that now), and then write a simpler `mark-defun' from scratch. WDYT? Best, Marcin On 2016-06-05, at 08:30, Marcin Borkowski wrote: > On 2016-05-07, at 08:47, Eli Zaretskii wrote: > >>> From: Marcin Borkowski >>> Cc: rfflrccrd@gmail.com, 21072@debbugs.gnu.org >>> Date: Sat, 07 May 2016 05:47:18 +0200 >>> >>> I'm not sure what to do next with this bug. I tried with the >>> abovementioned short Elisp file and failed. Since no-one said that the >>> current behavior is wrong, maybe I'll try to study the code of >>> `mark-defun' and modify the docstring/manual accordingly. >> >> I'd suggest to change the doc string according to what I recommended a >> few messages ago. I think that would be good enough. > > Hi Eli, hi all, > > and sorry for replying after such a long time (again) - I'm afraid > I cannot help this, my time has become extremely limited recently. > > I studied the code of mark-defun, and it seems that the reason for > #21072 is quite simple. I enclose a patch where the two (seemingly) > offending lines are commented; if this is acceptable, of course I'll > prepare a proper patch. (And while at that, I'll propose replacing > `(and transient-mark-mode mark-active)' with `(use-region-p)'.) > > The problem is, I'm not sure whether this change won't break anything. > The only tests I found that deal with `mark-defun' are in > python-tests.el, and my version passes all three of them. > >> Thanks. > > Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University