http://www.perlmonks.org?node_id=157139


in reply to Post a journal entry to use.perl.org

This bit of elisp is something I use to post the contents of a buffer after editing it to my satisfaction. I'm posting it separately so that it doesn't interfere with the "Download Code" link for the Perl utility itself. It is not really complete, and certainly not perfect. Right now, you have to have the desired data in the region, I'd like for it to default to the whole buffer if the region isn't active (but there is no shell-command-on-buffer function in elisp, on the the region-oriented one).

When run, it will prompt you for your use.perl UID and password if those are not already available. It can be called non-interactively with those values, plus a yes/no setting for enabling comments, and the entry subject. The UID and password (as well as the location of the script that gets used) can be configured with the following global values:

perl-journal-uid
Set this to your use.perl.org user ID. The SOAP interface works on UID's, not text names.
perl-journal-passwd
Set this to your password (if you so desire to). If this is not set, you will be prompted, and the elisp API routine does an annoying video-inversion trick when reading a password. The defun tries to set a variable to disable this, as per the elisp docs, but it has no effect. I have this set on my home desktop, but not on my laptop or other machines that are more easily accessed by others.
perl-journal-command
Set this to the path to the commands itself (from the parent post), if (X)Emacs is not likely to find it otherwise. For safety's sake, I have this set, to the value:
(concat (getenv "HOME") "/bin/upj_post.pl")

The code:

(defun perl-journal-post-entry (&optional uid &optional passwd &optional comment &optional subject) "Post the contents of the the current region as a use.perl.org journ +al entry." (interactive) (make-local-variable 'perl-journal-uid) (make-local-variable 'perl-journal-passwd) (make-local-variable 'perl-journal-command) (make-local-variable 'passwd-invert-frame-when-keyboard-grabbed) (let* ((p-command (cond (perl-journal-command) (t "upj_post.pl"))) (p-uid (cond (uid) (perl-journal-uid) (t (read-string "use.perl.org UID: ")))) (p-passwd (cond (passwd) (perl-journal-passwd) (t (read-passwd "use.perl.org Password: "))) +) (p-comment (cond ((= comment "no") "no") (t "yes"))) (p-subject (cond (subject) (t (read-string "Entry subject: ")))) (passwd-invert-frame-when-keyboard-grabbed nil) (command (format "%s -m %S -c %s -C %S" p-command p-subject p-comment (format "%s:%s" p-uid p-passwd)))) (shell-command-on-region (region-beginning) (region-end) command)) +)

--rjray

Replies are listed 'Best First'.
http://lispmonks.org
by Fletch (Bishop) on Apr 07, 2002 at 01:00 UTC
    Right now, you have to have the desired data in the region, I'd like for it to default to the whole buffer if the region isn't active (but there is no shell-command-on-buffer function in elisp, on the the region-oriented one).

    Perhaps . . .

    (if (not (region-exists-p)) (mark-whole-buffer))

    Update: You might want to do a save-excursion before that so you don't leave it marked afterwards. Of course it's been so long since I even tried diddling with elisp I can't remember if that's recommended or not.