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 Subject: bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp Date: Tue, 11 Oct 2016 14:31:38 +0200 Message-ID: <87bmyrvzh1.fsf@mbork.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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1476189154 25805 195.159.176.226 (11 Oct 2016 12:32:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Oct 2016 12:32:34 +0000 (UTC) User-Agent: mu4e 0.9.17; emacs 26.0.50.1 Cc: rfflrccrd@gmail.com, 21072@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 11 14:32:30 2016 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 1btwEB-00049h-2X for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Oct 2016 14:32:15 +0200 Original-Received: from localhost ([::1]:55438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btwEC-0006No-Ky for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Oct 2016 08:32:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btwE3-0006NY-DR for bug-gnu-emacs@gnu.org; Tue, 11 Oct 2016 08:32:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btwDy-0007cS-7x for bug-gnu-emacs@gnu.org; Tue, 11 Oct 2016 08:32:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btwDy-0007cJ-4J for bug-gnu-emacs@gnu.org; Tue, 11 Oct 2016 08:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1btwDx-0000TX-Qf for bug-gnu-emacs@gnu.org; Tue, 11 Oct 2016 08:32: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: Tue, 11 Oct 2016 12:32: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.14761890981794 (code B ref 21072); Tue, 11 Oct 2016 12:32:01 +0000 Original-Received: (at 21072) by debbugs.gnu.org; 11 Oct 2016 12:31:38 +0000 Original-Received: from localhost ([127.0.0.1]:51812 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1btwDa-0000Sq-4n for submit@debbugs.gnu.org; Tue, 11 Oct 2016 08:31:38 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:58005) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1btwDX-0000Sg-So for 21072@debbugs.gnu.org; Tue, 11 Oct 2016 08:31:36 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 9F2FCE6856; Tue, 11 Oct 2016 14:31:33 +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 cX_rIMbiXA6h; Tue, 11 Oct 2016 14:31:29 +0200 (CEST) Original-Received: from localhost (unknown [62.3.163.157]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 1B325E64AF; Tue, 11 Oct 2016 14:31:29 +0200 (CEST) In-reply-to: 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:124331 Archived-At: On 2016-05-07, at 07:07, Drew Adams wrote: > I agree that the behavior is not particularly consistent, and it > does not completely correspond to the doc. What the best fix is, > I don't know. > > It's been this way for a long time, so there might be people > who expect or like it to do what it does, in which case the > doc should probably be fixed somewhat. > > On the other hand, I'd bet that few, if any, would complain if > better behavior were implemented. > > In any case, the behavior of being able to repeat to keep selecting > more defuns further down should be kept. > > I'd suggest that Someone (TM) (Marcin?) implement a better > behavior and propose it to emacs-devel. ;-) > > What might be better? > > 1. At least consistency wrt which defun gets selected, when > betweeen defuns. The doc suggests a general rule (the next > defun), but that is not always respected. > > 2. Something consistent also wrt a comment before the defun > that will be selected. > > 3. It could be good for a numeric prefix arg to select that > many defuns. > > 4. It could be good for a negative prefix arg to select in > the opposite direction. This is the main improvement I'd > like to see. E.g. `M-- C-M-h' selects the previous defun; > `M-2 C-M-h' selects the two previous defuns. > > Someone should play around and dream up something useful. > > Wrt #2, I'm not sure what the best approach might be. Hi all, it's been some time, and I implemented a better (?) behavior indeed. (Yes, I know a few months passed. But I don't have a lot of time to work on Emacs bugs now. This bug took me almost 8 hours over the past few months.) Basically, I took into consideration all the points Drew mentioned. I'd like to submit my work for review. I have one technical problem, though: I have it as a series of commits on a separate branch in my repo, and I'm not Git-literate enough to make one patch from them. Should I submit a series of patches? Should I rebase my commits into one big one? (No big deal, this might be a good idea anyway.) In the course of my work, I have also implemented a macro to help write tests for the new behavior (there are 6 ERT tests, with 40 assertions total). Here it is (for review): --8<---------------cut here---------------start------------->8--- (defvar elisp-test-point-marker-regex "=!\\([a-zA-Z0-9-]+\\)=" "A regexp matching placeholders for point position for `elisp-tests-with-temp-buffer'.") ;; Copied and heavily modified from `python-tests-with-temp-buffer' (defmacro elisp-tests-with-temp-buffer (contents &rest body) "Create a `emacs-lisp-mode' enabled temp buffer with CONTENTS. BODY is code to be executed within the temp buffer. Point is always located at the beginning of buffer. Special markers of the form =!NAME= in CONTENTS are removed, and a for each one a variable called NAME is bound to the position of such a marker." (declare (indent 1) (debug t)) `(with-temp-buffer (emacs-lisp-mode) (insert ,contents) (goto-char (point-min)) (while (re-search-forward elisp-test-point-marker-regex nil t) (delete-region (match-beginning 0) (match-end 0))) (goto-char (point-min)) ,(let (marker-list) (with-temp-buffer (insert (cond ((symbolp contents) (symbol-value contents)) (t contents))) (goto-char (point-min)) (while (re-search-forward elisp-test-point-marker-regex nil t) (push (list (intern (match-string-no-properties 1)) (match-beginning 0)) marker-list) (delete-region (match-beginning 0) (match-end 0)))) `(let ,marker-list ,@body)))) --8<---------------cut here---------------end--------------->8--- And it can be used like this: --8<---------------cut here---------------start------------->8--- (defvar mark-defun-test-buffer ";; Comment header =!before-1= \(defun func-1 (arg) =!inside-1=\"docstring\" body) =!after-1==!before-2= ;; Comment before a defun \(d=!inside-2=efun func-2 (arg) \"docstring\" body) =!after-2==!before-3= \(defun func-3 (arg) \"docstring\"=!inside-3= body) =!after-3==!before-4=(defun func-4 (arg) \"docstring\"=!inside-4= body) =!after-4= ;; end " "Test buffer for `mark-defun'.") (ert-deftest mark-defun-no-arg-region-inactive () "Test `mark-defun' with no prefix argument and inactive region." (elisp-tests-with-temp-buffer mark-defun-test-buffer ;; mark-defun inside a defun, with comments and an empty line ;; before (goto-char inside-1) (mark-defun) (should (= (point) before-1)) (should (= (mark) after-1)))) --8<---------------cut here---------------end--------------->8--- WDYT? -- Marcin Borkowski