Subject: bug#20161: Fwd: Requesting review for change to lisp/textmodes/sgml-mode.el

From: Jackson Hamilton <[email-masked]>
Date: Sun, 22 Mar 2015 08:39:22 -0700

Okay, created a defcustom for it. Patch is attached.

On Sun, Mar 22, 2015 at 7:03 AM, Stefan Monnier <[email-masked]>
wrote:

> > He could break the attribute onto a new line and it would be indented
> like
> > so:
>
> > <element
> >    attribute="value">
>
> > But sgml-basic-offset defaults to 2, not 3, so it doesn't make much sense
> > that
> > the attribute is indented by 3 spaces.
>
> As is clear from the code you're changing the "1+" is quite deliberate,
> which shows some people prefer it that way.
>
> So as discussed, this indentation step should have its own custom var.
> You can make it default to the behavior you prefer if you want.
>
> Other than that, the patch looks OK.
>
>
>         Stefan
>
From c4ab20eb5a0454438d96635b1c12f7b299e10579 Mon Sep 17 00:00:00 2001
From: Jackson Ray Hamilton <[email-masked]>
Date: Sun, 22 Mar 2015 08:22:29 -0700
Subject: [PATCH] Have `sgml-attribute-offset' control SGML attribute
 indentation

Fixes: debbugs:20161

* textmodes/sgml-mode.el (sgml-attribute-offset): New defcustom.
(sgml-calculate-indent): Use `sgml-attribute-offset' for attribute
indentation.
---
 lisp/ChangeLog                       |  6 ++++++
 lisp/textmodes/sgml-mode.el          | 23 +++++++++++++++++++++--
 test/indent/sgml-mode-attribute.html | 14 ++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 test/indent/sgml-mode-attribute.html

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2f9c430..ba95401 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-22  Jackson Ray Hamilton  <[email-masked]>
+
+	* textmodes/sgml-mode.el (sgml-attribute-offset): New defcustom.
+	(sgml-calculate-indent): Use `sgml-attribute-offset' for attribute
+	indentation.
+
 2015-03-21  Titus von der Malsburg  <[email-masked]>
 
 	* window.el (window-font-width, window-font-height)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 12d98c8..8266647 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -46,6 +46,25 @@
   :type 'integer
   :group 'sgml)
 
+(defcustom sgml-attribute-offset 0
+  "Specifies a delta for attribute indentation in `sgml-indent-line'.
+
+When 0, attribute indentation looks like this:
+
+  <element
+    attribute=\"value\">
+  </element>
+
+When 2, attribute indentation looks like this:
+
+  <element
+      attribute=\"value\">
+  </element>"
+  :version "25.1"
+  :type 'integer
+  :safe 'integerp
+  :group 'sgml)
+
 (defcustom sgml-xml-mode nil
   "When non-nil, tag insertion functions will be XML-compliant.
 It is set to be buffer-local when the file has
@@ -1510,13 +1529,13 @@ LCON is the lexical context, if any."
     (`pi nil)
 
     (`tag
-     (goto-char (1+ (cdr lcon)))
+     (goto-char (+ (cdr lcon) sgml-attribute-offset))
      (skip-chars-forward "^ \t\n")	;Skip tag name.
      (skip-chars-forward " \t")
      (if (not (eolp))
 	 (current-column)
        ;; This is the first attribute: indent.
-       (goto-char (1+ (cdr lcon)))
+       (goto-char (+ (cdr lcon) sgml-attribute-offset))
        (+ (current-column) sgml-basic-offset)))
 
     (`text
diff --git a/test/indent/sgml-mode-attribute.html b/test/indent/sgml-mode-attribute.html
new file mode 100644
index 0000000..4cbec0a
--- /dev/null
+++ b/test/indent/sgml-mode-attribute.html
@@ -0,0 +1,14 @@
+<element attribute="value"></element>
+
+<element
+    attribute="value">
+  <element
+      attribute="value">
+  </element>
+</element>
+
+<!--
+    Local Variables:
+    sgml-attribute-offset: 2
+    End:
+  -->
-- 
1.9.1