From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?iso-8859-1?Q?Vincent_Bela=EFche?= Newsgroups: gmane.emacs.devel Subject: SES local variables to define printers Date: Thu, 23 May 2013 22:52:07 +0200 Message-ID: <80li75ifm0.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1369342372 27860 80.91.229.3 (23 May 2013 20:52:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 23 May 2013 20:52:52 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 23 22:52:51 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UfcVG-0005M5-4g for ged-emacs-devel@m.gmane.org; Thu, 23 May 2013 22:52:50 +0200 Original-Received: from localhost ([::1]:46186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfcVF-0006ut-RT for ged-emacs-devel@m.gmane.org; Thu, 23 May 2013 16:52:49 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfcVB-0006tv-MM for emacs-devel@gnu.org; Thu, 23 May 2013 16:52:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfcV8-0003Q5-Cq for emacs-devel@gnu.org; Thu, 23 May 2013 16:52:45 -0400 Original-Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:35710 helo=smtp.smtpout.orange.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfcV8-0003PU-39 for emacs-devel@gnu.org; Thu, 23 May 2013 16:52:42 -0400 Original-Received: from CHOUNEK ([92.135.239.251]) by mwinf5d03 with ME id fYsf1l00H5S8RGC03YsfHs; Thu, 23 May 2013 22:52:40 +0200 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.12.242.124 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:159752 Archived-At: --=-=-= Content-Type: text/plain Hello, I have come across a ``regression'' in SES --- well I am not sure that one can call it a ``regression'', let us rather say that one year ago it was possible to play some borderline trick which is now no longer possible with a recent EMACS. That sort of trick was to define a file local variable foo to a lambda expression defining a printer function, and then use the foo symbol as a printer when setting the printer for a cell. I wrote that this is a ``borderline trick'' because when you do that you set the symbol-value of foo to the printer, and not its symbol-function. But that was working --- I don't know why. By the way, that kind of things was a security breach because you allow to call a function defined in the file without any control. I suspect that the root cause why this is no longer working is that EMACS has been made more secure on that respect --- sorry I am not a regular lurker of what is going on on this forum, so indeed I have no idea. Now, I would like to have again the same sort of feature in SES, so I did a quick hack herein attached --- there is a defcustom, so that the user who re-enables this, does it at his/her own perils. But I am not really satisfied with that patch --- so I did not commit it --- because I think I should do more security checks if possible on the printer function that is defined as a buffer local lambda expression. So, I have a few questions to you experts: - is that possible to check that a function do no border effect, like a SES printer function should do --- well, I presume, at least for buffer locally defined function --- anyway I would create some defcustom to deactivate that security check. - is that possible to check that when a function is executing, that takes a reasonable time, and if not to interact with the use and ask whether he/she would like to double that time VBR, Vincent. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=ses.el.diff === modified file 'lisp/ses.el' --- lisp/ses.el 2013-01-02 16:13:04 +0000 +++ lisp/ses.el 2013-05-22 16:09:39 +0000 @@ -100,6 +100,26 @@ :group 'ses :type 'hook) +(defcustom ses-enable-local-variables nil + "Non-nil if SES should process local-variables lists in ses buffers. +\(You can explicitly request processing the local-variables by +executing `(hack-local-variables)'). Local variables are useful +to define file local printers or values but raise a security +issue if the printer function is used to do border effects. If +you select `Filename test', then you should configure a function +symbol or lambda expression which takes one argument, then the +local variables are processed iff the buffer file name passed to +this function returns a non nil. For instance you could configure: + + (lambda (x) + (string-match \"^/dir/where/local/var/are/allowed\" + (expand-file-name x))) +" + :type '(choice + (const :tag "No" nil) + (const :tag "Yes" t) + (function :tag "Filename test")) + :group 'ses) ;;---------------------------------------------------------------------------- ;; Global variables and constants @@ -661,9 +681,11 @@ (defun ses-printer-validate (printer) "Signal an error if PRINTER is not a valid SES cell printer." + (or (not printer) (stringp printer) (functionp printer) + (and (symbolp printer) (boundp printer) (functionp (symbol-value printer))) (and (stringp (car-safe printer)) (not (cdr printer))) (error "Invalid printer function")) printer) @@ -1261,6 +1283,10 @@ (format (car printer) value) "")) (t + (and (symbolp printer) + (boundp printer) + (functionp (symbol-value printer)) + (setq printer (symbol-value printer))) (setq value (funcall printer (or value ""))) (if (stringp value) value @@ -1899,9 +1925,17 @@ (unless (and (boundp 'ses--deferred-narrow) (eq ses--deferred-narrow 'ses-mode)) (kill-all-local-variables) + (setq major-mode 'ses-mode) + (and + enable-local-variables + ses-enable-local-variables + (or (eq ses-enable-local-variables t) + (let ((bfn (buffer-file-name))) + (and (stringp bfn) + (funcall ses-enable-local-variables bfn)))) + (hack-local-variables)) (ses-set-localvars) - (setq major-mode 'ses-mode - mode-name "SES" + (setq mode-name "SES" next-line-add-newlines nil truncate-lines t ;; SES deliberately puts lots of trailing whitespace in its buffer. --=-=-=--