all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: 21072@debbugs.gnu.org
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	[thread overview]
Message-ID: <87oa6u7t44.fsf@mbork.pl> (raw)
In-Reply-To: <225dd67a-7980-ca40-bcbd-b4669b392c4a@easy-emacs.de>


On 2016-06-21, at 11:05, Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:

> On 21.06.2016 09:58, Marcin Borkowski wrote:
>> On 2016-06-09, at 13:56, Marcin Borkowski <mbork@mbork.pl> 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 <mbork@mbork.pl>
>> ;; Author: Dmitry Gutov <dgutov@yandex.ru>
>> ;; Author: Stephen Leake <stephen_leake@member.fsf.org>
>>
>> ;; 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 <http://www.gnu.org/licenses/>.
>>
>> ;;; Code:
>>
>> (require 'ert)
>>
>> \f
>> ;;; 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)))
>>
>> \f
>> ;;; 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





      reply	other threads:[~2016-06-21 10:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16  6:12 bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp Raffaele Ricciardi
2016-04-25 11:11 ` Marcin Borkowski
2016-05-01 17:17   ` Eli Zaretskii
2016-05-01 17:49     ` Marcin Borkowski
2016-05-01 18:09       ` Eli Zaretskii
2016-05-01 19:45         ` Marcin Borkowski
2016-05-01 19:56           ` Eli Zaretskii
2016-05-03 18:58             ` Marcin Borkowski
2016-05-04 14:45               ` Eli Zaretskii
2016-05-06 12:27                 ` Marcin Borkowski
2016-05-06 12:59                   ` Eli Zaretskii
2016-05-07  3:47                     ` Marcin Borkowski
2016-05-07  5:07                       ` Drew Adams
2016-10-11 12:31                         ` Marcin Borkowski
2016-10-11 15:30                           ` Drew Adams
2016-10-11 17:07                             ` Marcin Borkowski
2016-10-11 17:52                               ` Clément Pit--Claudel
2016-10-11 20:26                               ` Drew Adams
2016-10-11 21:15                               ` Drew Adams
2016-10-28  5:35                                 ` Marcin Borkowski
2016-10-28 14:32                                   ` Drew Adams
2016-11-02  7:28                                 ` Marcin Borkowski
2016-11-02 18:25                                   ` Drew Adams
2016-11-04  7:48                                     ` Marcin Borkowski
2016-11-27  7:40                                       ` Marcin Borkowski
2016-11-27 18:51                                         ` Drew Adams
2017-02-07  6:22                                           ` Marcin Borkowski
2017-02-07 16:14                                             ` Drew Adams
2016-05-07  6:47                       ` Eli Zaretskii
2016-06-05  6:30                         ` Marcin Borkowski
2016-06-05  7:01                           ` bug#21072: Forgotten attachment (was: bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp) Marcin Borkowski
2016-06-09 11:56                           ` bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp Marcin Borkowski
2016-06-21  7:58                             ` Marcin Borkowski
2016-06-21  9:05                               ` Andreas Röhler
2016-06-21 10:07                                 ` Marcin Borkowski [this message]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oa6u7t44.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=21072@debbugs.gnu.org \
    --cc=andreas.roehler@easy-emacs.de \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.