5

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.

Andrew Swann
  • 3,436
  • 2
  • 15
  • 43
Patrick J. S.
  • 235
  • 1
  • 7
  • Are you using the latest version of `web-mode`? (If not you can try installing it directly from [the GitHub repo](https://github.com/fxbois/web-mode).) – Scott Weldon Jun 03 '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 03 '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 04 '15 at 01:23

1 Answers1

6

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

fxbois
  • 442
  • 2
  • 8
  • 1
    Yes! I changed it with customize, but it works. Thank you. Is that a bug that I should report? – Patrick J. S. Jun 04 '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 04 '15 at 13:04
  • I do not understand why ```indent-tabs-mode``` is ```t``` by default – fxbois Jun 04 '15 at 19:14
  • @fxbois: [just a guess](https://www.kernel.org/doc/Documentation/CodingStyle). But seriously, yes you answered my question, but could you elaobrate on the why? – Patrick J. S. Jun 07 '15 at 01:58
  • While this change may be the "right this to do" given `indent-tabs-mode` purpose, [this commit](https://github.com/fxbois/web-mode/commit/0f1b1bcd#diff-65d99b4476be4737f539e1bc19325383R2200), 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 03:30