I have been looking around the internets and have not come up with a solution. Does anyone know how to jump to a css declaration inside an html file and have a new buffer open with point at or close to that declaration?
After more searching I decided to go with a search open buffers for 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 feels like this is a hack though.
There's a couple of things that make this non-generic:
Having said that, here's an example, for nxml-mode (though it could easily be 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)))))
It works ok.
PS it requires thing-at-point which is in emacs by default these days
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With