From: Richard Stallman <rms@gnu.org>
Cc: kfogel@red-bean.com, emacs-devel@gnu.org
Subject: Re: [PATCH] allow function values for `enable-local-eval'
Date: Mon, 1 Jul 2002 08:10:00 -0600 (MDT) [thread overview]
Message-ID: <200207011410.g61EA0Q07792@aztec.santafe.edu> (raw)
In-Reply-To: <5x8z4wzbw7.fsf@kfs2.cua.dk> (storm@cua.dk)
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))))
next prev parent reply other threads:[~2002-07-01 14:10 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E17NLww-0005Cn-00@floss>
2002-06-28 17:41 ` [PATCH] allow function values for `enable-local-eval' Richard Stallman
[not found] ` <87u1nnnqlp.fsf@floss.i-did-not-set--mail-host-address--so-shoot-me>
2002-06-29 0:55 ` Kim F. Storm
2002-06-29 22:22 ` Richard Stallman
2002-06-30 21:37 ` Kim F. Storm
2002-07-01 14:10 ` Richard Stallman [this message]
2002-07-01 21:26 ` Kim F. Storm
2002-07-02 19:46 ` Richard Stallman
2002-07-02 20:11 ` Stefan Monnier
2002-07-02 21:49 ` Kim F. Storm
2002-07-04 7:07 ` Richard Stallman
2002-07-04 15:28 ` Stefan Monnier
2002-07-04 19:38 ` Kim F. Storm
2002-07-04 18:46 ` Stefan Monnier
2002-07-04 21:58 ` Kim F. Storm
2002-07-05 1:26 ` Miles Bader
2002-07-05 13:39 ` Kai Großjohann
2002-07-04 19:36 ` Kim F. Storm
2002-07-05 22:05 ` Richard Stallman
2002-07-02 21:20 ` Kim F. Storm
2002-07-04 7:06 ` Richard Stallman
2002-07-04 15:13 ` Stefan Monnier
2002-07-05 10:48 ` Richard Stallman
2002-07-03 1:28 ` Kevin Ryde
2002-06-29 22:22 ` Richard Stallman
[not found] ` <877kkhlmgw.fsf@floss.i-did-not-set--mail-host-address--so-shoot-me>
2002-07-01 14:10 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200207011410.g61EA0Q07792@aztec.santafe.edu \
--to=rms@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=kfogel@red-bean.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.