From a1e9cbc2102677d654e6307a54801173dc7bf710 Mon Sep 17 00:00:00 2001 From: Ilia Kruglov Date: Sun, 24 Sep 2023 21:25:44 -0300 Subject: [PATCH 1/5] Implemented non-broad-word-char vi mode option. --- extensions/vi-mode/options.lisp | 36 ++++++++++++++++++++++++++++++--- extensions/vi-mode/word.lisp | 5 +++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/extensions/vi-mode/options.lisp b/extensions/vi-mode/options.lisp index 7d2e22e91..06def335a 100644 --- a/extensions/vi-mode/options.lisp +++ b/extensions/vi-mode/options.lisp @@ -317,9 +317,7 @@ (:set-hook (new-value) (setf (lem:variable-value 'lem/line-numbers:line-numbers :global) new-value))) -(defvar *default-iskeyword* '("@" "48-57" "_" "192-255")) - -(defun compile-iskeyword (value) +(defun compile-rules (value) (apply #'disjoin (mapcar (lambda (rule) (check-type rule string) @@ -350,6 +348,11 @@ (char= c rule-char)))))))) value))) +(defvar *default-iskeyword* '("@" "48-57" "_" "192-255")) + +(defun compile-iskeyword (value) + (compile-rules value)) + (define-option "iskeyword" ((cons *default-iskeyword* (compile-iskeyword *default-iskeyword*)) :type list @@ -376,6 +379,33 @@ (option-value option)) :test 'equal))))) +(defvar *default-non-broad-word-char* (mapcar #'string '(#\Newline #\Space #\Tab))) + +(define-option "non-broad-word-char" ((cons *default-non-broad-word-char* + (compile-rules *default-non-broad-word-char*)) + :type list + :aliases ("nbwc") + :scope :buffer) + (:documentation "Comma-separated string to specify the characters that should be recognized as non broad word characters. (buffer local) + Aliases: nbwc") + (:getter (option) + (car (option-raw-value option))) + (:setter (new-value option) + (setf (option-%value option) + (cons new-value + (compile-rules new-value)))) + (:initializer (option) + (let ((syntax-table (lem:mode-syntax-table (lem:buffer-major-mode (lem:current-buffer))))) + (setf (option-value option) + (delete-duplicates + (nconc (mapcar (lambda (c) + (if (char= c #\@) + "@-@" + (string c))) + (lem-base::syntax-table-space-chars syntax-table)) + (option-value option)) + :test 'equal))))) + (define-option "scrolloff" (0 :type number :aliases ("so")) (:documentation "The minimal number of lines to keep above of below the cursor. Default: 0 diff --git a/extensions/vi-mode/word.lisp b/extensions/vi-mode/word.lisp index 2353514f8..f84391aff 100644 --- a/extensions/vi-mode/word.lisp +++ b/extensions/vi-mode/word.lisp @@ -30,10 +30,15 @@ ((blank-char-p char) :blank) (t :non-word)))) +(defun non-broad-word-char-p (char) + (funcall (cdr (option-raw-value "non-broad-word-char")) + char)) + (defun broad-word-char-type (char) (when char (cond ((blank-char-p char) :blank) + ((non-broad-word-char-p char) :non-word) (t :word)))) (defun forward-word-begin (char-type-fn &optional (point (current-point))) From 1d2139aedb338a4f40303db125269fafb208bb48 Mon Sep 17 00:00:00 2001 From: Ilia Kruglov Date: Sun, 24 Sep 2023 23:54:39 -0300 Subject: [PATCH 2/5] Added non-broad-word-char option tests. --- extensions/vi-mode/tests/options.lisp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/extensions/vi-mode/tests/options.lisp b/extensions/vi-mode/tests/options.lisp index d4c0f5fa1..9683a80e8 100644 --- a/extensions/vi-mode/tests/options.lisp +++ b/extensions/vi-mode/tests/options.lisp @@ -7,9 +7,13 @@ (:import-from :lem-fake-interface :with-fake-interface) (:shadowing-import-from :lem-vi-mode/tests/utils - :with-current-buffer)) + :with-current-buffer) + (:import-from :named-readtables + :in-readtable)) (in-package :lem-vi-mode/tests/options) +(in-readtable :interpol-syntax) + (deftest get-option (ok (typep (get-option "number") 'option) "Can get a global option") @@ -24,3 +28,18 @@ (with-current-buffer (buf) (ok (equalp (option-value "iskeyword") isk) "Another buffer's local option is not changed")))))) + +(deftest non-broad-word-char-option + (ok (typep (get-option "non-broad-word-char") 'option) + "Can get non-broad-word-char option") + (ok (typep (get-option "nbwc") 'option) + "Can get non-broad-word-char option by alias") + (with-fake-interface () + (with-vi-buffer (#?"abc\n[(]def)\n") + (cmd "E") + (ok (buf= #?"abc\n(def[)]\n"))) + (with-vi-buffer (#?"abc\n[(]def)\n") + (execute-set-command "nbwc+=(") + (execute-set-command "nbwc+=)") + (cmd "WE") + (ok (buf= #?"abc\n(de[f])\n"))))) \ No newline at end of file From b9b22fd4aaa06b8573a1872e7974618b1a88ab5e Mon Sep 17 00:00:00 2001 From: Ilia Kruglov Date: Mon, 25 Sep 2023 02:00:05 -0300 Subject: [PATCH 3/5] Fixes for COMPILE-RULES implementation and usage. --- extensions/vi-mode/options.lisp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/extensions/vi-mode/options.lisp b/extensions/vi-mode/options.lisp index 06def335a..00c018815 100644 --- a/extensions/vi-mode/options.lisp +++ b/extensions/vi-mode/options.lisp @@ -317,7 +317,7 @@ (:set-hook (new-value) (setf (lem:variable-value 'lem/line-numbers:line-numbers :global) new-value))) -(defun compile-rules (value) +(defun compile-rules (value option-name) (apply #'disjoin (mapcar (lambda (rule) (check-type rule string) @@ -341,8 +341,8 @@ (progn (unless (= (length rule) 1) (error 'option-error - :format-control "Invalid rule in iskeyword: ~A" - :format-arguments (list rule))) + :format-control "Invalid rule in ~A: ~A" + :format-arguments (list option-name rule))) (let ((rule-char (aref rule 0))) (lambda (c) (char= c rule-char)))))))) @@ -351,7 +351,7 @@ (defvar *default-iskeyword* '("@" "48-57" "_" "192-255")) (defun compile-iskeyword (value) - (compile-rules value)) + (compile-rules value "iskeyword")) (define-option "iskeyword" ((cons *default-iskeyword* (compile-iskeyword *default-iskeyword*)) @@ -381,11 +381,15 @@ (defvar *default-non-broad-word-char* (mapcar #'string '(#\Newline #\Space #\Tab))) -(define-option "non-broad-word-char" ((cons *default-non-broad-word-char* - (compile-rules *default-non-broad-word-char*)) - :type list - :aliases ("nbwc") - :scope :buffer) +(defun compile-non-broad-word-char (value) + (compile-rules value "non-broad-word-char")) + +(define-option "non-broad-word-char" + ((cons *default-non-broad-word-char* + (compile-non-broad-word-char *default-non-broad-word-char*)) + :type list + :aliases ("nbwc") + :scope :buffer) (:documentation "Comma-separated string to specify the characters that should be recognized as non broad word characters. (buffer local) Aliases: nbwc") (:getter (option) @@ -393,7 +397,7 @@ (:setter (new-value option) (setf (option-%value option) (cons new-value - (compile-rules new-value)))) + (compile-non-broad-word-char new-value)))) (:initializer (option) (let ((syntax-table (lem:mode-syntax-table (lem:buffer-major-mode (lem:current-buffer))))) (setf (option-value option) From 4d78c81fd4a5263aa022d56eddfe40710e658bc1 Mon Sep 17 00:00:00 2001 From: Ilia Kruglov Date: Tue, 26 Sep 2023 21:17:06 -0300 Subject: [PATCH 4/5] Renamed non-broad-word-char to isWORDseparator. --- extensions/vi-mode/options.lisp | 18 +++++++++--------- extensions/vi-mode/tests/options.lisp | 14 +++++++------- extensions/vi-mode/word.lisp | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/extensions/vi-mode/options.lisp b/extensions/vi-mode/options.lisp index 00c018815..0d855c438 100644 --- a/extensions/vi-mode/options.lisp +++ b/extensions/vi-mode/options.lisp @@ -379,25 +379,25 @@ (option-value option)) :test 'equal))))) -(defvar *default-non-broad-word-char* (mapcar #'string '(#\Newline #\Space #\Tab))) +(defvar *default-isWORDseparator* (mapcar #'string '(#\Newline #\Space #\Tab))) -(defun compile-non-broad-word-char (value) - (compile-rules value "non-broad-word-char")) +(defun compile-isWORDseparator (value) + (compile-rules value "isWORDseparator")) -(define-option "non-broad-word-char" - ((cons *default-non-broad-word-char* - (compile-non-broad-word-char *default-non-broad-word-char*)) +(define-option "isWORDseparator" + ((cons *default-isWORDseparator* + (compile-isWORDseparator *default-isWORDseparator*)) :type list - :aliases ("nbwc") + :aliases ("isWs") :scope :buffer) (:documentation "Comma-separated string to specify the characters that should be recognized as non broad word characters. (buffer local) - Aliases: nbwc") + Aliases: isWs") (:getter (option) (car (option-raw-value option))) (:setter (new-value option) (setf (option-%value option) (cons new-value - (compile-non-broad-word-char new-value)))) + (compile-isWORDseparator new-value)))) (:initializer (option) (let ((syntax-table (lem:mode-syntax-table (lem:buffer-major-mode (lem:current-buffer))))) (setf (option-value option) diff --git a/extensions/vi-mode/tests/options.lisp b/extensions/vi-mode/tests/options.lisp index 9683a80e8..ebbc60ade 100644 --- a/extensions/vi-mode/tests/options.lisp +++ b/extensions/vi-mode/tests/options.lisp @@ -29,17 +29,17 @@ (ok (equalp (option-value "iskeyword") isk) "Another buffer's local option is not changed")))))) -(deftest non-broad-word-char-option - (ok (typep (get-option "non-broad-word-char") 'option) - "Can get non-broad-word-char option") - (ok (typep (get-option "nbwc") 'option) - "Can get non-broad-word-char option by alias") +(deftest isWORDseparator-option + (ok (typep (get-option "isWORDseparator") 'option) + "Can get isWORDseparator option") + (ok (typep (get-option "isWs") 'option) + "Can get isWORDseparator option by alias") (with-fake-interface () (with-vi-buffer (#?"abc\n[(]def)\n") (cmd "E") (ok (buf= #?"abc\n(def[)]\n"))) (with-vi-buffer (#?"abc\n[(]def)\n") - (execute-set-command "nbwc+=(") - (execute-set-command "nbwc+=)") + (execute-set-command "isWs+=(") + (execute-set-command "isWs+=)") (cmd "WE") (ok (buf= #?"abc\n(de[f])\n"))))) \ No newline at end of file diff --git a/extensions/vi-mode/word.lisp b/extensions/vi-mode/word.lisp index f84391aff..5c69450ab 100644 --- a/extensions/vi-mode/word.lisp +++ b/extensions/vi-mode/word.lisp @@ -31,7 +31,7 @@ (t :non-word)))) (defun non-broad-word-char-p (char) - (funcall (cdr (option-raw-value "non-broad-word-char")) + (funcall (cdr (option-raw-value "isWORDseparator")) char)) (defun broad-word-char-type (char) From 2502287b966e41833f2b20efd69cd0b6dfef82aa Mon Sep 17 00:00:00 2001 From: Ilia Kruglov Date: Wed, 27 Sep 2023 18:34:12 -0300 Subject: [PATCH 5/5] Renamed isWORDseparator to isseparator. --- extensions/vi-mode/options.lisp | 18 +++++++++--------- extensions/vi-mode/tests/options.lisp | 14 +++++++------- extensions/vi-mode/word.lisp | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/extensions/vi-mode/options.lisp b/extensions/vi-mode/options.lisp index 0d855c438..a055e9157 100644 --- a/extensions/vi-mode/options.lisp +++ b/extensions/vi-mode/options.lisp @@ -379,25 +379,25 @@ (option-value option)) :test 'equal))))) -(defvar *default-isWORDseparator* (mapcar #'string '(#\Newline #\Space #\Tab))) +(defvar *default-isseparator* (mapcar #'string '(#\Newline #\Space #\Tab))) -(defun compile-isWORDseparator (value) - (compile-rules value "isWORDseparator")) +(defun compile-isseparator (value) + (compile-rules value "isseparator")) -(define-option "isWORDseparator" - ((cons *default-isWORDseparator* - (compile-isWORDseparator *default-isWORDseparator*)) +(define-option "isseparator" + ((cons *default-isseparator* + (compile-isseparator *default-isseparator*)) :type list - :aliases ("isWs") + :aliases ("iss") :scope :buffer) (:documentation "Comma-separated string to specify the characters that should be recognized as non broad word characters. (buffer local) - Aliases: isWs") + Aliases: iss") (:getter (option) (car (option-raw-value option))) (:setter (new-value option) (setf (option-%value option) (cons new-value - (compile-isWORDseparator new-value)))) + (compile-isseparator new-value)))) (:initializer (option) (let ((syntax-table (lem:mode-syntax-table (lem:buffer-major-mode (lem:current-buffer))))) (setf (option-value option) diff --git a/extensions/vi-mode/tests/options.lisp b/extensions/vi-mode/tests/options.lisp index ebbc60ade..473868c9c 100644 --- a/extensions/vi-mode/tests/options.lisp +++ b/extensions/vi-mode/tests/options.lisp @@ -29,17 +29,17 @@ (ok (equalp (option-value "iskeyword") isk) "Another buffer's local option is not changed")))))) -(deftest isWORDseparator-option - (ok (typep (get-option "isWORDseparator") 'option) - "Can get isWORDseparator option") - (ok (typep (get-option "isWs") 'option) - "Can get isWORDseparator option by alias") +(deftest isseparator-option + (ok (typep (get-option "isseparator") 'option) + "Can get isseparator option") + (ok (typep (get-option "iss") 'option) + "Can get isseparator option by alias") (with-fake-interface () (with-vi-buffer (#?"abc\n[(]def)\n") (cmd "E") (ok (buf= #?"abc\n(def[)]\n"))) (with-vi-buffer (#?"abc\n[(]def)\n") - (execute-set-command "isWs+=(") - (execute-set-command "isWs+=)") + (execute-set-command "iss+=(") + (execute-set-command "iss+=)") (cmd "WE") (ok (buf= #?"abc\n(de[f])\n"))))) \ No newline at end of file diff --git a/extensions/vi-mode/word.lisp b/extensions/vi-mode/word.lisp index 5c69450ab..3f00867a1 100644 --- a/extensions/vi-mode/word.lisp +++ b/extensions/vi-mode/word.lisp @@ -31,7 +31,7 @@ (t :non-word)))) (defun non-broad-word-char-p (char) - (funcall (cdr (option-raw-value "isWORDseparator")) + (funcall (cdr (option-raw-value "isseparator")) char)) (defun broad-word-char-type (char)