From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: Re: Inheriting some local variables from source code block editing buffers Date: Mon, 14 May 2018 14:33:09 +0100 Message-ID: <87h8najrai.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIDbJ-0002o7-77 for emacs-orgmode@gnu.org; Mon, 14 May 2018 09:33:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIDbG-0008EK-3J for emacs-orgmode@gnu.org; Mon, 14 May 2018 09:33:17 -0400 Received: from mail-wr0-x236.google.com ([2a00:1450:400c:c0c::236]:42424) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fIDbF-0008Dl-TA for emacs-orgmode@gnu.org; Mon, 14 May 2018 09:33:14 -0400 Received: by mail-wr0-x236.google.com with SMTP id v5-v6so12379999wrf.9 for ; Mon, 14 May 2018 06:33:13 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: =?utf-8?B?R8O2a3R1xJ8=?= Kayaalp , emacs-orgmode@gnu.org Hi G=C3=B6ktu=C4=9F, This patch looks good, thanks. Of course, for merging to org core it will need to be an actual patch and not advice. There is also copyright assignment to think of. Do you already have a FSF copyright assignment on file? 2018ko maiatzak 14an, G=C3=B6ktu=C4=9F Kayaalp-ek idatzi zuen: [...] > One =E2=80=98gotcha=E2=80=99 is that :edit-bindings requires a quoted lis= t whereas the > explicit quote is not necessary with ATTR_EDIT: >=20 > #+BEGIN_SRC elisp :edit-bindings '((lexical-binding t)) > #+ATTR_EDIT: ((lexical-binding t)) That quote is required for the src block version is inherent in the design of babel. For consistency, you could require (or at least permit without requiring) a quote in the other case as well. >=20 > Another problem is that I was not able to define a new element property > named EDIT_BINDINGS, and had to take the shortcut with naming it as an > ATTR_* variable. Preferably, it'd be EDIT_BINDINGS instead: >=20 > #+BEGIN_SRC elisp :edit-bindings '((lexical-binding t)) > #+EDIT_BINDINGS: ((lexical-binding t)) >=20 > But personally I don't think it's that big of a problem. >=20 >=20 > The advice: >=20 > (define-advice org-src--edit-element > (:around > (fn datum &rest args) > attr-edit&edit-bindings) > "Apply edit-special bindings." > (let ((attr-edit (org-element-property :attr_edit datum)) > (edit-bindings > (assoc :edit-bindings (caddr (org-babel-get-src-block-info nil d= atum)))) > (source-buffer (current-buffer)) > (sub (lambda (varlist source-buffer) > (let (var val) > (dolist (form varlist) > ;; If it's a symbol, inherit from the Org mode buffer. > (if (symbolp form) > (setq var form > val (with-current-buffer source-buffer (eval= var))) > ;; Else, apply the specified value. > (setq var (car form) val (cadr form))) > (unless (symbolp var) > ;; XXX: maybe tell where it is? > (user-error "Bad varlist at ATTR_EDIT")) > (set (make-local-variable var) val)))))) I think you could replace the (let (var val)...) form with: #+begin_src emacs-lisp (pcase-dolist ((or (and (pred symbolp) var (let val (buffer-local-value var source-buffer))) `(,var ,val)) varlist) (set (make-local-variable var) val)) #+end_src This silently skips varlist entries that are of the wrong shape, but it would be possible to make it raise an error as in your version. I like the pcase version better because it=CA=BCs shorter and has fewer nested conditionals, but it=CA=BCs ultimately a matter of taste. --=20 Aaron Ecay