emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple bugs in lisp-mode M-q on paragraphs within #|..|# comments


From: martin rudalics
Subject: Re: Multiple bugs in lisp-mode M-q on paragraphs within #|..|# comments
Date: Sun, 25 Mar 2007 12:18:17 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

>    Then the problem is with the following stretch of code in
>    `fill-paragraph':
>
>      (and fill-paragraph-handle-comment
>          ;; Our code only handles \n-terminated comments right now.
>          comment-start (equal comment-end "")
>          (let ((fill-paragraph-handle-comment nil))
>            (fill-comment-paragraph arg)))
>
>    We have to find something more intelligent here.
>
> Is this really the place?  If I add a call to error just before the
> fill-comment-paragraph call, none of the four bugs cause it to be
> called.

Correct.  But what I wanted to express was that `fill-comment-paragraph'
will get it wrong for a block comment.  The following part is used to
find the end of the region to fill by searching for `comment-re' at the
begin of every line which fails for block comments.

             ;; Find the beginning of the first line past the region to fill.
             (save-excursion
               (while (progn (forward-line 1)
                             (looking-at comment-re)))

>    It might be better to recognize Lisp "#|...|#" comments explicitly at
> a point where we know we're dealing with Lisp.  The attached patch is a
> total hack, but it seems to relieve the symptoms of the first three bugs
> (and changes that of the fourth).  This style of comment can be nested,
> so the hack will get confused if still inside a comment but after an
> inner comment.  The changed symptoms of the fourth bug suggest that the
> bounds passed to the fill-region-as-paragraph call are wrong.  But I'll
> bet someone else can do better.

I'm afraid this problem is not restricted to the Lisp case.  I think we
should modify `fill-comment-paragraph' to

(1) check whether the current major mode allows comments that are not
terminated by a newline,

(2) if (1) applies parse whether we are in such a comment or a nested
comment, and

(3) call `fill-comment-paragraph' iff (2) doesn't apply.

Anyway please try the attached patch.  I'm confident Stefan will find
a better solution soon.
*** lisp-mode.el        Fri Mar  9 06:48:38 2007
--- lisp-mode.el        Sun Mar 25 12:12:38 2007
***************
*** 1246,1252 ****
  paragraph of it that point is in, preserving the comment's indentation
  and initial semicolons."
    (interactive "P")
!   (or (fill-comment-paragraph justify)
        ;; Since fill-comment-paragraph returned nil, that means we're not in
        ;; a comment: Point is on a program line; we are interested
        ;; particularly in docstring lines.
--- 1246,1258 ----
  paragraph of it that point is in, preserving the comment's indentation
  and initial semicolons."
    (interactive "P")
!   (or (and (equal major-mode 'lisp-mode)
!          (let ((state (syntax-ppss (point))))
!            (and (nth 4 state) (eq (nth 7 state) t)))
!          (let ((comment-end "|#")) 
!            (fill-paragraph justify)
!            t))
!       (fill-comment-paragraph justify)
        ;; Since fill-comment-paragraph returned nil, that means we're not in
        ;; a comment: Point is on a program line; we are interested
        ;; particularly in docstring lines.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]