Folding multi-line comments in emacs automatically

in my .emacs configuration, I have the following:

(defun fold-long-comment-lines ()
"This functions allows us to fold long comment lines
 automatically in programming modes. Quite handy."
 (auto-fill-mode 1)
 (set (make-local-variable 'fill-no-break-predicate)
     (lambda ()
         (not (eq (get-text-property (point) 'face)
                'font-lock-comment-face)))))

the above is called as part of the "c-mode-common-hook" and correctly provides automatic folding of long comment lines.

however, the above thing works indiscriminately, regardless of whether I use one line comment, for example. a description of the structure fields or multi-line comments describing a complex piece of code.

So, the main question: how can I automatically add long lines of comments only if it is a multi-line comment?

thanks Anupam

edit-1: explanation of several lines when I say "multi-line comment", it basically means comments like this:

/*
 * this following piece of code does something totally funky with client
 * state, but it is ok.
*/
code follows

a respectively, a single line comment would be something like this

struct foo {
   char buf_state : 3; // client protocol state 
   char buf_value : 5; // some value
}

elisp, . , .

+3
1

, auto-fill-mode, (, M-q), comment-auto-fill-only-comments. , " ", , , . , , , - , Emacs , , , .

- :

(set (make-local-variable 'fill-no-break-predicate)
     (lambda ()
       (let ((ppss (syntax-ppss)))
         (or (null (nth 4 ppss)) ;; Not inside a comment.
             (save-excursion
               (goto-char (nth 8 ppss))
               (skip-chars-backward " \t")
               (not (bolp))))))) ;; Comment doesn't start at indentation.
+1

All Articles