aboutsummaryrefslogtreecommitdiff
path: root/evil-types.el
diff options
context:
space:
mode:
authorEvgeni Kolev <evgenysw@gmail.com>2017-05-07 18:25:04 -0700
committerEvgeni Kolev <evgenysw@gmail.com>2017-05-07 18:25:04 -0700
commitd1775bf71c1e022cc904fbde142a94742447aec5 (patch)
tree12317b59b09de8a934676d9554f614b7a948523f /evil-types.el
parenta6ef14e5e938ab7cb934c16740284f7000728810 (diff)
Don't validate REGISTER with regex. Fix error message for negative COUNTs
Diffstat (limited to 'evil-types.el')
-rw-r--r--evil-types.el25
1 files changed, 16 insertions, 9 deletions
diff --git a/evil-types.el b/evil-types.el
index 4695b80..65ca57c 100644
--- a/evil-types.el
+++ b/evil-types.el
@@ -382,8 +382,7 @@ Returns a list (REGISTER COUNT)."
(arg-count (length split-args))
(arg0 (car split-args))
(arg1 (cadr split-args))
- (number-regex "^[1-9][0-9]*$")
- (register-regex "^[a-zA-Z]$")
+ (number-regex "^-?[1-9][0-9]*$")
(register nil)
(count nil))
(cond
@@ -400,13 +399,21 @@ Returns a list (REGISTER COUNT)."
((> arg-count 2)
(user-error "Invalid use")))
- (when (and register (not (string-match-p register-regex register)))
- (user-error "Invalid register"))
- (when (and count (not (string-match-p number-regex count)))
- (user-error "Invalid count"))
-
- (list (if register (string-to-char register) nil)
- (if count (string-to-number count) nil))))
+ ;; if register is given, check it's valid
+ (when register
+ (unless (= (length register) 1)
+ (user-error "Invalid register"))
+ (setq register (string-to-char register)))
+
+ ;; if count is given, check it's valid
+ (when count
+ (unless (string-match-p number-regex count)
+ (user-error "Invalid count"))
+ (setq count (string-to-number count))
+ (unless (> count 0)
+ (user-error "Invalid count")))
+
+ (list register count)))
(provide 'evil-types)