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: Tue, 21 Jun 2016 12:07:23 +0200 Message-ID: <87oa6u7t44.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> <83a8k2fjpi.fsf@gnu.org> <87y46kb11o.fsf@mbork.pl> <8737omh8yk.fsf@amu.edu.pl> <87shw76ki1.fsf@amu.edu.pl> <225dd67a-7980-ca40-bcbd-b4669b392c4a@easy-emacs.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1466505069 19165 80.91.229.3 (21 Jun 2016 10:31:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Jun 2016 10:31:09 +0000 (UTC) Cc: 21072@debbugs.gnu.org To: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 21 12:30:53 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 1bFIxB-0006wN-La for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 Jun 2016 12:30:45 +0200 Original-Received: from localhost ([::1]:50525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFIxA-0003hQ-V6 for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 Jun 2016 06:30:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFIbG-0001AS-Gg for bug-gnu-emacs@gnu.org; Tue, 21 Jun 2016 06:08:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFIbC-0001NN-8f for bug-gnu-emacs@gnu.org; Tue, 21 Jun 2016 06:08:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFIbC-0001N9-4b for bug-gnu-emacs@gnu.org; Tue, 21 Jun 2016 06:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bFIbB-0005Aj-Ny for bug-gnu-emacs@gnu.org; Tue, 21 Jun 2016 06:08: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, 21 Jun 2016 10:08: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.146650365319843 (code B ref 21072); Tue, 21 Jun 2016 10:08:01 +0000 Original-Received: (at 21072) by debbugs.gnu.org; 21 Jun 2016 10:07:33 +0000 Original-Received: from localhost ([127.0.0.1]:48580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFIae-00059w-F3 for submit@debbugs.gnu.org; Tue, 21 Jun 2016 06:07:33 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:45253) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFIab-00059l-Ea for 21072@debbugs.gnu.org; Tue, 21 Jun 2016 06:07:26 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id D8ADDC3A102; Tue, 21 Jun 2016 12:07:23 +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 OCZ3nD+1UaO8; Tue, 21 Jun 2016 12:07:20 +0200 (CEST) Original-Received: from localhost (unknown [150.254.81.161]) by mail.mojserwer.eu (Postfix) with ESMTPSA id A42D4C3A0FF; Tue, 21 Jun 2016 12:07:20 +0200 (CEST) User-agent: mu4e 0.9.16; emacs 25.1.50.3 In-reply-to: <225dd67a-7980-ca40-bcbd-b4669b392c4a@easy-emacs.de> 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:119868 Archived-At: On 2016-06-21, at 11:05, Andreas Röhler wrote: > On 21.06.2016 09:58, Marcin Borkowski wrote: >> On 2016-06-09, at 13:56, Marcin Borkowski wrote: >> >>> 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). >> Hi all, >> >> it seems nobody cared enough to answer my question, so I made the choice >> of doing the Right Thing™, and started from developing some tests for >> mark-defun. Here's what I've got now. >> >> --8<---------------cut here---------------start------------->8--- >> ;;; elisp-mode-tests.el --- Tests for emacs-lisp-mode -*- lexical-binding: t; -*- >> >> ;; Copyright (C) 2015-2016 Free Software Foundation, Inc. >> >> ;; Author: Marcin Borkowski >> ;; Author: Dmitry Gutov >> ;; Author: Stephen Leake >> >> ;; This file is part of GNU Emacs. >> >> ;; GNU Emacs is free software: you can redistribute it and/or modify >> ;; it under the terms of the GNU General Public License as published by >> ;; the Free Software Foundation, either version 3 of the License, or >> ;; (at your option) any later version. >> >> ;; GNU Emacs is distributed in the hope that it will be useful, >> ;; but WITHOUT ANY WARRANTY; without even the implied warranty of >> ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> ;; GNU General Public License for more details. >> >> ;; You should have received a copy of the GNU General Public License >> ;; along with GNU Emacs. If not, see . >> >> ;;; Code: >> >> (require 'ert) >> >> >> ;;; Helpers >> >> ;; Copied and 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." >> (declare (indent 1) (debug t)) >> `(with-temp-buffer >> (emacs-lisp-mode) >> (insert ,contents) >> (goto-char (point-min)) >> ,@body)) >> >> (defmacro conditional-save-excursion (arg &rest body) >> "Wrap BODY in `save-excursion', but only if ARG is non-nil." >> (declare (indent 1) (debug t)) >> `(if ,arg >> (save-excursion ,@body) >> ,@body)) >> >> (defun look-at (string &optional count restore-point) >> "Move the point to the beginning of STRING in current buffer. >> Return the new point value. If COUNT is non-nil, move to COUNTth >> occurrence. If RESTORE-POINT is non-nil, return the found >> position, but do not move point." >> (conditional-save-excursion restore-point >> (setq count (or count 1)) >> (when (search-forward string nil t count) >> (goto-char (match-beginning 0))) >> (point))) >> >> >> ;;; Mark >> >> (ert-deftest mark-defun-1 () >> "Test `mark-defun' with point inside the defun." >> (elisp-tests-with-temp-buffer >> " >> \(defun func-a () >> \"A parameterless function.\" >> (ignore)) >> >> ;; A comment right before a defun. >> \(defun func-b (argument) >> \"A function with one ARGUMENT.\" >> (ignore argument) >> (message \"%s\" \"Argument ignored.\")) >> >> \(defmacro macro-a (&rest body) >> \"A macro with BODY.\" >> `(,@body)) >> " >> (let ((expected-mark-beginning-position-1-2 >> (progn >> (look-at "(defun func-a ") >> (previous-line 1) >> (point))) >> (expected-mark-end-position-1 >> (save-excursion >> (look-at "(ignore))") >> (next-line 1) >> (point))) >> (expected-mark-end-position-2 >> (save-excursion >> (point) >> (look-at "\"))") >> (next-line 1) >> (point))) >> (expected-mark-beginning-position-3 >> (progn >> (look-at "(defmacro macro-a ") >> (previous-line 1) >> (point))) >> (expected-mark-end-position-3 >> (progn >> (look-at "(,@body)") >> (next-line 1) >> (point)))) >> ;; select the first defun >> (goto-char (point-min)) >> (look-at "A parameterless function.") >> (mark-defun) >> (should (= (point) expected-mark-beginning-position-1-2)) >> (should (= (marker-position (mark-marker)) >> expected-mark-end-position-1)) >> ;; expand to the second defun >> (mark-defun 1) >> (should (= (point) expected-mark-beginning-position-1-2)) >> (should (= (marker-position (mark-marker)) >> expected-mark-end-position-2)) >> ;; select the macro >> (look-at "A macro") >> (mark-defun) >> (should (= (point) expected-mark-beginning-position-3)) >> (should (= (marker-position (mark-marker)) >> expected-mark-end-position-3))))) >> >> (ert-deftest mark-defun-2 () >> "Test `mark-defun' with point between defuns." >> (elisp-tests-with-temp-buffer >> " >> \(defun func-a () >> \"A parameterless function.\" >> (ignore)) >> >> ;; A comment right before a defun. >> \(defun func-b (argument) >> \"A function with one ARGUMENT.\" >> (ignore argument) >> (message \"%s\" \"Argument ignored.\")) >> >> \(defmacro macro-a (&rest body) >> \"A macro with BODY.\" >> `(,@body)) >> " >> (let ((expected-mark-beginning-position-1 >> (progn >> (look-at "(defun func-b ") >> (point))) >> (expected-mark-end-position-1 >> (save-excursion >> (look-at "ignored.\"))") >> (next-line 1) >> (point)))) >> ;; select the first defun >> (goto-char expected-mark-end-position-1) >> (previous-line 1) >> (mark-defun) >> (should (= (point) expected-mark-beginning-position-1)) >> (should (= (marker-position (mark-marker)) >> expected-mark-end-position-1))))) >> >> (provide 'elisp-mode-tests) >> ;;; elisp-mode-tests.el ends here >> --8<---------------cut here---------------end--------------->8--- >> >> These two tests pass now. The next thing would be to change them to >> what /should/ pass. Before that, though, let me ask: what are your >> opinion on these simple tests? Are they enough? Would you add >> something? >> >> Best, >> > > Hi Marcin, > > should no one else respond for now: please come back after release. > AFAIU the current implemention of beginning-of-defun prevents a > consistent setup of related commands. A change here would include resp. > require a major change... OK, I see. > Don't give up :) I don't, I'm patient - I'm also working very slowly on this... > Andreas Thanks, best -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University