After being fed up with spam I decided to install "SpamAssassin":http://www.spamassassin.org/ on my server. This was very easy and with a bit of tweaking to the suggested .procmailrc everything's running fine. The only thing missing was a keyboard shortcut in "Gnus":http://www.gnus.org/ running sa-learn for spam & ham mails...
I found some elisp code to run a command on the current article over on "my.gnus.org":http://my.gnus.org/ (specifically the howto Pipe an article through a command) but found that the code didn't really work as I wanted it to. Running sa-learn only produces one line of ouput (unless you're debugging with "-D"), and I wanted that output to show up in the minibuffer. I ended up with this edited version of the function:
(defun pfm-run-command-on-article (command &optional replace)
"Run the full text of the current article through a filter.
The full text of the current article is run through the specified COMMAND
as a filter. The output of the command is returned."
(interactive "sCommand: \nP")
(let ((n (gnus-summary-article-number))
(g gnus-newsgroup-name))
(with-temp-buffer
(gnus-request-article n g (current-buffer))
(shell-command-on-region
(point-min) (point-max)
command)
(if replace
(gnus-request-replace-article n g (current-buffer)))
)))
Then I've added two keyboard shortcuts to the gnus-summary-mode-map keymap:
(define-key gnus-summary-mode-map
(read-kbd-macro "C-c R s")
'(lambda () (interactive) (pfm-run-command-on-article "sa-learn --spam --single" ))
)
(define-key gnus-summary-mode-map
(read-kbd-macro "C-c R h")
'(lambda () (interactive) (pfm-run-command-on-article "sa-learn --ham --single"))
[Update 2003-08-14 21:45 - Changed the define-key code so it binds to gnus-summary-mode-map instead of global-map. Tested it in Gnus 5.10.1, and it worked nicely. 'C-c R' is by default not bound to anything, so it should be safe to use]
[Update 2003-08-15 10:18 - Changed to fix the errors gAm commented]
Comments (4)
I am not sure whether this is the proscribed way to perform bindings into the keymap for the *summary ...* buffer, but substituting gnus-summary-mode-map for global-map in your keybinding binds into the required map, given that gnus is already loaded (and the keymap created).
(require 'gnus)
(define-key gnus-summary-mode-map
(kbd "v")
'(lambda () (interactive) (message "Test of keybinding in summary mode" )))
Just ran a quick test to check if I could rebind the 'v' key to display a test message in the minibuffer.
Just be careful not to clobber existing bindings. ;)
Posted by gAm | August 14, 2003 6:28 PM
Posted on August 14, 2003 18:28
The key binding worked brilliantly, I'll update the article. Thanks!
Posted by morten | August 14, 2003 9:48 PM
Posted on August 14, 2003 21:48
Since you've edited the article, you should also remove the reference to global bindings in the text (as well as you claim of lacking knowledge of binding keys in local maps).
Posted by gAm | August 15, 2003 1:58 AM
Posted on August 15, 2003 01:58
Good point, fixed that too now. Thanks!
Posted by morten | August 15, 2003 10:20 AM
Posted on August 15, 2003 10:20