Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vi lisp word separators #1159

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 55 additions & 56 deletions extensions/vi-mode/options.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -348,67 +348,66 @@
(char= c rule-char))))))))
value)))

(defvar *default-iskeyword* '("@" "48-57" "_" "192-255"))
(defgeneric rules-option-init-chars (option-symbol syntax-table))

(defun compile-iskeyword (value)
(compile-rules value "iskeyword"))
(defmethod rules-option-init-chars ((option-symbol (eql :iskeyword)) syntax-table)
(declare (ignorable option-symbol))
(lem-base::syntax-table-symbol-chars syntax-table))

(define-option "iskeyword" ((cons *default-iskeyword*
(compile-iskeyword *default-iskeyword*))
:type list
:aliases ("isk")
:scope :buffer)
(:documentation "Comma-separated string to specify the characters should be recognized as a keyword. (buffer local)
(defmethod rules-option-init-chars ((option-symbol (eql :iskeyword))
(syntax-table (eql lem-lisp-syntax:*syntax-table*)))
(declare (ignorable option-symbol))
(set-difference (lem-base::syntax-table-symbol-chars syntax-table)
'(#\/ #\. #\: #\-)))

(defmethod rules-option-init-chars ((option-symbol (eql :isseparator)) syntax-table)
(declare (ignorable option-symbol))
(lem-base::syntax-table-space-chars syntax-table))

(defmethod rules-option-init-chars ((option-symbol (eql :isseparator))
(syntax-table (eql lem-lisp-syntax:*syntax-table*)))
(declare (ignorable option-symbol))
(union (lem-base::syntax-table-space-chars syntax-table)
'(#\( #\) #\")))

(defmacro define-rules-option (name default &key (alias (subseq name 0 3)) doc)
(once-only (default)
`(define-option ,name ((cons ,default
(compile-rules ,default ,name))
:type list
:aliases (,alias)
:scope :buffer)
(:documentation ,doc)
(:getter (option)
(car (option-raw-value option)))
(:setter (new-value option)
(setf (option-%value option)
(cons new-value
(compile-rules new-value ,name))))
(: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)))
(rules-option-init-chars
(intern ,(string-upcase name) "KEYWORD")
syntax-table))
(option-value option))
:test 'equal)))))))

(define-rules-option "iskeyword" '("@" "48-57" "_" "192-255")
:doc "Comma-separated string to specify the characters should be recognized as a keyword. (buffer local)
Default: @,48-57,_,192-255
Aliases: isk")
(:getter (option)
(car (option-raw-value option)))
(:setter (new-value option)
(setf (option-%value option)
(cons new-value
(compile-iskeyword 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-symbol-chars syntax-table))
(option-value option))
:test 'equal)))))

(defvar *default-isseparator* (mapcar #'string '(#\Newline #\Space #\Tab)))

(defun compile-isseparator (value)
(compile-rules value "isseparator"))

(define-option "isseparator"
((cons *default-isseparator*
(compile-isseparator *default-isseparator*))
:type list
:aliases ("iss")
:scope :buffer)
(:documentation "Comma-separated string to specify the characters that should be recognized as non broad word characters. (buffer local)

(define-rules-option
"isseparator"
(mapcar 'string (lem-base::syntax-table-space-chars (lem:fundamental-syntax-table)))
:doc "Comma-separated string to specify the characters that should be recognized as a non broad word characters. (buffer local)
Aliases: iss")
(:getter (option)
(car (option-raw-value option)))
(:setter (new-value option)
(setf (option-%value option)
(cons 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)
(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.
Expand Down
33 changes: 32 additions & 1 deletion extensions/vi-mode/tests/options.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,35 @@
(execute-set-command "iss+=(")
(execute-set-command "iss+=)")
(cmd "WE")
(ok (buf= #?"abc\n(de[f])\n")))))
(ok (buf= #?"abc\n(de[f])\n")))))

(deftest lisp-word-separators
(with-fake-interface ()
(with-vi-buffer (#?"[(]qwe/rty.uio:pas-dfg hjk
\"lzx\")")
(change-buffer-mode (current-buffer) 'lem-lisp-mode:lisp-mode)
(cmd "w")
(ok (buf= "([q]we/rty.uio:pas-dfg hjk
\"lzx\")"))
(cmd "w")
(ok (buf= "(qwe[/]rty.uio:pas-dfg hjk
\"lzx\")"))
(cmd "ww")
(ok (buf= "(qwe/rty[.]uio:pas-dfg hjk
\"lzx\")"))
(cmd "ww")
(ok (buf= "(qwe/rty.uio[:]pas-dfg hjk
\"lzx\")"))
(cmd "ww")
(ok (buf= "(qwe/rty.uio:pas[-]dfg hjk
\"lzx\")"))
(cmd "ww")
(ok (buf= "(qwe/rty.uio:pas-dfg [h]jk
\"lzx\")"))
(cmd "ww")
(ok (buf= "(qwe/rty.uio:pas-dfg hjk
\"[l]zx\")"))
(cmd "BBB")
(ok (buf= "([q]we/rty.uio:pas-dfg hjk
\"lzx\")"))
)))
Loading