php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

Non-C-style comments are filled incorrectly

Open NateEag opened this issue 11 years ago • 11 comments

Consider the following set of comments:

// This is a test comment. If I get it to go a very long way, my autowrapping will work, but you will find that Meta-Q will
// not fill the comment correctly.

# What happens when I write a lengthy comment prefixed by the # symbol? I am not sure, but I guess I am about to find out.

/* However, something very similar will actually work exactly the way you would expect it to in a C-style comment. Any ideas why this is?
 */

All three are correctly highlighted as comments by php-mode.

However, if you use Meta-Q to wrap the comments, only the last comment is filled correctly. The first two are wrapped, but no comment prefix is inserted at the beginning of the new lines.

NateEag avatar Mar 09 '13 04:03 NateEag

What version of Emacs and php-mode are you using?

M-q works for the first and third comments for me, although when I M-q the first there is a brief moment where Flymake thinks the code is in error. But it still adds the // prefix.

The second comment screws up on M-q for me in the same way it does for you.

ejmr avatar Mar 09 '13 18:03 ejmr

I'm using Aquamacs 2.4, which is built on Emacs 23.3.50.1.

My php-mode.el has the following version info in it:

(defconst php-mode-version-number "1.10"
  "PHP Mode version number.")

(defconst php-mode-modified "2013-02-15"
  "PHP Mode build date.")

I believe it is current master (I use subtree merging to pull it into my .emacs.d, which is a git repo).

NateEag avatar Mar 09 '13 19:03 NateEag

I believe it is current master...

It is. Thanks for the info. I have no access to a computer which Aquamacs but I'll try getting a friend to see if he can duplicate it.

ejmr avatar Mar 09 '13 19:03 ejmr

I just tried firing up an instance of Emacs 24, freshly downloaded from Emacs for OS X, and in Emacs 24, I see the behavior you describe.

So, that difference is probably a discrepancy between Emacs 23 and 24.

NateEag avatar Mar 09 '13 20:03 NateEag

Here's what I've figured out so far, just in case anyone else whats to pitch in.

I started looking at the code in sh-script.el.gz because it handles comments beginning with # in the way we want for php-mode. It gives the # character a slightly different syntax class, but when I tried copying that in php-mode it did not work. That mode also sets the local variable comment-start to the string "# ", but I doubt we want to do this either. The shell script mode has the benefit of only dealing with one style of comments, while we have to support three.

But I still feel like some tweaking to the syntax class of # is the solution to this. I just haven't exactly figured it out yet.

ejmr avatar Mar 12 '13 23:03 ejmr

Thanks very much for looking into this.

Maybe looking at C++-mode's innards would help? Filling both /*- and //-style comments works as expected there, so it might give useful hints on how to handle #, too.

NateEag avatar Mar 13 '13 00:03 NateEag

Thanks very much for looking into this.

No problem, it's my job. :)

Maybe looking at C++-mode's innards would help?

That's a good idea. I'll check it out.

ejmr avatar Mar 13 '13 00:03 ejmr

Maybe a hacky way to approach this would be to see if a fill was triggered on a #-style comment, then if so, manually prefix the line for now?

tigerhawkvok avatar Jun 10 '14 21:06 tigerhawkvok

Like (defadvice c-fill-paragraph ...)? That could be a viable band aid.

ejmr avatar Jun 13 '14 00:06 ejmr

@NateEag I've found that all three styles of comment can be indented correctly after you evaluate this form:

;; this is the relevant bit, you'll notice it's adding # as a comment start char
(setq-local comment-start-skip "\\(//+\\|#+\\|/[*]\\{1,2\\}\\)\\s *") 

I'll write a php-mode test and raise a PR this weekend if you're happy with the fix. In the meanwhile you can solve the problem by adding that configuration to your php-mode-hook.

Here's a gif showing the behaviour of Emacs 24.5.1 before and after evaluating the form above: php-mode-76

metaturso avatar Feb 12 '16 10:02 metaturso

@trashofmasters I am not actively using php-mode these days, but thanks for the info. Glad to hear you've found a workaround for this.

NateEag avatar Feb 14 '16 20:02 NateEag

I wasn't aware of this issue, but maybe https://github.com/emacs-php/php-mode/pull/530/files seems to fix this issue. Thanks for reporting!

zonuexe avatar Mar 08 '23 14:03 zonuexe

You're very welcome. Thanks for your years of faithful maintenance, @zonuexe !

NateEag avatar Mar 08 '23 14:03 NateEag