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

Update filling functionality. #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
720 changes: 720 additions & 0 deletions kotlin-mode-fill.el

Large diffs are not rendered by default.

872 changes: 872 additions & 0 deletions kotlin-mode-kdoc-comment-parser.el

Large diffs are not rendered by default.

37 changes: 34 additions & 3 deletions kotlin-mode-lexer.el
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ It have the type and the start position.")
"Return the start position of the CHUNK."
(and chunk (oref chunk start)))

(defun kotlin-mode--chunk-end (chunk)
"Return the end position of the CHUNK."
(save-excursion
(goto-char (oref chunk start))
(if (kotlin-mode--chunk-comment-p chunk)
(forward-comment 1)
(kotlin-mode--forward-token))
(point)))

(defun kotlin-mode--chunk-comment-p (chunk)
"Return non-nil if the CHUNK is a comment."
(and chunk
Expand Down Expand Up @@ -455,6 +464,17 @@ If PARSER-STATE is given, it is used instead of (syntax-ppss)."
(t
nil))))

(defun kotlin-mode--chunk-after-spaces ()
"Return the chunk at the point or after spaces.

If there is no chunk at the point nor after spaces, return nil."
(or (kotlin-mode--chunk-after)
(save-excursion
(skip-chars-forward " ")
(when (memq (char-after) '(?\" ?/))
(forward-char)
(kotlin-mode--chunk-after)))))

;; Syntax table

(defvar kotlin-mode-syntax-table
Expand Down Expand Up @@ -607,8 +627,8 @@ expression as a token with one of the following types:
:end (point))))
(cond
;; Tokens that end a statement
((memq (kotlin-mode--token-text previous-token)
'("return" "continue" "break"))
((member (kotlin-mode--token-text previous-token)
'("return" "continue" "break"))
t)

;; .* in import declarations end a statement.
Expand Down Expand Up @@ -1635,7 +1655,7 @@ the same line, \"->\", or \"{\"."
(kotlin-mode--forward-token-simple))))
(and (equal (kotlin-mode--token-text token) "else")
(not (eq (kotlin-mode--token-type next-token) '{))
(not (eq (kotlin-mode--token-text next-token) "->"))
(not (equal (kotlin-mode--token-text next-token) "->"))
(not (and
(equal (kotlin-mode--token-text next-token) "if")
(save-excursion
Expand Down Expand Up @@ -2584,6 +2604,17 @@ Newlines inside comments are ignored."
(forward-comment (- (point)))
(point)))))

(defun kotlin-mode--same-line-p (point1 point2)
"Return non-nil if POINT1 and POINT2 is on the same line.

Return nil otherwise."
(= (save-excursion
(goto-char point1)
(line-beginning-position))
(save-excursion
(goto-char point2)
(line-beginning-position))))

(provide 'kotlin-mode-lexer)

;;; kotlin-mode-lexer.el ends here
20 changes: 10 additions & 10 deletions kotlin-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

(require 'kotlin-mode-lexer)
(require 'kotlin-mode-indent)
(require 'kotlin-mode-fill)

(defgroup kotlin nil
"A Kotlin major mode."
Expand Down Expand Up @@ -358,18 +359,17 @@ and return non-nil. Return nil otherwise."
;; Multi-line comment
(seq "/" (one-or-more "*"))
;; Middle of multi-line-comment
(seq (one-or-more "*") " "))
(seq (one-or-more "*") (zero-or-one " ")))
(zero-or-more (syntax whitespace)))))
(setq-local adaptive-fill-regexp
(rx (seq (zero-or-more (syntax whitespace))
(or
;; Single-line comment
(seq "/" (one-or-more "/"))
;; Middle of multi-line-comment
(seq (one-or-more "*") " "))
(zero-or-more (syntax whitespace)))))
(setq-local fill-indent-according-to-mode t)
(setq-local adaptive-fill-first-line-regexp ".*")
(setq-local adaptive-fill-function #'kotlin-mode--adaptive-fill)
(setq-local fill-indent-according-to-mode nil)
(setq-local comment-multi-line t)
(setq-local fill-paragraph-function #'kotlin-mode--fill-paragraph)
(setq-local fill-forward-paragraph-function
#'kotlin-mode--fill-forward-paragraph)
(setq-local normal-auto-fill-function #'kotlin-mode--do-auto-fill)
(kotlin-mode--install-fill-region-as-paragraph-advice)

(setq-local indent-line-function 'kotlin-mode--indent-line)

Expand Down
2 changes: 1 addition & 1 deletion scripts/run_linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ rm -f *-autoloads.el || exit 1
-l elisp-lint.el \
--eval '(setq elisp-lint--debug t)' \
-f elisp-lint-files-batch \
*.el || exit 1
*.el "$@" || exit 1
rm -f *.elc test/*.elc || exit 1
rm -f *-autoloads.el || exit 1
5 changes: 3 additions & 2 deletions scripts/run_linter_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Cask does't support Emacs 24.
for version in 28 27 26 25 # 24
do
ARGS=$( [ "$version" -lt 26 ] && echo "--no-checkdoc" )
docker \
run \
--rm \
Expand All @@ -13,8 +14,8 @@ do
--workdir="/src" \
--env=ELDEV_DIR=/src/.eldev \
--env=HOME=/tmp \
silex/emacs:${version} \
bash -c "/src/scripts/run_linter.sh" \
silex/emacs:${version}-ci \
bash -c "/src/scripts/run_linter.sh $ARGS" \
|| exit 1
done

Expand Down
2 changes: 1 addition & 1 deletion scripts/run_test_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
--workdir="/src" \
--env=ELDEV_DIR=/src/.eldev \
--env=HOME=/tmp \
silex/emacs:${version} \
silex/emacs:${version}-ci \
bash -c "/src/scripts/run_test.sh" \
|| exit 1
done
Expand Down
Loading