2

When I insert a portion of JavaScript code within an HTML file, Emacs convert some basic JS symbols to their HTML code. For example when I type >, Emacs convert it automatically to > which this makes it impossible to code JS.

How to circumvent this issue?

EDIT:

Here is the content of my .emacs file:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
 '(custom-enabled-themes (quote (tango-dark)))
 '(package-selected-packages (quote (js2-mode green-is-the-new-black-theme))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
(package-initialize)
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "http://melpa-stable.milkbox.net/packages/"))


(require 'green-is-the-new-black-theme)

(setq column-number-mode t)     

(setq-default indent-tabs-mode nil)

(setq sgml-quick-keys 'indent)

;; For JavaScript
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;; Better imenu
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
  • I can't replicate this in emacs 25.3 in html-mode. I suspect you're using some mode or configuration which you haven't detailed in your question. Please show how to replicate the problem, starting from emacs -Q. – phils Aug 12 '18 at 11:05
3

This is because you've configured:

(setq sgml-quick-keys 'indent)

C-hv sgml-quick-keys tells us:

sgml-quick-keys is a variable defined in ‘sgml-mode.el’.

Documentation:
Use <, >, &, /, SPC and ‘sgml-specials’ keys "electrically" when non-nil.
This takes effect when first loading the ‘sgml-mode’ library.

As html-mode is derived from sgml-mode, this applies there as well.

Many people like http://web-mode.org/ for editing files which mix HTML/JS/CSS.

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.