Last active
December 12, 2016 10:12
-
-
Save ceving/7ba174960b9dd3516fff to your computer and use it in GitHub Desktop.
Narrow to CSS and JavaScript parts while editing a HTML file with embedded STYLE and SCRIPT tags using Emacs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun narrow-to-html-style () | |
"Narrow a HTML buffer to the style part and switch to css-mode." | |
(interactive) | |
(widen) | |
(goto-char (point-min)) | |
(re-search-forward "<style") | |
(forward-line 1) | |
(beginning-of-line) | |
(let ((b (point))) | |
(re-search-forward "</style>") | |
(beginning-of-line) | |
(let ((e (point))) | |
(narrow-to-region b e) | |
(css-mode)))) | |
(defun narrow-to-html-script () | |
"Narrow a HTML buffer to the script part and switch to js-mode." | |
(interactive) | |
(widen) | |
(goto-char (point-min)) | |
(re-search-forward "<script") | |
(forward-line 1) | |
(beginning-of-line) | |
(let ((b (point))) | |
(re-search-forward "</script>") | |
(beginning-of-line) | |
(let ((e (point))) | |
(narrow-to-region b e) | |
(js-mode)))) | |
(defun widen-to-html () | |
"Widen a HTML buffer and reenable html-mode." | |
(interactive) | |
(widen) | |
(html-mode)) | |
(defun narrow-to-last-html-script () | |
"Narrow a HTML buffer to the last script part and switch to | |
js-mode or scheme-mode, if it is a BiwaScheme script." | |
(interactive) | |
(widen) | |
(end-of-buffer) | |
(re-search-backward "</script>") | |
(beginning-of-line) | |
(let ((end-of-script (point))) | |
(re-search-backward "<script") | |
(let ((mode (if (looking-at ".*biwascheme") | |
'scheme-mode | |
'js-mode))) | |
(forward-line 1) | |
(beginning-of-line) | |
(narrow-to-region (point) end-of-script) | |
(funcall mode)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment