emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <dandavison7@gmail.com>
To: emacs org-mode mailing list <emacs-orgmode@gnu.org>
Subject: [PATCH] org-edit-src-code
Date: Fri, 03 Dec 2010 18:33:15 +0000	[thread overview]
Message-ID: <874oau6710.fsf@gmail.com> (raw)

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

                 reply	other threads:[~2010-12-03 18:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874oau6710.fsf@gmail.com \
    --to=dandavison7@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).