Path: utzoo!mnetor!uunet!husc6!bu-cs!bucsb!jbw From: jbw@bucsb.UUCP (Joe Wells) Newsgroups: comp.emacs Subject: Re: Changing major mode in server mode Message-ID: <1519@bucsb.UUCP> Date: 19 Mar 88 03:31:45 GMT References: <480@sol.warwick.ac.uk> Reply-To: jbw@bucsb.bu.edu (Joe Wells) Followup-To: comp.emacs Organization: Boston Univ Comp. Sci. Lines: 57 Keywords: GNU emacs kill-all-local-variables major-modes Summary: kill-all-local-variables sucks In article <480@sol.warwick.ac.uk> cudcv@cu.warwick.ac.uk (Rob McMahon) writes: >The second problem is if I change major mode in the buffer created in >the server emacs, it calls kill-all-local-variables, which includes >server-buffer-clients, which means C-x# doesn't work any more. > >Is there any way round this ? Can I protect server-buffer-clients for a >while, or can I 'push' a mode and then exit it leaving all my variables >the way they were before ? Or do I have to write my own alternatives to >c-mode and text-mode (and tex-mode, and ...) that don't call >kill-all-local-variables ? > >UUCP: ...!mcvax!ukc!warwick!cudcv PHONE: +44 203 523037 >JANET: cudcv@uk.ac.warwick.cu ARPA: cudcv@cu.warwick.ac.uk >Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England I have run into this same problem in the past. My solution was to rewrite kill-all-local-variables so that it left my variables alone. This is not straightforward, since there is no function to kill a single local variable. kill-all-local-variables is one of the C functions, so my function had to use the original kill-all-local-variables, and then restore the variables that I wanted to keep. My version of kill-all-local-variables follows. ---- Joe Wells can be reached at: UUCP: ..!harvard!bu-cs!bucsb!jbw _ /| ARPANET: jbw@bucsb.bu.edu \`o_O' CSNET: jbw%bucsb@bu-cs ( ) "Ack! Phft!" BITNET: clxj9lc@bostonu U ;;; save the original kill-all-local-variables ;;; must check if we have already changed it (if (not (fboundp 'old-kill-all-local-variables)) (fset 'old-kill-all-local-variables (symbol-function 'kill-all-local-variables))) (defun kill-all-local-variables () "Eliminate all the buffer-local variable values of the current buffer. This buffer will then see the default values of all variables. NOTE: This function has been modified to ignore buffer-local variables which match the regexp in save-local-variables." (let ((oldvars (buffer-local-variables))) (old-kill-all-local-variables) (while oldvars (let* ((elem (car oldvars)) (var (car elem)) (value (cdr elem))) (cond ((string-match save-local-variables (symbol-name var)) (make-local-variable var) (set var value)))) (setq oldvars (cdr oldvars))))) (defvar save-local-variables "" "This is a regexp which is used each time kill-local-variables is called to determine which variables not to kill. The variable name is matched against the regexp.")