From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] allow function values for `enable-local-eval' Date: Mon, 1 Jul 2002 08:10:00 -0600 (MDT) Sender: emacs-devel-admin@gnu.org Message-ID: <200207011410.g61EA0Q07792@aztec.santafe.edu> References: <200206281741.g5SHfAa04345@santafe.santafe.edu> <87u1nnnqlp.fsf@floss.i-did-not-set--mail-host-address--so-shoot-me> <5xit42rjic.fsf@kfs2.cua.dk> <200206292222.g5TMMKx10256@santafe.santafe.edu> <5x8z4wzbw7.fsf@kfs2.cua.dk> Reply-To: rms@gnu.org NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1025532717 23832 127.0.0.1 (1 Jul 2002 14:11:57 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 1 Jul 2002 14:11:57 +0000 (UTC) Cc: kfogel@red-bean.com, emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 17P1uH-0006CH-00 for ; Mon, 01 Jul 2002 16:11:57 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17P1yq-0004wV-00 for ; Mon, 01 Jul 2002 16:16:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 17P1uP-0001nF-00; Mon, 01 Jul 2002 10:12:05 -0400 Original-Received: from pele.santafe.edu ([192.12.12.119]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 17P1sQ-0001bx-00; Mon, 01 Jul 2002 10:10:02 -0400 Original-Received: from aztec.santafe.edu (aztec [192.12.12.49]) by pele.santafe.edu (8.11.6+Sun/8.11.6) with ESMTP id g61EA3B17020; Mon, 1 Jul 2002 08:10:03 -0600 (MDT) Original-Received: (from rms@localhost) by aztec.santafe.edu (8.10.2+Sun/8.9.3) id g61EA0Q07792; Mon, 1 Jul 2002 08:10:00 -0600 (MDT) X-Authentication-Warning: aztec.santafe.edu: rms set sender to rms@aztec using -f Original-To: storm@cua.dk In-Reply-To: <5x8z4wzbw7.fsf@kfs2.cua.dk> (storm@cua.dk) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:5289 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:5289 I edited out the details but here it is: eval: (c-add-style "StyleX" (quote ((c-basic-offset . 4) (c-offsets-alist (label . *) ...))) t) This suggests we add a feature where a function can be marked as "ok to call", provided its arguments are all constant. That way, this would work with no user customization required. Similar cases with other functions could be enabled globally, and local customization would be easy too. We can add something more completely general if desired, but I suspect this will handle all actual needs. Its advantage is that we can make it DTRT for most of the cases, straight out of the box. Please try this code. It seemed to work for me. (defun hack-one-local-variable-constantp (exp) (or (and (not (symbolp exp)) (not (consp exp))) (memq exp '(t nil)) (keywordp exp) (hack-one-local-variable-quotep exp))) (defun hack-one-local-variable-eval-safep (exp) "Return t if it is safe to eval EXP when it is found in a file." (and (consp exp) (or (and (eq (car exp) 'put) (hack-one-local-variable-quotep (nth 1 exp)) (hack-one-local-variable-quotep (nth 2 exp)) (memq (nth 1 (nth 2 exp)) '(lisp-indent-hook)) ;; Only allow safe expues of lisp-indent-hook; ;; not functions. (or (numberp (nth 3 exp)) (equal (nth 3 exp) ''defun))) (and (symbolp (car exp)) (get (car exp) 'safe-local-eval-function) (let ((ok t)) (dolist (arg (cdr exp)) (unless (hack-one-local-variable-constantp arg) (setq ok nil))) ok))))) (defun hack-one-local-variable (var val) "\"Set\" one variable in a local variables spec. A few patterns are specified so that any name which matches one is considered risky." (cond ((eq var 'mode) (funcall (intern (concat (downcase (symbol-name val)) "-mode")))) ((eq var 'coding) ;; We have already handled coding: tag in set-auto-coding. nil) ((memq var ignored-local-variables) nil) ;; "Setting" eval means either eval it or do nothing. ;; Likewise for setting hook variables. ((or (get var 'risky-local-variable) (and (string-match "-hooks?$\\|-functions?$\\|-forms?$\\|-program$\\|-command$\\|-predicate$\\|font-lock-keywords$\\|font-lock-keywords-[0-9]+$\\|font-lock-syntactic-keywords$\\|-frame-alist$\\|-mode-alist$\\|-map$\\|-map-alist$" (symbol-name var)) (not (get var 'safe-local-variable)))) ;; Permit evalling a put of a harmless property. ;; if the args do nothing tricky. (if (or (and (eq var 'eval) (hack-one-local-variable-eval-safep val)) ;; Permit eval if not root and user says ok. (and (not (zerop (user-uid))) (or (eq enable-local-eval t) (and enable-local-eval (save-window-excursion (switch-to-buffer (current-buffer)) (save-excursion (beginning-of-line) (set-window-start (selected-window) (point))) (setq enable-local-eval (y-or-n-p (format "Process `eval' or hook local variables in %s? " (if buffer-file-name (concat "file " (file-name-nondirectory buffer-file-name)) (concat "buffer " (buffer-name))))))))))) (if (eq var 'eval) (save-excursion (eval val)) (make-local-variable var) (set var val)) (message "Ignoring `eval:' in the local variables list"))) ;; Ordinary variable, really set it. (t (make-local-variable var) ;; Make sure the string has no text properties. ;; Some text properties can get evaluated in various ways, ;; so it is risky to put them on with a local variable list. (if (stringp val) (set-text-properties 0 (length val) nil val)) (set var val))))