emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using org-learn and babel to learn foreign words
@ 2009-10-27 12:01 Richard Riley
  2009-10-27 12:58 ` Richard Riley
  2009-10-30 14:32 ` Richard Riley
  0 siblings, 2 replies; 3+ messages in thread
From: Richard Riley @ 2009-10-27 12:01 UTC (permalink / raw)
  To: emacs-orgmode


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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using org-learn and babel to learn foreign words
  2009-10-27 12:01 Using org-learn and babel to learn foreign words Richard Riley
@ 2009-10-27 12:58 ` Richard Riley
  2009-10-30 14:32 ` Richard Riley
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Riley @ 2009-10-27 12:58 UTC (permalink / raw)
  To: emacs-orgmode


A small follow up which includes the auto schedule of the new org item:-

,----
| (defvar rgr/learn-first-lesson 1) ; when to schedule first reminder
| 
| (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 
| 	  (progn
| 	    (org-remember nil ?v)
| 	    (org-schedule nil (time-add (current-time) (days-to-time rgr/learn-first-lesson)))))
|       (rgr/notify rgr/trans-word)
|       (message "%s" rgr/trans-word))))
`----

Any other updates will just silently make their way into my published
files.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using org-learn and babel to learn foreign words
  2009-10-27 12:01 Using org-learn and babel to learn foreign words Richard Riley
  2009-10-27 12:58 ` Richard Riley
@ 2009-10-30 14:32 ` Richard Riley
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Riley @ 2009-10-30 14:32 UTC (permalink / raw)
  To: emacs-orgmode

Richard Riley <rileyrgdev@gmail.com> writes:

> 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)))

Correction:

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-10-30 14:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-27 12:01 Using org-learn and babel to learn foreign words Richard Riley
2009-10-27 12:58 ` Richard Riley
2009-10-30 14:32 ` Richard Riley

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).