2

FlyCheck had dynamic modeline that shows real-time errors information: FlyC:0/21

How to have the similar ability for flyspell, to show the current dictionary used in the current buffer, the info should be updated whenever the user switch to another buffer with different local dictionary value.

Eg: It should show FlyS:en

I've tried to use (flyspell-mode-line-string (concat " FlyS:" ispell-local-dictionary)) but it failed, I am sure it's because it's only accepted string, not lisp expression.

Thanks.

1

I have something in my configuration that may be of help. Since I write both in English and Italian, I want Flyspell to check the spelling for the current language of the buffer. So I like to see in the mode-line if Flyspell is set on the correct language, and I want to be able to change the language when I need.

This is what I have in my configuration:

  (setq ispell-dictionary "en_GB"
        ispell-program-name (executable-find "hunspell"))    

  (defun mu-current-dictionary-mode-line (language)
    "Return the current dictionary from LANGUAGE for the mode line."
    (interactive)
    (let ((dict (substring language 0 2)))
      (concat " FlyS:" dict)))

  (defvar mu-languages-ring nil "Languages ring for Ispell")

  (let ((languages '("it_IT" "en_GB")))
    (setq mu-languages-ring (make-ring (length languages)))
    (dolist (elem languages) (ring-insert mu-languages-ring elem)))

  (defun mu-cycle-ispell-languages ()
    "Cycle ispell languages in `mu-languages-ring'.
Change dictionary and mode-line lighter accordingly."
    (interactive)
    (let ((language (ring-ref mu-languages-ring -1)))
      (ring-insert mu-languages-ring language)
      (ispell-change-dictionary language)
      (setq flyspell-mode-line-string (mu-current-dictionary-mode-line language))
      (force-mode-line-update)))

  (setq flyspell-mode-line-string (mu-current-dictionary-mode-line ispell-dictionary))

Now I see what the current spell-checker language is in the modeline and I can switch to the language I want with mu-cycle-ispell-languages, with the mode-line lighter updated accordingly.

You can use only mu-current-dictionary-mode-line with flyspell-mode-line-string if you only need to display one language.

Note that I am using hunspell as ispell-program-name, your settings for ispell may have to change if you use a different program. You will also need to check the value your spell-checker uses to identify the current language and understand if mu-current-dictionary-mode-line needs to be changed.

  • for interactive usage, it works great. Sadly, it didn't aware of internal change (non interactive) caused by local variable like %%% ispell-local-dictionary: "it_It" in LaTex. – azzamsa Apr 17 at 7:48
  • I see. But I never set up languages non-interactively. :) – Manuel Uberti Apr 17 at 8:05
  • Alright, I will add that ability later. Thanks for the code :) – azzamsa Apr 17 at 8:46
1

Since I didn't often change my ispell dictionary interactively/manually, (I love to use local variable a lot) e.g:

-*- mode: Org; ispell-local-dictionary: "id";  -*-  ;; in org buffers
%%% ispell-local-dictionary: "id" ;; in tex buffers

Manuel Uberti's code didn't help me because it's not aware of internal language change caused by ispell. So I add the advice below for ispell-init-process function, a function that runs every time a new ispell process started (dictionary changed included):

(defadvice ispell-init-process (after ispell-init-process-after activate)
  (setq flyspell-mode-line-string
        (concat " ⛿:" (or ispell-local-dictionary ispell-dictionary "default"))))

Now I can have the Flyspell modeline updated, whether ispell changed the dictionary internally (by a local variable) or manually (by M-x ispell-change-dictionary). Of course, you can still use Manuel Uberti's cycling code to cycle dictionary easily (with some redundant line removed, cause we already had the advice above).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.