From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?= Subject: Inheriting some local variables from source code block editing buffers Date: Sun, 29 Apr 2018 20:19:03 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCpyl-0002fB-6f for emacs-orgmode@gnu.org; Sun, 29 Apr 2018 13:19:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCpyi-00018i-12 for emacs-orgmode@gnu.org; Sun, 29 Apr 2018 13:19:15 -0400 Received: from [195.159.176.226] (port=43483 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fCpyh-00018I-PV for emacs-orgmode@gnu.org; Sun, 29 Apr 2018 13:19:11 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fCpwY-0000Zk-FV for emacs-orgmode@gnu.org; Sun, 29 Apr 2018 19:16:58 +0200 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hello, when editing a source block, passing some local variables from the original buffer into the buffer in which the source code is edited might be useful. My use case is passing the value of ‘lexical-binding’ when editing Elisp source code blocks in my literate .emacs so that I don't mistakenly evaluate code in a non-lexical environment thinking it's the opposite instead. I've implemented this with the patch attached to this message, if it's deemed useful, I can revise it for inclusion upstream (just wanted to see what you think about the idea with this one). -- İ. Göktuğ Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=org-src-inherit.patch Content-Description: the patch diff --git a/lisp/org-src.el b/lisp/org-src.el index 850525b8d..248b46462 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -196,6 +196,14 @@ For example, there is no ocaml-mode in Emacs, but the mode to use is (string "Language name") (symbol "Major mode")))) +(defcustom org-src-inherited-local-variables '() + "Local variables to be copied into source code editing buffers. +This variable contains a list of symbols, whose values in the Org +mode buffer that contains the source block are to be interited by +the source code editing buffer." + :group 'org-edit-structure + :type '(repeat symbol)) + (defcustom org-src-block-faces nil "Alist of faces to be used for source-block. Each element is a cell of the format @@ -947,9 +955,13 @@ name of the sub-editing buffer." (unless (and (memq type '(example-block src-block)) (org-src--on-datum-p element)) (user-error "Not in a source or example block")) - (let* ((lang + (let* ((org-buffer (current-buffer)) + (lang (if (eq type 'src-block) (org-element-property :language element) "example")) + (buffer-name (or edit-buffer-name + (org-src--construct-edit-buffer-name + (buffer-name) lang))) (lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang))) (babel-info (and (eq type 'src-block) (org-babel-get-src-block-info 'light))) @@ -957,10 +969,7 @@ name of the sub-editing buffer." (when (and (eq type 'src-block) (not (functionp lang-f))) (error "No such language mode: %s" lang-f)) (org-src--edit-element - element - (or edit-buffer-name - (org-src--construct-edit-buffer-name (buffer-name) lang)) - lang-f + element buffer-name lang-f (and (null code) (lambda () (org-escape-code-in-region (point-min) (point-max)))) (and code (org-unescape-code-in-string code))) @@ -973,6 +982,9 @@ name of the sub-editing buffer." (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (when (fboundp edit-prep-func) (funcall edit-prep-func babel-info)))) + (dolist (localvar org-src-inherited-local-variables) + (set (make-local-variable localvar) + (with-current-buffer org-buffer (eval localvar)))) t))) (defun org-edit-inline-src-code () --=-=-=--