From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: html, css, and js modes working together Date: Tue, 31 Jan 2017 13:34:40 -0700 Message-ID: <87o9ynarz3.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1485895087 765 195.159.176.226 (31 Jan 2017 20:38:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 31 Jan 2017 20:38:07 +0000 (UTC) To: Emacs discussions Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 31 21:37:55 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cYfBZ-00088W-To for ged-emacs-devel@m.gmane.org; Tue, 31 Jan 2017 21:37:54 +0100 Original-Received: from localhost ([::1]:41085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYfBf-0004rF-7h for ged-emacs-devel@m.gmane.org; Tue, 31 Jan 2017 15:37:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYf8q-0002ej-MX for emacs-devel@gnu.org; Tue, 31 Jan 2017 15:35:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYf8m-000807-Jk for emacs-devel@gnu.org; Tue, 31 Jan 2017 15:35:04 -0500 Original-Received: from gproxy4-pub.mail.unifiedlayer.com ([69.89.23.142]:59810) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1cYf8m-0007yw-1i for emacs-devel@gnu.org; Tue, 31 Jan 2017 15:35:00 -0500 Original-Received: (qmail 19090 invoked by uid 0); 31 Jan 2017 20:34:48 -0000 Original-Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy4.mail.unifiedlayer.com with SMTP; 31 Jan 2017 20:34:48 -0000 Original-Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id f8aj1u00Q2f2jeq018amc6; Tue, 31 Jan 2017 13:34:48 -0700 X-Authority-Analysis: v=2.1 cv=Pets2ERd c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=IgFoBzBjUZAA:10 a=uUEaCB_WrpbFSeCVnhoA:9 a=QEXdDO2ut3YA:10 a=L03L2QfmqWoA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=fUfQGIwkEr8BTXI9ogzqQWi+n0VJVkdvIzZBjYGSheo=; b=fZLehJaR/2HJ8LCJ6fYfdqu4zP IhGi8ZTIK+jVDYyJIOoJprp0Tkj9OsCq1J1k2cBj/3NZuToHepxMLSICHjdCTmmh3fE/B3w4RVOk8 fD350zstwl0mx0qIU5Sg2wp30; Original-Received: from 174-16-146-181.hlrn.qwest.net ([174.16.146.181]:50708 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cYf8U-00027i-J9; Tue, 31 Jan 2017 13:34:42 -0700 X-Attribution: Tom X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box522.bluehost.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.146.181 X-Exim-ID: 1cYf8U-00027i-J9 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-146-181.hlrn.qwest.net (bapiya) [174.16.146.181]:50708 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 69.89.23.142 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:211819 Archived-At: I tried to send this last night but it bounced for some reason. This patch changes the html, css, and js modes to work together a bit. With this, the contents of a " + (1 + (prog1 css-mode-syntax-table + (let ((start (nth 2 (match-data))) + (end (nth 3 (match-data)))) + (funcall css-syntax-propertize-function start end) + (add-text-properties start end '(syntax-multiline t)))))) + ("\\(\\(\n\\|.\\)*?\\)" + (1 + (prog1 js-mode-syntax-table + (let ((start (nth 2 (match-data))) + (end (nth 3 (match-data)))) + (js-syntax-propertize start end) + (add-text-properties start end '(syntax-multiline t)))))) + sgml-syntax-propertize-rules) + "Syntactic keywords for `html-mode'.") + +(defun html-indent-line () + "Indent the current line as HTML." + (interactive) + (let* ((context (save-excursion (car (last (sgml-get-context))))) + (tag (when (and context + (eq (sgml-tag-type context) 'open) + (> (point) (sgml-tag-start context))) + (sgml-tag-name context)))) + (cond + ((equal tag "style") + ;; CSS. + (save-restriction + (let ((base-indent (save-excursion + (goto-char (sgml-tag-end context)) + (sgml-calculate-indent)))) + (narrow-to-region (sgml-tag-end context) (point-max)) + (let ((prog-indentation-context (list base-indent + (cons (point-min) nil) + nil))) + (with-smie-rules (css-smie-grammar #'css-smie-rules) + (smie-indent-line)))))) + ((equal tag "script") + ;; Javascript. + (save-restriction + (let ((base-indent (save-excursion + (goto-char (sgml-tag-end context)) + (sgml-calculate-indent)))) + (narrow-to-region (sgml-tag-end context) (point-max)) + (let ((prog-indentation-context (list base-indent + (cons (point-min) nil) + nil))) + (js-indent-line))))) + (t + ;; HTML. + (sgml-indent-line))))) + + + ;;;###autoload (define-derived-mode html-mode sgml-mode '(sgml-xml-mode "XHTML" "HTML") "Major mode based on SGML mode for editing HTML documents. @@ -2270,6 +2345,8 @@ html-mode (eval-after-load \"sgml-mode\" \\=3D'(aset sgml-char-names ?\\=3D' nil)) =20 \\{html-mode-map}" + ;; A hack to avoid a circular dependency. + (require 'js) (setq-local sgml-display-text html-display-text) (setq-local sgml-tag-face-alist html-tag-face-alist) (setq-local sgml-tag-alist html-tag-alist) @@ -2281,6 +2358,11 @@ html-mode (lambda () (char-before (match-end 0)))) (setq-local add-log-current-defun-function #'html-current-defun-name) (setq-local sentence-end-base "[.?!][]\"'=E2=80=9D)}]*\\(<[^>]*>\\)*") + (setq-local indent-line-function #'html-indent-line) + + (setq-local syntax-propertize-function html-syntax-propertize-function) + (add-hook 'syntax-propertize-extend-region-functions + #'syntax-propertize-multiline 'append 'local) =20 (when (fboundp 'libxml-parse-html-region) (defvar css-class-list-function)