* 26.0.90: mark-defun problem in c-mode @ 2017-12-30 9:49 zhang cc 2017-12-30 10:30 ` Eli Zaretskii 0 siblings, 1 reply; 18+ messages in thread From: zhang cc @ 2017-12-30 9:49 UTC (permalink / raw) To: emacs-devel@gnu.org [-- Attachment #1: Type: text/plain, Size: 283 bytes --] When cursor is in the second function body, mark-defun can’t mark the second function. But c-mark-defun can, and also the mark-defun in Emacs 25.3. Is it intended? int test_func1(int a) { int i; return 0; } int test_func2(int a) { int i; return 0; } [-- Attachment #2: Type: text/html, Size: 968 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: 26.0.90: mark-defun problem in c-mode 2017-12-30 9:49 26.0.90: mark-defun problem in c-mode zhang cc @ 2017-12-30 10:30 ` Eli Zaretskii 2017-12-30 10:34 ` Alan Mackenzie 0 siblings, 1 reply; 18+ messages in thread From: Eli Zaretskii @ 2017-12-30 10:30 UTC (permalink / raw) To: zhang cc; +Cc: emacs-devel > From: zhang cc <ccsmile2008@outlook.com> > Date: Sat, 30 Dec 2017 09:49:17 +0000 > > When cursor is in the second function body, mark-defun can’t mark > the second function. "M-x mark-defun" works fine here with your example. Where exactly should cursor be in the second function body to reproduce the problem? ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: 26.0.90: mark-defun problem in c-mode 2017-12-30 10:30 ` Eli Zaretskii @ 2017-12-30 10:34 ` Alan Mackenzie 2017-12-30 12:01 ` beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] Alan Mackenzie 0 siblings, 1 reply; 18+ messages in thread From: Alan Mackenzie @ 2017-12-30 10:34 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel, zhang cc Hello, Eli and Zhang. On Sat, Dec 30, 2017 at 12:30:29 +0200, Eli Zaretskii wrote: > > From: zhang cc <ccsmile2008@outlook.com> > > Date: Sat, 30 Dec 2017 09:49:17 +0000 > > > > When cursor is in the second function body, mark-defun can’t mark > > the second function. > "M-x mark-defun" works fine here with your example. Where exactly > should cursor be in the second function body to reproduce the problem? I see the error, with point anywhere in the body of the second function. Critical seems to be there being no blank line between the functions. I think there's a bug in beginning-of-defun-comments, which I'm in the middle of edebugging. It moves point into the first function. -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 18+ messages in thread
* beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 10:34 ` Alan Mackenzie @ 2017-12-30 12:01 ` Alan Mackenzie 2017-12-30 12:53 ` Eli Zaretskii 0 siblings, 1 reply; 18+ messages in thread From: Alan Mackenzie @ 2017-12-30 12:01 UTC (permalink / raw) To: Eli Zaretskii; +Cc: zhang cc, Noam Postavsky, emacs-devel Hello, Eli. On Sat, Dec 30, 2017 at 10:34:32 +0000, Alan Mackenzie wrote: > On Sat, Dec 30, 2017 at 12:30:29 +0200, Eli Zaretskii wrote: > > > From: zhang cc <ccsmile2008@outlook.com> > > > Date: Sat, 30 Dec 2017 09:49:17 +0000 > > > When cursor is in the second function body, mark-defun can’t mark > > > the second function. > > "M-x mark-defun" works fine here with your example. Where exactly > > should cursor be in the second function body to reproduce the problem? > I see the error, with point anywhere in the body of the second function. > Critical seems to be there being no blank line between the functions. > I think there's a bug in beginning-of-defun-comments, which I'm in the > middle of edebugging. It moves point into the first function. beginning-of-defun-comments has a bug. On doing M-x beginning-of-defun-comments from the inside of a function, when there's no blank lines between it and the previous function, point ends up inside that previous function, not at the comments which may separate them. Perhaps this bug should be fixed before the next Emacs-26 pretest. -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 12:01 ` beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] Alan Mackenzie @ 2017-12-30 12:53 ` Eli Zaretskii 2017-12-30 13:05 ` Alan Mackenzie 2017-12-30 15:43 ` Alan Mackenzie 0 siblings, 2 replies; 18+ messages in thread From: Eli Zaretskii @ 2017-12-30 12:53 UTC (permalink / raw) To: Alan Mackenzie; +Cc: ccsmile2008, npostavs, emacs-devel > Date: Sat, 30 Dec 2017 12:01:36 +0000 > Cc: emacs-devel@gnu.org, zhang cc <ccsmile2008@outlook.com>, > Noam Postavsky <npostavs@gmail.com> > From: Alan Mackenzie <acm@muc.de> > > > I see the error, with point anywhere in the body of the second function. > > Critical seems to be there being no blank line between the functions. > > > I think there's a bug in beginning-of-defun-comments, which I'm in the > > middle of edebugging. It moves point into the first function. > > beginning-of-defun-comments has a bug. On doing M-x > beginning-of-defun-comments from the inside of a function, when there's > no blank lines between it and the previous function, point ends up > inside that previous function, not at the comments which may separate > them. > > Perhaps this bug should be fixed before the next Emacs-26 pretest. How old is this problem? It looks like it's new in Emacs 26? If so, we should try fixing it on the release branch. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 12:53 ` Eli Zaretskii @ 2017-12-30 13:05 ` Alan Mackenzie 2018-01-03 4:51 ` Marcin Borkowski 2017-12-30 15:43 ` Alan Mackenzie 1 sibling, 1 reply; 18+ messages in thread From: Alan Mackenzie @ 2017-12-30 13:05 UTC (permalink / raw) To: Eli Zaretskii; +Cc: ccsmile2008, npostavs, emacs-devel Hello, Eli. On Sat, Dec 30, 2017 at 14:53:27 +0200, Eli Zaretskii wrote: > > Date: Sat, 30 Dec 2017 12:01:36 +0000 > > Cc: emacs-devel@gnu.org, zhang cc <ccsmile2008@outlook.com>, > > Noam Postavsky <npostavs@gmail.com> > > From: Alan Mackenzie <acm@muc.de> > > > I see the error, with point anywhere in the body of the second function. > > > Critical seems to be there being no blank line between the functions. > > > I think there's a bug in beginning-of-defun-comments, which I'm in the > > > middle of edebugging. It moves point into the first function. > > beginning-of-defun-comments has a bug. On doing M-x > > beginning-of-defun-comments from the inside of a function, when there's > > no blank lines between it and the previous function, point ends up > > inside that previous function, not at the comments which may separate > > them. > > Perhaps this bug should be fixed before the next Emacs-26 pretest. > How old is this problem? It looks like it's new in Emacs 26? If so, > we should try fixing it on the release branch. beginning-of-defun-comments came into existence on 2017-03-31, so this problem is definitely new in Emacs 26. I've diagnosed the bug. At one place, it is necessary to scan a line of text from BOL to detect any non-comment/non-space character. The current code tries to do this by using parse-partial-sexp with the fourth argument STOPBEFORE non-nil. This STOPBEFORE causes the scanning to stop at any character which begins a sexp. A closing brace doesn't fit into this category. The scan therefore reaches EOL, and the code therefore falsely assumes there are no non-syntactic-ws characters on that line. I'm sure I can fix this today. -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 13:05 ` Alan Mackenzie @ 2018-01-03 4:51 ` Marcin Borkowski 2018-01-03 16:24 ` Alan Mackenzie 0 siblings, 1 reply; 18+ messages in thread From: Marcin Borkowski @ 2018-01-03 4:51 UTC (permalink / raw) To: Alan Mackenzie; +Cc: Eli Zaretskii, emacs-devel, npostavs, ccsmile2008 On 2017-12-30, at 14:05, Alan Mackenzie <acm@muc.de> wrote: > Hello, Eli. > > On Sat, Dec 30, 2017 at 14:53:27 +0200, Eli Zaretskii wrote: >> > Date: Sat, 30 Dec 2017 12:01:36 +0000 >> > Cc: emacs-devel@gnu.org, zhang cc <ccsmile2008@outlook.com>, >> > Noam Postavsky <npostavs@gmail.com> >> > From: Alan Mackenzie <acm@muc.de> > >> > > I see the error, with point anywhere in the body of the second function. >> > > Critical seems to be there being no blank line between the functions. > >> > > I think there's a bug in beginning-of-defun-comments, which I'm in the >> > > middle of edebugging. It moves point into the first function. > >> > beginning-of-defun-comments has a bug. On doing M-x >> > beginning-of-defun-comments from the inside of a function, when there's >> > no blank lines between it and the previous function, point ends up >> > inside that previous function, not at the comments which may separate >> > them. > >> > Perhaps this bug should be fixed before the next Emacs-26 pretest. > >> How old is this problem? It looks like it's new in Emacs 26? If so, >> we should try fixing it on the release branch. > > beginning-of-defun-comments came into existence on 2017-03-31, so this > problem is definitely new in Emacs 26. Yep, it was committed by me. Sorry for the mess. And I thought I had tested that thoroughly... > I've diagnosed the bug. At one place, it is necessary to scan a line of > text from BOL to detect any non-comment/non-space character. The > current code tries to do this by using parse-partial-sexp with the > fourth argument STOPBEFORE non-nil. > > This STOPBEFORE causes the scanning to stop at any character which > begins a sexp. A closing brace doesn't fit into this category. The > scan therefore reaches EOL, and the code therefore falsely assumes there > are no non-syntactic-ws characters on that line. > > I'm sure I can fix this today. Any success? If not, can I help in any way? (At the very least, I could write some more tests to cover this case.) Best, -- Marcin Borkowski ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2018-01-03 4:51 ` Marcin Borkowski @ 2018-01-03 16:24 ` Alan Mackenzie 2018-01-05 14:55 ` zhang cc 2018-03-26 6:57 ` Marcin Borkowski 0 siblings, 2 replies; 18+ messages in thread From: Alan Mackenzie @ 2018-01-03 16:24 UTC (permalink / raw) To: Marcin Borkowski; +Cc: Eli Zaretskii, ccsmile2008, npostavs, emacs-devel Hello, Marcin. On Wed, Jan 03, 2018 at 05:51:35 +0100, Marcin Borkowski wrote: > On 2017-12-30, at 14:05, Alan Mackenzie <acm@muc.de> wrote: > > On Sat, Dec 30, 2017 at 14:53:27 +0200, Eli Zaretskii wrote: > >> > Date: Sat, 30 Dec 2017 12:01:36 +0000 > >> > Cc: emacs-devel@gnu.org, zhang cc <ccsmile2008@outlook.com>, > >> > Noam Postavsky <npostavs@gmail.com> > >> > From: Alan Mackenzie <acm@muc.de> > >> > > I see the error, with point anywhere in the body of the second function. > >> > > Critical seems to be there being no blank line between the functions. > >> > > I think there's a bug in beginning-of-defun-comments, which I'm in the > >> > > middle of edebugging. It moves point into the first function. > >> > beginning-of-defun-comments has a bug. On doing M-x > >> > beginning-of-defun-comments from the inside of a function, when there's > >> > no blank lines between it and the previous function, point ends up > >> > inside that previous function, not at the comments which may separate > >> > them. > >> > Perhaps this bug should be fixed before the next Emacs-26 pretest. > >> How old is this problem? It looks like it's new in Emacs 26? If so, > >> we should try fixing it on the release branch. > > beginning-of-defun-comments came into existence on 2017-03-31, so this > > problem is definitely new in Emacs 26. > Yep, it was committed by me. Sorry for the mess. And I thought I had > tested that thoroughly... These things are tricky to test properly. ;-) > > I've diagnosed the bug. At one place, it is necessary to scan a line of > > text from BOL to detect any non-comment/non-space character. The > > current code tries to do this by using parse-partial-sexp with the > > fourth argument STOPBEFORE non-nil. > > This STOPBEFORE causes the scanning to stop at any character which > > begins a sexp. A closing brace doesn't fit into this category. The > > scan therefore reaches EOL, and the code therefore falsely assumes there > > are no non-syntactic-ws characters on that line. > > I'm sure I can fix this today. > Any success? If not, can I help in any way? (At the very least, > I could write some more tests to cover this case.) Sorry, I got distracted by the turn of the year, and one or two other things. Please try this: diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 6952ef4cf4..28605cd35c 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -405,12 +405,13 @@ beginning-of-defun--in-emptyish-line-p ;; See https://lists.gnu.org/r/help-gnu-emacs/2016-08/msg00141.html (save-excursion (forward-line 0) - (< (line-end-position) - (let ((ppss (syntax-ppss))) - (when (nth 4 ppss) - (goto-char (nth 8 ppss))) - (forward-comment (point-max)) - (point))))) + (let ((ppss (syntax-ppss))) + (and (null (nth 3 ppss)) + (< (line-end-position) + (progn (when (nth 4 ppss) + (goto-char (nth 8 ppss))) + (forward-comment (point-max)) + (point))))))) (defun beginning-of-defun-comments (&optional arg) "Move to the beginning of ARGth defun, including comments." @@ -428,10 +429,7 @@ beginning-of-defun-comments (progn (skip-syntax-backward "-" (line-beginning-position)) (not (bolp))) ; Check for blank line. - (progn (parse-partial-sexp - (line-beginning-position) (line-end-position) - nil t (syntax-ppss (line-beginning-position))) - (eolp))))) ; Check for non-comment text. + (beginning-of-defun--in-emptyish-line-p)))) ; Check for non-comment text. (forward-line (if first-line-p 0 1)))) (defvar end-of-defun-function > Best, > -- > Marcin Borkowski -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2018-01-03 16:24 ` Alan Mackenzie @ 2018-01-05 14:55 ` zhang cc 2018-01-06 12:00 ` Alan Mackenzie 2018-03-26 6:57 ` Marcin Borkowski 1 sibling, 1 reply; 18+ messages in thread From: zhang cc @ 2018-01-05 14:55 UTC (permalink / raw) To: Marcin Borkowski, Alan Mackenzie Cc: Eli Zaretskii, npostavs@gmail.com, emacs-devel@gnu.org [-- Attachment #1: Type: text/plain, Size: 1913 bytes --] On 4 Jan 2018, 12:28 AM +0800, Alan Mackenzie <acm@muc.de>, wrote: Sorry, I got distracted by the turn of the year, and one or two other things. Please try this: diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 6952ef4cf4..28605cd35c 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -405,12 +405,13 @@ beginning-of-defun--in-emptyish-line-p ;; See https://lists.gnu.org/r/help-gnu-emacs/2016-08/msg00141.html (save-excursion (forward-line 0) - (< (line-end-position) - (let ((ppss (syntax-ppss))) - (when (nth 4 ppss) - (goto-char (nth 8 ppss))) - (forward-comment (point-max)) - (point))))) + (let ((ppss (syntax-ppss))) + (and (null (nth 3 ppss)) + (< (line-end-position) + (progn (when (nth 4 ppss) + (goto-char (nth 8 ppss))) + (forward-comment (point-max)) + (point))))))) (defun beginning-of-defun-comments (&optional arg) "Move to the beginning of ARGth defun, including comments." @@ -428,10 +429,7 @@ beginning-of-defun-comments (progn (skip-syntax-backward "-" (line-beginning-position)) (not (bolp))) ; Check for blank line. - (progn (parse-partial-sexp - (line-beginning-position) (line-end-position) - nil t (syntax-ppss (line-beginning-position))) - (eolp))))) ; Check for non-comment text. + (beginning-of-defun--in-emptyish-line-p)))) ; Check for non-comment text. (forward-line (if first-line-p 0 1)))) (defvar end-of-defun-function Best, -- Marcin Borkowski -- Alan Mackenzie (Nuremberg, Germany). I applied the patch, and I can’t reproduce the problem now. But there is something I don’t known if it is intended. With the following c code, run mark-defun with cursor in the body of the second function, and the comment above of the function is also marked. int test_func1(int a) { int i; return 0; } /* * aa */ int test_func2(int a) { int i; return 0; } [-- Attachment #2: Type: text/html, Size: 3430 bytes --] ^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2018-01-05 14:55 ` zhang cc @ 2018-01-06 12:00 ` Alan Mackenzie 2018-01-06 13:54 ` zhang cc 2018-01-07 6:25 ` Marcin Borkowski 0 siblings, 2 replies; 18+ messages in thread From: Alan Mackenzie @ 2018-01-06 12:00 UTC (permalink / raw) To: zhang cc; +Cc: Eli Zaretskii, npostavs@gmail.com, emacs-devel@gnu.org Hello, Zhang, Eli, and Marcin. On Fri, Jan 05, 2018 at 14:55:54 +0000, zhang cc wrote: > On 4 Jan 2018, 12:28 AM +0800, Alan Mackenzie <acm@muc.de>, wrote: > I applied the patch, and I can’t reproduce the problem now. But there > is something I don’t known if it is intended. Thanks for doing this test. > With the following c code, run mark-defun with cursor in the body of > the second function, and the comment above of the function is also > marked. There was a long discussion about this and related matters on emacs-devel about a year ago, I think. I'm assuming that this marking of the preceding comment is in accordance with that thread on emacs-devel. > int test_func1(int a) > { > int i; > return 0; > } > /* > * aa > */ > int test_func2(int a) > { > int i; > return 0; > } I've committed the change to the emacs-26 branch. -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2018-01-06 12:00 ` Alan Mackenzie @ 2018-01-06 13:54 ` zhang cc 2018-01-07 6:25 ` Marcin Borkowski 1 sibling, 0 replies; 18+ messages in thread From: zhang cc @ 2018-01-06 13:54 UTC (permalink / raw) To: Alan Mackenzie; +Cc: Eli Zaretskii, npostavs@gmail.com, emacs-devel@gnu.org [-- Attachment #1: Type: text/plain, Size: 181 bytes --] On 6 Jan 2018, 8:04 PM +0800, Alan Mackenzie <acm@muc.de>, wrote: I've committed the change to the emacs-26 branch. -- Alan Mackenzie (Nuremberg, Germany). Ok. Thanks. [-- Attachment #2: Type: text/html, Size: 673 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2018-01-06 12:00 ` Alan Mackenzie 2018-01-06 13:54 ` zhang cc @ 2018-01-07 6:25 ` Marcin Borkowski 1 sibling, 0 replies; 18+ messages in thread From: Marcin Borkowski @ 2018-01-07 6:25 UTC (permalink / raw) To: Alan Mackenzie Cc: Eli Zaretskii, emacs-devel@gnu.org, npostavs@gmail.com, zhang cc On 2018-01-06, at 13:00, Alan Mackenzie <acm@muc.de> wrote: > There was a long discussion about this and related matters on > emacs-devel about a year ago, I think. I'm assuming that this marking of > the preceding comment is in accordance with that thread on emacs-devel. More or less, yes. The rationale is that in many languages, the comment preceding the function is basically its docstring. Thus marking the function should also mark that comment. > I've committed the change to the emacs-26 branch. Thanks a lot for working on this. Best, -- Marcin Borkowski ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2018-01-03 16:24 ` Alan Mackenzie 2018-01-05 14:55 ` zhang cc @ 2018-03-26 6:57 ` Marcin Borkowski 1 sibling, 0 replies; 18+ messages in thread From: Marcin Borkowski @ 2018-03-26 6:57 UTC (permalink / raw) To: Alan Mackenzie; +Cc: Eli Zaretskii, ccsmile2008, npostavs, emacs-devel [-- Attachment #1: Type: text/plain, Size: 312 bytes --] On 2018-01-03, at 17:24, Alan Mackenzie <acm@muc.de> wrote: > These things are tricky to test properly. ;-) Fair enough. But we should at least try to prepare a regression test when a bug pops its head. ;-) I attach a set of two patches wit such a test. WDYT? Best, -- Marcin Borkowski http://mbork.pl [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-a-more-general-tests-with-temp-buffer-macro.patch --] [-- Type: text/x-patch; size=2.61KiB, Size: 2671 bytes --] From fb6fa889ec026f2b5d265a043ae5c7e0813aa7c5 Mon Sep 17 00:00:00 2001 From: Marcin Borkowski <mbork@mbork.pl> Date: Tue, 6 Mar 2018 06:46:10 +0100 Subject: [PATCH 1/2] Add a more general "tests-with-temp-buffer" macro --- test/lisp/emacs-lisp/lisp-tests.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index 07eddb74d5..ec197602b6 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -307,12 +307,12 @@ backward-up-list-basic ;;; Helpers (eval-and-compile - (defvar elisp-test-point-position-regex "=!\\([a-zA-Z0-9-]+\\)=" + (defvar test-point-position-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) +(defmacro tests-with-temp-buffer (mode contents &rest body) "Create an `emacs-lisp-mode' enabled temp buffer with CONTENTS. BODY is the code to be executed within the temp buffer. Point is always located at the beginning of buffer. CONTENTS is an @@ -320,12 +320,12 @@ elisp-tests-with-temp-buffer of the form =!NAME= in CONTENTS are removed, and a for each one a variable called NAME is bound to the position of the word's start." - (declare (indent 1) (debug (def-form body))) + (declare (indent 2) (debug (def-form body))) (let* ((var-pos nil) (text (with-temp-buffer (insert (eval contents)) (goto-char (point-min)) - (while (re-search-forward elisp-test-point-position-regex nil t) + (while (re-search-forward test-point-position-regex nil t) (push (list (intern (match-string-no-properties 1)) (match-beginning 0)) var-pos) @@ -333,7 +333,7 @@ elisp-tests-with-temp-buffer (match-end 0))) (buffer-string)))) `(with-temp-buffer - (emacs-lisp-mode) + (,mode) (insert ,text) (goto-char (point-min)) (let ,var-pos @@ -341,6 +341,11 @@ elisp-tests-with-temp-buffer ,@(mapcar (lambda (v-p) `(ignore ,(car v-p))) var-pos) ,@body)))) +(defmacro elisp-tests-with-temp-buffer (contents &rest body) + "Use TESTS-WITH-TEMP-BUFFER with Emacs Lisp mode." + (declare (indent 1) (debug (def-form body))) + `(tests-with-temp-buffer emacs-lisp-mode ,contents ,@body)) + ;;; mark-defun (eval-and-compile -- 2.16.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-Add-a-regression-test-for-beginning-of-defun-comment.patch --] [-- Type: text/x-patch; size=1.09KiB, Size: 1116 bytes --] From 098f49607e19a3246b087afbebb624a3736ef300 Mon Sep 17 00:00:00 2001 From: Marcin Borkowski <mbork@mbork.pl> Date: Mon, 19 Mar 2018 06:17:31 +0100 Subject: [PATCH 2/2] Add a regression test for `beginning-of-defun-comments` --- test/lisp/emacs-lisp/lisp-tests.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index ec197602b6..b456a65737 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -372,6 +372,26 @@ elisp-tests-with-temp-buffer " "Test buffer for `mark-defun'.")) +(ert-deftest mark-defun-c-mode () + "Test `mark-defun` in C mode." + (setq last-command nil) + (tests-with-temp-buffer c-mode + "int test_func1(int a) +{ + int i; + + return 0; +} +=!beg-of-defun=int test_func2(int a) +{ + int i=!inside-2=; + + return 0; +}" + (goto-char inside-2) + (mark-defun) + (should (= (point) beg-of-defun)))) + (ert-deftest mark-defun-no-arg-region-inactive () "Test `mark-defun' with no prefix argument and inactive region." -- 2.16.2 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 12:53 ` Eli Zaretskii 2017-12-30 13:05 ` Alan Mackenzie @ 2017-12-30 15:43 ` Alan Mackenzie 2017-12-30 18:43 ` Stephen Leake 2017-12-31 4:26 ` Stefan Monnier 1 sibling, 2 replies; 18+ messages in thread From: Alan Mackenzie @ 2017-12-30 15:43 UTC (permalink / raw) To: Eli Zaretskii; +Cc: ccsmile2008, npostavs, Stefan Monnier, emacs-devel Hello, Eli. On Sat, Dec 30, 2017 at 14:53:27 +0200, Eli Zaretskii wrote: > > Date: Sat, 30 Dec 2017 12:01:36 +0000 > > Cc: emacs-devel@gnu.org, zhang cc <ccsmile2008@outlook.com>, > > Noam Postavsky <npostavs@gmail.com> > > From: Alan Mackenzie <acm@muc.de> > > > I see the error, with point anywhere in the body of the second function. > > > Critical seems to be there being no blank line between the functions. > > > I think there's a bug in beginning-of-defun-comments, which I'm in the > > > middle of edebugging. It moves point into the first function. > > beginning-of-defun-comments has a bug. On doing M-x > > beginning-of-defun-comments from the inside of a function, when there's > > no blank lines between it and the previous function, point ends up > > inside that previous function, not at the comments which may separate > > them. > > Perhaps this bug should be fixed before the next Emacs-26 pretest. > How old is this problem? It looks like it's new in Emacs 26? If so, > we should try fixing it on the release branch. OK. I've hacked together the following, which seems to work, but I'm not altogether happy with it. non-syntactic-ws-in-line should not be so hard to write; ideally, it should be available directly from parse-partial-sexp, possibly by enhancing the meaning of argument STOPBEFORE. Also, non-syntactic-ws-in-line doesn't really seem to belong in this file. Possibly it should be in syntax.el. I also think somebody else should eyeball non-syntactic-ws-in-line to try and catch some wierd case I've missed. The following is based on the emacs-26 branch. diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 6952ef4cf4..251db2cb08 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -412,6 +412,35 @@ beginning-of-defun--in-emptyish-line-p (forward-comment (point-max)) (point))))) +(defun non-syntactic-ws-in-line () + "Is there a non-whitespace, non-comment character in the current line? +If so, return the position of the first such character, otherwise return + nil." + (save-excursion + (forward-line 0) ; to BOL. + (let ((ppss (syntax-ppss)) + (eol (save-excursion (end-of-line) (point))) + (start (point)) + end + ) + (if (nth 3 ppss) ; in a string + start + (when (nth 4 ppss) ; in a comment + (setq ppss + (parse-partial-sexp (point) eol nil nil ppss 'syntax-table))) + (catch 'got-it + (while (< (point) eol) + (setq start (point)) + (setq ppss (parse-partial-sexp (point) eol nil nil ppss t)) + (setq end (if (nth 4 ppss) (nth 8 ppss) eol)) + (goto-char start) + (skip-syntax-forward "-" end) + (when (< (point) end) + (throw 'got-it (point))) + (unless (forward-comment 1) ; comment straddles line break. + (throw 'got-it nil)) + (setq ppss (syntax-ppss)))))))) + (defun beginning-of-defun-comments (&optional arg) "Move to the beginning of ARGth defun, including comments." (interactive "^p") @@ -428,10 +457,7 @@ beginning-of-defun-comments (progn (skip-syntax-backward "-" (line-beginning-position)) (not (bolp))) ; Check for blank line. - (progn (parse-partial-sexp - (line-beginning-position) (line-end-position) - nil t (syntax-ppss (line-beginning-position))) - (eolp))))) ; Check for non-comment text. + (not (non-syntactic-ws-in-line))))) ; Check for non-comment text. (forward-line (if first-line-p 0 1)))) (defvar end-of-defun-function -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 15:43 ` Alan Mackenzie @ 2017-12-30 18:43 ` Stephen Leake 2017-12-31 10:55 ` Alan Mackenzie 2017-12-31 4:26 ` Stefan Monnier 1 sibling, 1 reply; 18+ messages in thread From: Stephen Leake @ 2017-12-30 18:43 UTC (permalink / raw) To: emacs-devel Alan Mackenzie <acm@muc.de> writes: > + (eol (save-excursion (end-of-line) (point))) You can use `line-end-position' for this. -- -- Stephe ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 18:43 ` Stephen Leake @ 2017-12-31 10:55 ` Alan Mackenzie 0 siblings, 0 replies; 18+ messages in thread From: Alan Mackenzie @ 2017-12-31 10:55 UTC (permalink / raw) To: Stephen Leake; +Cc: emacs-devel Hello, Stephen. On Sat, Dec 30, 2017 at 12:43:02 -0600, Stephen Leake wrote: > Alan Mackenzie <acm@muc.de> writes: > > + (eol (save-excursion (end-of-line) (point))) > You can use `line-end-position' for this. Thanks! I thought there was some function like that, but I couldn't find `end-of-line-position', so gave up looking. As it turns out, there's an already existing function beginning-of-defun--in-emptyish-line-p in the same place in the code which I ought to have spotted and used, which I surely will use in the near future. > -- > -- Stephe -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-30 15:43 ` Alan Mackenzie 2017-12-30 18:43 ` Stephen Leake @ 2017-12-31 4:26 ` Stefan Monnier 2017-12-31 10:50 ` Alan Mackenzie 1 sibling, 1 reply; 18+ messages in thread From: Stefan Monnier @ 2017-12-31 4:26 UTC (permalink / raw) To: Alan Mackenzie; +Cc: Eli Zaretskii, ccsmile2008, npostavs, emacs-devel > + (if (nth 3 ppss) ; in a string > + start > + (when (nth 4 ppss) ; in a comment > + (setq ppss > + (parse-partial-sexp (point) eol nil nil ppss 'syntax-table))) > + (catch 'got-it > + (while (< (point) eol) > + (setq start (point)) > + (setq ppss (parse-partial-sexp (point) eol nil nil ppss t)) > + (setq end (if (nth 4 ppss) (nth 8 ppss) eol)) > + (goto-char start) > + (skip-syntax-forward "-" end) > + (when (< (point) end) > + (throw 'got-it (point))) > + (unless (forward-comment 1) ; comment straddles line break. > + (throw 'got-it nil)) > + (setq ppss (syntax-ppss)))))))) Why not use something like (>= (forward-comment (point-max)) (line-end-position)) ? Stefan ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] 2017-12-31 4:26 ` Stefan Monnier @ 2017-12-31 10:50 ` Alan Mackenzie 0 siblings, 0 replies; 18+ messages in thread From: Alan Mackenzie @ 2017-12-31 10:50 UTC (permalink / raw) To: Stefan Monnier; +Cc: Eli Zaretskii, emacs-devel, npostavs, ccsmile2008 Hello, Stefan. On Sat, Dec 30, 2017 at 23:26:24 -0500, Stefan Monnier wrote: > > + (if (nth 3 ppss) ; in a string > > + start > > + (when (nth 4 ppss) ; in a comment > > + (setq ppss > > + (parse-partial-sexp (point) eol nil nil ppss 'syntax-table))) > > + (catch 'got-it > > + (while (< (point) eol) > > + (setq start (point)) > > + (setq ppss (parse-partial-sexp (point) eol nil nil ppss t)) > > + (setq end (if (nth 4 ppss) (nth 8 ppss) eol)) > > + (goto-char start) > > + (skip-syntax-forward "-" end) > > + (when (< (point) end) > > + (throw 'got-it (point))) > > + (unless (forward-comment 1) ; comment straddles line break. > > + (throw 'got-it nil)) > > + (setq ppss (syntax-ppss)))))))) > Why not use something like > (>= (forward-comment (point-max)) (line-end-position)) > ? Indeed. Why not just use beginning-of-defun--in-emptyish-line-p, which is in the same file, in the same place as I coded non-syntactic-ws-in-line, yet I failed to notice it? It is also somewhat more elegantly coded than my new function. However, beginning-of-defun--in-emptyish-line-p isn't quite right, in that it fails to check whether BOL is inside a string. Something like the following (untested) should fix it: (defun beginning-of-defun--in-emptyish-line-p () "Return non-nil if the point is in an \"emptyish\" line. This means a line that consists entirely of comments and/or whitespace." ;; See https://lists.gnu.org/r/help-gnu-emacs/2016-08/msg00141.html (save-excursion (forward-line 0) (let ((ppss (syntax-ppss))) (and (null (nth 3 ppss)) (< (line-end-position) (progn (when (nth 4 ppss) (goto-char (nth 8 ppss))) (forward-comment (point-max)) (point))))))) Happy New Year! > Stefan -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2018-03-26 6:57 UTC | newest] Thread overview: 18+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-12-30 9:49 26.0.90: mark-defun problem in c-mode zhang cc 2017-12-30 10:30 ` Eli Zaretskii 2017-12-30 10:34 ` Alan Mackenzie 2017-12-30 12:01 ` beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] Alan Mackenzie 2017-12-30 12:53 ` Eli Zaretskii 2017-12-30 13:05 ` Alan Mackenzie 2018-01-03 4:51 ` Marcin Borkowski 2018-01-03 16:24 ` Alan Mackenzie 2018-01-05 14:55 ` zhang cc 2018-01-06 12:00 ` Alan Mackenzie 2018-01-06 13:54 ` zhang cc 2018-01-07 6:25 ` Marcin Borkowski 2018-03-26 6:57 ` Marcin Borkowski 2017-12-30 15:43 ` Alan Mackenzie 2017-12-30 18:43 ` Stephen Leake 2017-12-31 10:55 ` Alan Mackenzie 2017-12-31 4:26 ` Stefan Monnier 2017-12-31 10:50 ` Alan Mackenzie
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.