info-gnus-english
[Top][All Lists]
Advanced

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

Re: Cursoring in an article : want to add a hook.


From: Richard G Riley
Subject: Re: Cursoring in an article : want to add a hook.
Date: Tue, 04 Mar 2008 19:00:23 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux)

Tassilo Horn <tassilo@member.fsf.org> writes:

> Richard G Riley <rileyrgdev@gmail.com> writes:
>
> Hi Richard,
>
>> Works well. I'd already done this last night actually but used
>> setq. Is this bad?
>
> Not really.  You will get compiler warnings when trying to byte-compile
> it and it's not a clean style.
>
> | (defun rdictcc-rgr-translate()
> |   (interactive)
> | ;  (save-window-excursion
> |   (message "myt")
> |   (save-selected-window
> |     (let ((word (rdictcc-current-word)))
> |       (when (and word rdictcc-rgr-show-translations (not(eq word 
> rdictcc-rgr-last-word)))
> |     (rdictcc-translate-word word)
> |     )
> |       (setq rdictcc-rgr-last-word word)
> |       )
> |     )
> |   )
>
> I've "corrected" it to this:
>
> (defun rdictcc-rgr-translate()
>   (interactive)
>   (save-selected-window
>     (let ((word (rdictcc-current-word)))
>       (when (and word
>                  rdictcc-rgr-show-translations
>                  (not (string= word rdictcc-rgr-last-word)))
>       (rdictcc-translate-word word)
>         (setq rdictcc-rgr-last-word word)))))
>
> When comparing strings you normally use `string=', because two strings
> may have the same contents but are not `eq', e.g. they're not the same
> lisp object.
>
> And I've moved the last setq into the `when', cause if the word didn't
> change there's no reason to re-set it.
>
> Bye,
> Tassilo

Hi Tassilo,

I followed your advice and used defvar and went a step further and made
tthe use of rdictcc in Gnus articles or w3m buffer customisable. I
include the code below in case you think its handy enough to include on
your wiki page. I can only say that as a native English speaker living
in Germany I use it a lot! I can pretty much guarantee the code can be
improved upon as I'm most certainly not an elisp wizard.

Thanks for your help and rdictcc in the first place.

The default binding to toggle all rdictcc auto popups is "f5-o"

r.

,----
| (defvar rdictcc-show-translations nil )
| 
| (defcustom rdictcc-show-translations
|   nil
|   "Whether to popup translations when you cursor to a word in either a Gnus 
article buffer or a w3m buffer. Also see rdictcc-gnus-article and rdictcc-w3m 
settings. Setting this to nil stops all pop ups."
|   :group 'rdictcc
|   :type 'boolean)
| 
| (defcustom rdictcc-w3m
|   nil
|   "Whether to show rdictcc translations in w3m buffers"
|   :group 'rdictcc
|   :type 'boolean
| )
| 
| (defcustom rdictcc-gnus-article
|   nil
|   "Whether to show rdictcc translations for words in Gnus article buffers."
|   :group 'rdictcc
|   :type 'boolean
| )
| 
| 
| (defvar rdictcc-last-word nil "The last word translated by rdictcc. Used to 
stop multiple translations as you cursor through a word.")
| 
| (defun rdictcc-translate()
|   (interactive)
|   (save-selected-window
|     (let ((word (rdictcc-current-word)))
|       (when (and word
|                  rdictcc-show-translations
|                  (not (string= word rdictcc-last-word)))
|       (rdictcc-translate-word word)
|         (setq rdictcc-last-word word)))))
| 
| 
| (add-hook 'w3m-after-cursor-move-hook (lambda() (interactive) (when 
rdictcc-w3m (rdictcc-translate))))
| 
| (define-key gnus-article-mode-map [right] (lambda () (interactive)(when 
rdictcc-gnus-article (rdictcc-translate))(forward-char)))
| (define-key gnus-article-mode-map [left] (lambda () (interactive)(when 
rdictcc-gnus-article (rdictcc-translate))(backward-char)))
| (define-key gnus-article-mode-map [up] (lambda () (interactive)(when 
rdictcc-gnus-article (rdictcc-translate))(previous-line)))
| (define-key gnus-article-mode-map [down] (lambda () (interactive)(when 
rdictcc-gnus-article (rdictcc-translate))(next-line)))
| 
| (global-set-key (kbd "<f5> T") 'rdictcc-translate)
| (global-set-key (kbd "<f5> o") (lambda()(interactive)(setq 
rdictcc-show-translations (not rdictcc-show-translations))))
`----



reply via email to

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