4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Emacs 精進 18: 今日だけ SKK

4
Last updated at Posted at 2025-12-24

この記事は Emacs 精進 Advent Calendar 2025 18 日目の投稿です。

背景

日本語変換のソリッドなソリューションとして、一部で SKK が重宝されています (いました) 。 SKK は簡素な IME であり、文節の区切りをユーザが都度手動で指定して変換するスタイルが特徴的です。

『Emacsen なのに SKK を使っていないなんてありえない!』と煽られたり、 Vim を OS の SKK にしている連中が跋扈していたり、 SKK 世紀末な現代ですので、僕も今日だけ SKK を覗き見てみます。

SKK 入門への入門

SKK を習得するには skk-tutorial をやれば良いですが、 37 点もの綿密なチュートリアルであるのが難点です。『どこまで進めたか忘れた』『過去のレッスンを振り返りたい』など、数々の僕から心の声が寄せられています。

クリアフラグと、少なくともレッスン一覧の表示機能が必要ではないかと思います。

セットアップ (NixOS)

NixOS 上の ddskk セットアップをローテクで実施します。 Nix の意味が全く無いです。

まず辞書データは init.el の隣に解凍しておきます:

$ curl -L 'https://skk-dev.github.io/dict/SKK-JISYO.L.gz'
$ gunzip SKK-JISYO.L.gz

またチュートリアルファイルが欲しいので、 ddskk のリポジトリを init.el の隣に解凍してしまいます:

$ git clone git@github.com:skk-dev/ddskk

最悪のセットアップでしたね……。後は普通に ddskk の設定を書きます:

(leaf ddskk
  :bind
  (("C-x C-j" . skk-mode)
   ("C-x j" . skk-auto-fill-mode)
   ("C-x t" . skk-tutorial))
  :init
  (setq skk-large-jisyo (concat user-emacs-directory "SKK-JISYO.L"))
  (setq skk-tut-file (concat user-emacs-directory "ddskk/etc/SKK.tut")))

これで skk-tutorial を起動できます:

18-skk-tutorial.png

えらい疲れました。NixOS 上で skk-tutorial を一発で動かす方法を募集しています。

skktut-get-question-page

skk-tutorial は全部で 37 問ありますが、後戻りを考慮しない設計のようです:

18-skktut.png

実際に取り組むと、 37 問は一日で終わらない割に、前の問題までの操作方法を忘れると詰むなどの問題があります。中断後、再開させる風でもなく、皆さんはこのチュートリアルは余裕でしたか……?

describe-funtion で検索すると、指定ページに飛べる skktut-get-question-page が見つかります:

skktut-get-question-page

これは interactive にしておいて欲しかったですね。それと前の問題へ戻る skktut-prev-question もほしいです。

skktut-prev-question

これが一発で定義できました:

(defun skktut-prev-question ()
  (interactive)
  (skktut-skip-question -1))

ここまで行き届いた実装になっていながら、なぜエンドユーザに届けられていないのか……? 否! きっとパワーユーザには届いているのです。

C-x p バインドを定義します。パッケージが古いためか、 skktut-mode-map というのはありません。

一応、以下の設定が動きます:

(require 'ddskk-autoloads)

(defadvice skk-tutorial (after add-prev-key-binding activate)
  (keymap-local-set "C-x p" #'skktut-prev-question))

consult-skk-tutorial

最後に問題を consult から選択可能にします。

(defun consult-skk-tutorial ()
  "Select and jump to a specific SKK tutorial problem using consult."
  (interactive)
  (require 'consult)
  (let ((tut-file (skk-tut-find-tut-file skk-tut-file))
        (problems nil))
    (unless (file-exists-p tut-file)
      (error "Tutorial file not found: %s" tut-file))

    ;; Set problems
    (with-temp-buffer
      (insert-file-contents tut-file)
      (goto-char (point-min))
      (let ((problem-num 0))
        (while (re-search-forward "^----$" nil t)
          (setq problem-num (1+ problem-num))
          (next-line)
          (while (looking-at-p "\\s-*;;")
            ;; Ignore ;; lines
            (forward-line 1))
          (let ((title (buffer-substring (line-beginning-position) (line-end-position))))
            (push `(,problem-num ,(format "%d %s" problem-num title))
                  problems)))))

    (pop problems) ;; discard the last one
    (setq problems (reverse problems))

    ;; consult
    (when problems
      (let* ((candidates (mapcar #'cdr problems))
             (selection (consult--read
                         candidates
                         :prompt "SKK Tutorial Problem: "
                         :require-match t
                         :category 'consult-skk-tutorial
                         :sort nil)))
        (let ((entry (cl-find selection problems
                              :key #'cadr
                              :test #'string=)))
          (when entry
            (skktut-get-question-page (car entry))))))))

18-skk-consult.png

最終的な ddskk の設定は以下の通りです:

(leaf ddskk
  :bind
  (("C-x C-j" . skk-mode)
   ("C-x j" . skk-auto-fill-mode)
   ("C-x t" . skk-tutorial))

  :init
  (setq skk-large-jisyo (concat user-emacs-directory "SKK-JISYO.L"))
  (setq skk-tut-file (concat user-emacs-directory "ddskk/etc/SKK.tut"))

  (defun skktut-prev-question ()
    (interactive)
    (skktut-skip-question -1))

  (defadvice skk-tutorial (after add-prev-key-binding activate)
    (keymap-set (current-local-map) "C-x p" #'skktut-prev-question)
    (keymap-set (current-local-map) "C-x <RET>" #'consult-skk-tutorial))

  :config
  (require 'ddskk-autoloads))

まとめ

FHS-incompatible な NixOS 上で、 ddskkskk-tutorial を起動しました (やたら苦労しました) 。また skk-tutorial を便利にしてみました。歴史あるパッケージだけあって、 keymap が定義されていないなど、改善の余地を感じました。

みなさんは skk-tutorial に苦労しなかったのでしょうか……? 『良かった』みたいな感想しか無くて、誰も詰まっているように見えないのが謎です。

……さてやっと SKK (skk tutorial) の記事を書くことができました。そこそこちゃんとした内容になったと思いますが、今日中にあと 11 記事を投稿するのは絶望的です。

それでは、次の記事でお会いしましょう!

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?