0

Emacs displays the code snippet as shown below.

    <header>
      <nav>
        <ul>
          <li>About</li>
          <li>Code review</li>
          <li>Projects</li>
        </ul>
      </nav>
    </header>

Web browsers display the code snippet as shown below.

    <header>
      <nav>
    <ul>
      <li>About</li>
      <li>Code review</li>
      <li>Projects</li>
    </ul>
      </nav>
    </header>

I like to browse the source code of Web pages in my browser (Ctrl + U | View Source).

Is there anything I can do to make the code display with proper indentation in Web browsers?

6
  • Use spaces to indent code. Or set same width for the tab both for emacs and web browser view source.
    – Maxim Kim
    Oct 9, 2023 at 8:45
  • Welcome to Emacs.SE! Is your question about Emacs, or about web browsers? If the latter, this is the wrong forum for your question.
    – Dan
    Oct 9, 2023 at 8:49
  • @MaximKim: Thanks a lot! I'll answer my question.
    – gilaro
    Oct 9, 2023 at 9:17
  • @Dan: Yes, my question is about Emacs. I used to be a regular Emacs Stack Exchange user in the past.
    – gilaro
    Oct 9, 2023 at 9:38
  • Is this actually about emacs? It sounds like you want your web browser to act differently, not emacs; if so, this doesn't seem like an emacs question.
    – Dan Drake
    Oct 11, 2023 at 20:41

1 Answer 1

1

The HTML source code is indented with tabs and spaces. It seems that you need to modify the local variable indent-tabs-mode. For simplicity's sake, I've created a directory local variable.

;; File: .dir-locals.el
;;; Directory Local Variables            -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables")

((mhtml-mode . ((indent-tabs-mode . nil))))

But it didn't work in my configuration (remote connection using Tramp). The manual explains that you also need to enable searching for remote connections by modifying the variable enable-remote-dir-locals.

;; File: .emacs
(setq enable-remote-dir-locals t)

See also: Javascript mode mixes tabs and spaces for indent

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.