1

I have the following lines activated:

(setq indent-tabs-mode nil)
(setq tab-width 1)
(setq web-mode-markup-indent-offset 1)
(setq web-mode-css-indent-offset 1)
(setq web-mode-code-indent-offset 1)

but when I do C-x h then indent-region, it does indent it with 4 spaces everywhere, when I do tab on a line, it sets line indentation to 2 spaces(relevant to other lines). What am I doing wrong? I also didn't find anything useful in M-x customize

thanks

5
  • What does M-: (featurep 'web-mode) RET tell you? What does M-: major mode RET (run in the HTML file buffer) tell you?
    – NickD
    Feb 29 at 13:28
  • 1
    NickD the first one is t the second one is major-mode gave me web-mode Feb 29 at 13:40
  • What does C-h v indent-line-function say?
    – NickD
    Feb 29 at 15:08
  • 1
    It says: ``` indent-line-function is a variable defined in ‘indent.el’. Its value is ‘web-mode-indent-line’ Local in buffer checkout.html; global value is indent-relative (description)... ``` Feb 29 at 15:29
  • Not sure why you are getting this. I cannot reproduce it with a minimal init file and a minimal HTML file - see my answer for details.
    – NickD
    Feb 29 at 16:11

2 Answers 2

1

With a minimal init file foo.el like this:

(add-to-list 'load-path "~/.config/emacs/elpa/web-mode-17.3.17/")

(require 'web-mode)

(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))

(setq indent-tabs-mode nil)
(setq tab-width 1)
(setq web-mode-markup-indent-offset 1)
(setq web-mode-css-indent-offset 1)
(setq web-mode-code-indent-offset 1)

a minimal HTML file foo.html like this:

<!DOCTYPE html>
<html lang="en-us" >
<head>
<title>Title</title>
  
<link rel="stylesheet" type="text/css" href="../css/base.css" />
<script type="text/javascript" src="../js/base.js"></script>
<meta charset="utf-8" name="robots" content="NONE,NOARCHIVE" />
</head>
<body class="">
Body
</body>
</html>

and starting emacs like this:

emacs -Q -l foo.el foo.html

indenting either with C-x h C-M-\ or with TABs on each line gives me this:

<!DOCTYPE html>
<html lang="en-us" >
 <head>
  <title>Title</title>
  
  <link rel="stylesheet" type="text/css" href="../css/base.css" />
  <script type="text/javascript" src="../js/base.js"></script>
  <meta charset="utf-8" name="robots" content="NONE,NOARCHIVE" />
 </head>
 <body class="">
  Body
 </body>
</html>

All I can suggest is that the rest of your init file is causing the problem, so maybe try with -Q and a minimal init as above (but adjust the load-path appropriately for your setup).

0

One better-than-nothing solution would be: C-x h M-: (indent-region-line-by-line (region-beginning) (region-end)) RET

At least it works for me with those variables( (setq web-mode-code-indent-offset 1) )

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.