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.
emacs-lisp source:(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:
emacs-lisp source:(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
nix source: :tangle ~/arroyo-nix/nixos/japanese.nix{ pkgs, ... }: { fonts.packages = [ 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.
emacs-lisp source:(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 roam: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!
emacs-lisp source:(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
nix source: :tangle ~/arroyo-nix/pkgs/jisho-api.nix{ pkgs ? import <nixpkgs> {}, python ? pkgs.python39 }: python.pkgs.buildPythonPackage { name = "jisho-api"; version = pkgs.lib.pkgVersions.jisho-api.version; format = "pyproject"; inherit python; src = pkgs.callPackage pkgs.lib.pkgVersions.jisho-api.src {}; postPatch = '' substituteInPlace pyproject.toml \ --replace 'rich = "^10.11.0"' 'rich = ">12.0.0"' \ --replace 'bs4 = "^0.0.1"' 'beautifulsoup4 = "^4.11.1"' ''; propagatedBuildInputs = with python.pkgs; [ poetry-core click pydantic_1 requests rich beautifulsoup4 ]; }