[β]
β
bitchan
[?] help
π
host1.bitchan.one
π
@aQ6+a?fA
β±
1w seen
β
0
π
0
β§
1
π hide
send βΏitcoin
[!] follow
[@] review
posts 1
/ 1
[β₯] sort newest
β±
filter [-]
languages:
on
other
/technology
I made something like this, but it relies on a Common Lisp library to do the Japanese to English translation. Ichiran is the Common Lisp library.
https://github.com/tshatrov/ichiran
β§
On the Emacs side, the requirements are: - You have to have sly or slime running. - org-babel-lisp-eval-fn must be setup to either #'sly-eval or #'slime-eval depending on which CL REPL you're using. - In that CL REPL, you have to (ql:quickload :ichiran) . If you've done all that, you can use this Elisp function to do lookups. (defun ichiran-romanize (phrase) "Romanize a Japanese PHRASE using ichiran. Results are displayed in an *ichiran* `org-mode' buffer. For this to work: 1. `sly' or `slime' must already be running. 2. `org-babel-lisp-eval-fn' must be set appropriately. 3. The ichiran CL library must be loaded into that sly (or slime) instance." (interactive "MPhrase: ") (unless (stringp phrase) (user-error "Phrase must be a string.")) (let* ((result (funcall org-babel-lisp-eval-fn `(cl:multiple-value-list (ichiran:romanize ,phrase :with-info t)))) (romanized-text (car result)) (romanized-info (cadr result)) (buffer (get-buffer-create "*ichiran*")) (window (or (get-buffer-window buffer) (switch-to-buffer-other-window buffer)))) (with-current-buffer buffer (when view-mode (view-mode -1)) (delete-region (point-min) (point-max)) (unless (equal major-mode 'org-mode) (org-mode)) ;; Insert `romanized-text' at the top. (insert (concat romanized-text "\n" ;; Insert a level 1 org headline for each segment. (cl-loop for part in romanized-info concat (concat "* " (car part) " = " (cdr part) "\n\n")))) ;; Fold headlines on initial load. (org-cycle '(4)) (view-mode 1) )))
β±
1w
β©
1
I also have an Elisp function that takes functions that accept a string and generate a derivative function that works on regions. (defun u/funcall-with-dwim-fn (fn) "Return a function that either operates on the word at point or region if a region is selected. Region selection takes precedence over `word-at-point'." (interactive) (lambda () (interactive) (let* ((query (if (use-region-p) (buffer-substring (use-region-beginning) (use-region-end)) (word-at-point)))) (funcall fn query)))) This is how I apply it to ichiran-romanize to create ichiran-romanize-dwim. (defalias #'ichiran-romanize-dwim (u/funcall-with-dwim-fn #'ichiran-romanize) "Romanize the region or word at point (if no region is selected) with ichiran.") The ichiran-romanize-dwim is the function that I bind to a key to do phrase lookups.
β±
1w
β©