1 ;;; riece-kill.el --- enter the element in kill-ring
2 ;; Copyright (C) 2004 Masatake YAMATO
4 ;; Author: Masatake YAMATO <jet@gyve.org>
5 ;; Keywords: IRC, riece
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
24 ;; In riece's command buffer, you can send the top element of kill-ring
26 ;; Don't forget do (riece-command-enable-addon 'riece-yank).
29 (require 'riece-commands)
31 (defgroup riece-yank nil
32 "Enter the element of `kill-ring'"
37 (defcustom riece-yank-tick 1
38 "Time span in second to send multiple lines."
42 (defcustom riece-yank-strip-space nil
43 "If non-nil, strip common spaces in front of lines and blank lines
44 before/after the first/last non-blank line."
48 (defvar riece-yank-enabled nil)
50 (defun riece-yank-insinuate ()
53 (defun riece-yank-enable ()
54 (define-key riece-command-mode-map "\C-cy" 'riece-command-yank)
55 (setq riece-yank-enabled t))
56 (defun riece-yank-disable ()
57 (define-key riece-command-mode-map "\C-cy" 'undefined)
58 (setq riece-yank-enabled nil))
60 (defun riece-command-yank (prefix)
61 (interactive "sPrefix: ")
62 (when (or (not prefix)
65 (let* ((kill (current-kill 0))
68 (error "Nothing to send in kill-ring"))
69 (if riece-yank-strip-space
72 (untabify (point-min) (point-max))
73 ;; Delete blank lines before the first non-blank line.
74 (goto-char (point-min))
75 (while (looking-at " *$")
76 (delete-region (point) (progn (forward-line) (point))))
77 ;; Delete blank lines after the last non-blank line.
78 (goto-char (point-max))
79 (while (progn (beginning-of-line) (looking-at " *$"))
80 (delete-region (point) (progn (end-of-line 0) (point))))
81 ;; Delete common spaces in front of lines.
82 (setq space-width (point-max))
83 (while (looking-at " +")
84 (setq space-width (min space-width (length (match-string 0))))
86 (goto-char (point-min))
88 (delete-char space-width)
90 (setq kill (buffer-string))))
91 (setq msg (split-string kill "\n"))
92 (when (y-or-n-p (format "Send \"%s\"\n? " kill))
95 (riece-command-send-message (concat prefix x) nil)
96 ;; Without next line, you will be kicked out from ircd.
97 ;; It may means "Don't send much data at once."
98 (sit-for riece-yank-tick))
101 (provide 'riece-yank)
102 ;;; riece-yank.el ends here