* sgml-mode.el fixes for html-mode
@ 2005-03-08 0:35 Juri Linkov
2005-03-08 13:18 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: Juri Linkov @ 2005-03-08 0:35 UTC (permalink / raw)
I propose the following fixes for html-mode in sgml-mode.el.
1. With sgml-xml-mode=t HTML skeletons insert empty XHTML elements
without a space before the trailing `/>'. But HTML compatibility
guidelines recommend using such a space for compatibility with
existing HTML user agents (i.e. `<hr />' instead of `<hr/>').
2. One bug fix for `C-c DEL' (`sgml-delete-tag') which on an empty
XHTML element (e.g `<hr />') deletes the subsequent unrelated tag
too. This should check whether the tag ends with `/>'.
3. html-href-anchor skeleton asking for an URL has an initial input
`http:'. This is inconvenient since `http://' is not the only one
possible URL prefix. And even if it is more frequent, full URLs
are rarely typed by hand, but more often copied from other places.
4. html-image could be consistent with html-href-anchor and ask
for URL of an image and set the default point inside the `alt=""'
HTML required attribute for the image description like html-href-anchor
does for the link description between <a...> and </a>.
5. XHTML standard recommends for compatibility with with existing HTML
clients which don't support the use of ID-type attributes, to write
the same ID and Name attributes, (e.g. <a id="foo" name="foo">).
6. XML does not support attribute minimization. Attribute names such
as `checked' cannot occur in elements without their value being
specified. This means using `checked="checked"' instead of `checked'.
7. \n before <p> in the html-paragraph skeleton is a disservice
rather than a convenience.
Index: lisp/textmodes/sgml-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/textmodes/sgml-mode.el,v
retrieving revision 1.103
diff -u -r1.103 sgml-mode.el
--- lisp/textmodes/sgml-mode.el 9 Feb 2005 15:50:36 -0000 1.103
+++ lisp/textmodes/sgml-mode.el 8 Mar 2005 00:21:42 -0000
@@ -629,7 +629,7 @@
(backward-char)
'(("") " [ " _ " ]]"))
((and (eq v2 t) sgml-xml-mode (member ,str sgml-empty-tags))
- '(("") -1 "/>"))
+ '(("") -1 " />"))
((or (and (eq v2 t) (not sgml-xml-mode)) (string-match "^[/!?]" ,str))
nil)
((symbolp v2)
@@ -818,7 +818,8 @@
(goto-char close)
(kill-sexp 1))
(setq open (point))
- (when (sgml-skip-tag-forward 1)
+ (when (and (sgml-skip-tag-forward 1)
+ (not (looking-back "/>")))
(kill-sexp -1)))
;; Delete any resulting empty line. If we didn't kill-sexp,
;; this *should* do nothing, because we're right after the tag.
@@ -1572,7 +1573,7 @@
("dir" ,@list)
("font" nil "size" ("-1") ("+1") ("-2") ("+2") ,@1-7)
("form" (\n _ \n "<input type=\"submit\" value=\"\""
- (if sgml-xml-mode "/>" ">"))
+ (if sgml-xml-mode " />" ">"))
("action" ,@(cdr href)) ("method" ("get") ("post")))
("h1" ,@align)
("h2" ,@align)
@@ -1891,13 +1892,15 @@
(define-skeleton html-href-anchor
"HTML anchor tag with href attribute."
"URL: "
- '(setq input "http:")
+ ;; '(setq input "http:")
"<a href=\"" str "\">" _ "</a>")
(define-skeleton html-name-anchor
"HTML anchor tag with name attribute."
"Name: "
- "<a name=\"" str "\">" _ "</a>")
+ "<a name=\"" str "\""
+ (if sgml-xml-mode (concat " id=\"" str "\""))
+ ">" _ "</a>")
(define-skeleton html-headline-1
"HTML level 1 headline tags."
@@ -1932,18 +1935,18 @@
(define-skeleton html-horizontal-rule
"HTML horizontal rule tag."
nil
- (if sgml-xml-mode "<hr/>" "<hr>") \n)
+ (if sgml-xml-mode "<hr />" "<hr>") \n)
(define-skeleton html-image
"HTML image tag."
- nil
- "<img src=\"" _ "\""
- (if sgml-xml-mode "/>" ">"))
+ "Image URL: "
+ "<img src=\"" str "\"" " alt=\"" _ "\""
+ (if sgml-xml-mode " />" ">"))
(define-skeleton html-line
"HTML line break tag."
nil
- (if sgml-xml-mode "<br/>" "<br>") \n)
+ (if sgml-xml-mode "<br />" "<br>") \n)
(define-skeleton html-ordered-list
"HTML ordered list tags."
@@ -1969,7 +1972,7 @@
"HTML paragraph tag."
nil
(if (bolp) nil ?\n)
- \n "<p>" _ (if sgml-xml-mode "</p>"))
+ "<p>" _ (if sgml-xml-mode "</p>"))
(define-skeleton html-checkboxes
"Group of connected checkbox inputs."
@@ -1981,12 +1984,13 @@
"\" name=\"" (or v1 (setq v1 (skeleton-read "Name: ")))
"\" value=\"" str ?\"
(when (y-or-n-p "Set \"checked\" attribute? ")
- (funcall skeleton-transformation " checked"))
- (if sgml-xml-mode "/>" ">")
+ (funcall skeleton-transformation
+ (if sgml-xml-mode " checked=\"checked\"" " checked")))
+ (if sgml-xml-mode " />" ">")
(skeleton-read "Text: " (capitalize str))
(or v2 (setq v2 (if (y-or-n-p "Newline after text? ")
(funcall skeleton-transformation
- (if sgml-xml-mode "<br/>" "<br>"))
+ (if sgml-xml-mode "<br />" "<br>"))
"")))
\n))
@@ -2000,12 +2004,13 @@
"\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: ")))
"\" value=\"" str ?\"
(when (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? ")))
- (funcall skeleton-transformation " checked"))
- (if sgml-xml-mode "/>" ">")
+ (funcall skeleton-transformation
+ (if sgml-xml-mode " checked=\"checked\"" " checked")))
+ (if sgml-xml-mode " />" ">")
(skeleton-read "Text: " (capitalize str))
(or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ")
(funcall skeleton-transformation
- (if sgml-xml-mode "<br/>" "<br>"))
+ (if sgml-xml-mode "<br />" "<br>"))
"")))
\n))
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: sgml-mode.el fixes for html-mode
2005-03-08 0:35 sgml-mode.el fixes for html-mode Juri Linkov
@ 2005-03-08 13:18 ` Stefan Monnier
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2005-03-08 13:18 UTC (permalink / raw)
Cc: emacs-devel
> I propose the following fixes for html-mode in sgml-mode.el.
Feel free to install them.
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-03-08 13:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-08 0:35 sgml-mode.el fixes for html-mode Juri Linkov
2005-03-08 13:18 ` Stefan Monnier
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).