From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "N. Raghavendra" Newsgroups: gmane.emacs.help Subject: Re: nXML mode indentation Date: Wed, 09 May 2018 08:52:36 +0530 Message-ID: <871selv7gj.fsf@gmail.com> References: <87a7tedxyb.fsf@gmail.com> <8736z2ydeq.fsf@gmail.com> <878t8uwouz.fsf@gmail.com> <87muxaupvd.fsf@gmail.com> Reply-To: "N. Raghavendra" NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1525836074 1501 195.159.176.226 (9 May 2018 03:21:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 9 May 2018 03:21:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 09 05:21:09 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGFf8-0000Eo-4G for geh-help-gnu-emacs@m.gmane.org; Wed, 09 May 2018 05:21:06 +0200 Original-Received: from localhost ([::1]:54213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGFhF-0006jj-AQ for geh-help-gnu-emacs@m.gmane.org; Tue, 08 May 2018 23:23:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGFgp-0006jN-BI for help-gnu-emacs@gnu.org; Tue, 08 May 2018 23:22:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGFgk-0004Yk-J8 for help-gnu-emacs@gnu.org; Tue, 08 May 2018 23:22:51 -0400 Original-Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]:39756) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGFgk-0004Xn-Ai for help-gnu-emacs@gnu.org; Tue, 08 May 2018 23:22:46 -0400 Original-Received: by mail-pf0-x229.google.com with SMTP id a22so10822093pfn.6 for ; Tue, 08 May 2018 20:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:user-agent:reply-to :mail-followup-to:date:message-id:mime-version; bh=AypKh2jnEDkzwQ3Xy7XYgswjA9hgx+PUDshH7pDEjvs=; b=eXPZ6VT2aiQk+5AUVqj8D8mw+H1LC70eD4pQT3kIWgI3wiRItxSvN7wVj7bTtglpMc i7htmjh3mqLXOb6focvNUxucG6eRXJNV4nGSqDC3d5hdC150OPU/ZJnbVHTRPamukAp1 b+tZn1zV+Hqs1Vns6E5ULOaVw+2TRsM+HJQbSQMbRPjLRtBE6Im8npfVZXjkefMfRr8W hqyFOHV87T91PJKLfcpWbKU7aTdZS24b2Sn2KIC5aD+6sOGSf6spGpcrQVbuk3y6K+Ch NdLSRGgIdgyeU3+aDjDAQVgqx7wgQ9pZ1orAXvhKtPjKF32LWmyYvJZQZoYBibyzqqJY SAeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references :user-agent:reply-to:mail-followup-to:date:message-id:mime-version; bh=AypKh2jnEDkzwQ3Xy7XYgswjA9hgx+PUDshH7pDEjvs=; b=lQmrMnbHdGdHGkGrmgjwH1NwXRr6NAhTiaI2E73VRgMCAPqdly2BgvY6Ch+Vfhg/QB emCTEfLqjS/bUr17ENmupHfpCkDQFpIhcVeDm+h5Qf9AtivkZdbVenREaorYhod5w/D9 6SUIvMjW/fOG29LjmXgtkBHgtOE2UA0BOUqKbxRqUIxUJbwaEgQhnXTkLKEehrK/bWKL vEbGT0hUMhhf7QJEbi1jJqX4gWnr1zv5FyDeFJ5GWL1PoLIs5AlWAiF+MfqcSU5y8KH+ VGyiL2BvB86uj0yOdPCObohrk83iW13jZBpbyuBHJ/oa2EsUuPLRE9rU/+iwlE6DjwB+ 0ueQ== X-Gm-Message-State: ALQs6tAFkIF2iNJBBwZYnpRuUR4w6i0FCT7Bgi5ELCq4fQSNcTYmnaz8 ciwk8bU+EOD7KHdPj9rRGCO5yA== X-Google-Smtp-Source: AB8JxZpjBMSIwFjlACZsUCPL9hYA29ueyLeSLSJ1XiGPVe5Hzdk1uE+UzksMTBhn1xgtEUyH4g4dQg== X-Received: by 10.98.156.13 with SMTP id f13mr40961538pfe.15.1525836161045; Tue, 08 May 2018 20:22:41 -0700 (PDT) Original-Received: from ailuros ([14.139.59.140]) by smtp.gmail.com with ESMTPSA id b6-v6sm43451437pgr.52.2018.05.08.20.22.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 20:22:40 -0700 (PDT) In-Reply-To: <87muxaupvd.fsf@gmail.com> (N. Raghavendra's message of "Tue, 08 May 2018 21:00:14 +0530") Mail-Followup-To: help-gnu-emacs@gnu.org X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::229 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116697 Archived-At: At 2018-05-08T21:00:14+05:30, N. Raghavendra wrote: > 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. I've found a fix for this also. I've seen references to difficulties with nXML mode indentation, so I am enclosing the changes in case someone else is bugged by the problem. Using the advice mechanism seems a kludge, but it will do for me at present. Thanks, Raghu. ---------- ;; Fix indentation, so that it conforms to the guidelines of the ;; FreeBSD Documentation Project. ;; https://www.freebsd.org/doc/en_US.ISO8859-1/books/fdp-primer/writing-style-guide.html#writing-style-indentation (defun my-nxml-compute-indent-from-matching-start-tag () "Compute the indent for an end tag line using its start tag. This function is meant to be an overriding advice for `nxml-compute-indent-from-matching-start-tag'. Adds a local variable ONLY-END-TAG to distinguish between end tags that are alone on a line, from end tags that are accompanied by text on a line." (save-excursion (back-to-indentation) (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 (and (= xmltok-start bol) (setq only-end-tag t)) (save-excursion (goto-char bol) (nxml-token-after) (= xmltok-start bol)) (eq xmltok-type 'data)) (condition-case nil (nxml-scan-element-backward (point) nil (- (point) nxml-end-tag-indent-scan-distance)) (nxml-scan-error nil)) (< xmltok-start bol) (progn (goto-char xmltok-start) (skip-chars-backward " \t") (bolp)) (if only-end-tag (current-indentation) (+ (current-indentation) nxml-child-indent)))))) (advice-add 'nxml-compute-indent-from-matching-start-tag :override #'my-nxml-compute-indent-from-matching-start-tag) (defun my-nxml-compute-indent-from-previous-line () "Compute the indent for a line using the previous line. This function is meant to be an overriding advice for `nxml-compute-indent-from-previous-line'. Considers extra cases depending on the context of the line." (save-excursion (end-of-line) (let ((eol (point)) bol prev-bol ref before-context after-context) (back-to-indentation) (setq bol (point)) (catch 'indent ;; Move backwards until the start of a non-blank line that is ;; not inside a token. (while (progn (when (= (forward-line -1) -1) (throw 'indent 0)) (back-to-indentation) (if (looking-at "[ \t]*$") t (or prev-bol (setq prev-bol (point))) (nxml-token-after) (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) (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)))))))))) (advice-add 'nxml-compute-indent-from-previous-line :override #'my-nxml-compute-indent-from-previous-line) (defun my-nxml-do-fill-paragraph (arg) "Fill paragraph in `nxml-mode'. This function is meant to be an overriding advice for `nxml-do-fill-paragraph'. Adds some space to `fill-prefix'." (let (fill-paragraph-function fill-prefix start end) (save-excursion (nxml-forward-paragraph) (setq end (point)) (nxml-backward-paragraph) (skip-chars-forward " \t\r\n") (setq start (point)) (beginning-of-line) (setq fill-prefix (concat (buffer-substring-no-properties (point) start) (make-string nxml-child-indent ?\s))) (when (and (not (nxml-get-inside (point))) (looking-at "[ \t]*