emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

some proposed tweaks to HTML mode


From: Eric Abrahamsen
Subject: some proposed tweaks to HTML mode
Date: Thu, 21 Mar 2019 15:11:17 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

I've always found vanilla HTML mode kind of annoying to use, and finally
tried to figure out why. (I assume everyone is using some fancier HTML
authoring mode, but that's no reason not to fix this one.)

Embarrassingly, the main pain point seemed to be that, when you insert
<ul> or <ol>, the closing tag isn't indented properly. Not the end of
the world, but enough to bug me. That led to a few other tweaks, and I'm
inserting the whole diff here for consideration, with notes:

diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 21b7082b85..9aae47ca09 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -775,8 +775,9 @@ sgml-attributes
                (symbolp (car (car alist))))
            (setq car (car alist)
                  alist (cdr alist)))
-       (or quiet
-           (message "No attributes configured."))
+        (unless (or alist quiet)
+         (message "No attributes configured.")))

Currently, this function _always_ flashes the "No attributes
configured" message.

(if (stringp (car alist))
            (progn
              (insert (if (eq (preceding-char) ?\s) "" ?\s)
@@ -1743,6 +1744,8 @@ html-mode-map
     (define-key map "\C-c1" 'html-headline-1)
     (define-key map "\C-c\r" 'html-paragraph)
     (define-key map "\C-c\n" 'html-line)
+    (define-key map "\C-cd" 'html-div)
+    (define-key map "\C-cs" 'html-span)
     (define-key map "\C-c\C-c-" 'html-horizontal-rule)
     (define-key map "\C-c\C-co" 'html-ordered-list)
     (define-key map "\C-c\C-cu" 'html-unordered-list)
@@ -1962,7 +1965,7 @@ html-tag-alist
       ("dd" ,(not sgml-xml-mode))
       ("del" nil ("cite") ("datetime"))
       ("dfn")
-      ("div")
+      ("div" nil ("class") ("id"))

The <div> and <span> elements have literally no use except for a place
to hang the "class" and/or "id" attribute, so I don't see why we don't
accept those here. In fact, I'd rather just automatically add "class"
and "id" as potential attributes on all the tags.

       ("dl" (nil \n
                 ( "Term: "
                   "<dt>" str (if sgml-xml-mode "</dt>")
@@ -2045,7 +2048,8 @@ html-tag-alist
         ("string")
         ("type")
         ("variable-name")
-        ("warning")))
+        ("warning"))
+        ("id"))
       ("strong")
       ("style" \n ("type") ("media") ("title"))
       ("sub")
@@ -2451,26 +2455,38 @@ html-ordered-list
   nil
   "<ol>" \n
   "<li>" _ (if sgml-xml-mode "</li>") \n
-  "</ol>")
+  "</ol>" >)
 
 (define-skeleton html-unordered-list
   "HTML unordered list tags."
   nil
   "<ul>" \n
   "<li>" _ (if sgml-xml-mode "</li>") \n
-  "</ul>")
+  "</ul>" >)
 
 (define-skeleton html-list-item
   "HTML list item tag."
   nil
-  (if (bolp) nil '\n)
+  (if (re-search-backward "^[[:blank:]]+") nil '\n)
   "<li>" _ (if sgml-xml-mode "</li>"))
 
 (define-skeleton html-paragraph
   "HTML paragraph tag."
   nil
-  (if (bolp) nil ?\n)
-  "<p>" _ (if sgml-xml-mode "</p>"))
+  (if (re-search-backward "^[[:blank:]]+") nil ?\n)
+  "<p>" > _ (if sgml-xml-mode "</p>"))
+
+(define-skeleton html-div
+  "HTML div tag."
+  nil
+  (if (re-search-backward "^[[:blank:]]+") nil ?\n)
+  "<div>" > \n _ \n "</div>" >)
+
+(define-skeleton html-span
+  "HTML span tag."
+  nil
+  (if (re-search-backward "^[[:blank:]]+") nil ?\n)
+  "<span>" > _ "</span>")
 
 (define-skeleton html-checkboxes
   "Group of connected checkbox inputs."


The above changes (in addition to adding skeletons for div and span
tags) assume that what we want is a nicely indented HTML buffer. Nested
divs should be indented, etc. This is what I want when writing HTML, but
it's an assumption that might not be welcomed by everyone. Also, there
might be a better way of ensuring proper indentation, I'm not that
familiar with skeletons. Essentially, in my opinion, every line should
always be indented.

WDYT?
Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]