emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Inheriting some local variables from source code block editing b


From: Aaron Ecay
Subject: Re: [O] Inheriting some local variables from source code block editing buffers
Date: Mon, 14 May 2018 14:33:09 +0100
User-agent: Notmuch/0.26 (https://notmuchmail.org) Emacs/27.0.50 (x86_64-pc-linux-gnu)

Hi Göktuğ,

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öktuğ Kayaalp-ek idatzi zuen:

[...]

> One ‘gotcha’ is that :edit-bindings requires a quoted list whereas the
> explicit quote is not necessary with ATTR_EDIT:
> 
> #+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.

> 
> 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:
> 
> #+BEGIN_SRC elisp :edit-bindings '((lexical-binding t))
> #+EDIT_BINDINGS: ((lexical-binding t))
> 
> But personally I don't think it's that big of a problem.
> 
> 
> The advice:
> 
> (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 
> datum))))
>         (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ʼs shorter and has fewer nested
conditionals, but itʼs ultimately a matter of taste.

-- 
Aaron Ecay



reply via email to

[Prev in Thread] Current Thread [Next in Thread]