Emacs goes to css declaration from html file

I look around the Internet and do not come up with a solution. Does anyone know how to go to the css declaration inside the html file and open a new buffer with a dot or next to this declaration?

Edit

After a larger search, I decided to go with search open buffers for the string approach.

;; CSS search open buffers
(defun search-open-css-buffers-for-region-or-word ()
  "Use the current region/point and search open css buffers"
  (interactive)
  (let (searchTerm)
    (setq searchTerm
          (if (region-active-p)
              (buffer-substring-no-properties (region-beginning) (region-end))
            (thing-at-point 'symbol)))
    (multi-occur (mapcar (lambda (buf)
                           (if (string-match "\w*.css" (buffer-name buf))
                               buf)) (buffer-list))
                 searchTerm 5)))

(global-set-key (kbd "M-s-.") 'search-open-css-buffers-for-region-or-word)

It seems like a hack.

+5
source share
1 answer

There are several things that make this not common:

  • depending on which HTML mode you are using, you may need different ways to determine what is in point.
  • Where are your CSS files? people have all kinds of project structures.
  • how do you want the result to look?

Having said that, here is an example for nxml-mode (although it can be easily adapted).

(defun find-css-defun ()
  (interactive)
  (when (memq 'nxml-attribute-value
              (get-text-property (point) 'face))
    (let ((css-buffers
           (mapcar
            (lambda (file)
              (find-file-noselect file))
            (directory-files default-directory t ".*\\.css$"))))
      (multi-occur css-buffers
                   (thing-at-point 'symbol)))))
  • , nxml, , CSS
  • , CSS , HTML, css-buffers - CSS;
  • multi-origin

.

PS --, emacs

+3
source

All Articles