fxbois / web-mode

web template editing mode for emacs
https://web-mode.org
GNU General Public License v3.0
1.64k stars 260 forks source link

After latest changes cannot apply web-mode #1294

Closed uskebasi closed 9 months ago

uskebasi commented 9 months ago

File mode specification error: (args-out-of-range 0) web-mode-scan-region: Args out of range: "", 0

fxbois commented 9 months ago

could you send me the template ?

uskebasi commented 9 months ago

This is my init.el portion (use-package web-mode :ensure t :config (with-eval-after-load "lsp" (assq-delete-all 'web-mode lsp-language-id-configuration) (add-to-list 'lsp-language-id-configuration '(web-mode . "php"))) (setq web-mode-extra-snippets '(("erb" . (("toto" . "<% toto | %>\n\n<% end %>"))) ("php" . (("dowhile" . "<?php do { ?>\n\n<?php } while (|); ?>") ("debug" . "<?php error_log(LINE); ?>"))) ))

  (add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
  (add-hook 'web-mode-hook #'lsp)
  )

(add-hook 'web-mode-hook #'(lambda ()
                             (enable-minor-mode
                              '("\\.jsx?\\'" . prettier-js-mode))))

(eval-after-load 'web-mode
  '(progn
     (add-hook 'web-mode-hook #'add-node-modules-path)
     ))

(defun my-web-mode-hook ()
  (add-hook 'before-save-hook #'web-mode-buffer-indent))

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

     ;; When called this automatically detects the submode at the current location.
     ;; It will then either forward to end of tag(HTML) or end of code block(JS/CSS).
     ;; This will be passed to hs-minor-mode to properly navigate and fold the code.

(defun mhtml-forward (arg)
  (interactive "P")
  (pcase (get-text-property (point) 'mhtml-submode)
    ('nil (sgml-skip-tag-forward 1))
    (submode (forward-sexp))))

     ;; Adds the tag and curly-brace detection to hs-minor-mode for mhtml.

(add-to-list 'hs-special-modes-alist
             '(mhtml-mode
               "{\\|<[^/>]+?"
               "}\\|</[^/>]*[^/]>"
               "<!--"
               mhtml-forward
               nil))

This is one of my project files: same behavior with any aother of them

<?php $root_dir_path = "./"; session_start(); ?> <?php include "adminMiddleware/adminMiddleware.php"; ?> <?php include "includes/header.php"; ?>

Sorgenti Sigillate

2


AttivitΓ 

2,300


Macchine Radiogene

3


person_add

Utenti Registrati

9


<?php include "includes/footer.php"; ?>

takueof commented 9 months ago

@fxbois Hi. I'm using web-mode df57cd0beea9c6bdc64259bd11bde0c076a64cc9 (from MELPA) but work fine.

However, I confirmed that I get the same error occur that @uskebasi reported after update to 9586a44b05d8bfdef2371461d896db01737dfee1 (latest master commit) from MELPA.

I think it's better to revert the master branch to df57cd0beea9c6bdc64259bd11bde0c076a64cc9, what do you think?

(Thanks: @uskebasi πŸ‘)

fxbois commented 9 months ago

Could you tell me how to trigger the bug ?

debiru commented 9 months ago

I am currently installing Emacs (GNU Emacs 27.1) on Ubuntu 22.04. I too have encountered this problem.

Could you tell me how to trigger the bug ?

$ cat ~/.emacs.d/init.el
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

(setq package-list '(web-mode))

(unless package-archive-contents
  (package-refresh-contents))

(dolist (package package-list)
  (unless (package-installed-p package)
    (package-install package)))

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

The trigger is to open any html file after install web-mode (20231223.1924) by melpa package. Then can't open the file and Emacs says Args out of range: "", 0 in footer field.

I investigated this in the environment at hand, but on Ubuntu 20.04 (GNU Emacs 26.3) and macOS X (GNU Emacs 28.1), I was able to open the file in web-mode without error after following the same procedure. Perhaps the reproducibility may vary depending on the OS.

takueof commented 9 months ago

@debiru Good job, Thanks! πŸ‘

takueof commented 9 months ago

@fxbois I also wrote a minimal configuration init.el:

;;; init.el --- "GNU Emacs" main config file to composition for debug -*- lexical-binding: t; -*-

;;; Commentary:

;; This GNU Emacs config file is minimum composition for debug.

;;; Code:

(setq debug-on-error t)

(require 'package)
(add-to-list 'package-archives '("MELPA" . "https://melpa.org/packages/"))
(package-initialize)
(package-refresh-contents)

;; `web-mode'
(package-install 'web-mode)
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))

;; Local Variables:
;; coding: utf-8-unix
;; mode: Emacs-Lisp
;; no-byte-compile: t
;; End:

;;; init.el ends here

The startup command is:

emacs -nw --init-directory=~/.emacs.d.minimum

Below is my GNU Emacs environment (Please let me know if you would like additional information):

Below is a test HTML file:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Test</title>
  </head>
  <body>
    <h1>Hello, World!</h1>
    <p>Paragraph</p>
  </body>
</html>

Finally, here is the stack trace when opening the HTML file mentioned above:

Debugger entered--Lisp error: (args-out-of-range "" 0)
  web-mode-scan-elements(1 181)
  web-mode-scan-region(1 181)
  web-mode-invalidate-region(1 181)
  web-mode-scan(1 181)
  web-mode-extend-region()
  font-lock-default-fontify-region(1 181 nil)
  font-lock-fontify-region(1 181 nil)
  font-lock-default-fontify-buffer()
  font-lock-fontify-buffer()
  font-lock-initial-fontify()
  font-lock-mode()
  turn-on-font-lock()
  turn-on-font-lock-if-desired()
  global-font-lock-mode-enable-in-buffers()
  run-hooks(after-change-major-mode-hook)
  run-mode-hooks(web-mode-hook)
  web-mode()
  set-auto-mode-0(web-mode nil)
  set-auto-mode--apply-alist((("\\.html\\'" . web-mode) ("\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'" nil epa-file) ("\\.elc\\'" . elisp-byte-code-mode) ("\\.\\(?:3fr\\|arw\\|bmp\\|cr[2w]\\|d\\(?:cr\\|ds\\|ng\\)\\|ex..." . image-mode) ("\\.zst\\'" nil jka-compr) ("\\.dz\\'" nil jka-compr) ("\\.xz\\'" nil jka-compr) ("\\.lzma\\'" nil jka-compr) ("\\.lz\\'" nil jka-compr) ("\\.g?z\\'" nil jka-compr) ("\\.bz2\\'" nil jka-compr) ("\\.Z\\'" nil jka-compr) ("\\.vr[hi]?\\'" . vera-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-mode) ("\\.re?st\\'" . rst-mode) ("\\.py[iw]?\\'" . python-mode) ("\\.m\\'" . octave-maybe-mode) ("\\.less\\'" . less-css-mode) ("\\.scss\\'" . scss-mode) ("\\.cs\\'" . csharp-mode) ("\\.awk\\'" . awk-mode) ("\\.\\(u?lpc\\|pike\\|pmod\\(\\.in\\)?\\)\\'" . pike-mode) ("\\.idl\\'" . idl-mode) ("\\.java\\'" . java-mode) ("\\.m\\'" . objc-mode) ("\\.ii\\'" . c++-mode) ("\\.i\\'" . c-mode) ("\\.lex\\'" . c-mode) ("\\.y\\(acc\\)?\\'" . c-mode) ("\\.h\\'" . c-or-c++-mode) ("\\.c\\'" . c-mode) ("\\.\\(CC?\\|HH?\\)\\'" . c++-mode) ("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode) ("\\.\\(cc\\|hh\\)\\'" . c++-mode) ("\\.\\(bat\\|cmd\\)\\'" . bat-mode) ("\\.[sx]?html?\\(\\.[a-zA-Z_]+\\)?\\'" . mhtml-mode) ("\\.svgz?\\'" . image-mode) ("\\.svgz?\\'" . xml-mode) ("\\.x[bp]m\\'" . image-mode) ("\\.x[bp]m\\'" . c-mode) ("\\.p[bpgn]m\\'" . image-mode) ("\\.tiff?\\'" . image-mode) ("\\.gif\\'" . image-mode) ("\\.png\\'" . image-mode) ("\\.jpe?g\\'" . image-mode) ("\\.webp\\'" . image-mode) ("\\.te?xt\\'" . text-mode) ("\\.[tT]e[xX]\\'" . tex-mode) ("\\.ins\\'" . tex-mode) ("\\.ltx\\'" . latex-mode) ...) nil nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer index.html> "~/.emacs.d.minimum/index.html" nil nil "~/.emacs.d.minimum/index.html" (167475415 16777220))
  find-file-noselect("~/.emacs.d.minimum/index.html" nil nil t)
  find-file("~/.emacs.d.minimum/index.html" t)
  funcall-interactively(find-file "~/.emacs.d.minimum/index.html" t)
  call-interactively(find-file nil nil)
  command-execute(find-file)

I would be happy if you could use it as a reference πŸ™

debiru commented 9 months ago

Note: Workaround for those encountering the same problem.

Use stable.melpa.org instead of melpa.org.

(setq package-archives '(("melpa-stable" . "https://stable.melpa.org/packages/")))
(package-initialize)
  1. delete current package. M-x package-delete web-mode
  2. install as stable package. M-x package-install web-mode

You can install web-mode-17.3.13 instead of web-mode-20231223.1924.

fxbois commented 9 months ago

thank you @takueof , I'll work on this today

fxbois commented 9 months ago

should be fixed with last commit ... sorry to have disturbed your studious Christmas Holidays !

takueof commented 9 months ago

@fxbois I'm installed web-mode 20231225.1458 via MELPA, and verified that the problem was fixed! Thank you for your quick fix even during the holiday season πŸ™

Happy holidays (and hacking)! πŸŽ„