[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode b170500 416/468: Add backport of string-trim not
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode b170500 416/468: Add backport of string-trim not available in Emacs 24 |
Date: |
Thu, 5 Aug 2021 04:59:20 -0400 (EDT) |
branch: elpa/lua-mode
commit b17050051164f9ff79451f2e744bc7891206e83d
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Add backport of string-trim not available in Emacs 24
---
test/test-indentation.el | 7 ++-----
test/utils.el | 31 +++++++++++++++----------------
2 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/test/test-indentation.el b/test/test-indentation.el
index 8cc4356..7cc6d12 100644
--- a/test/test-indentation.el
+++ b/test/test-indentation.el
@@ -7,9 +7,6 @@
(require 'buttercup)
(require 'cl-lib)
-(defun lua--string-trim-safe (str)
- (save-match-data (string-trim str)))
-
(defun lua--get-indentation-test-sections (file-path)
(with-temp-buffer
@@ -26,10 +23,10 @@
;; Scan towards the next comment or end of file, save the comment as
;; the name for the section that comes AFTER the current one.
(setq next-section-name
- (when (re-search-forward "^--\\(.*\\)" nil 'noerror)
(lua--string-trim-safe (match-string-no-properties 1))))
+ (when (re-search-forward "^--\\(.*\\)" nil 'noerror)
(lua--string-trim (match-string-no-properties 1))))
;; Record current section bounds and contents
(setq end (if next-section-name (match-beginning 0) (point-max)))
- (setq cur-str (lua--string-trim-safe (buffer-substring-no-properties
begin end)))
+ (setq cur-str (lua--string-trim (buffer-substring-no-properties begin
end)))
;; Save current section to be returned
(if (> (length cur-str) 0)
(push (list (or section-name (format "section %d" (1+ (length
results))))
diff --git a/test/utils.el b/test/utils.el
index 8636108..4192db0 100644
--- a/test/utils.el
+++ b/test/utils.el
@@ -230,20 +230,19 @@ This is a mere typing/reading aid for lua-mode's
font-lock tests."
(apply #'with-point-at-matcher `(:lua-code ,(car args) :with-point-at ,@(cdr
args))))
-(require 'subr-x)
-
-;; (describe "foo"
-;; (it "runs hello"
-;; (expect "function foo()\nreturn 123\nend"
:to-be-reindented-the-same-way)))
-
-;; (defun lua--explain-indentation-mismatch (strs indented-strs)
-;; (cl-loop for i in (number-sequence 1 (length strs))
-;; for s1 in strs
-;; for s2 in indented-strs
-;; if (not (string-equal s1 s2))
-;; collect (format "Mismatch on line %s:\nExpected: %S\nActual :
%S" i s1 s2)))
-
-
+(defun lua--string-trim (string &optional trim-left trim-right)
+ ;; Backport of string-trim for Emacs 24 that doesn't have subr-x lib.
+ (let ((sub-start 0) sub-end)
+ (or trim-left (setq trim-left "[ \t\n\r]+"))
+ (or trim-right (setq trim-right "[ \t\n\r]+"))
+ (save-match-data
+ (when (string-match (concat "\\`" trim-left) string)
+ (setq sub-start (match-end 0)))
+ (when (string-match (concat trim-right "\\'") string sub-start)
+ (setq sub-end (match-beginning 0))))
+ (if (or sub-start sub-end)
+ (substring string sub-start sub-end)
+ string)))
(buttercup-define-matcher :to-be-reindented-the-same-way (str)
@@ -251,7 +250,7 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
(indented-lines (lua-get-indented-strs lines)))
(buttercup--test-expectation (equal lines indented-lines)
:expect-match-phrase (format "Indentation check
failed:\n=========\nExpected:\n---------\n%s\n---------\nActual:\n---------\n%s\n========="
- (string-trim (mapconcat 'identity lines
"\n"))
- (string-trim (mapconcat 'identity
indented-lines "\n")))
+ (lua--string-trim (mapconcat 'identity
lines "\n"))
+ (lua--string-trim (mapconcat 'identity
indented-lines "\n")))
:expect-mismatch-phrase (format "Expected `%S' to not be reindented like
that"
lines))))
- [nongnu] elpa/lua-mode 4db05e8 389/468: Use cl-lib instead of cl, (continued)
- [nongnu] elpa/lua-mode 4db05e8 389/468: Use cl-lib instead of cl, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3f67365 394/468: Renamed word “Result” to “Actual” in matcher's message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 658bf8f 397/468: Merge pull request #166 from veprbl/patch-1, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6436a45 398/468: Index "require" as imenu items, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0e6813a 405/468: Refactor indentation tests to use test cases defined in *.lua files, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode acbcdc9 407/468: Don't prevent "block starter" tokens from starting continuation lines, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4a45c6d 410/468: lua-make-indentation-info-pair: optimize "same-line" checks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8270df5 411/468: lua-is-continuing-statement-p: remove N^2 complexity on openers/closers, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bf80b7e 414/468: Enable continuation after comma outside of parens/braces/brackets, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode afd5aa3 415/468: test-indentation: remove unused subr-x dependency, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b170500 416/468: Add backport of string-trim not available in Emacs 24,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 5bfdea5 420/468: Merge pull request #177 from immerrr/refactor-variable-list-fontification, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0546418 423/468: Extend lua-default-application doc a bit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9d46ad3 424/468: Update readme, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 345ebfc 425/468: Merge pull request #174 from immerrr/assorted-fixes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 85d01e9 429/468: `lua-funcname-at-point': fix regexes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b647537 428/468: `lua-start-proces': don't hang if already running, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 853b040 432/468: `lua-start-process': start a new process sometimes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fbdbf05 439/468: Merge pull request #181 from immerrr/treat-comment-delimiters-as-comments-too, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d63f2af 441/468: Merge pull request #183 from immerrr/add-lua-skip-ws-comment-functions, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e81d0f2 442/468: Merge pull request #179 from nbfalcon/code-cleanup/fix-fixmes, Philip Kaludercic, 2021/08/05