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

How do I successfully add a new filter to emmet-filters?

Open stephenwithav opened this issue 4 years ago • 2 comments

Goal: Use emmet-mode to successfully generate TensorFlow code in Python. (e.g., Dense*3 returns layer.Dense() three times.)

Approach: add "py" mapping to emmet-filters and emmet-default-filter, along with the accompanying json in preferences.json.

Result: emmet-filters fails to include "py" entry when debugging email-process-filter, so no work is done.

Question: Do you have any idea why emmet-filters lacks the "py" entry?

(defvar emmet-filters
  '("html" (emmet-primary-filter emmet-make-html-tag)
    "c"    (emmet-primary-filter emmet-make-commented-html-tag)
    "haml" (emmet-primary-filter emmet-make-haml-tag)
    "hic"  (emmet-primary-filter emmet-make-hiccup-tag)
    "py"   (emmet-primary-filter emmet-make-python-tag)
    "e"    (emmet-escape-xml)))

...

(defun emmet-default-filter ()
  "Default filter(s) to be used if none is specified."
  (let* ((file-ext (car (emmet-regex ".*\\(\\..*\\)" (or (buffer-file-name) "") 1)))
         (defaults '(".html" ("html")
                     ".htm"  ("html")
                     ".haml" ("haml")
                     ".py"   ("py")
                     ".clj"  ("hic")))
         (default-else      '("html"))
         (selected-default (member file-ext defaults)))
    (if selected-default
        (cadr selected-default)
      default-else)))
  "py": {
    "tags": {
      "dense":      {"block": false, "selfClosing": false, "defaultAttr": {"units": ""}}
    }
  }
(defun emmet-process-filter (filters input)
  "Process filters, chain one filter output as the input of the next filter."
  (debug)
  (let ((filter-data (member (car filters) emmet-filters))
        (more-filters (cdr filters)))
    (if filter-data
        (let* ((proc   (cadr filter-data))
               (fun    (car proc))
               (filter-output (funcall fun input proc)))
          (if more-filters
              (emmet-process-filter more-filters filter-output)
            filter-output))
      nil)))

stephenwithav avatar Apr 10 '20 18:04 stephenwithav

Full code here:

https://github.com/stephenwithav/emmet-mode/tree/develop

stephenwithav avatar Apr 10 '20 20:04 stephenwithav

I haven't checked it out and tested it, but one thing I'm immediately seeing is that this is showing up in the src/ directory files, but not the compiled el - emmet-mode has a build step using make that I think you didn't run.

Details (well, instructions, anyway, they're not very detailed) are here: https://github.com/smihica/emmet-mode/#development-notes

pobocks avatar Apr 10 '20 20:04 pobocks