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

Support blank space. #3

Merged
merged 1 commit into from Oct 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 42 additions & 21 deletions deno-bridge-jieba.el
Expand Up @@ -61,41 +61,66 @@
(deno-bridge-jieba-start)
(list-processes))

(defun deno-bridge-jieba-blank-after-cursor-p ()
"Have blank after cursor."
(not (split-string (buffer-substring-no-properties
(min (1+ (point)) (point-at-eol))
(point)))))

(defun deno-bridge-jieba-blank-before-cursor-p ()
"Have blank before cursor."
(not (split-string (buffer-substring-no-properties
(max (1- (point)) (line-beginning-position))
(point)))))

(defun deno-bridge-jieba-single-char-after-cursor-p ()
"Check following char if a single width char."
(= (string-width (string (char-after))) 1))

(defun deno-bridge-jieba-single-char-before-cursor-p ()
"Check before char if a single width char."
(= (string-width (string (char-before))) 1))

(defun deno-bridge-jieba-forward-word ()
"Send request to deno for forward chinese word."
(interactive)
(if (or (= (line-end-position) (point)) ;; if current point is line end, just forward-word
;; if following char is single width, is ASCII char, just forward-word
(deno-bridge-jieba-single-width-char?))
(forward-word)
(deno-bridge-call "deno-bridge-jieba" "forward-word"
(thing-at-point 'line)
(- (point) (line-beginning-position)))))
(cond ((= (line-end-position) (point))
(forward-word))
((deno-bridge-jieba-blank-after-cursor-p)
(search-forward-regexp "\\s-+" nil (point-at-eol)))
((deno-bridge-jieba-single-char-after-cursor-p)
(forward-word))
(t
(deno-bridge-call "deno-bridge-jieba" "forward-word"
(thing-at-point 'line nil)
(- (point) (line-beginning-position))))))

(defun deno-bridge-jieba-backward-word ()
"Send request to deno for backward chinese word."
(interactive)
(if (or (= (line-beginning-position) (point)) ;; if current point is line beginning, just backward-word
;; if following char is single width, is ASCII char, just backward-word
(deno-bridge-jieba-single-width-char?))
(backward-word)
(deno-bridge-call "deno-bridge-jieba" "backward-word"
(thing-at-point 'line)
(- (point) (line-beginning-position)))))

(cond ((= (line-beginning-position) (point))
(backward-word))
((deno-bridge-jieba-blank-before-cursor-p)
(search-backward-regexp "\\s-+" nil (point-at-bol)))
((deno-bridge-jieba-single-char-before-cursor-p)
(backward-word))
(t
(deno-bridge-call "deno-bridge-jieba" "backward-word"
(thing-at-point 'line nil)
(- (point) (line-beginning-position))))))

(defun deno-bridge-jieba-mark-word ()
"Send request to deno for mark chinese word."
(interactive)
(deno-bridge-call "deno-bridge-jieba" "mark-word"
(thing-at-point 'line)
(thing-at-point 'line nil)
(- (point) (line-beginning-position))))

(defun deno-bridge-jieba-kill-word ()
"Send request to deno for kill chinese word."
(interactive)
(deno-bridge-call "deno-bridge-jieba" "kill-word"
(thing-at-point 'line)
(thing-at-point 'line nil)
(- (point) (line-beginning-position))))

(defun deno-bridge-jieba-kill-from (begin end)
Expand All @@ -115,10 +140,6 @@
(beginning-of-line)
(forward-char num))

(defun deno-bridge-jieba-single-width-char? ()
"Check following char if a single width char."
(= (string-width (string (following-char))) 1))

(deno-bridge-jieba-start) ;; start deno-bridge-jieba when load package.
(provide 'deno-bridge-jieba)
;;; deno-bridge-jieba.el ends here
3 changes: 2 additions & 1 deletion deno-bridge-jieba.ts
Expand Up @@ -87,7 +87,8 @@ function bacwardWord(column: number) {
const start = tokens[i].start;
const end = tokens[i].end;
var movePosition: string;
if (column > start && column < end) {

if (column > start && column <= end) {
// when current column is in the middle of a word
// jump to word beginning
movePosition = start;
Expand Down