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

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

[elpa] externals/yaml c3988d10e2 098/124: store current indent level and


From: ELPA Syncer
Subject: [elpa] externals/yaml c3988d10e2 098/124: store current indent level and use that for basis of block indent
Date: Fri, 29 Nov 2024 16:00:06 -0500 (EST)

branch: externals/yaml
commit c3988d10e24f21cd7a25e796c647599a14409a3d
Author: Zachary Romero <zacromero@posteo.net>
Commit: Zachary Romero <zacromero@posteo.net>

    store current indent level and use that for basis of block indent
---
 yaml-tests.el | 21 +++++++++++++++++++--
 yaml.el       | 44 +++++++++++++++++++++++++++-----------------
 2 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/yaml-tests.el b/yaml-tests.el
index d3d53182ab..1421a07aac 100644
--- a/yaml-tests.el
+++ b/yaml-tests.el
@@ -390,8 +390,25 @@ ship-to:
   (should (equal (progn
                    (yaml-parse-string-with-pos "- # Empty\n- abc")
                    (yaml-parse-string "- # Empty\n- abc"))
-                 [:null "abc"])))
-
+                 [:null "abc"]))
+  (should (equal (yaml-parse-string "deeply:\n  nested:\n    value: >-1\n      
test string"
+                                    :object-type 'alist)
+                 '((deeply (nested (value . " test string"))))))
+  (should (equal (yaml-parse-string "deeply:\n  nested:\n    value: >-\n      
test string"
+                                    :object-type 'alist)
+                 '((deeply (nested (value . "test string"))))))
+  (should (equal (yaml-parse-string "deeply:\n  nested:\n    value: >-2\n      
test string"
+                                    :object-type 'alist)
+                 '((deeply (nested (value . "test string"))))))
+  (should (equal (yaml-parse-string "deeply:\n  nested:\n    value: >-7\n      
     test string"
+                                    :object-type 'alist)
+                 '((deeply (nested (value . "test string"))))))
+  (should (equal (yaml-parse-string "deeply:\n  nested:\n    value: |-6\n      
     test string"
+                                    :object-type 'alist)
+                 '((deeply (nested (value . " test string"))))))
+  (should (equal (yaml-parse-string "deeply:\n  nested:\n    value: |-\n       
    test string"
+                                    :object-type 'alist)
+                 '((deeply (nested (value . "test string")))))))
 
 (ert-deftest yaml-parsing-completes ()
   "Tests that the yaml parses."
diff --git a/yaml.el b/yaml.el
index 01e0545df7..18447416fb 100644
--- a/yaml.el
+++ b/yaml.el
@@ -3,7 +3,7 @@
 ;; Copyright © 2021 Zachary Romero <zkry@posteo.org>
 
 ;; Author: Zachary Romero <zkry@posteo.org>
-;; Version: 0.1.0
+;; Version: 0.5.0
 ;; Homepage: https://github.com/zkry/yaml.el
 ;; Package-Requires: ((emacs "25.1"))
 ;; Keywords: tools
@@ -45,6 +45,8 @@
 (require 'seq)
 (require 'cl-lib)
 
+(defconst yaml-parser-version "0.5.0")
+
 (defvar yaml--parse-debug nil
   "Turn on debugging messages when parsing YAML when non-nil.
 
@@ -258,22 +260,24 @@ This flag is intended for development purposes.")
 
 (defun yaml--process-literal-text (text)
   "Remove the header line for a folded match and return TEXT body formatted."
-  (let* ((header-line (substring text 0 (string-match "\n" text)))
-         (text-body (substring text (1+ (string-match "\n" text))))
-         (parsed-header (yaml--parse-block-header header-line))
-         (chomp (car parsed-header))
-         (starting-spaces-ct
-          (or (cadr parsed-header)
-              (let ((_ (string-match "^\n*\\( *\\)" text-body)))
-                (length (match-string 1 text-body)))))
-         (lines (split-string text-body "\n"))
-         (striped-lines
-          (seq-map (lambda (l)
-                     (replace-regexp-in-string
-                      (format "\\` \\{0,%d\\}" starting-spaces-ct) "" l))
-                   lines))
-         (text-body (string-join striped-lines "\n")))
-    (yaml--chomp-text text-body chomp)))
+  (let ((n (get-text-property 0 'yaml-n text)))
+    (setq text (substring-no-properties text 0 (length text)))
+    (let* ((header-line (substring text 0 (string-match "\n" text)))
+           (text-body (substring text (1+ (string-match "\n" text))))
+           (parsed-header (yaml--parse-block-header header-line))
+           (chomp (car parsed-header))
+           (starting-spaces-ct
+            (or (and (cadr parsed-header) (+ n (cadr parsed-header)))
+                (let ((_ (string-match "^\n*\\( *\\)" text-body)))
+                  (length (match-string 1 text-body)))))
+           (lines (split-string text-body "\n"))
+           (striped-lines
+            (seq-map (lambda (l)
+                       (replace-regexp-in-string
+                        (format "\\` \\{0,%d\\}" starting-spaces-ct) "" l))
+                     lines))
+           (text-body (string-join striped-lines "\n")))
+      (yaml--chomp-text text-body chomp))))
 
 ;; TODO: Process tags and use them in this function.
 (defun yaml--resolve-scalar-tag (scalar)
@@ -759,6 +763,12 @@ repeat for each character in a text.")
             ((or (assoc ,name yaml--grammar-events-in)
                  (assoc ,name yaml--grammar-events-out))
              (let ((str (substring yaml--parsing-input beg 
yaml--parsing-position)))
+               (when yaml--parsing-store-position
+                 (setq str (propertize str 'yaml-position
+                                       (cons (1+ beg)
+                                             (1+ yaml--parsing-position)))))
+               (when (member ,name '("c-l+folded" "c-l+literal"))
+                 (setq str (propertize str 'yaml-n n)))
                (list ,name
                      (if yaml--parsing-store-position
                          (propertize str 'yaml-position (cons (1+ beg)



reply via email to

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