home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume40 / plod / part01 / plod.el.v2 < prev    next >
Lisp/Scheme  |  1993-11-02  |  6KB  |  177 lines

  1. ;; Plod sending commands for Emacs.
  2.  
  3. ;; This file is not part of GNU Emacs.
  4.  
  5. ;; GNU Emacs is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation; either version 1, or (at your option)
  8. ;; any later version.
  9.  
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;; GNU General Public License for more details.
  14.  
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  17. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. ;; Suggested addition to .emacs:
  20. ;;     (load-library "plod-mode")
  21. ;;     (plod-alarm-on 60) ; once an hour
  22. ;;
  23. ;; When you are tired of PLODding use "M-x plod-alarm-off"
  24. ;; 
  25. ;; Alternately, use "M-x plod" whenever you want to log something.
  26. ;; 
  27. ;; paul@ascent.com (Paul Foley)    Wednesday January 20, 1993
  28. ;; paulh@harlequin.com (Paul Hudson) Later in 1993 (I forget when :-)
  29.  
  30.  
  31. (provide 'plod)
  32.  
  33. (defvar send-plod-function 'plod-send-it
  34.   "Function to call to send the current buffer as plod.")
  35.  
  36. (defvar plod-mode-map nil)
  37.  
  38. (defun plod-mode ()
  39.   "Major mode for editing text to be sent to plod.
  40. Like Text Mode but with these additional commands:
  41. C-c C-s  plod-send (send the message)    C-c C-c  plod-send-and-exit"
  42.   (interactive)
  43.   (kill-all-local-variables)
  44.   (make-local-variable 'plod-reply-buffer)
  45.   (setq plod-reply-buffer nil)
  46.   (set-syntax-table text-mode-syntax-table)
  47.   (use-local-map plod-mode-map)
  48.   (setq local-abbrev-table text-mode-abbrev-table)
  49.   (setq major-mode 'plod-mode)
  50.   (setq mode-name "Plod")
  51.   (setq buffer-offer-save t)
  52.   (run-hooks 'text-mode-hook 'plod-mode-hook))
  53.  
  54. (if plod-mode-map
  55.     nil
  56.   (setq plod-mode-map (make-sparse-keymap))
  57.   (define-key plod-mode-map "\C-c?" 'describe-mode)
  58.   (define-key plod-mode-map "\C-c\C-c" 'plod-send-and-exit)
  59.   (define-key plod-mode-map "\C-c\C-s" 'plod-send))
  60.  
  61. (defun plod-send-and-exit (arg)
  62.   "Send message like plod-send, then, if no errors, exit from plod buffer.
  63. Prefix arg means don't delete this window."
  64.   (interactive "P")
  65.   (plod-send)
  66.   (bury-buffer (current-buffer))
  67.   (if (and (not arg)
  68.        (not (one-window-p)))
  69.       (delete-window)
  70.     (switch-to-buffer (other-buffer (current-buffer)))))
  71.  
  72. (defun plod-send ()
  73.   "Send the message in the current buffer to plod."
  74.   (interactive)
  75.   (message "Sending...")
  76.   (funcall send-plod-function)
  77.   (set-buffer-modified-p nil)
  78.   (delete-auto-save-file-if-necessary)
  79.   (message "Sending...done"))
  80.  
  81. (defun plod-send-it ()
  82.   (let ((tembuf (generate-new-buffer " plod temp"))
  83.     (plodbuf (current-buffer)))
  84.     (unwind-protect
  85.       (call-process-region (point-min) (point-max)
  86.                    (if (boundp 'plod-program)
  87.                    plod-program
  88.                  "/usr/local/bin/plod")
  89.                    nil tembuf nil)
  90.       (kill-buffer tembuf))))
  91.  
  92.  
  93. (defun plod (&optional noerase)
  94.   "Edit a message to be sent.  Argument means resume editing (don't erase).
  95. Returns with message buffer selected; value t if message freshly initialized.
  96. While editing message, type C-c C-c to send the message and exit.
  97.  
  98. \\{plod-mode-map}
  99.  
  100. If plod-setup-hook is bound, its value is called with no arguments
  101. after the message is initialized. "
  102.   (interactive "P")
  103.   (switch-to-buffer "*plod*")
  104.   (setq default-directory (expand-file-name "~/"))
  105.   (auto-save-mode auto-save-default)
  106.   (plod-mode)
  107.   (and (not noerase)
  108.        (or (not (buffer-modified-p))
  109.        (y-or-n-p "Unsent message being composed; erase it? "))
  110.        (progn (erase-buffer)
  111.           (set-buffer-modified-p nil)
  112.           (run-hooks 'plod-setup-hook)
  113.           t)))
  114.  
  115. (defun plod-other-window (&optional noerase)
  116.   "Like `plod' command, but display plod buffer in another window."
  117.   (interactive "P")
  118.   (let ((pop-up-windows t))
  119.     (pop-to-buffer "*plod*"))
  120.   (plod noerase))
  121.  
  122.  
  123. ;;;
  124. ;;; Alarm interface
  125. ;;;
  126.  
  127. (defvar plod-alarm-on-p nil)        ; t if alarm is on
  128. (defvar plod-alarm-process nil)
  129.  
  130. ;; run when plod-alarm-process is killed
  131. (defun plod-alarm-sentinel (proc reason)
  132.   (or (eq (process-status proc) 'run)
  133.       (setq plod-alarm-on-p nil)
  134.       (ding) 
  135.       (message "PLOD alarm off")))
  136.  
  137. ;; run every interval & at initial call to plod-alarm-on
  138. (defun plod-alarm-filter (proc string)
  139.   (if plod-alarm-on-p
  140.       (plod)
  141.     (setq plod-alarm-on-p t)))
  142.  
  143. ;; Set alarm to call PLOD every so often
  144. ;;
  145. (defun plod-alarm-on (interval)
  146.   "Turn the Emacs PLOD alarm on.  The alarm goes off every INTERVAL minutes
  147. and you will be switched to the PLOD buffer automatically.  
  148. Use plod-alarm-off to stop this behaviour."
  149.   (interactive "nEnter PLOD alarm interval (in minutes): ")
  150.   (let ((live (and plod-alarm-process
  151.            (eq (process-status plod-alarm-process) 'run))))
  152.     (if (not live)
  153.     (progn
  154.       (setq plod-alarm-on-p nil)
  155.       (if plod-alarm-process
  156.           (delete-process plod-alarm-process))
  157.       (let ((process-connection-type nil))
  158.         (setq plod-alarm-process
  159.           (start-process "plod-alarm" nil 
  160.                  (concat exec-directory "wakeup")
  161.                  ; convert minutes -> seconds for wakeup
  162.                  (int-to-string (* 60 interval)))))
  163.       (process-kill-without-query plod-alarm-process)
  164.       (set-process-sentinel plod-alarm-process 'plod-alarm-sentinel)
  165.       (set-process-filter plod-alarm-process 'plod-alarm-filter)))))
  166.  
  167. ;; Turn PLOD alarm off
  168. ;;
  169. (defun plod-alarm-off ()
  170.   "Turn the Emacs PLOD alarm off."
  171.   (interactive)
  172.   (if plod-alarm-on-p (kill-process plod-alarm-process)))
  173.  
  174. ;;; End
  175.  
  176.  
  177.