;;; dired-livrinho.el -- interface para uso de livrinho.sh 
;;;                      atraves do dired
;;
;; $Id: dired-livrinho.el,v 1.1 2004/11/14 01:56:25 mario Exp $
;; 
;; Copyright (C) 2004, 2005 Mario Domenech Goulart
;;
;; Author: Mario Domenech Goulart <mario@inf.ufrgs.br>
;;
;;
;; This code is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 1, or (at your
;; option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;
;;; Como utilizar:
;;
;; Certifique-se de que o arquivo dired-livrinho.el esteja em um
;; diretorio procurado pelo Emacs. Ou coloque o dired-livrinho.el no
;; seu diretorio preferido e adicione a seguinte linha ao seu .emacs:
;;
;; (add-to-list 'load-path "/meu/diretorio/preferido")
;; 
;; Adicione a seguinte linha ao seu .emacs
;;      (require 'dired-livrinho)
;;
;; Para gerar um livrinho atraves do dired, coloque o cursor sobre a
;; linha do arquivo alvo e execute
;;
;;  M-x dired-livrinho
;;
;; Ou coloque o seguinte trecho no seu .emacs e gere o livrinho com
;; C-c 2, estando com o cursor sobre o arquivo alvo.
;;
;; (add-hook 'dired-load-hook
;; 	  (lambda ()
;; 	    (define-key dired-mode-map "\C-c2" 'dired-livrinho)))


(defvar dired-livrinho-args "-ps -g2")
(defvar dired-livrinho-prog "livrinho.sh")
(defvar dired-livrinho-output-buffer "*dired-livrinho*")

(defun dired-livrinho ()
  (interactive)
  (set-process-sentinel 
   (start-process-shell-command
    "dired-livrinho" dired-livrinho-output-buffer dired-livrinho-prog
    (concat dired-livrinho-args " " (dired-get-filename)))
   (lambda (process event) 
     (if (string-equal event "finished\n")
	 (dired-revert)
       (progn
	 (split-window (selected-window))
	 (pop-to-buffer dired-livrinho-output-buffer))))))
    

(provide 'dired-livrinho)