;;; pure-pr-filter.el --- Filter function management for PURE ;; Copyright (C) 2000 Project Pure. ;; Author: SHIMADA Mitsunobu ;; Keywords: PURE, process, filter ;; $Id: pure-pr-filter.el,v 1.3 2001/06/06 14:24:51 simm Exp $ ;; This file 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 2, or (at your option) ;; any later version. ;; This file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; PURE means "Primitive Universal Relay-chat Environment" ;; PR means "process" ;;; Code: (require 'pure-bl) (defconst pure-pr-filter-local-variables '([pure-pr-filter-parser nil "Parser function fore PURE filter function."]) "List of buffer-local variables for PURE filter function management.") (defun pure-pr-filter-set-filter (proc func) "Set filter function for PURE. Filter function is `pure-pr-filter-loop', and set parser function for PURE filter function. This function is called when first setting of filter." (save-excursion (set-buffer (process-buffer proc)) (pure-bl-defvar pure-pr-filter-local-variables) (pure-bl-make-current pure-pr-filter-local-variables) (setq pure-pr-filter-parser func) (set-process-filter proc 'pure-pr-filter-loop))) (defun pure-pr-filter-set-parser (proc func) "Set parser function for PURE filter function. This function is called when changing filter body." (save-excursion (set-buffer (process-buffer proc)) (setq pure-pr-filter-parser func))) (defun pure-pr-filter-loop (proc msg) "Main loop of PURE filter function. This function is skelton and main process is pointed by `pure-pr-filter-parser'. So remember to set parser function by `pure-pr-filter-set-filter' or `pure-pr-filter-set-parser'." (save-match-data (save-excursion (set-buffer (process-buffer proc)) (goto-char (point-max)) (insert msg) (while (and (goto-char (point-min)) (= 0 (forward-line 1)) (bolp)) (while (and (char-before) (or (= 10 (char-before)) (= 13 (char-before)))) (delete-backward-char 1)) (save-restriction (narrow-to-region (point-min) (point)) (goto-char (point-min)) (if (fboundp pure-pr-filter-parser) (funcall pure-pr-filter-parser proc)) (delete-region (point-min) (point-max))))))) ;; That's all (provide 'pure-pr-filter) ;;; pure-pr-filter.el ends here