unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* some proposed tweaks to HTML mode
@ 2019-03-21 22:11 Eric Abrahamsen
  2019-03-21 22:21 ` Andreas Schwab
  2019-03-22 17:58 ` Stefan Monnier
  0 siblings, 2 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2019-03-21 22:11 UTC (permalink / raw)
  To: emacs-devel

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




^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-05-05 18:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-21 22:11 some proposed tweaks to HTML mode Eric Abrahamsen
2019-03-21 22:21 ` 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

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).