;;; pure-bl.el --- Library for buffer-local variables (common part, loader) ;; Copyright (C) 2000 by Project Pure. ;; Author: SHIMADA Mitsunobu ;; Keywords: PURE, buffer-local variables ;; $Id: pure-bl.el,v 1.3 2000/10/18 14:46:49 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" ;; BL means buffer-local ;;; Code: (defun pure-bl-common (alist efunc func) "Do common action to use buffer-local variables according to `alist' structured below: '([symbol0 value0 desc0] [symbol1 value0 desc1] ... )" (let (vsym desc init (count 0)) (mapcar '(lambda (item) (cond ((consp item) (setq vsym (car item) init (if (consp (cdr item)) (cddr item) nil) desc (if (consp (cdr item)) (cadr item) nil)) (and (stringp vsym) (setq vsym (intern vsym)))) ((symbolp item) (setq vsym item init nil desc nil)) ((stringp item) (setq vsym (intern item) init nil desc nil)) ((arrayp item) (setq vsym (aref item 0) init (aref item 1) desc (if (< 2 (length item)) (aref item 2) nil))) (t (setq vsym nil init nil desc nil))) ;; `vsym' must be a symbol (cond ((symbolp vsym) (funcall func vsym (eval init) desc) (setq count (1+ count))) ((eq efunc t)) (efunc (funcall efunc vsym init)) (t (error "Error: pure-bl-common: \"%s\" must be a symbol" (prin1-to-string vsym))))) alist) count)) (defun pure-bl-defvar (alist &optional efunc) "Buffer-local variable treatment: do `defvar'" (pure-bl-common alist efunc '(lambda (vsym init desc) (if (stringp desc) (eval (list 'defvar vsym init desc)) (eval (list 'defvar vsym init)))))) (defun pure-bl-make-current (alist &optional efunc) "Buffer-local variable treatment: make variables this-buffer-local" (pure-bl-common alist efunc '(lambda (vsym init desc) (make-local-variable vsym) (set vsym init)))) (defun pure-bl-make-permanent (alist &optional efunc) "Buffer-local variable treatment: make variables permanent-buffer-local" (pure-bl-common alist efunc '(lambda (vsym init desc) (or (boundp vsym) (if (stringp desc) (eval (list 'defvar vsym init desc)) (eval (list 'defvar vsym init)))) (make-variable-buffer-local vsym) (set-default vsym init)))) ;; That's all (provide 'pure-bl) ;;; pure-bl.el ends here