emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Inheriting some local variables from source code block editing buffers
@ 2018-04-29 17:19 Göktuğ Kayaalp
  2018-04-29 22:09 ` Bastien
  2018-05-14  5:44 ` Göktuğ Kayaalp
  0 siblings, 2 replies; 28+ messages in thread
From: Göktuğ Kayaalp @ 2018-04-29 17:19 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]

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	<https://www.gkayaalp.com/>
			 024C 30DD 597D 142B 49AC
			 40EB 465C D949 B101 2427


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: the patch --]
[-- Type: text/x-diff, Size: 2363 bytes --]

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 ()

^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2018-05-21 14:21 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-29 17:19 Inheriting some local variables from source code block editing buffers Göktuğ Kayaalp
2018-04-29 22:09 ` Bastien
2018-05-01  3:30   ` Göktuğ Kayaalp
2018-05-01  8:43     ` Nicolas Goaziou
2018-05-01  8:45       ` Nicolas Goaziou
2018-05-01 11:41       ` Göktuğ Kayaalp
2018-05-01 11:55         ` Nicolas Goaziou
     [not found]           ` <ygmvac7lcl1.fsf@gkayaalp.com>
2018-05-01 14:00             ` Nicolas Goaziou
2018-05-01 16:37           ` Aaron Ecay
     [not found]             ` <ygmin87kwua.fsf@gkayaalp.com>
2018-05-01 19:35               ` Aaron Ecay
2018-05-01 20:04                 ` Göktuğ Kayaalp
2018-05-01 20:53                   ` Aaron Ecay
2018-05-01 22:12                     ` Göktuğ Kayaalp
2018-05-01 22:19                       ` Aaron Ecay
2018-05-01 22:26                       ` Göktuğ Kayaalp
2018-05-02 10:16                         ` Nicolas Goaziou
2018-05-02 19:52                           ` Göktuğ Kayaalp
2018-05-01 11:45       ` Göktuğ Kayaalp
2018-05-14  5:44 ` Göktuğ Kayaalp
2018-05-14 12:13   ` Nicolas Goaziou
2018-05-14 16:34     ` Göktuğ Kayaalp
2018-05-14 16:47       ` Nicolas Goaziou
2018-05-15 18:36         ` Göktuğ Kayaalp
2018-05-18 21:48           ` Göktuğ Kayaalp
2018-05-19 12:26             ` Nicolas Goaziou
2018-05-21 14:20             ` Aaron Ecay
2018-05-14 13:33   ` Aaron Ecay
2018-05-14 16:46     ` Göktuğ Kayaalp

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).