help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nXML mode indentation


From: N. Raghavendra
Subject: Re: nXML mode indentation
Date: Tue, 08 May 2018 21:00:14 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

At 2018-05-08T08:19:45Z, Yuri Khan wrote:

> On Tue, May 8, 2018 at 3:09 PM N. Raghavendra <nyraghu27132@gmail.com>
> wrote:
>
> That probably means the indentation for that line is computed in
> ‘nxml-compute-indent-from-matching-start-tag’.

Thank you, that's absolutely correct, as I confirmed by putting a
`message' form at the end of that function.  I have now changed
nxml-mode.el as in the diff below.  With that, I get the required
indentation, as in

----------
<article>
  <section>
    <title>Kant lipsum</title>

    <para>Let us suppose that the noumena have nothing to do with
      necessity, since knowledge of the Categories is a posteriori.
      Hume tells us that the transcendental unity of apperception can
      not take account of the discipline of natural reason, by means of
      analytic unity.</para>
  </section>
</article>
----------

The change to `nxml-compute-indent-from-matching-start-tag' introduces a
local variable `only-end-tag' to distinguish between the line starting
with "analytic", and the last two lines.

Now, the next thing I see is that if, after this indentation, I do
`fill-paragraph', it goes back to the old indentation.  Anyway, I'll
deal with that later.  For now, I'll make do with these changes, which
at least give me the indentation I want.

Thanks very much for your help.

Best regards,

Raghu.

----------
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index e2b51bc..a2e92f4 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -1297,14 +1297,16 @@ nxml-compute-indent-from-matching-start-tag
 its line.  Otherwise return nil."
   (save-excursion
     (back-to-indentation)
-    (let ((bol (point)))
+    (let ((bol (point))
+          (only-end-tag nil))
       (let ((inhibit-field-text-motion t))
        (end-of-line))
       (skip-chars-backward " \t")
       (and (= (nxml-token-before) (point))
           (memq xmltok-type '(end-tag partial-end-tag))
           ;; start of line must not be inside a token
-          (or (= xmltok-start bol)
+          (or (and (= xmltok-start bol)
+                    (setq only-end-tag t))
               (save-excursion
                 (goto-char bol)
                 (nxml-token-after)
@@ -1322,7 +1324,9 @@ nxml-compute-indent-from-matching-start-tag
             (goto-char xmltok-start)
             (skip-chars-backward " \t")
             (bolp))
-          (current-indentation)))))
+           (if only-end-tag
+              (current-indentation)
+             (+ (current-indentation) nxml-child-indent))))))

 (defun nxml-compute-indent-from-previous-line ()
   "Compute the indent for a line using the indentation of a previous line."
@@ -1377,10 +1381,17 @@ nxml-compute-indent-from-previous-line
                        (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))))))))
+        (message "bc=%s ac=%s" before-context after-context)
+        (cond ((and (eq before-context 'mixed)
+                    (eq after-context 'markup))
+               (+ (current-column) nxml-child-indent))
+              ((and (eq before-context 'markup)
+                    (eq after-context 'markup))
+               (current-column))
+             (t (+ (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'.
----------

--
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]