web-dev-qa-db-ja.com

ispellを使用しているときにEmacsで言語を変更するにはどうすればよいですか?

Emacsでispell-bufferコマンドを使いたいのですが。デフォルトでは英語を使用します。別の辞書(たとえば、別の言語)に切り替える簡単な方法はありますか?

45

次のコマンドは、使用するインストール済み辞書のリストを提案します。

M-x ispell-change-dictionary

通常、M-x isp-c-d上記にも展開されます。

43
stephanea

Ispell.elファイルから、ispellコマンドにいくつかのオプションを指定できます。これは、次のようにファイルの最後にセクションを追加することで発生します。

;; Local Variables:
;; ispell-check-comments: exclusive
;; ispell-local-dictionary: "american"
;; End:

二重セミコロンは、現在のモードでのコメントの開始を示していることに注意してください。 Javaの場合は//のように、ファイル(プログラミング言語)がコメントを導入する方法を反映するように変更する必要があります。

24
Pierre

LaTeXファイルの最後に使用できるもの:

%%% Local Variables:
%%% ispell-local-dictionary: "british"
%%% End:

これにより、そのファイルにのみ使用される辞書が設定されます。

15
boclodoa

M-x ispell-change-dictionaryを使用してTABを押すと、使用可能な辞書が表示されます。

次に、デフォルトの辞書の設定を.emacsに書き込み、フックを追加して、特定のモードでispellを自動的に開始します(必要な場合)。

たとえば、イギリス英語を使用してAUCTeXでispellを自動的に開始します(デフォルトでは、英語の辞書はアメリカ英語です)。

(add-hook 'LaTeX-mode-hook 'flyspell-mode) ;start flyspell-mode
(setq ispell-dictionary "british")    ;set the default dictionary
(add-hook 'LaTeX-mode-hook 'ispell)   ;start ispell
11
oracleyue

ディレクトリごとに言語を変更したい場合は、これを.dir-locals.elファイルに追加できます。

(ispell-local-dictionary . "american")

.dir-locals.elファイルがまだない場合は、次のようになります。

((nil .
   ((ispell-local-dictionary . "american")))
)

詳細については、 ディレクトリ変数に関するemacs wikiページ を参照してください。

2
spookylukey

便宜上(f7).emacsに以下を追加しました:

(global-set-key [f7] 'spell-checker)

(require 'ispell)
(require 'flyspell)

(defun spell-checker ()
  "spell checker (on/off) with selectable dictionary"
  (interactive)
  (if flyspell-mode
      (flyspell-mode-off)
    (progn
      (flyspell-mode)
      (ispell-change-dictionary
       (completing-read
        "Use new dictionary (RET for *default*): "
        (and (fboundp 'ispell-valid-dictionary-list)
         (mapcar 'list (ispell-valid-dictionary-list)))
        nil t))
      )))

ところで:必要な辞書をインストールすることを忘れないでください。例えば。 debian/ubuntuで、ドイツ語と英語の辞書の場合:

Sudo apt install aspell-de aspell-en
1
return42