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

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

bug#27552: 25.2.50; Indentation problem in rnc-mode


From: Stefan Monnier
Subject: bug#27552: 25.2.50; Indentation problem in rnc-mode
Date: Wed, 15 Jun 2022 11:15:28 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Lars Ingebrigtsen [2022-06-15 16:25:29] wrote:
> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> I guess this "=" rule is for stuff like the "pattern =" etc.  But it
>> leads to things like this being indented more for each line:
>>
>> default namesace rng = "http://relaxng.org/ns/structure/1.0";
>> namespace local = ""
>> datatypes xsd = "http://www.w3.org/2001/XMLSchema-datatypes";

Part of the problem is that the grammar we use is incorrect, so we
parse incorrectly, and we have to patch things up in the indentation
rules :-(

> Or...  is the problem here that we don't end pattern with a newline?

Kind of, yes.  There are various places where we could try and fix
this problem, but this might be the simplest, indeed.
I pushed the patch below which does that.


        Stefan


diff --git a/rnc-mode.el b/rnc-mode.el
index 30f3c39970..33363d2057 100644
--- a/rnc-mode.el
+++ b/rnc-mode.el
@@ -1,6 +1,6 @@
 ;;; rnc-mode.el --- Emacs mode to edit Relax-NG Compact files  -*- 
lexical-binding:t -*-
 
-;; Copyright (C) 1994-1998, 2001-2016 Free Software Foundation, Inc.
+;; Copyright (C) 1994-1998, 2001-2022 Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; Keywords: xml relaxng
@@ -96,11 +96,18 @@
     '((assoc "," "&" "|") (nonassoc "?" "*" "+"))
     )))
 
+(defconst rnc-smie--def-regexp
+  (concat "\\(?:\\(?:namespace\\|datatypes\\)[ \t\n]+\\)?"
+          "\\(?:\\s_\\|\\sw\\)+[ \t\n]*[|&]?=")
+  "Regexp matching a \"definition\".
+Any line that starts with this is presumed to start a new definition,
+so the preceding newline is turned into an implicit \" ; \" token.")
+
 (defun rnc-smie-forward-token ()
   (let ((start (point)))
     (forward-comment (point-max))
     (if (and (> (point) start)
-             (looking-at "\\(?:\\s_\\|\\sw\\)+[ \t\n]*[|&]?=")
+             (looking-at rnc-smie--def-regexp)
              (save-excursion
                (goto-char start)
                (forward-comment -1)
@@ -120,7 +127,7 @@
              (let ((pos (point)))
                (goto-char start)
                (prog1
-                   (looking-at "\\(?:\\s_\\|\\sw\\)+[ \t\n]*[|&]?=")
+                   (looking-at rnc-smie--def-regexp)
                  (goto-char pos))))
         " ; "
       (if (looking-back "\\s." (1- (point)))






reply via email to

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