Tassilo Horn <[EMAIL PROTECTED]> writes: > Richard G Riley <[EMAIL PROTECTED]> 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)))) `---- _______________________________________________ info-gnus-english mailing list [email protected] http://lists.gnu.org/mailman/listinfo/info-gnus-english
