1

Consider the following php function:

public function test(array $a, SomeObject $b)
{
  return 0;
}

I would like to automatically generate the following code block:

/**
 * @param  array       $a
 * @param  SomeObject  $b
 * @return int
 */
public function test(array $a, SomeObject $b)
{
  return 0;
}

Also, after modifying the code block, I would like to reformat the code block so that all the types, names and documentation are aligned as columns e.g. if the type of SomeObject changes to SomeOtherObject, the line with the variable $a is also updated with the required spaces:

/**
 * @param  array       _____$a  // 5 spaces added to align $a with $b
 * @param  SomeOtherObject  $b
 * @return int
 */
public function test(array $a, SomeOtherObject $b)
{
  return 0;
}

Is there a minor mode available that does this?

I have looked at: Is there a yasnippet producing a prepopulated doxygen comment?, but it relies on doxymacs which I believe is not maintained anymore.

2 Answers 2

1

You could try something like this:

(defun align-doxi ()
  (interactive)
  (save-excursion
    (let ((begin (re-search-backward "/\\*"))
          (end (re-search-forward "\\*/"))
          (re "@param\\s-+\\w+")
          indents max-indent)
      (goto-char begin)
      (while (and (< (point) end)
                  (re-search-forward re end t))
        (push (1+ (current-column)) indents))
      (setf max-indent (apply 'max indents))
      (goto-char begin)
      (while (and (< (point) end)
                  (re-search-forward re end t))
        (delete-horizontal-space)
        (insert (make-string (- max-indent (current-column)) ?\ ))))))

It worked with the examples I could think of. Let me know if I missed anything.

1

There is doxymacs. I set it up and it works fine. Has bunch of comment types defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.