From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Riley Subject: Using org-learn and babel to learn foreign words Date: Tue, 27 Oct 2009 13:01:40 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2klL-0001fW-40 for emacs-orgmode@gnu.org; Tue, 27 Oct 2009 08:02:55 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2klG-0001er-Hd for emacs-orgmode@gnu.org; Tue, 27 Oct 2009 08:02:54 -0400 Received: from [199.232.76.173] (port=57304 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2klG-0001eo-Ek for emacs-orgmode@gnu.org; Tue, 27 Oct 2009 08:02:50 -0400 Received: from lo.gmane.org ([80.91.229.12]:42719) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N2klF-0008IT-Jw for emacs-orgmode@gnu.org; Tue, 27 Oct 2009 08:02:49 -0400 Received: from list by lo.gmane.org with local (Exim 4.50) id 1N2kkd-00039w-73 for emacs-orgmode@gnu.org; Tue, 27 Oct 2009 13:02:11 +0100 Received: from 85.183.18.158 ([85.183.18.158]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 27 Oct 2009 13:02:11 +0100 Received: from rileyrgdev by 85.183.18.158 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 27 Oct 2009 13:02:11 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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 "") (lambda()(interactive)(rgr/context-babel))) | (global-set-key (kbd "C-") (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.