emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-edit-src-code
@ 2010-12-03 18:33 Dan Davison
  0 siblings, 0 replies; only message in thread
From: Dan Davison @ 2010-12-03 18:33 UTC (permalink / raw)
  To: emacs org-mode mailing list

Sometimes one wants to set `org-edit-src-content-indentation' for a
single buffer, without running the risk of altering the indentation in
other files. At the moment it's not possible to use a buffer-local value
for that variable, because the buffer-local value is not inherited
correctly by the org-src edit buffer.

This patch fixes that. It also substantially tidies up the code in
org-edit-src-code. It changes quite a few lines in the function, so if
any src block users could stick the patch in their set ups and watch for
problems that would be good.

Dan

commit 85597d28b25f4e64d535f61d2115ed2069a28be8
Author: Dan Davison <dandavison7@gmail.com>
Date:   Fri Dec 3 18:24:38 2010 +0000

    Reorganize org-edit-src-code; allow buffer-local `org-edit-src-content-indentation'
    
    * lisp/org-src.el (org-edit-src-code): When generating the code edit
    buffer, it is necessary for several variables to inherit their values
    from the parent org buffer. These changes collect all such variables
    together into a single association list of (variable-name value)
    pairs. In addition, a new variable is added to the list:
    `org-edit-src-content-indentation'. This has the effect that a buffer
    local value can be used for that variable.

diff --git a/lisp/org-src.el b/lisp/org-src.el
index fd827f9..06d0297 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -215,14 +215,12 @@ buffer."
   (let ((mark (and (org-region-active-p) (mark)))
 	(case-fold-search t)
 	(info (org-edit-src-find-region-and-lang))
-	(babel-info (org-babel-get-src-block-info 'light))
-	(org-mode-p (eq major-mode 'org-mode))
+	(org-mode-p (org-mode-p))
 	(beg (make-marker))
 	(end (make-marker))
-	(preserve-indentation org-src-preserve-indentation)
 	(allow-write-back-p (null code))
 	block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
-	begline markline markcol line col)
+	begline markline markcol line col transmitted-variables)
     (if (not info)
 	nil
       (setq beg (move-marker beg (nth 0 info))
@@ -236,10 +234,22 @@ buffer."
                      (nth 2 info))
 	    lang (if (symbolp lang) (symbol-name lang) lang)
 	    single (nth 3 info)
-	    lfmt (nth 4 info)
 	    block-nindent (nth 5 info)
 	    lang-f (intern (concat lang "-mode"))
-	    begline (save-excursion (goto-char beg) (org-current-line)))
+	    begline (save-excursion (goto-char beg) (org-current-line))
+	    transmitted-variables
+	    `((org-edit-src-content-indentation
+	       ,org-edit-src-content-indentation)
+	      (org-edit-src-force-single-line ,single)
+	      (org-edit-src-from-org-mode ,org-mode-p)
+	      (org-edit-src-allow-write-back-p ,allow-write-back-p)
+	      (org-src-preserve-indentation ,org-src-preserve-indentation)
+	      (org-src-babel-info ,(org-babel-get-src-block-info 'light))
+	      (org-coderef-label-format
+	       ,(or (nth 4 info) org-coderef-label-format))
+	      (org-edit-src-beg-marker ,beg)
+	      (org-edit-src-end-marker ,end)
+	      (org-edit-src-block-indentation ,block-nindent)))
       (if (and mark (>= mark beg) (<= mark (1+ end)))
 	  (save-excursion (goto-char (min mark end))
 			  (setq markline (org-current-line)
@@ -279,27 +289,23 @@ buffer."
 		       (define-key map [mouse-1] 'org-edit-src-continue)
 		       map))
 	(overlay-put ovl :read-only "Leave me alone")
+	(setq transmitted-variables
+	      (append transmitted-variables `((org-edit-src-overlay ,ovl))))
 	(org-src-switch-to-buffer buffer 'edit)
 	(if (eq single 'macro-definition)
 	    (setq code (replace-regexp-in-string "\\\\n" "\n" code t t)))
 	(insert code)
 	(remove-text-properties (point-min) (point-max)
 				'(display nil invisible nil intangible nil))
-	(unless preserve-indentation
+	(unless (cadr (assq 'org-src-preserve-indentation transmitted-variables))
 	  (setq total-nindent (or (org-do-remove-indentation) 0)))
 	(let ((org-inhibit-startup t))
 	  (condition-case e
 	      (funcall lang-f)
 	    (error
 	     (error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
-	(set (make-local-variable 'org-edit-src-force-single-line) single)
-	(set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
-	(set (make-local-variable 'org-edit-src-allow-write-back-p) allow-write-back-p)
-	(set (make-local-variable 'org-src-preserve-indentation) preserve-indentation)
-	(when babel-info
-	  (set (make-local-variable 'org-src-babel-info) babel-info))
-	(when lfmt
-	  (set (make-local-variable 'org-coderef-label-format) lfmt))
+	(dolist (pair transmitted-variables)
+	  (org-set-local (car pair) (cadr pair)))
 	(when org-mode-p
 	  (goto-char (point-min))
 	  (while (re-search-forward "^," nil t)
@@ -308,16 +314,13 @@ buffer."
 	(when markline
 	  (org-goto-line (1+ (- markline begline)))
 	  (org-move-to-column
-	   (if preserve-indentation markcol (max 0 (- markcol total-nindent))))
+	   (if org-src-preserve-indentation markcol
+	     (max 0 (- markcol total-nindent))))
 	  (push-mark (point) 'no-message t)
 	  (setq deactivate-mark nil))
 	(org-goto-line (1+ (- line begline)))
 	(org-move-to-column
-	 (if preserve-indentation col (max 0 (- col total-nindent))))
-	(org-set-local 'org-edit-src-beg-marker beg)
-	(org-set-local 'org-edit-src-end-marker end)
-	(org-set-local 'org-edit-src-overlay ovl)
-	(org-set-local 'org-edit-src-block-indentation block-nindent)
+	 (if org-src-preserve-indentation col (max 0 (- col total-nindent))))
 	(org-src-mode)
 	(set-buffer-modified-p nil)
 	(and org-edit-src-persistent-message

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-03 18:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-03 18:33 [PATCH] org-edit-src-code Dan Davison

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