* bug#7937: not entirely sure how to go about this, my first bug fix.
@ 2023-03-26 11:54 Stephen Meister
2023-03-26 14:19 ` Michael Albinus
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Meister @ 2023-03-26 11:54 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 672 bytes --]
Hi,
I've tried to fix bug #7937 (my patch is attached). I've also tried to
join the bug-gnu-emacs mailing list but I don't think the subscription
request has completed yet. Is it required to be a member of that mailing
list before sending a message to bug-gnu-emacs@gnu.org?
Also, is it ok to have the subject of my email formatted as I do here
("bug#XYZ: --description--")?
Further, given that I'm currently unemployed for the next week is it
acceptable to submit code without an employer signing any paperwork as I
don't technically have an employer? In the past I have completed the
copyright assignment for emacs ( gnu.org #1776190 via Craig Topham).
-steve
[-- Attachment #2: bug7937.patch --]
[-- Type: text/x-patch, Size: 5861 bytes --]
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 3869d0327fd..7317f7186ff 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -1378,60 +1378,35 @@ nxml-compute-indent-from-previous-line
(not (or (= xmltok-start (point))
(eq xmltok-type 'data))))))
(setq ref (point))
- ;; Now scan over tokens until the end of the line to be indented.
- ;; Determine the context before and after the beginning of the
- ;; line.
- (while (< (point) eol)
- (nxml-tokenize-forward)
- (cond ((<= bol xmltok-start)
- (setq after-context
- (nxml-merge-indent-context-type after-context)))
- ((and (<= (point) bol)
- (not (and (eq xmltok-type 'partial-start-tag)
- (= (point) bol))))
- (setq before-context
- (nxml-merge-indent-context-type before-context)))
- ((eq xmltok-type 'data)
- (setq before-context
- (nxml-merge-indent-context-type before-context))
- (setq after-context
- (nxml-merge-indent-context-type after-context)))
- ;; If in the middle of a token that looks inline,
- ;; then indent relative to the previous non-blank line
- ((eq (nxml-merge-indent-context-type before-context)
- 'mixed)
- (goto-char prev-bol)
- (throw 'indent (current-column)))
- (t
- (throw 'indent
- (nxml-compute-indent-in-token bol))))
- (skip-chars-forward " \t\r\n"))
- (goto-char ref)
- (+ (current-column)
- (* nxml-child-indent
- (+ (if (eq before-context 'start-tag) 1 0)
- (if (eq after-context 'end-tag) -1 0))))))))
-
-(defun nxml-merge-indent-context-type (context)
- "Merge the indent context type CONTEXT with the token in `xmltok-type'.
-Return the merged indent context type. An indent context type is
-either nil or one of the symbols `start-tag', `end-tag', `markup',
-`comment', `mixed'."
- (cond ((memq xmltok-type '(start-tag partial-start-tag))
- (if (memq context '(nil start-tag comment))
- 'start-tag
- 'mixed))
- ((memq xmltok-type '(end-tag partial-end-tag))
- (if (memq context '(nil end-tag comment))
- 'end-tag
- 'mixed))
- ((eq xmltok-type 'comment)
- (cond ((memq context '(start-tag end-tag comment))
- context)
- (context 'mixed)
- (t 'comment)))
- (context 'mixed)
- (t 'markup)))
+ ;; scan over the prevous line to determine the additional
+ ;; depth of element nesting. Also collect the depth change at
+ ;; the beginning of the line.
+ (let ((depth-before 0)
+ (depth-bol 0))
+ (nxml-tokenize-forward)
+ (when (> (point) bol) ; one token spans this and the line before
+ (throw 'indent (nxml-compute-indent-in-token bol)))
+ (while (< (point) bol)
+ (cond ((eq xmltok-type 'partial-start-tag)
+ (throw 'indent (nxml-compute-indent-in-token bol)))
+ ((memq xmltok-type '(start-tag))
+ (cl-incf depth-before))
+ ((memq xmltok-type '(end-tag partial-end-tag))
+ (cl-incf depth-before -1)))
+ (skip-chars-forward " \t\r\n")
+ (nxml-tokenize-forward))
+ (when (<= xmltok-start eol)
+ (cond ((memq xmltok-type '(start-tag partial-start-tag data))
+ (setq depth-bol 1))
+ ((memq xmltok-type '(end-tag partial-end-tag))
+ (setq depth-bol -1))))
+ (goto-char ref)
+ (+ (current-column)
+ (* nxml-child-indent
+ ;; never change more than one indent level
+ (cl-signum (if (eq depth-before 0)
+ (min 0 depth-bol)
+ (+ (cl-signum depth-before) depth-bol))))))))))
(defun nxml-compute-indent-in-token (pos)
"Return the indent for a line that starts inside a token.
diff --git a/test/lisp/nxml/nxml-mode-tests.el b/test/lisp/nxml/nxml-mode-tests.el
index 973f2ebb67e..f5a691ee181 100644
--- a/test/lisp/nxml/nxml-mode-tests.el
+++ b/test/lisp/nxml/nxml-mode-tests.el
@@ -31,6 +31,17 @@ nxml-mode-tests-correctly-indented-string
(ert-deftest nxml-indent-line-after-attribute ()
(should (nxml-mode-tests-correctly-indented-string "
+<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"
+ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+ xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0
+ https://maven.apache.org/xsd/settings-1.0.0.xsd\">
+ <mirrors one=\"two\"
+ three=\"four\">
+ ...
+ </mirrors>
+</settings>
+"))
+ (should (nxml-mode-tests-correctly-indented-string "
<settings
xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
@@ -155,5 +166,46 @@ nxml-mode-test-comment-bug-17264
;; Inside comment
(should (eq (nth 4 (syntax-ppss)) t)))))
+(ert-deftest nxml-mode-test-multiple-start-tags-single-line ()
+ "Test for Bug#7937."
+ (with-temp-buffer
+ (should (nxml-mode-tests-correctly-indented-string "<kml>
+ <Document>
+ <Folder><name>abc</name>
+ <Folder><name>123</name>
+ </Folder>
+ </Folder>
+ </Document>
+</kml>"))
+ (should (nxml-mode-tests-correctly-indented-string "<kml>
+ <Document>
+ <Folder><name>abc</name>
+ <Folder></Folder>
+ </Folder>
+ </Document>
+</kml>"))
+ (should (nxml-mode-tests-correctly-indented-string "<kml>
+ <document></document>
+ <more><name></name>
+ </more>
+ abckde
+ <!-- stuff -->
+ <more><name>e<inner><!-- x --></inner>
+ <inner2 />
+ </name></more>
+ <more><name></name><inner>
+ <inner2 />
+ </inner></more>
+ <up>
+ <more><name><here><name>x
+ </name></here></name></more>
+ <nl>abc</nl>
+ <nl>abc</nl>
+ </up>
+ <nl>abc</nl>
+</kml>
+"))))
+x
+
(provide 'nxml-mode-tests)
;;; nxml-mode-tests.el ends here
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: bug#7937: not entirely sure how to go about this, my first bug fix.
2023-03-26 11:54 bug#7937: not entirely sure how to go about this, my first bug fix Stephen Meister
@ 2023-03-26 14:19 ` Michael Albinus
0 siblings, 0 replies; 2+ messages in thread
From: Michael Albinus @ 2023-03-26 14:19 UTC (permalink / raw)
To: Stephen Meister; +Cc: help-gnu-emacs
Stephen Meister <pallagun@gmail.com> writes:
> Hi,
Hi steve,
> I've tried to fix bug #7937 (my patch is attached). I've also tried to
> join the bug-gnu-emacs mailing list but I don't think the subscription
> request has completed yet. Is it required to be a member of that mailing
> list before sending a message to bug-gnu-emacs@gnu.org?
You should reply to the bug specifiy mail address, <7937@debbugs.gnu.org>
this case. Your message will *also* be visible in the bug-gnu-emacs ML.
> Also, is it ok to have the subject of my email formatted as I do here
> ("bug#XYZ: --description--")?
Yep.
> Further, given that I'm currently unemployed for the next week is it
> acceptable to submit code without an employer signing any paperwork as I
> don't technically have an employer? In the past I have completed the
> copyright assignment for emacs ( gnu.org #1776190 via Craig Topham).
Don't know. Personally, I have no employer (anymore), and so it is
sufficient to have signed the FSF papers by myself. Until you have a new
employer, this should also be OK for you, but IANAL.
> -steve
Best regards, Michael.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-26 14:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-26 11:54 bug#7937: not entirely sure how to go about this, my first bug fix Stephen Meister
2023-03-26 14:19 ` Michael Albinus
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).