unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-devel@gnu.org
Subject: some proposed tweaks to HTML mode
Date: Thu, 21 Mar 2019 15:11:17 -0700	[thread overview]
Message-ID: <875zsbri7u.fsf@ericabrahamsen.net> (raw)

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	other threads:[~2019-03-21 22:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-21 22:11 Eric Abrahamsen [this message]
2019-03-21 22:21 ` some proposed tweaks to HTML mode Andreas Schwab
2019-03-21 22:32   ` Eric Abrahamsen
2019-03-21 22:44     ` Eric Abrahamsen
2019-03-21 22:53     ` Eric Abrahamsen
2019-03-22 17:58 ` Stefan Monnier
2019-03-22 19:26   ` Eric Abrahamsen
2019-03-22 20:04     ` Stefan Monnier
2019-03-22 22:55       ` Eric Abrahamsen
2019-03-23 15:29         ` Eric Abrahamsen
2019-05-05 18:43         ` Eric Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zsbri7u.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).