emmet-mode icon indicating copy to clipboard operation
emmet-mode copied to clipboard

Readd emmet-expand-jsx-className or alternative variable

Open rikberkelder opened this issue 2 years ago • 3 comments

Hi. I use Emmet mode with web-mode and JSX. I always used (setq-local emmet-expand-jsx-className? t) from a custom web-mode hook that checks the file extension for "jsx" or "tsx" to get className= instead of class=. The new approach of emmet-jsx-major-modes doesn't work well with web-mode + JSX, because the major mode is always web-mode for both HTML as JSX/TSX files. Is there any workaround for this, or a way to bring a variable like emmet-expand-jsx-className back?

rikberkelder avatar Dec 04 '21 19:12 rikberkelder

Any fix?

anhsirk0 avatar Sep 25 '22 13:09 anhsirk0

I found a work around for this. emmet-mode uses a functions to check if major-mode is a jsx supported mode. I updated that function to also compare buffer-file extension.

Replace the function definition in emmet-mode.el and byte-compile the file with M-x byte-recompile-file.

(defun emmet-jsx-supported-mode? ()
  "Is the current mode we're on enabled for jsx class attribute expansion?"
  (or (member (file-name-extension buffer-file-name) '("jsx" "tsx"))
      (member major-mode emmet-jsx-major-modes)))

anhsirk0 avatar Sep 29 '23 16:09 anhsirk0

Had to do a similar thing:

(defun emmet-jsx-supported-mode? ()
    "Is the current mode we're on enabled for jsx class attribute expansion?"
    (or (member major-mode emmet-jsx-major-modes)
        (and (string= major-mode "web-mode") (string= web-mode-content-type "jsx"))))

Would be nice addition if we had the ability to extend that function. Something like:

(defun emmet-jsx-supported-mode? ()
  "Is the current mode we're on enabled for jsx class attribute expansion?"
  (or (member major-mode emmet-jsx-major-modes) 
        (emmet-jsx-supported-func)))

(defcustom emmet-jsx-support-func nil
"User defined custom that returns `t` if jsx support should be enabled, and `nil` for not"
)

gopar avatar Apr 29 '24 20:04 gopar