center-text-inside-comment

Asked by Andreas Roehler on 2012-07-26

http://stackoverflow.com/questions/11651604/how-to-center-text-in-emacs

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

Question information

Language:
English Edit question
Status:
Solved
For:
Emacs Werkstatt Edit question
Assignee:
No assignee Edit question
Last query:
2012-07-26
Last reply:
Andreas Roehler (a-roehler) said : #1

Am 26.07.2012 09:56, schrieb Andreas Roehler:
> New question #204235 on S-X-Emacs Werkstatt:
> https://answers.launchpad.net/s-x-emacs-werkstatt/+question/204235
>
> http://stackoverflow.com/questions/11651604/how-to-center-text-in-emacs
>
>
> 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 -->
>
>
>

M-x query-replace-regexp RET
^\(<!--\([ ]+\)\([^ ]+\)\(.+\)\([^ ]+\)\([ ]+\)-->\)
RET
\,(concat "<!--" (make-string (/ (abs (- (length \0) (+ (length \2)(length \3)(length \4)) 7))2) 32) \2 \3 \4 (make-string (/ (abs (- (length \0) (+ (length \2)(length
\3)(length \4)) 7))2) 32) "-->")
RET

Andreas Roehler (a-roehler) said : #2

comments still hardcoded, just an example