branch: externals/yaml commit 2aa5a6faf7e45f4f1bd6e9be3541f9bce807307d Merge: d8ac09e8ca a47f5a8274 Author: Zachary Romero <zacrom...@posteo.net> Commit: GitHub <nore...@github.com>
Merge pull request #16 from conao3/indent Indent buffer --- yaml-tests.el | 20 +++---- yaml.el | 166 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/yaml-tests.el b/yaml-tests.el index aee8f78246..7df19c9663 100644 --- a/yaml-tests.el +++ b/yaml-tests.el @@ -429,16 +429,16 @@ foo: bar - c")) ;; example 8.1 -;; (should (yaml-parse-string "- | -;; \sdetected -;; - > -;; \s -;; \s\s -;; \s\s# detected -;; - |1 -;; \s\sexplicit -;; - > -;; \s\t + ;; (should (yaml-parse-string "- | + ;; \sdetected + ;; - > + ;; \s + ;; \s\s + ;; \s\s# detected + ;; - |1 + ;; \s\sexplicit + ;; - > + ;; \s\t ;; \sdetected")) diff --git a/yaml.el b/yaml.el index a858a82d76..6f2f583b7f 100644 --- a/yaml.el +++ b/yaml.el @@ -51,20 +51,20 @@ This flag is intended for development purposes.") (defconst yaml--tracing-ignore '("s-space" - "s-tab" - "s-white" - "l-comment" - "b-break" - "b-line-feed" - "b-carriage-return" - "s-b-comment" - "b-comment" - "l-comment" - "ns-char" - "nb-char" - "b-char" - "c-printable" - "b-as-space")) + "s-tab" + "s-white" + "l-comment" + "b-break" + "b-line-feed" + "b-carriage-return" + "s-b-comment" + "b-comment" + "l-comment" + "ns-char" + "nb-char" + "b-char" + "c-printable" + "b-as-space")) (defvar yaml--parsing-input "" "The string content of the current item being processed.") @@ -80,7 +80,7 @@ This flag is intended for development purposes.") (defvar yaml--parsing-false-object nil) (cl-defstruct (yaml--state (:constructor yaml--state-create) - (:copier nil)) + (:copier nil)) doc tt m name lvl beg end) (defmacro yaml--parse (data &rest forms) @@ -103,12 +103,12 @@ This flag is intended for development purposes.") (while states (let* ((top-state (car states)) (new-state (yaml--state-create :doc (yaml--state-doc top-state) - :tt (yaml--state-tt top-state) - :m val - :name (yaml--state-name top-state) - :lvl (yaml--state-lvl top-state) - :beg (yaml--state-beg top-state) - :end (yaml--state-end top-state)))) + :tt (yaml--state-tt top-state) + :m val + :name (yaml--state-name top-state) + :lvl (yaml--state-lvl top-state) + :beg (yaml--state-beg top-state) + :end (yaml--state-end top-state)))) (setcar states new-state)) (setq states (cdr states))))) @@ -118,12 +118,12 @@ This flag is intended for development purposes.") (while states (let* ((top-state (car states)) (new-state (yaml--state-create :doc (yaml--state-doc top-state) - :tt val - :m (yaml--state-m top-state) - :name (yaml--state-name top-state) - :lvl (yaml--state-lvl top-state) - :beg (yaml--state-beg top-state) - :end (yaml--state-end top-state)))) + :tt val + :m (yaml--state-m top-state) + :name (yaml--state-name top-state) + :lvl (yaml--state-lvl top-state) + :beg (yaml--state-beg top-state) + :end (yaml--state-end top-state)))) (setcar states new-state)) (setq states (cdr states))))) @@ -147,40 +147,40 @@ This flag is intended for development purposes.") "Add a new state frame with NAME." (let* ((curr-state (yaml--state-curr)) (new-state (yaml--state-create - :doc (yaml--state-curr-doc) - :tt (yaml--state-curr-t) - :m (yaml--state-curr-m) - :name name - :lvl (1+ (yaml--state-lvl curr-state)) - :beg yaml--parsing-position - :end nil))) + :doc (yaml--state-curr-doc) + :tt (yaml--state-curr-t) + :m (yaml--state-curr-m) + :name name + :lvl (1+ (yaml--state-lvl curr-state)) + :beg yaml--parsing-position + :end nil))) (push new-state yaml--states))) (defun yaml--pop-state () "Pop the current state." (let ((popped-state (car yaml--states))) - (setq yaml--states (cdr yaml--states)) - (let ((top-state (car yaml--states))) - (when top-state - (setcar yaml--states - (yaml--state-create :doc (yaml--state-doc top-state) - :tt (yaml--state-tt top-state) - :m (yaml--state-m top-state) - :name (yaml--state-name top-state) - :lvl (yaml--state-lvl top-state) - :beg (yaml--state-beg popped-state) - :end yaml--parsing-position)))))) + (setq yaml--states (cdr yaml--states)) + (let ((top-state (car yaml--states))) + (when top-state + (setcar yaml--states + (yaml--state-create :doc (yaml--state-doc top-state) + :tt (yaml--state-tt top-state) + :m (yaml--state-m top-state) + :name (yaml--state-name top-state) + :lvl (yaml--state-lvl top-state) + :beg (yaml--state-beg popped-state) + :end yaml--parsing-position)))))) (defun yaml--initialize-state () "Initialize the yaml state for parsing." (setq yaml--states (list (yaml--state-create :doc nil - :tt nil - :m nil - :name nil - :lvl 0 - :beg nil - :end nil)))) + :tt nil + :m nil + :name nil + :lvl 0 + :beg nil + :end nil)))) (defconst yaml--grammar-resolution-rules '(("ns-plain" . literal)) @@ -216,12 +216,12 @@ This flag is intended for development purposes.") (char (and (< pos (length header)) (aref header pos))) (process-char (lambda (char) (when char - (cond - ((< ?0 char ?9) - (progn (setq indentation-indicator (- char ?0)))) - ((equal char ?\-) (setq chomp-indicator :strip)) - ((equal char ?\+) (setq chomp-indicator :keep))) - (setq pos (1+ pos)))))) + (cond + ((< ?0 char ?9) + (progn (setq indentation-indicator (- char ?0)))) + ((equal char ?\-) (setq chomp-indicator :strip)) + ((equal char ?\+) (setq chomp-indicator :keep))) + (setq pos (1+ pos)))))) (when (or (eq char ?\|) (eq char ?\>)) (setq pos (1+ pos)) (setq char (and (< pos (length header)) (aref header pos)))) @@ -551,7 +551,7 @@ reverse order." (if (> (length x) 1) (substring x 1) "'")) - replaced))) + replaced))) (yaml--scalar-event "single" (substring replaced 1 (1- (length replaced))))))) ("c-double-quoted" . (lambda (text) (let* ((replaced (replace-regexp-in-string @@ -665,28 +665,28 @@ reverse order." (replace-regexp-in-string "\n" "↓" (yaml--slice yaml--parsing-position))))) (_ (yaml--push-state ,name)) (,res-symbol ,rule)) - (when (and yaml--parse-debug ,res-symbol (not (member ,name yaml--tracing-ignore))) - (message "<%s|%s %40s = '%s'" - (make-string (length yaml--states) ?-) - (make-string (- 70 (length yaml--states)) ?\s) - ,name - (replace-regexp-in-string "\n" "↓" (substring yaml--parsing-input beg yaml--parsing-position)))) - (yaml--pop-state) - (if (not ,res-symbol) - nil - (let ((res-type (cdr (assoc ,name yaml--grammar-resolution-rules))) - (,res-symbol (if (member ,name yaml--terminal-rules) - t ;; Ignore children if at-rule is indicated to be terminal. - ,res-symbol))) - (cond - ((or (assoc ,name yaml--grammar-events-in) - (assoc ,name yaml--grammar-events-out)) - (list ,name - (substring yaml--parsing-input beg yaml--parsing-position) - ,res-symbol)) - ((equal res-type 'list) (list ,name ,res-symbol)) - ((equal res-type 'literal) (substring yaml--parsing-input beg yaml--parsing-position)) - (t ,res-symbol))))))) + (when (and yaml--parse-debug ,res-symbol (not (member ,name yaml--tracing-ignore))) + (message "<%s|%s %40s = '%s'" + (make-string (length yaml--states) ?-) + (make-string (- 70 (length yaml--states)) ?\s) + ,name + (replace-regexp-in-string "\n" "↓" (substring yaml--parsing-input beg yaml--parsing-position)))) + (yaml--pop-state) + (if (not ,res-symbol) + nil + (let ((res-type (cdr (assoc ,name yaml--grammar-resolution-rules))) + (,res-symbol (if (member ,name yaml--terminal-rules) + t ;; Ignore children if at-rule is indicated to be terminal. + ,res-symbol))) + (cond + ((or (assoc ,name yaml--grammar-events-in) + (assoc ,name yaml--grammar-events-out)) + (list ,name + (substring yaml--parsing-input beg yaml--parsing-position) + ,res-symbol)) + ((equal res-type 'list) (list ,name ,res-symbol)) + ((equal res-type 'literal) (substring yaml--parsing-input beg yaml--parsing-position)) + (t ,res-symbol))))))) (defun yaml--end-of-stream () "Return non-nil if the current position is after the end of the document." @@ -745,7 +745,7 @@ reverse order." `(yaml--run-all ,@(mapcar (lambda (form) `(lambda () ,form)) - forms))) + forms))) (defmacro yaml--any (&rest forms) "Pass if any of FORMS pass." @@ -2397,8 +2397,8 @@ If AUTO-INDENT is non-nil, start the list on the current line, auto-detecting the indentation. Functionality defers to `yaml--encode-list'." (yaml--encode-list (seq-map #'identity a) - indent - auto-indent)) + indent + auto-indent)) (defun yaml--encode-scalar (s)