From b51377207327b5fe7fe62049afa75bb5b58b298e Mon Sep 17 00:00:00 2001 From: David Shepherd Date: Sat, 19 Mar 2016 18:44:03 +0000 Subject: [PATCH 3/3] In sgml-mode add option to disable alignment of strings and attributes --- etc/NEWS | 6 ++++++ lisp/textmodes/sgml-mode.el | 26 ++++++++++++++++++++------ test/lisp/textmodes/sgml-mode-tests.el | 27 +++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 9695a55..5af1ccf 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -129,6 +129,12 @@ different group ID. --- ** `auto-revert-use-notify' is set back to t in `global-auto-revert-mode'. +** sgml-mode + ++++ +*** New option `sgml-indentation-align' controls whether indenting + aligns strings and attributes with the previous line. + * New Modes and Packages in Emacs 25.2 diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index e6eb060..4c82f56 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -65,6 +65,13 @@ sgml-attribute-offset :safe 'integerp :group 'sgml) +(defcustom sgml-indentation-align t + "Specifies whether `sgml-indent-line' should align attributes +and strings with the previous line." + :type 'boolean + :version "25.2" + :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 @@ -1523,7 +1530,9 @@ sgml-calculate-indent ;; Previous line is inside the string. (current-indentation) (goto-char (cdr lcon)) - (1+ (current-column)))) + (if sgml-indentation-align + (1+ (current-column)) + (+ (current-indentation) sgml-basic-offset)))) (`comment (let ((mark (looking-at "--"))) @@ -1552,11 +1561,16 @@ sgml-calculate-indent (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 (+ (cdr lcon) sgml-attribute-offset)) - (+ (current-column) sgml-basic-offset))) + (cond ((and sgml-indentation-align (not (eolp))) + (current-column)) + (sgml-indentation-align + ;; This is the first attribute: indent. + (goto-char (+ (cdr lcon) sgml-attribute-offset)) + (+ (current-column) sgml-basic-offset)) + (t + (goto-char (cdr lcon)) + (+ (current-indentation) sgml-basic-offset)))) + (`text (while (looking-at " test @@ -152,7 +154,7 @@ sgml-test-indentation
test
-")) +"))) (ert-deftest sgml-indent-should-align-attributes () (sgml-test-indentation " @@ -205,6 +207,27 @@ sgml-test-indentation attribute=\"value\"> "))) +(ert-deftest sgml-indent-should-be-able-to-disable-align-attributes () + (let ((sgml-indentation-align nil)) + (sgml-test-indentation " +
+" " +
+"))) + +(ert-deftest sgml-indent-should-be-able-to-disable-align-strings () + (let ((sgml-indentation-align nil)) + (sgml-test-indentation " +
+" " +
+"))) (provide 'sgml-mode-tests) -- 2.1.4