Skip to content

Commit

Permalink
Release Version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PillFall committed Jan 22, 2023
2 parents 503d18b + 5e93094 commit 57af28a
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 238 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/byte-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
emacs_version:
- 27.1
- 27.2
- snapshot
- 28.1
- 28.2
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install emacs
uses: purcell/setup-emacs@master
with:
Expand Down
7 changes: 7 additions & 0 deletions ChangeLog.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Versioning]].

** [Unreleased]

** [1.2.0]
*** Added
- Support for ~ispell~ ~LocalWords~ ignored words.

*** Removed
- Package ~request 0.3.*~ dependency.

** [1.1.0]
*** Added
- Support for API premium features.
Expand Down
64 changes: 64 additions & 0 deletions Contributing.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
* Contributing

In this guide you will get an overview of the contribution workflow from opening
an issue, creating a PR, reviewing, and merging the PR.

** Issues

*** Create a new issues

If you spot a problem with the package, [[https://github.com/PillFall/languagetool.el/issues][search if an issue already exists]]. If a
related issue doesn't exist, you can open a new issue using a relevant [[https://github.com/PillFall/languagetool.el/issues/new/choose][issue
form]].

*** Solve an issue

Scan through our [[https://github.com/PillFall/languagetool.el/issues][existing issues]] to find one that interests you. You can narrow
down the search using ~labels~ as filters. See Labels for more information. If
you find an issue to work on, you are welcome to open a PR with a fix.



** Pull Request

When you're finished with the changes, create a pull request, also known as a
PR.

- Brach out from ~develop~, name the branch the way you want, but keep in mind
that is better to name the branch after the feature or fix.
- All PR that doesn't come from-to ~develop~ will be rejected.
- Don't forget to link PR to issue if you are solving one.
- Enable the checkbox to allow maintainer edits so the branch can be update for
a merge. Once you submit your PR, your code will be reviewed. We may ask
questions or request additional information.
- We may ask for changes to be made before a PR can be merged, either using
suggested changes or pull request comments. You can apply suggested changes
directly through the UI. You can make any other changes in your fork, then
commit them to your branch.
- As you update your PR and apply changes, mark each conversation as resolved.
- If you run into any merge issues, checkout this [[https://github.com/skills/resolve-merge-conflicts][git tutorial]] to help you
resolve merge conflicts and other issues.


** Commit your update

Commit the changes once you are happy with them. Remember to always test:

- The Emacs Lisp files should follow the [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Tips.html][Emacs Lisp conventions]] and the
[[https://github.com/bbatsov/emacs-lisp-style-guide][Emacs Lisp Style Guide]].
- Your code byte-compiles cleanly.
- Use the last version of ~package-lint~ to check for packaging issues, and
address its feedback.
- ~M-x checkdoc~ is happy with your docstrings.



** Your PR is merged!

Congratulations!

Once your PR is merged, your contributions will be publicly visible on the
package.

Now that you are part of the ~languagetool.el~ developers, see how else you can
contribute.
13 changes: 11 additions & 2 deletions ReadMe.org
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ will call LanguageTool from its class, so set ~languagetool-java-arguments~,
languagetool-server-command "org.languagetool.server.HTTPServer")
#+END_SRC

If you pay for LanguageTool Premium features, you can add the keys for the LanguageTool api as follows:
If you pay for [[https://languagetool.org/proofreading-api][LanguageTool Proofreading API]] features, you can add the keys for
the LanguageTool API as follows:

#+BEGIN_SRC elisp
(setq languagetool-api-key "xxxxxxxxxxxx"
Expand All @@ -154,6 +155,14 @@ or call ~languagetool-set-language~.
If you want to know more customization options you can find those at the
/customize/ interface.

When you decide to ignore a word, this package will add a /comment like/
following ~ispell~ conventions. So, after the ignore you'll get a comment like
this at the end of your file.

#+BEGIN_SRC org
# LocalWords: seplling
#+END_SRC



** Quick Usage
Expand Down Expand Up @@ -197,7 +206,7 @@ to Emacs (If you close Emacs, it's over). This server starts to listen in port
another value.

If you are going to use a server with another configuration, like servers not
located in your localhost, you must set ~languagetool-server-host~ and
located in your localhost, you must set ~languagetool-server-url~ and
~languagetool-server-port~ to whatever adjust your needs. These variables play
in the communication to the LanguageTool HTTP API.

Expand Down
99 changes: 47 additions & 52 deletions languagetool-console.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
;; Author: Joar Buitrago <jebuitragoc@unal.edu.co>
;; Keywords: grammar text docs tools convenience checker
;; URL: https://github.com/PillFall/Emacs-LanguageTool.el
;; Version: 1.1.0
;; Package-Requires: ((emacs "27.0") (request "0.3.2"))
;; Version: 1.2.0
;; Package-Requires: ((emacs "27.1"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -32,11 +32,13 @@
(require 'languagetool-core)
(require 'languagetool-issue)
(require 'languagetool-java)
(eval-when-compile
(require 'subr-x))

;; Group definition:

(defgroup languagetool-console nil
"LanguageTool command line parser and checking"
"LanguageTool command line parser and checking."
:tag "Console"
:prefix "languagetool-console-"
:group 'languagetool)
Expand Down Expand Up @@ -74,7 +76,7 @@ Command Line.")
;;; Function definitions:

(defun languagetool-console-class-p ()
"Return nil if `languagetool-console-command' is not a Java class."
"Return non-nil if `languagetool-console-command' is a Java class."
(let ((regex (rx
line-start
(zero-or-more
Expand All @@ -90,7 +92,7 @@ Command Line.")
(string-match-p regex languagetool-console-command)))

(defun languagetool-console-command-exists-p ()
"Return t is `languagetool-console-command' can be used or exists.
"Return non-nil if `languagetool-console-command' can be used or exists.
Also sets `languagetool-console-command' to a full path if needed
for this package to work."
Expand All @@ -104,63 +106,55 @@ for this package to work."
(unless (listp languagetool-console-arguments)
(error "LanguageTool Console Arguments must be a list of strings"))

(let ((arguments nil))
(let (arguments)

;; Appends LanguageTool Console Command
(unless (languagetool-console-class-p)
(setq arguments (append arguments (list "-jar"))))
(setq arguments (append arguments (list languagetool-console-command)))
(push "-jar" arguments))
(push languagetool-console-command arguments)

;; Appends the LanguageTool arguments
(setq arguments (append arguments languagetool-console-arguments))
(push languagetool-console-arguments arguments)

;; Appends the common arguments
(setq arguments (append arguments
(list "--encoding" "utf8")
(list "--json")))
(push (list "--encoding" "utf8" "--json") arguments)

;; Appends the correction language information
(if (string= languagetool-correction-language "auto")
(setq arguments (append arguments (list "--autoDetect")))
(setq arguments (append arguments (list "--language" languagetool-correction-language))))
(push "--autoDetect" arguments)
(push (list "--language" languagetool-correction-language) arguments))

;; Appends the mother tongue information
(when (stringp languagetool-mother-tongue)
(setq arguments (append arguments (list "--mothertongue" languagetool-mother-tongue))))
(push (list "--mothertongue" languagetool-mother-tongue) arguments))

;; Appends the disabled rules
(let ((rules ""))
;; Global disabled rules
(dolist (rule languagetool-disabled-rules)
(if (string= rules "")
(setq rules (concat rules rule))
(setq rules (concat rules "," rule))))
;; Local disabled rules
(dolist (rule languagetool-local-disabled-rules)
(if (string= rules "")
(setq rules (concat rules rule))
(setq rules (concat rules "," rule))))
(let ((rules (string-join (append languagetool-disabled-rules languagetool-local-disabled-rules) ",")))
(unless (string= rules "")
(setq arguments (append arguments (list "--disable" rules)))))
arguments))
(push (list "--disable" rules) arguments )))
(flatten-tree (reverse arguments))))

(defun languagetool-console-write-debug-info (text)
"Write debug info in `languagetool-console-output-buffer-name'.
The argument TEXT is the region passed to LanguageTool for
checking."
(insert (propertize " ----- LanguageTool Command:" 'face 'font-lock-warning-face)
"\n\n")
(insert languagetool-java-bin " "
(mapconcat (lambda (x) (format "%s" x)) (append
(languagetool-console-parse-arguments)
(languagetool-java-parse-arguments)) " ")
"\n\n\n\n")
(insert (propertize " ----- LanguageTool Text:" 'face 'font-lock-warning-face)
"\n\n")
(insert text "\n\n\n\n")
(insert (propertize " ----- LanguageTool Output:" 'face 'font-lock-warning-face)
"\n\n"))
(insert
(propertize " ----- LanguageTool Command:" 'face 'font-lock-warning-face)
"\n\n"
(string-join
(append
(list languagetool-java-bin)
(languagetool-java-parse-arguments)
(languagetool-console-parse-arguments))
" ")
"\n\n\n\n"
(propertize " ----- LanguageTool Text:" 'face 'font-lock-warning-face)
"\n\n"
text
"\n\n\n\n"
(propertize " ----- LanguageTool Output:" 'face 'font-lock-warning-face)
"\n\n"))

(defun languagetool-console-invoke-command-region (begin end)
"Invoke LanguageTool passing the current region to STDIN.
Expand Down Expand Up @@ -219,24 +213,25 @@ Found no errors.")

(defun languagetool-console-matches-exists-p ()
"Return t if issues where found by LanguageTool or nil otherwise."
(/= 0 (length (cdr (assoc 'matches languagetool-console-output-parsed)))))
(/= 0 (length (alist-get 'matches languagetool-console-output-parsed))))

(defun languagetool-console-highlight-matches (begin)
"Highlight issues in the buffer.
BEGIN defines the start of the current region."
(let ((corrections (cdr (assoc 'matches languagetool-console-output-parsed)))
(correction nil))
(let ((corrections (alist-get 'matches languagetool-console-output-parsed)))
(dotimes (index (length corrections))
(setq correction (aref corrections index))
(let ((offset (cdr (assoc 'offset correction)))
(size (cdr (assoc 'length correction))))
(languagetool-issue-create-overlay
(+ begin offset) (+ begin offset size)
correction))))
(setq languagetool-core-hint-timer
(run-with-idle-timer languagetool-hint-idle-delay t
languagetool-hint-function)))
(let* ((correction (aref corrections index))
(offset (alist-get 'offset correction))
(size (alist-get 'length correction))
(start (+ begin offset))
(end (+ begin offset size))
(word (buffer-substring-no-properties start end)))
(unless (languagetool-core-correct-p word)
(languagetool-issue-create-overlay start end correction))))
(setq languagetool-core-hint-timer
(run-with-idle-timer languagetool-hint-idle-delay t
languagetool-hint-function))))

(provide 'languagetool-console)

Expand Down
47 changes: 31 additions & 16 deletions languagetool-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
;; Author: Joar Buitrago <jebuitragoc@unal.edu.co>
;; Keywords: grammar text docs tools convenience checker
;; URL: https://github.com/PillFall/Emacs-LanguageTool.el
;; Version: 1.1.0
;; Package-Requires: ((emacs "27.0") (request "0.3.2"))
;; Version: 1.2.0
;; Package-Requires: ((emacs "27.1"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -29,6 +29,10 @@

;; Variable definitions:

(require 'ispell)
(eval-when-compile
(require 'subr-x))

(defcustom languagetool-api-key nil
"LanguageTool API Key for Premium features."
:group 'languagetool
Expand Down Expand Up @@ -163,13 +167,12 @@ A example hint function:
(when (overlay-get ov 'languagetool-message)
(unless (current-message)
(message
\"%s%s\" (overlay-get ov 'languagetool-short-message)
(if (/= 0
(length (overlay-get ov 'languagetool-replacements)))
\"%s%s\"
(overlay-get ov 'languagetool-short-message)
(if (/= 0 (length (overlay-get ov 'languagetool-replacements)))
(concat
\" -> (\"
(mapconcat
#'identity (languagetool-core-get-replacements ov) \", \")
(string-join (languagetool-core-get-replacements ov) \", \")
\")\")
\"\"))))))"
:group 'languagetool
Expand Down Expand Up @@ -206,24 +209,36 @@ A example hint function:
(when (overlay-get ov 'languagetool-message)
(unless (current-message)
(message
"%s%s" (overlay-get ov 'languagetool-short-message)
(if (/= 0
(length (overlay-get ov 'languagetool-replacements)))
"%s%s"
(overlay-get ov 'languagetool-short-message)
(if (/= 0 (length (overlay-get ov 'languagetool-replacements)))
(concat
" -> ("
(mapconcat
#'identity (languagetool-core-get-replacements ov) ", ")
(string-join (languagetool-core-get-replacements ov) ", ")
")")
""))))))

(defun languagetool-core-get-replacements (overlay)
"Return the replacements of OVERLAY in a list."
(let ((replacements (overlay-get overlay 'languagetool-replacements))
(replace nil))
replace)
(dotimes (index (length replacements))
(setq replace (append replace
(list (cdr (assoc 'value (aref replacements index)))))))
replace))
(push (alist-get 'value (aref replacements index)) replace))
(reverse replace)))

(defun languagetool-core-correct-p (word)
"Return non-nil if WORD is on the LocalWords comment in the current buffer."
(save-excursion
(goto-char (point-min))
(let (found)
(while (and (search-forward ispell-words-keyword nil t)
(not found))
(when (re-search-forward (rx
(zero-or-more space)
(group (literal word))
(zero-or-more space)) (line-end-position) t)
(setq found t)))
found)))

(provide 'languagetool-core)

Expand Down
Loading

0 comments on commit 57af28a

Please sign in to comment.