emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Using org-learn and babel to learn foreign words


From: Richard Riley
Subject: [Orgmode] Using org-learn and babel to learn foreign words
Date: Tue, 27 Oct 2009 13:01:40 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

This little set up uses org-learn in conjunction with babel in emacs to
automatically store all translations looked up from within emacs when
preceded with the prefix key. I'm not much of an elisp programmer but
here is the stuff for anyone interested:-

1) The key bindings:-

Invoke a translation on the word or region at point

,----
| (global-set-key (kbd "<f5>") (lambda()(interactive)(rgr/context-babel)))
| (global-set-key (kbd "C-<f5>") (lambda()(interactive)(rgr/context-babel)))
`----

f5 uses defaults for translation, C-f5 prompts for languages and
translation engine.

2) The translation stuff (calls org-remember if you prefix the keys
above with C-u) :-

(definitely room for an elisp meister to tidy no doubt)

,----
| (defvar rgr/orig-word)
| (defvar rgr/trans-word)
| 
| (defun rgr/orig-word() ; simplify org template sexp
|   rgr/orig-word
|   )
| 
| (defun rgr/trans-word() ; simplify org template sexp
|   rgr/trans-word
|   )
| 
| (defun rgr/from-lang()
|   babel-preferred-from-language
|   )
| 
| (defun rgr/to-lang()
|   babel-preferred-to-language
|   )
| 
| (defvar  babel-echo-area t)
| (defvar babel-preferred-from-language "English")
| (defvar babel-preferred-to-language "German")
| 
| 
| (defun rgr/babel-language-code (lang)
|   (cdr (assoc lang babel-languages)))
| 
| 
| (defun rgr/context-babel( &optional usedef )
|   (interactive)
|   (let* ((default (region-or-word-at-point)))
|     (setq default (read-string (format "Translate \"%s\" :" default) nil nil 
default))
|     (when (length default)
|       (setq rgr/trans-word (babel default nil usedef))
|       (setq rgr/orig-word default)
|       (if current-prefix-arg (org-remember nil ?v))
|       (rgr/notify rgr/trans-word))))
`----

The main function being "babel" available from babel.el.

http://www.emacswiki.org/emacs/babel.el

My version is tagged as 2009 so no idea why the wiki version says 2008.

3) The gnome based rgr/notify stuff which puts up a floating notify with
displays the translation:-

,----
| (defvar rgr/notify-last '(0 0 0))
| (defvar rgr/notify-delay '(0 5 0))
| (defvar rgr/notify-cmd "notify-send")
| (defvar rgr/notify-icon "~/.emacs.d/images/mail.png")
| (defvar rgr/notify-timeout 10000)
| (defvar rgr/notify-urgency "low")
| (defvar rgr/notify-category "im.received")
| 
| (defun rgr/notify(message)
|   (shell-command (concat rgr/notify-cmd
|                        " -i " rgr/notify-icon
|                        " -t " (int-to-string
|                                rgr/notify-timeout)
|                        " -c " rgr/notify-category
|                        " '" message "'")))
`----

This code was originally from an extension by Andy Stewart. Note the use
of notify-send.

Originally I had used "(message)" but the auto saving of the org files
caused this to be overwritten for some reason. This nice pop up is much
better as you can configure how long it stays on the screen and have
multiple of them stacked on top of each other. Non linux users will need
to do their own 'thang.

4) The org-mode stuff :-

I use an org remember template to automatically store the orig text and the 
translated
text (works with regions too) in addition to the source and destination 
languages.

Add to org-remember-templates:

              ("vocab" ?v "** TODO Learn
              
%(rgr/orig-word)\t:VOCAB:\n:PROPERTIES:\n:from:\t%(rgr/from-lang)\n:to:\t%(rgr/to-lang)\n:orig:\t%(rgr/orig-word)\n:trans:\t%(rgr/trans-word)\n:END:\n%!"
              "vocab.org" bottom)

And of course a special key to see all vocab items as an agenda report

add to org-agenda-custom-commands :

              ("v" "Vocab" tags "VOCAB"
              ((org-agenda-todo-ignore-with-date nil)))

CAVEAT/WISHLIST:- It would be nice to be able to auto schedule this N
days in the future with no input required. Is there a code snippet out
there to use as a sexp which can throw out the "schedule" attribute set
to N days into the future?

Also to be able to store propertices based on sexp values with no user
interaction : as it is I specifically write out the properties marker to
store the translation text as properties. Is it currently possible to do
this? I only saw the ability to prompt for property values.

5) The org-learn integration:-

Couldn't be simpler really .. just two functions to reschedule the item
based on how well you remembered it. One for general org files and one
from the agenda. Possibly one function would be nicer that detected its
context.

,----
| (eval-after-load "org"
| '(progn
|    (define-key org-mode-map "\C-r" 'org-smart-reschedule)))
| 
| (eval-after-load "org-agenda"
| '(progn
|    (define-key org-agenda-mode-map "\C-r" 'org-agenda-smart-reschedule)))
`----

The org-learn code was posted here by John Wiegly followed by an update
or two. I don't know off hand where the original repository is.


6) conclusion:-

I think that's it. But updates/things missing can be found (if you have
the patience to locate specific files) here :-

http://richardriley.net/projects/emacs/dotemacs.html

Apologies for the sloppiness of the elisp and if you have suggestions to
tidy it up then please email me!

regards,

r.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]