>From 3928b1a04deaf74812bffa221d0883da9a52bab3 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Tue, 30 Apr 2019 16:00:46 -0700 Subject: [PATCH] Tweaks to html mode * lisp/textmodes/sgml-mode.el (sgml-attributes): Add the "class" and "id" attributes when needed. (html-mode-map): Add the `html-div' and `html-span' commands to the `html-quick-keys' map. (html-ordered-list, html-unordered-list, html-paragraph): Use the "\n" element properly. (html-div, html-span): New HTML skeletons. --- lisp/textmodes/sgml-mode.el | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 9e3be99af1..28ca40b733 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -773,8 +773,16 @@ 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.")) + (when alist + ;; Add class and id attributes if a) the element has any + ;; other attributes configured, and b) they're not already + ;; present. + (unless (assoc-string "class" alist) + (setq alist (cons '("class") alist))) + (unless (assoc-string "id" alist) + (setq alist (cons '("id") alist)))) (if (stringp (car alist)) (progn (insert (if (eq (preceding-char) ?\s) "" ?\s) @@ -1752,6 +1760,7 @@ html-mode-map (define-key map "\C-c\C-ci" 'html-image) (when html-quick-keys (define-key map "\C-c-" 'html-horizontal-rule) + (define-key map "\C-cd" 'html-div) (define-key map "\C-co" 'html-ordered-list) (define-key map "\C-cu" 'html-unordered-list) (define-key map "\C-cr" 'html-radio-buttons) @@ -1759,7 +1768,8 @@ html-mode-map (define-key map "\C-cl" 'html-list-item) (define-key map "\C-ch" 'html-href-anchor) (define-key map "\C-cn" 'html-name-anchor) - (define-key map "\C-ci" 'html-image)) + (define-key map "\C-ci" 'html-image) + (define-key map "\C-cs" 'html-span)) (define-key map "\C-c\C-s" 'html-autoview-mode) (define-key map "\C-c\C-v" 'browse-url-of-buffer) (define-key map [menu-bar html] (cons "HTML" menu-map)) @@ -1960,7 +1970,7 @@ html-tag-alist ("dd" ,(not sgml-xml-mode)) ("del" nil ("cite") ("datetime")) ("dfn") - ("div") + ("div" \n ("id") ("class")) ("dl" (nil \n ( "Term: " "
" str (if sgml-xml-mode "
") @@ -2446,16 +2456,16 @@ html-line (define-skeleton html-ordered-list "HTML ordered list tags." nil - "
    " \n + \n "
      " \n "
    1. " _ (if sgml-xml-mode "
    2. ") \n - "
    ") + "
" > \n) (define-skeleton html-unordered-list "HTML unordered list tags." nil - "" > \n) (define-skeleton html-list-item "HTML list item tag." @@ -2466,8 +2476,17 @@ html-list-item (define-skeleton html-paragraph "HTML paragraph tag." nil - (if (bolp) nil ?\n) - "

" _ (if sgml-xml-mode "

")) + \n "

" _ (if sgml-xml-mode "

")) + +(define-skeleton html-div + "HTML div tag." + nil + "
" > \n _ \n "
" >) + +(define-skeleton html-span + "HTML span tag." + nil + "" > _ "") (define-skeleton html-checkboxes "Group of connected checkbox inputs." -- 2.21.0