[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr b2ba4c46b5 82/84: refactor: Minor code reorg
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr b2ba4c46b5 82/84: refactor: Minor code reorg |
Date: |
Tue, 3 May 2022 09:58:16 -0400 (EDT) |
branch: externals/tomelr
commit b2ba4c46b59d7baa4a6d02ba64657c08776d2d0e
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
refactor: Minor code reorg
---
tomelr.el | 65 +++++++++++++++++++++++++++++++--------------------------------
1 file changed, 32 insertions(+), 33 deletions(-)
diff --git a/tomelr.el b/tomelr.el
index 650328e5ce..6a41d14719 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -147,12 +147,12 @@ Return the same STRING passed as input."
(let ((special-chars '((?b . ?\b) ;U+0008
(?f . ?\f) ;U+000C
(?\\ . ?\\)))
- (special-chars-re (rx (in cntrl ?\u007F)))
+ (special-chars-re (rx (in ?\" ?\\ cntrl ?\u007F))) ;cntrl is same as
(?\u0000 . ?\u001F)
begin-q end-q)
+
(cond
;; Use multi-line string quotation if the string contains a "
- ;; char or a newline - """STRING""", and only if the string
- ;; doesn't have a "key type".
+ ;; char or a newline - """STRING""".
((string-match-p "\n\\|\"" string)
;; From https://toml.io/en/v1.0.0#string, Any Unicode
;; character may be used except those that must be escaped:
@@ -167,13 +167,13 @@ Return the same STRING passed as input."
(setq begin-q "\"\"\"\n")
(setq end-q "\"\"\""))
(t ;Basic quotation "STRING"
- (setq special-chars-re (rx (in ?\" ?\\ cntrl ?\u007F))) ;cntrl is same
as (?\u0000 . ?\u001F)
(push '(?\" . ?\") special-chars)
(push '(?t . ?\t) special-chars) ;U+0009
(push '(?n . ?\n) special-chars) ;U+000A
(push '(?r . ?\r) special-chars) ;U+000D
(setq begin-q "\"")
(setq end-q begin-q)))
+
(and begin-q (insert begin-q))
(goto-char (prog1 (point) (princ string)))
(while (re-search-forward special-chars-re nil :noerror)
@@ -250,36 +250,35 @@ Return nil if OBJECT cannot be encoded as a TOML string."
;; Normal keys (Alist and Plist keys)
((equal key-type 'normal-key)
(princ str))
- ;; Coercing
- ((and (stringp str)
- (or
- ;; RFC 3339 Date/Time
- (string-match-p tomelr--date-time-regexp str)
-
- ;; Integer that can be stored in the system as a fixnum.
- ;; For example, if `object' is "10040216507682529280" that
- ;; needs more than 64 bits to be stored as a signed
- ;; integer, it will be automatically stored as a float.
- ;; So (integerp (string-to-number object)) will return nil
- ;; [or `fixnump' instead of `integerp' in Emacs 27 or
- ;; newer].
- ;; https://github.com/toml-lang/toml#integer
- ;; Integer examples: 7, +7, -7, 7_000
- (and (or (symbolp object)
- (member 'integer tomelr-coerce-to-types))
- (string-match-p "\\`[+-]?[[:digit:]_]+\\'" str)
- (if (functionp #'fixnump) ;`fixnump' and `bignump' get
introduced in Emacs 27.x
- (fixnump (string-to-number str))
- ;; On older Emacsen, `integerp' behaved the same as the
- ;; new `fixnump'.
- (integerp (string-to-number str))))))
- (princ str))
- ((symbolp object)
- (princ (format "%S" str)))
- ((stringp object)
- (tomelr--print-string str))
(str
- (princ str)))))
+ (cond
+ ((or
+ ;; RFC 3339 Date/Time
+ (string-match-p tomelr--date-time-regexp str)
+
+ ;; Coercing
+ ;; Integer that can be stored in the system as a fixnum.
+ ;; For example, if `object' is "10040216507682529280" that
+ ;; needs more than 64 bits to be stored as a signed
+ ;; integer, it will be automatically stored as a float.
+ ;; So (integerp (string-to-number object)) will return nil
+ ;; [or `fixnump' instead of `integerp' in Emacs 27 or
+ ;; newer].
+ ;; https://github.com/toml-lang/toml#integer
+ ;; Integer examples: 7, +7, -7, 7_000
+ (and (or (symbolp object)
+ (member 'integer tomelr-coerce-to-types))
+ (string-match-p "\\`[+-]?[[:digit:]_]+\\'" str)
+ (if (functionp #'fixnump) ;`fixnump' and `bignump' get
introduced in Emacs 27.x
+ (fixnump (string-to-number str))
+ ;; On older Emacsen, `integerp' behaved the same as the
+ ;; new `fixnump'.
+ (integerp (string-to-number str)))))
+ (princ str))
+ (t
+ (tomelr--print-string str))))
+ (t
+ nil))))
(defun tomelr--print-key (key &optional key-type)
"Insert a TOML key representation of KEY at point.
- [elpa] externals/tomelr 5959b90ffa 44/84: fix: Don't let TOML tables be recognized as TOML tables arrays, (continued)
- [elpa] externals/tomelr 5959b90ffa 44/84: fix: Don't let TOML tables be recognized as TOML tables arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b64eb07e99 49/84: fix: Detect TT with sub-tables correctly, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4386d99a85 65/84: refactor(minor): Use `tomelr--toml-table-p`, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 26f1fc2f3c 55/84: doc: Update the medley example, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr e2b313ca3b 52/84: feat: Implement everything planned in the initial spec, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4434ccc64b 70/84: chore: Bump version, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 10a1994aed 51/84: feat: Support (lightly tested) nested TOML Table Arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr df0e73334f 59/84: Revert "doc: Update the medley example", ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ec381fd723 79/84: fix: Auto-stringify and auto-quote symbol values, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a25d952a17 77/84: feat: Auto-coerce string to integers, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b2ba4c46b5 82/84: refactor: Minor code reorg,
ELPA Syncer <=
- [elpa] externals/tomelr d86fd721ce 63/84: fix: Compatibility for emacs 26.3, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a1fa47379e 84/84: chore: Add CHANGELOG generated using git cliff tool, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ae983711be 78/84: fix: Auto-stringify symbols like 1.10.1, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 61397410af 01/84: Initial empty commit, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 846676a172 06/84: feat: Add plist example, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 8bc506af5a 02/84: Add s-exp->toml examples and spec, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 7d8d41f15b 19/84: feat: Encode to multi-line TOML string automatically, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 0ba5f2ff69 24/84: chore(readme): Move mixed type array example to the 'medley' example, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ca9245038a 35/84: fix: Attempt to make tomelr--toml-table-p more robust, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 000067cf7d 14/84: chore(readme): Update, ELPA Syncer, 2022/05/03