The Complete Computing Environment

Japanese Study

LifeTechEmacsTopicsArcology

I am trying to learn the Japanese language. I want to able to read some Gundam novels and what not, I'm using SRS to do that, and this stuff helps out.

Emacs functions for studying Japanese

jisho-this aka cce/jisho-at-point will open up Jisho with the word under point searched.

SPC SPC jisho RET will open the kanji at point in Jisho.

(require 'thingatpt)
(require 'org-collector)

(defalias 'jisho-this 'cce/jisho-at-point)

(defun cce/jisho-at-point ()
  (interactive)
  (let ((chr (thing-at-point 'word)))
    (browse-url (format "https://jisho.org/search/%s" chr))))

Configure Emacs to use the IPAex fonts instead of Unifont:

(defun cce/enable-ipaex-font (&optional size)
  (interactive)
  (dolist (charset '(kana han cjk-misc bopomofo))
    (set-fontset-font (frame-parameter nil 'font) charset
                      (font-spec :family "IPAexGothic" :size (or size 36)))))

(provide 'cce/japanese-study)

Using jisho-api to populate SRS cards

{ pkgs, ... }:
{
  fonts.fonts = [ pkgs.ipaexfont ];
  environment.systemPackages = [ pkgs.jisho-api ];
}
jisho search kanji 実

to make a new card, start with a second-level heading with only the character at point * 田. The first level is usually something to capture tags since org-fc will inherit tree tags, but not FILETAGS.

invoking cce/template-kanji-card at that character's point will populate a card with Kunyomi and Onyomi readings, optionally with cloze format. Finish them up, and then make sure to initialize the cards. It's a lot quicker than doing this all by hand.

(defun cce/template-kanji-card--extract-readings (buf)
  (with-current-buffer buf
    (goto-char (point-min))
    (search-forward-regexp (rx "[Kun: " (group (one-or-more (not "]"))) "]"
                               " | [On: " (group (one-or-more (not "]"))) "]"))
    (list (s-split ", " (match-string 1))
          (s-split ", " (match-string 2)))))

(defun cce/template-kanji-card--insert-readings (readings type-id)
  (insert "*** [[id:" type-id "][" type-id "]] readings\n")
  (if (= (length readings) 1)
      (insert (first readings) "\n")
    (dolist (cloze (--map-indexed
                    (concat "- {{" it "}@" (number-to-string it-index) "}" "\n")
                    readings))
      (insert cloze))))

(defun cce/template-kanji-card ()
  (interactive)
  (save-excursion
    (let* ((char (thing-at-point 'word t))
           (cmd (format "jisho search kanji %s" char))
           (buf  " *jisho-card*")
           (ret (shell-command cmd buf)))
      (pcase-let ((`(,kuns ,ons) (cce/template-kanji-card--extract-readings buf)))
        (evil-open-below 1)
        (mark)
        (cce/template-kanji-card--insert-readings kuns "kunyomi")
        (cce/template-kanji-card--insert-readings ons "onyomi")
        (pop-mark)
        (evil-normal-state)))))

Show Hiragana and Katakana as eldoc

This is a fun little hack: show the name of hiragana and katakana when I point over them. Eldoc is enabled in my Basic Emacs Coding Config and here I am using it outside of code!

(with-eval-after-load 'org
  (defun cce/eldoc-jhk (&rest args)
    (when (looking-at "[ぁ-ヿ]")
      (get-char-code-property (string-to-char (thing-at-point 'char)) 'name)))

  (defun cce/eldoc-jhk-setup ()
    (add-hook 'eldoc-documentation-functions
              #'cce/eldoc-jhk nil t))

  (add-hook 'org-mode-hook #'cce/eldoc-jhk-setup))

jisho-api Python nixpkgs

{ pkgs ? import <nixpkgs> {},
  python ? pkgs.python39 }:

python.pkgs.buildPythonPackage {
  name = "jisho-api";
  version = "0.1.8";
  format = "pyproject";

  inherit python;

  src = pkgs.fetchFromGitHub {

    owner = "pedroallenrevez";
    repo = "jisho-api";
    rev = "b80bff460a0f6826232cafce68cb75ef83543a23";
    sha256 = "sha256-3oEhr/kXesxp5vnELlciaizq88Jwzw2ahTgooA946Pc=";
  };

  postPatch = ''
        substituteInPlace pyproject.toml \
          --replace 'rich = "^10.11.0"' 'rich = "^12.4.4"' \
          --replace 'bs4 = "^0.0.1"' 'beautifulsoup4 = "^4.11.1"' 
      '';

  propagatedBuildInputs = with python.pkgs; [
    poetry
    click pydantic requests rich beautifulsoup4
  ];
}

INPROGRESS Japanese phrasebook - Wikitravel

NEXT Japanese counter words

NEXT List of japanese typographic symbols

NEXT Japanese Verb Conjugation Cheatsheet

NEXT Japanese Particles

watch some subtitled movies

INPROGRESS Kanji for 6 y/o kids