Skip to main content
34 votes
Accepted

How do I set up indentation to 2 spaces in web-mode

According to the web-mode documentation, you can do that with the following: (defun my-web-mode-hook () "Hooks for Web mode." (setq web-mode-markup-indent-offset 2) ) (add-hook 'web-mode-hook '...
Ryan's user avatar
  • 4,059
15 votes
Accepted

turn off auto-quotes in web-mode

(setq web-mode-enable-auto-quoting nil) Add double quotes after the character = in a tag.
xuhdev's user avatar
  • 1,921
15 votes

How do I set up indentation to 2 spaces in web-mode

With use-package: (use-package web-mode :custom (web-mode-markup-indent-offset 2) (web-mode-css-indent-offset 2) (web-mode-code-indent-offset 2))
DomQ's user avatar
  • 297
8 votes
Accepted

Formatting jsx in js files with web-mode

The answer was to add the following to my init.el (setq web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'")))
dagda1's user avatar
  • 615
6 votes
Accepted

Change comment style in web-mode

web-mode-comment-formats is a buffer local variable. Also, add-to-list may not work correctly, since there is already a mapping for javascript to /*. You can try one of the following: (setq-default ...
punchagan's user avatar
  • 251
5 votes
Accepted

How to use web-mode engine-specific checkers in flycheck?

The following works, not sure if there's a "built-in" way of doing it... (flycheck-add-mode 'javascript-eslint 'web-mode) (defun my/configure-web-mode-flycheck-checkers () ;; in order to have ...
mgalgs's user avatar
  • 474
5 votes
Accepted

web-mode not installing?

I think what's happening is that the list of packages Emacs knows about is out of date; your system thinks web-mode 15 is the latest, but web-mode 16 has been published to the package repository. Your ...
zck's user avatar
  • 9,112
5 votes
Accepted

How to render html in web-mode?

You can find out what C-c C-v does by pressing F1 k C-c C-v in a html-mode buffer: C-c C-v runs the command browse-url-of-buffer (found in html-mode-map), which is an interactive autoloaded ...
wasamasa's user avatar
  • 22.2k
4 votes
Accepted

How can i start web-mode at a file's startup?

This line is in error: (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode)) It doesn't open .tpl files and .php files in web-mode, it opens files ending .tpl.php in web-mode. Amusingly, I ...
zck's user avatar
  • 9,112
4 votes
Accepted

Yasnippets for active web-mode engine

The right place to use yas-activate-extra-mode is web-mode-on-engine-setted since that function also sets the engine specific snippets of web-mode. Pityingly there is no hook so we have to add an ...
Tobias's user avatar
  • 33.3k
3 votes
Accepted

web-mode disable auto pairing mode does not work

In elisp nil represents a false value. Try: (setq web-mode-enable-auto-closing nil) (setq web-mode-enable-auto-pairing nil) -1 is non-nil (see: (if -1 "true!" "false!")).
ebpa's user avatar
  • 7,519
3 votes
Accepted

Select Within Quotes

You can use the expand-region or emacs-surround packages to select the text and then delete it. Watch an intro to expand-region on: Emacs Rocks. Or take a look at the examples of emacs-surround on ...
Alexandro de Oliveira's user avatar
3 votes
Accepted

Set web-mode engine per directory

Have you tried adding a web-mode-hook to check if you are in a projectile project? You would also have to check if the projectile project is a django one, but I am not that familiar with django. (...
CESCO's user avatar
  • 374
3 votes

Detect missing > html emacs web-mode

web-mode maintainer here. I've pushed a fix to use web-mode-html-tag-unclosed-face instead of web-mode-html-tag-face as long as the tag remains unclosed. This face can be customised (e.g. adding a red ...
fxbois's user avatar
  • 452
3 votes

Help with `replace-regexp-in-string`, to replace only first instance in every line

C-hf replace-regexp-in-string actually covers this exact requirement (or it does in Emacs 25.3, at any rate). To replace only the first match (if any), make REGEXP match up to \' and replace a sub-...
phils's user avatar
  • 51.7k
2 votes
Accepted

Getting proper indentation for Python Flask templates

You can call the web-mode-set-engine command from M-x this will allow you to set which template you want to use. The engine that you want it "django" (yes even though you are using flask/jinja). You ...
Jules's user avatar
  • 1,225
2 votes

Is it possible to disable aggressive indent mode per file extension?

This should do the trick: (add-hook 'web-mode-hook #'(lambda () (unless (and (stringp buffer-file-name) (string-match "\\.js\\'" ...
theldoria's user avatar
  • 1,845
2 votes

web-mode not working inside of org-mode src block

Use either css mode: #+BEGIN_SRC css .inputField { color: #525252; } #+END_SRC and add color fontification by using code found here, or inline the css in web: #+BEGIN_SRC web <style> ....
theldoria's user avatar
  • 1,845
2 votes

In web-mode PHP block in HTML file doesn't syntax highlight

Scenario 1: You are editing your own files. In this case, and if possible, it's better to identify the kind of HTML file you are editing by a unique extension: .djhtml for django files, etc. ...
Calaf's user avatar
  • 483
2 votes
Accepted

Web-mode uses 1 space indent instead of 2

Try (setq web-mode-script-padding 2). You should also call my-web-mode-hook only once, after you first load web-mode and not every time the mode is activated: (with-eval-after-load 'web-mode (my-...
caisah's user avatar
  • 4,096
2 votes
Accepted

how to get web-mode to ignore alignment in favor of indentation during method chaining?

ah, turns out it's the web-mode-indentation-params list: (add-to-list '(web-mode-indentation-params) '("lineup-calls" . nil))
Dan O's user avatar
  • 161
2 votes

go to symbol in javascript with web-mode

for javascript I highly recommend js2-mode. Take a look here https://elpa.gnu.org/packages/js2-mode.html it has function that you are looking for: js2-jump-to-definition which is by default bound to M-...
Jakub Ječmínek's user avatar
2 votes

go to symbol in javascript with web-mode

I submit critical patches to both web-mode and js2-mode. Currently as a front end architect, I'm developing a big ReactJS project from the scratch. The simple answer is: helm-etags+ctags or counsel-...
chen bin's user avatar
  • 4,877
2 votes
Accepted

Detect missing > html emacs web-mode

Use builit flymake plus old cli tidy. tidy is available on Mac/Linux/Windows, tested on Emacs 24.4 and Emacs 25.3: (defun flymake-html-init () (let* ((temp-file (flymake-init-create-temp-...
chen bin's user avatar
  • 4,877
2 votes

Help with `replace-regexp-in-string`, to replace only first instance in every line

You could look for the pattern "beginning of line, spaces, //, spaces" and replace that with the empty string: (replace-regexp-in-string "^\\s-*//\\s-*" "" comment)
Omar's user avatar
  • 4,842
2 votes
Accepted

Toggle major mode with a custom key binding

You can use the variable major-mode to find out the current Major Mode. The value is a Symbol, thus you can compare it using eq. (defun toggle-between-web-mode-and-js2-jsx-mode () (interactive) (...
xuchunyang's user avatar
  • 14.6k
2 votes

How to get current language at point?

web-mode-language-at-pos function is what are your looking for. Although it is not documented. Single function to get language at pos that will work across different modes might look like this: (...
muffinmad's user avatar
  • 2,320
2 votes

web dev environment setup

Install skewer-mode and js2-mode, then following below work flow: Add below config into init.el: (add-hook 'js2-mode-hook 'skewer-mode) (add-hook 'css-mode-hook 'skewer-css-mode) (add-...
beetlej's user avatar
  • 1,100
1 vote

How to detect and match indentation size of current buffer

As Python allows to change the indent blockwise, there is related stuff in Python-modes. python-mode.el uses py-guess-indent-offset, built-in python.el uses python-indent-guess-indent-offset ...
Andreas Röhler's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible