How to center text in Emacs?

centering, emacs, text

Solution

I've connected the dots below as an interactive command. @nicolasdudebout's algorithm is more or less sound with the addition that a "hard" `move-to-column` is needed to select the rectangle.

select your interesting (without arrows) rectangle and run:

(defun center-rectangle (beg end)
  (interactive "*r")
  (kill-rectangle beg end)
  (with-temp-buffer
    (yank-rectangle)
    (setq fill-column (current-column))
    (center-region (point-min) (point-max))
    (goto-char (point-max))
    (move-to-column fill-column t)
    (kill-rectangle (point-min) (point)))
  (goto-char beg)
  (yank-rectangle))

Problem

Is it possible in Emacs to transform this: ``` <!-- inclusion du code JavaScript --> <!-- inclusion des feuilles de style --> <!-- definition du ZHO --> ``` into this (approximate): ``` <!-- inclusion du code JavaScript --> <!-- inclusion des feuilles de style --> <!-- definition du ZHO --> ```

Original source