mhayashi1120 / Emacs-langtool

LanguageTool for Emacs
GNU General Public License v3.0
377 stars 31 forks source link

-d option clashes when setting other language #48

Open PillFall opened 4 years ago

PillFall commented 4 years ago

When I check any buffer without setting the language, the output is correct (says that I have errors if any).

But when I set any language. it always returns that the buffer is correct (I know is not).

Checking langtool debugging tool in Emacs I notice that when I delete the -d when it has no options (in log the command is langtool.jar -c ascii -d -l en-GB file.txt) that error is fixed. Is the only flag that clashes.

I propose to change the code in the langtool-command--invoke-process to avoid the -d flag is there is no options to pass.

(defun langtool-command--invoke-process (file begin finish &optional lang)
  (let ((version (langtool--jar-version)))
    (cl-destructuring-bind (command args)
        (langtool--basic-command&args)
      ;; Construct arguments pass to jar file.
      ;; http://wiki.languagetool.org/command-line-options
      (setq args (append
                  args
                  (list "-c" (langtool--java-coding-system
                              buffer-file-coding-system))
                  ;;-----------------------------
                  ;; Avoid using -d flag if not needed.
                  (if (string= (langtool--disabled-rules) "")
                      (list "")
                    (list "-d" (langtool--disabled-rules)))))
      (cond
       ((stringp (or lang langtool-default-language))
        (setq args (append args (list "-l" (or lang langtool-default-language)))))
       (t
        (setq args (append args (list "--autoDetect")))))
      (when langtool-mother-tongue
        (setq args (append args (list "-m" langtool-mother-tongue))))
      (setq args (append args (langtool--custom-arguments 'langtool-user-arguments)))
      (setq args (append args (list (langtool--process-file-name file))))
      (langtool--debug "Command" "%s: %s" command args)
      (let* ((buffer (langtool--process-create-client-buffer))
             (proc (langtool--with-java-environ
                    (apply 'start-process "LanguageTool" buffer command args))))
        (set-process-filter proc 'langtool-command--process-filter)
        (set-process-sentinel proc 'langtool-command--process-sentinel)
        (process-put proc 'langtool-source-buffer (current-buffer))
        (process-put proc 'langtool-region-begin begin)
        (process-put proc 'langtool-region-finish finish)
        (process-put proc 'langtool-jar-version version)
        proc))))
PillFall commented 4 years ago

Sorry for putting the code in the issue, I'm still pretty new and doesn't know how don't mess up a pull request.