all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#35517: 27.0.50; Small improvements to HTML mode
@ 2019-04-30 23:38 Eric Abrahamsen
  2019-05-05 18:38 ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2019-04-30 23:38 UTC (permalink / raw)
  To: 35517

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]


The attached patch provides some small improvements to HTML mode. It
adds `html-div' and `html-span' skeleton commands, and changes the
newline/indent behavior of `html-ordered-list', `html-unordered-list',
`html-list-item', and `html-paragraph'. It also offers "class" and "id"
attributes to most HTML tags in `sgml-attributes'.

Comments welcome!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Tweaks-to-html-mode.patch --]
[-- Type: text/x-patch, Size: 3306 bytes --]

From 0293d7bb423950264558363e4e3a3d695f323347 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
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 | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 9e3be99af1..b0d0ba8536 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))
@@ -2446,16 +2456,16 @@ html-line
 (define-skeleton html-ordered-list
   "HTML ordered list tags."
   nil
-  "<ol>" \n
+  \n "<ol>" \n
   "<li>" _ (if sgml-xml-mode "</li>") \n
-  "</ol>")
+  "</ol>" > \n)
 
 (define-skeleton html-unordered-list
   "HTML unordered list tags."
   nil
-  "<ul>" \n
+  \n "<ul>" \n
   "<li>" _ (if sgml-xml-mode "</li>") \n
-  "</ul>")
+  "</ul>" > \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)
-  "<p>" _ (if sgml-xml-mode "</p>"))
+  \n "<p>" _ (if sgml-xml-mode "</p>"))
+
+(define-skeleton html-div
+  "HTML div tag."
+  nil
+  "<div>" > \n _ \n "</div>" >)
+
+(define-skeleton html-span
+  "HTML span tag."
+  nil
+  "<span>" > _ "</span>")
 
 (define-skeleton html-checkboxes
   "Group of connected checkbox inputs."
-- 
2.21.0


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

* bug#35517: 27.0.50; Small improvements to HTML mode
  2019-04-30 23:38 bug#35517: 27.0.50; Small improvements to HTML mode Eric Abrahamsen
@ 2019-05-05 18:38 ` Eric Abrahamsen
  2019-06-23 17:16   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2019-05-05 18:38 UTC (permalink / raw)
  To: 35517

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> The attached patch provides some small improvements to HTML mode. It
> adds `html-div' and `html-span' skeleton commands, and changes the
> newline/indent behavior of `html-ordered-list', `html-unordered-list',
> `html-list-item', and `html-paragraph'. It also offers "class" and "id"
> attributes to most HTML tags in `sgml-attributes'.
>
> Comments welcome!

Here's an updated patch -- "div" elements should always have "span" and
"id" offered as attributes.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Tweaks-to-html-mode.patch --]
[-- Type: text/x-patch, Size: 3565 bytes --]

From 3928b1a04deaf74812bffa221d0883da9a52bab3 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
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: "
 		   "<dt>" str (if sgml-xml-mode "</dt>")
@@ -2446,16 +2456,16 @@ html-line
 (define-skeleton html-ordered-list
   "HTML ordered list tags."
   nil
-  "<ol>" \n
+  \n "<ol>" \n
   "<li>" _ (if sgml-xml-mode "</li>") \n
-  "</ol>")
+  "</ol>" > \n)
 
 (define-skeleton html-unordered-list
   "HTML unordered list tags."
   nil
-  "<ul>" \n
+  \n "<ul>" \n
   "<li>" _ (if sgml-xml-mode "</li>") \n
-  "</ul>")
+  "</ul>" > \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)
-  "<p>" _ (if sgml-xml-mode "</p>"))
+  \n "<p>" _ (if sgml-xml-mode "</p>"))
+
+(define-skeleton html-div
+  "HTML div tag."
+  nil
+  "<div>" > \n _ \n "</div>" >)
+
+(define-skeleton html-span
+  "HTML span tag."
+  nil
+  "<span>" > _ "</span>")
 
 (define-skeleton html-checkboxes
   "Group of connected checkbox inputs."
-- 
2.21.0


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

* bug#35517: 27.0.50; Small improvements to HTML mode
  2019-05-05 18:38 ` Eric Abrahamsen
@ 2019-06-23 17:16   ` Lars Ingebrigtsen
  2019-06-23 17:33     ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 17:16 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 35517

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Here's an updated patch -- "div" elements should always have "span" and
> "id" offered as attributes.

This made me confused until I read the code -- which is "class" and
"id", which makes more sense.  :-)

But...


[...]

> +	(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))))

Should <div>s always have class/id attributes?  I guess it's unusual to
have neither, but I find myself writing <div>s all the time with just
class.  Or just id...

> +(define-skeleton html-div
> +  "HTML div tag."
> +  nil
> +  "<div>" > \n _ \n "</div>" >)
> +
> +(define-skeleton html-span
> +  "HTML span tag."
> +  nil
> +  "<span>" > _ "</span>")

The skeleton commands look uncontroversial, though.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#35517: 27.0.50; Small improvements to HTML mode
  2019-06-23 17:16   ` Lars Ingebrigtsen
@ 2019-06-23 17:33     ` Eric Abrahamsen
  2019-06-23 17:39       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 17:33 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 35517


On 06/23/19 19:16 PM, Lars Ingebrigtsen wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Here's an updated patch -- "div" elements should always have "span" and
>> "id" offered as attributes.
>
> This made me confused until I read the code -- which is "class" and
> "id", which makes more sense.  :-)

Oops!

> But...
>
>
> [...]
>
>> +	(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))))
>
> Should <div>s always have class/id attributes?  I guess it's unusual to
> have neither, but I find myself writing <div>s all the time with just
> class.  Or just id...

The patch changes the default value of `html-tag-alist' as well, to add
id and class, so that's already taken care of.

>> +(define-skeleton html-div
>> +  "HTML div tag."
>> +  nil
>> +  "<div>" > \n _ \n "</div>" >)
>> +
>> +(define-skeleton html-span
>> +  "HTML span tag."
>> +  nil
>> +  "<span>" > _ "</span>")
>
> The skeleton commands look uncontroversial, though.

Cool.





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

* bug#35517: 27.0.50; Small improvements to HTML mode
  2019-06-23 17:33     ` Eric Abrahamsen
@ 2019-06-23 17:39       ` Lars Ingebrigtsen
  2019-06-23 18:35         ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 17:39 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 35517

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

>>> +	(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))))
>>
>> Should <div>s always have class/id attributes?  I guess it's unusual to
>> have neither, but I find myself writing <div>s all the time with just
>> class.  Or just id...
>
> The patch changes the default value of `html-tag-alist' as well, to add
> id and class, so that's already taken care of.

I may well be misreading the patch, but doesn't the change above mean
that the user will be prompted for class/id when they insert a <div>?
That's what I was worried about...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#35517: 27.0.50; Small improvements to HTML mode
  2019-06-23 17:39       ` Lars Ingebrigtsen
@ 2019-06-23 18:35         ` Eric Abrahamsen
  2019-06-23 18:37           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 18:35 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 35517


On 06/23/19 19:39 PM, Lars Ingebrigtsen wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>>>> +	(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))))
>>>
>>> Should <div>s always have class/id attributes?  I guess it's unusual to
>>> have neither, but I find myself writing <div>s all the time with just
>>> class.  Or just id...
>>
>> The patch changes the default value of `html-tag-alist' as well, to add
>> id and class, so that's already taken care of.
>
> I may well be misreading the patch, but doesn't the change above mean
> that the user will be prompted for class/id when they insert a <div>?
> That's what I was worried about...

Oh, no, those are two separate things. There are now keybindings for
inserting div/span, but no prompting happens until you try to insert an
attribute into a div. Now it offers you id/class, whereas before it told
you "No attributes configured", which I always found infuriating.





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

* bug#35517: 27.0.50; Small improvements to HTML mode
  2019-06-23 18:35         ` Eric Abrahamsen
@ 2019-06-23 18:37           ` Lars Ingebrigtsen
  2019-06-24 17:21             ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 18:37 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 35517

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Oh, no, those are two separate things. There are now keybindings for
> inserting div/span, but no prompting happens until you try to insert an
> attribute into a div. Now it offers you id/class, whereas before it told
> you "No attributes configured", which I always found infuriating.

Ah, I see.  Then the patch looks good to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#35517: 27.0.50; Small improvements to HTML mode
  2019-06-23 18:37           ` Lars Ingebrigtsen
@ 2019-06-24 17:21             ` Eric Abrahamsen
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2019-06-24 17:21 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 35517, 35517-done


On 06/23/19 20:37 PM, Lars Ingebrigtsen wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Oh, no, those are two separate things. There are now keybindings for
>> inserting div/span, but no prompting happens until you try to insert an
>> attribute into a div. Now it offers you id/class, whereas before it told
>> you "No attributes configured", which I always found infuriating.
>
> Ah, I see.  Then the patch looks good to me.

Okay, pushed and closing.

Thanks,
Eric





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

end of thread, other threads:[~2019-06-24 17:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-30 23:38 bug#35517: 27.0.50; Small improvements to HTML mode Eric Abrahamsen
2019-05-05 18:38 ` Eric Abrahamsen
2019-06-23 17:16   ` Lars Ingebrigtsen
2019-06-23 17:33     ` Eric Abrahamsen
2019-06-23 17:39       ` Lars Ingebrigtsen
2019-06-23 18:35         ` Eric Abrahamsen
2019-06-23 18:37           ` Lars Ingebrigtsen
2019-06-24 17:21             ` Eric Abrahamsen

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.