30 June 2008

del.icio.us and emacs

Posting directly to del.icio.us from emacs is pretty cool. Some quick changes to dp.pl make it even better:

use strict;
use lib "/path/to/perlmodule/dependencies";
use lib "/path/to/other/dependencies";
use Net::Delicious;
use Log::Dispatch::Screen;
my ($url,$dsc,$notes,$tag) = @ARGV;
my $USER='your_del.icio.us_name';
my $PASSWORD='your_del.icio.us_password';
die "use: dp.pl url title notes tag" unless (defined($tag));
my $del = Net::Delicious->new({'user'=>$USER,'pswd'=>$PASSWORD});
my $result = $del->add_post({'url'=>$url,
die "post failed\n" unless $result;

Then, slip the following into .emacs:

(defun delicious-post-url ()
  (if (null (w3m-anchor))
      (message "no anchor at point")
    (let ((url (w3m-anchor))
          (title (buffer-substring-no-properties
                  (previous-single-property-change (1+ (point)) 'w3m-href-anchor)
                  (next-single-property-change (point) 'w3m-href-anchor))))
      (if (w3m-url-valid url)
     (setq delicious-notes (read-string "post notes: "))
            (setq delicious-tags (read-string "post tags: "))
            (setq delicious-cmd (concat "~/bin/dp.pl \"" url 
                                        "\" \"" title 
     "\" \"" delicious-notes
                                        "\" \"" delicious-tags "\""))
            (shell-command (concat delicious-cmd)))
        (message "no URL at point!")))))

All code only slightly modified from here.



Post a Comment

<< Home