emacs-orgmode
[Top][All Lists]
Advanced

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

[Orgmode] [PATCH] org-edit-src-code


From: Dan Davison
Subject: [Orgmode] [PATCH] org-edit-src-code
Date: Fri, 03 Dec 2010 18:33:15 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

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 <address@hidden>
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 via email to

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