4

In web-mode, indentation for markup gets set to 8 when I open a new buffer.

I have set web-mode-indent-markup-indent-offset via customize to 2. When I check it outside of a web-mode buffer, it is set to 2.

Lines concerning web-mode in my .emacs:

(mapcar (lambda (plugin-dir)
          (add-to-list 'load-path (concat "~/.emacs.d/plugins/" plugin-dir)))
        '( ;; ... some more plugins
          "web-mode"))

(add-hook 'web-mode-hook 'zencoding-mode)

(custom-set-variables
 ;; ...
 '(web-mode-markup-indent-offset 2)
 ;; ...
 )

(require 'web-mode)

(mapcar (lambda (file-ending)
          (add-to-list 'auto-mode-alist (cons file-ending 'web-mode)))
        '("\\.php\\'" "\\.ejb\\'" "\\.django\\'" "\\.tt\\'" "\\.html\\'"))

(define-key web-mode-map (kbd "C-c /") 'web-mode-element-close)

(defun expand-for-web-mode ()
  (when (equal mode-name "Web")
    (make-local-variable 'yas-extra-modes)
    (setq yas-extra-modes
          (let ((web-lang (web-mode-language-at-pos)))
            (cond
             ((equal web-lang "html")       '(html-mode))
             ((equal web-lang "css")        '(css-mode))
             ((equal web-lang "javascript") '(javascript-mode))
             )))))

(add-hook 'yas-before-expand-snippet-hook 'expand-for-web-mode)

Furthermore, I use expand-region. It sets a hook to web-mode, but the hook just adds web-mode-mark-and-expand to a local er/try-expand-list variable.

I have tried a "minimal" configuration, by starting Emacs via emacs -q and just loading and requiring web-mode and setting the variable to 2 - same result.

Every time I enter a web-mode buffer it gets set locally to 8.

I know I could use a hook like this:

(add-hook 'web-mode-hook
  (lambda () ""
    (setq web-mode-markup-indent-offset 2)))

To set it to 2, but that defeats the purpose of customize.

  • Are you using the latest version of web-mode? (If not you can try installing it directly from the GitHub repo.) – Scott Weldon Jun 3 '15 at 16:59
  • If you are using the latest version, or if doing so doesn't help, then I suggest opening an issue at the GitHub repo. The author is usually very fast about responding, and getting problems fixed. – Scott Weldon Jun 3 '15 at 17:01
  • I am using the latest version of web-mode (11.2.2), but my emacs is the system emacs (24.4.1 on LMDE2 (Betsy)). l'll open an issue on github tomorrow. Thanks. – Patrick J. S. Jun 4 '15 at 1:23
5

Does adding (setq-default indent-tabs-mode nil)change anything ?

  • 1
    Yes! I changed it with customize, but it works. Thank you. Is that a bug that I should report? – Patrick J. S. Jun 4 '15 at 10:38
  • Likely not, web-mode was likely indenting with 2 tabs, and the variable tab-width was probably was probably a high value like 4 or 8 which made it look wrong. Just a guess though, @fxbois would know better than I. – Jordon Biondo Jun 4 '15 at 13:04
  • I do not understand why indent-tabs-mode is t by default – fxbois Jun 4 '15 at 19:14
  • @fxbois: just a guess. But seriously, yes you answered my question, but could you elaobrate on the why? – Patrick J. S. Jun 7 '15 at 1:58
  • While this change may be the "right this to do" given indent-tabs-mode purpose, this commit, as far as I know, prevents web-mode from respecting buffer local values for indent-tabs-mode . It also ignores web-mode-markup-indent-offset's value. – sshaw Jul 15 '15 at 3:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.