Skip to main content
added 1022 characters in body
Source Link
muffinmad
  • 2.3k
  • 9
  • 11

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:

(defun my/language-at-pos (pos)
  "Message language at POS."
  (interactive "d")
  (let ((lang (cond
               ;; web-mode
               ((eq major-mode 'web-mode)
                (web-mode-language-at-pos pos))
               ;; mhtml-mode
               ((derived-mode-p 'mhtml-mode) "HTML")
               ((eq major-mode 'js-mode) "JS")
               ((eq major-mode 'css-mode) "CSS")
               ;; html-mode
               ((derived-mode-p 'html-mode)
                (let ((submode (get-text-property pos 'mhtml-submode)))
                  (if submode
                      (mhtml--submode-name submode)
                    "HTML")))
               ;TODO: rjsx-mode and other
               (t
                (message "Don't know how to get language in %s" major-mode)
                nil))))
    (when lang
      (message "Language at point is %s" lang))))

It will work for vue-mode because vue-mode is derived from html-mode.

web-mode-language-at-pos function is what are your looking for. Although it is not documented.

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:

(defun my/language-at-pos (pos)
  "Message language at POS."
  (interactive "d")
  (let ((lang (cond
               ;; web-mode
               ((eq major-mode 'web-mode)
                (web-mode-language-at-pos pos))
               ;; mhtml-mode
               ((derived-mode-p 'mhtml-mode) "HTML")
               ((eq major-mode 'js-mode) "JS")
               ((eq major-mode 'css-mode) "CSS")
               ;; html-mode
               ((derived-mode-p 'html-mode)
                (let ((submode (get-text-property pos 'mhtml-submode)))
                  (if submode
                      (mhtml--submode-name submode)
                    "HTML")))
               ;TODO: rjsx-mode and other
               (t
                (message "Don't know how to get language in %s" major-mode)
                nil))))
    (when lang
      (message "Language at point is %s" lang))))

It will work for vue-mode because vue-mode is derived from html-mode.

Source Link
muffinmad
  • 2.3k
  • 9
  • 11

web-mode-language-at-pos function is what are your looking for. Although it is not documented.