From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: [PATCH] org-edit-src-code Date: Fri, 03 Dec 2010 18:33:15 +0000 Message-ID: <874oau6710.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=46416 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POaRl-0005CJ-ME for emacs-orgmode@gnu.org; Fri, 03 Dec 2010 13:33:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POaRg-0001qq-M1 for emacs-orgmode@gnu.org; Fri, 03 Dec 2010 13:33:26 -0500 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:37295) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POaRg-0001qF-D8 for emacs-orgmode@gnu.org; Fri, 03 Dec 2010 13:33:24 -0500 Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id oB3IXMYD023198 for ; Fri, 3 Dec 2010 18:33:22 GMT List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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 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