Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to indent 4 spaces under SGML mode

Tags:

emacs

You know under SGML mode (PSGML) Emacs could indent the XML buffer automatically.

C-x-h ;; Select all
M-C-\ ;; Indent

But all the indent was 2 spaces. How can I set to make auto indent to 4 spaces?

I tried (setq-default sgml-indent-step 4), but it doesn't work.

Current view is:

<TESTCASE>
  <NAME>00001<NAME>
  <TIMEOUT>600000</TIMEOUT>

My expectation is

<TESTCASE>
    <NAME>00001<NAME>
    <TIMEOUT>600000</TIMEOUT>

Thanks!

Using GNU Emacs 22.2.1 (i386-mingw-nt5.1.2600)
of 2008-03-26 on RELEASE

like image 456
Buzz Avatar asked Nov 29 '22 20:11

Buzz


1 Answers

You're looking for sgml-basic-offset

Edit: Actually, I should add how I figured that out. No one should understate the power that a self-documented editor provides:

Open an sgml document

C-h k tab says it's bound to a function that looks at variable indent-line-function.

C-h v indent-line-function told me to look at function sgml-indent-line

C-h f sgml-indent-line told me very little. Nothing really. But it also provided where it was implemented.

Well, looking at the implementation, I found that it's using sgml-calculate-indent. That's the meat of the algorithm... Go down and you can find the tag case, where the last element does

(+ (current-column) sgml-basic-offset)

A quick C-h v sgml-basic-offset will make sure we're looking at the one variable that is supposed to be customized. It indeed is.

like image 151
Bahbar Avatar answered Dec 06 '22 23:12

Bahbar