wcheck-mode icon indicating copy to clipboard operation
wcheck-mode copied to clipboard

Any other way to show `action-parser` suggestions

Open lonelyelk opened this issue 7 years ago • 4 comments

Is there any other way to show proposed corrections other than option selection. Can helm or company be used for that?

lonelyelk avatar Mar 30 '17 21:03 lonelyelk

In wcheck-mode the logic is to call action-program with action-args and the output is parsed by action-parser.

But if user wants to use other code for wcheck's marked words he is obviously free to do so. Wcheck's function "wcheck-marked-text-at" can be useful: it returns information about marked text at a buffer position.

tlikonen avatar Jun 17 '17 08:06 tlikonen

More precisely what I am asking is is there a documentation on how to write a function so that it can be provided via standard setq wcheck-language-data instead of, say, action-parser . wcheck-parser-ispell-suggestions or anywhere else so that output of an action-program with action-args would be put in a helm or company autocomplete-like interface instead of mini-buffer poll. I was looking for a standard way to do so using provided interfaces.

lonelyelk avatar Jun 18 '17 21:06 lonelyelk

I don't know about helm or company but custom "action" things for Wcheck must be written outside of wcheck-language-data variable. User's custom functions can use function "wcheck-marked-text-at" to get information about marked text. Information about language configuration can be queried with function "wcheck-query-language-data". With those functions user can write anything they want (and possibly connect it to other Emacs features).

tlikonen avatar Jun 20 '17 08:06 tlikonen

Here is my Wcheck + Aspell + Ivy config, redefined wcheck--choose-action-minibuffer to utilize Ivy, should not be too hard to do the same for helm.


(defconst vs-emacs-spellchecker (executable-find "aspell")
  "Spell checker program name.")

(defconst vs-aspell-dict-dir (expand-file-name "aspell" (getenv "XDG_DATA_HOME"))
  "Local Aspell dictionaries directory.")

(when vs-emacs-spellchecker
  (use-package wcheck-mode
    :hook (prog-mode text-mode)

    :bind (("C-c s" . wcheck-mode)
           ("C-c l" . wcheck-change-language)
           ("C-c c" . wcheck-actions)
           ("C-c n" . wcheck-jump-forward)
           ("C-c p" . wcheck-jump-backward))

    :config
    (defun vs:wcheck/args (lang &optional dict dict-dir)
      "Produce Aspell arguments list for language LANG,
dictionary DICT and extra dictionaries directory DICT-DIR."
      (let ((args `(,(format "--home-dir=%s" (expand-file-name "aspell" (getenv "XDG_CONFIG_HOME")))
                    ,(format "--personal=%s.pws" lang)
                    ,(format "--repl=%s.prepl" lang)
                    "-l" ,lang)))
        (when dict
          (setq args (append args `("-d" ,dict)))
          (when dict-dir
            (add-to-list 'args (format "--dict-dir=%s" dict-dir) t)))
        args))

    (defun wcheck--choose-action-minibuffer (actions)
      "Redefined `wcheck--choose-action-minibuffer' with `ivy-read' suport."
      (let ((ivy-use-selectable-prompt nil))
        (ivy-read "Choose: " actions)))

    (setq-default
     wcheck-language      "English"
     wcheck-language-data
     `(("English"
        (connection     . pty                             )
        (program        . ,vs-emacs-spellchecker          )
        (action-program . ,vs-emacs-spellchecker          )
        (action-parser  . wcheck-parser-ispell-suggestions)
        ,(append '(args)
                 (vs:wcheck/args "en" "en_US")
                 '("list"))
        ,(append '(action-args)
                 (vs:wcheck/args "en" "en_US")
                 '("pipe"))
        (read-or-skip-faces
         ((emacs-lisp-mode c-mode c++-mode python-mode shell-script-mode)
          read font-lock-comment-face font-lock-string-face)
         ((org-mode)
          skip org-block-begin-line org-block-end-line org-meta-line org-link)
         (nil)))

       ("Russian"
        (connection     . pty                             )
        (program        . ,vs-emacs-spellchecker          )
        (action-program . ,vs-emacs-spellchecker          )
        (action-parser  . wcheck-parser-ispell-suggestions)
        ,(append '(args)
                 (vs:wcheck/args "ru" "ru-ye" vs-aspell-dict-dir)
                 '("list"))
        ,(append '(action-args)
                 (vs:wcheck/args "ru" "ru-ye" vs-aspell-dict-dir)
                 '("pipe"))
        (read-or-skip-faces
         ((emacs-lisp-mode c-mode c++-mode python-mode shell-script-mode)
          read font-lock-comment-face font-lock-string-face)
         (org-mode
          skip org-block-begin-line org-block-end-line org-meta-line org-link)
         (nil)))))))

(provide 'use-wcheck)

vsemyonoff avatar Aug 11 '19 19:08 vsemyonoff