Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-C-style comments are filled incorrectly #76

Closed
NateEag opened this issue Mar 9, 2013 · 13 comments
Closed

Non-C-style comments are filled incorrectly #76

NateEag opened this issue Mar 9, 2013 · 13 comments
Labels

Comments

@NateEag
Copy link
Member

NateEag commented Mar 9, 2013

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.

@ejmr
Copy link
Collaborator

ejmr commented Mar 9, 2013

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.

@NateEag
Copy link
Member Author

NateEag commented Mar 9, 2013

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).

@ejmr
Copy link
Collaborator

ejmr commented Mar 9, 2013

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.

@NateEag
Copy link
Member Author

NateEag commented Mar 9, 2013

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.

@ejmr
Copy link
Collaborator

ejmr commented Mar 12, 2013

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.

@NateEag
Copy link
Member Author

NateEag commented Mar 13, 2013

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.

@ejmr
Copy link
Collaborator

ejmr commented Mar 13, 2013

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.

@tigerhawkvok
Copy link

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?

@ejmr
Copy link
Collaborator

ejmr commented Jun 13, 2014

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

@metaturso
Copy link

@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

@NateEag
Copy link
Member Author

NateEag commented Feb 14, 2016

@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.

@zonuexe
Copy link
Member

zonuexe commented Mar 8, 2023

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 zonuexe closed this as completed Mar 8, 2023
@NateEag
Copy link
Member Author

NateEag commented Mar 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants