Is there a similar command to comment-kill that kills all comments in a given region and saves them to the kill ring?

  • 1
    You can narrow to region, put point at the beginning of the region, and call comment-kill with a large numeric prefix-arg. Pitingly that does not concatenate all kills. You can reach that with the following advice (caution: hacky!): (defun comment-kill-ad (fun &rest args) (kill-new "") (let ((last-command 'kill-region)) (apply fun args))) (advice-add 'comment-kill :around 'comment-kill-ad)
    – Tobias
    Sep 3, 2019 at 10:52
  • 2
    Presumably you don't just want to kill the region or copy it to the kill-ring. Instead, you want to kill only the comments in the region. Do you want them concatenated in the kill-ring, as one ring entry? Or do you want each comment to be a separate kill-ring entry. The question could be clearer.
    – Drew
    Sep 3, 2019 at 15:47

1 Answer 1

   (defun ar-kill-comment-atpt ()
      "Deletes comment at point if any. "
      (interactive "*")
      (ar-th-kill 'comment))

Requires stuff from https://github.com/andreas-roehler/thingatpt-utils-core providing the ar-th-kill basics.

Deletes all comments at point. Narrow to region before in order to restrict.

Your Answer

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

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