emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/d-mode 175c6e5 193/346: Fix indentation of function constr


From: ELPA Syncer
Subject: [nongnu] elpa/d-mode 175c6e5 193/346: Fix indentation of function constraints/contracts?
Date: Sun, 29 Aug 2021 11:00:29 -0400 (EDT)

branch: elpa/d-mode
commit 175c6e5d48bba277bb5993fe5d057896cee77228
Author: Vladimir Panteleev <git@thecybershadow.net>
Commit: Vladimir Panteleev <git@thecybershadow.net>

    Fix indentation of function constraints/contracts?
    
    Further fixes issue #58.
    
    Watch me - current implementation might be overly permissive and match
    other constructs.
---
 d-mode-test.el |  5 ++--
 d-mode.el      | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/I0058.d  | 30 ++++++++++++++++----
 3 files changed, 114 insertions(+), 7 deletions(-)

diff --git a/d-mode-test.el b/d-mode-test.el
index 603526f..e8a3893 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -132,7 +132,8 @@
         (inlambda              . c-lineup-inexpr-block)
         (lambda-intro-cont     . +)
         (inexpr-statement      . +)
-        (inexpr-class          . +)))
+        (inexpr-class          . +)
+        (knr-argdecl-intro     . 0)))
     (c-echo-syntactic-information-p . t)
     (c-indent-comment-alist . nil))
   "Style for testing.")
@@ -311,7 +312,7 @@ is expected to succeed, and nil otherwise."
 (d-test-deftest i0039 "tests/I0039.d" (version< "24.4" emacs-version))
 (d-test-deftest i0049 "tests/I0049.d" t)
 (d-test-deftest i0054 "tests/I0054.d" t)
-(d-test-deftest i0058 "tests/I0058.d" t)
+(d-test-deftest i0058 "tests/I0058.d" (version< "24.4" emacs-version))
 (d-test-deftest i0064 "tests/I0064.d" t)
 (d-test-deftest i0069 "tests/I0069.txt" t)
 (d-test-deftest i0072 "tests/I0072.txt" t)
diff --git a/d-mode.el b/d-mode.el
index e00aa7f..59352b1 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -304,6 +304,9 @@ The expression is added to `compilation-error-regexp-alist' 
and
 ;;; This doesn't seem to have any effect.  They aren't exactly "K&R-regions".
 ;;  d '("in" "out" "body"))
 
+(c-lang-defconst c-recognize-knr-p
+  d t)
+
 (c-lang-defconst c-type-list-kwds
   d nil)
 
@@ -917,6 +920,89 @@ Key bindings:
  t)
 
 ;;----------------------------------------------------------------------------
+
+(defun d-in-knr-argdecl (&optional lim)
+  "Modified version of `c-in-knr-argdecl' for d-mode." ;; checkdoc-params: lim
+  (save-excursion
+    (save-restriction
+      ;; If we're in a macro, our search range is restricted to it.  Narrow to
+      ;; the searchable range.
+      (let* ((macro-start (save-excursion (and (c-beginning-of-macro) 
(point))))
+            (macro-end (save-excursion (and macro-start (c-end-of-macro) 
(point))))
+            (low-lim (max (or lim (point-min))   (or macro-start (point-min))))
+            before-lparen after-rparen
+            (here (point))
+            (pp-count-out 20)  ; Max number of paren/brace constructs before
+                               ; we give up.
+            ids              ; List of identifiers in the parenthesized list.
+            id-start after-prec-token decl-or-cast decl-res
+            c-last-identifier-range identifier-ok)
+       (narrow-to-region low-lim (or macro-end (point-max)))
+
+       (catch 'knr
+         (while (> pp-count-out 0) ; go back one paren/bracket pair each time.
+           (setq pp-count-out (1- pp-count-out))
+           (c-syntactic-skip-backward "^)]}=")
+           (cond ((eq (char-before) ?\))
+                  (setq after-rparen (point)))
+                 ((eq (char-before) ?\])
+                  (setq after-rparen nil))
+                 (t ; either } (hit previous defun) or = or no more
+                    ; parens/brackets.
+                  (throw 'knr nil)))
+
+           (if after-rparen
+               ;; We're inside a paren.  Could it be our argument list....?
+               (if
+                   (and
+                    (progn
+                      (goto-char after-rparen)
+                      (unless (c-go-list-backward) (throw 'knr nil)) ;
+                      ;; FIXME!!!  What about macros between the parens?  
2007/01/20
+                      (setq before-lparen (point)))
+
+                    ;; It can't be the arg list if next token is ; or {
+                    (progn (goto-char after-rparen)
+                           (c-forward-syntactic-ws)
+                           (not (memq (char-after) '(?\; ?\{ ?\=))))
+
+                    ;; Is the thing preceding the list an identifier (the
+                    ;; function name), or a macro expansion?
+                    (progn
+                      (goto-char before-lparen)
+                      (eq (c-backward-token-2) 0)
+                      (or (eq (c-on-identifier) (point))
+                          (and (eq (char-after) ?\))
+                               (c-go-up-list-backward)
+                               (eq (c-backward-token-2) 0)
+                               (eq (c-on-identifier) (point)))))
+
+                    ;; (... original c-in-knr-argdecl logic omitted here ...)
+                    t)
+                   ;; ...Yes.  We've identified the function's argument list.
+                   (throw 'knr
+                          (progn (goto-char after-rparen)
+                                 (c-forward-syntactic-ws)
+                                 (point)))
+                 ;; ...No.  The current parens aren't the function's arg list.
+                 (goto-char before-lparen))
+
+             (or (c-go-list-backward)  ; backwards over [ .... ]
+                 (throw 'knr nil)))))))))
+
+(defun d-around--c-in-knr-argdecl (orig-fun &rest args)
+  ;; checkdoc-params: (orig-fun args)
+  "Advice function for fixing cc-mode indentation in certain D constructs."
+  (apply
+   (if (string= major-mode "d-mode")
+       #'d-in-knr-argdecl
+     orig-fun)
+   args))
+
+(when (version<= "24.4" emacs-version)
+  (advice-add 'c-in-knr-argdecl :around #'d-around--c-in-knr-argdecl))
+
+;;----------------------------------------------------------------------------
 ;;
 ;; Support for "Adjusting Alignment Rules for UCFS-Chains in D",
 ;; cf. 
https://stackoverflow.com/questions/25797945/adjusting-alignment-rules-for-ucfs-chains-in-d
diff --git a/tests/I0058.d b/tests/I0058.d
index a405bbf..4f911db 100644
--- a/tests/I0058.d
+++ b/tests/I0058.d
@@ -1,10 +1,20 @@
 // #run: (d-test-indent)
 
-double foo()(double b)
-  in // TODO
-    {
-      assert(b == b);
-    }
+double foo(double b)
+in
+  {
+    assert(b == b);
+  }
+out (result)
+  {
+    assert(result == result);
+  }
+body
+  {
+    return b;
+  }
+
+double foo (double b)
 out (result)
   {
     assert(result == result);
@@ -13,3 +23,13 @@ body
   {
     return b;
   }
+
+double foo (double b)
+in
+  {
+    assert(b == b);
+  }
+body
+  {
+    return b;
+  }



reply via email to

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