summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <eric.schulte@gmx.com>2012-02-18 10:35:33 -0700
committerEric Schulte <eric.schulte@gmx.com>2012-02-18 10:38:32 -0700
commit19f1bf6bce8602725acb36691af2367d0a10e78e (patch)
tree01fa6d2c0b9f23e7e5eb524b98853c675d3062de
parent40b3b323f879c987376cb4c039b22e01eb07ec15 (diff)
downloadorg-mode-19f1bf6bce8602725acb36691af2367d0a10e78e.tar.gz
unified stripping of protective commas -- idempotent org-edit-src-code
* lisp/ob.el (org-babel-strip-protective-commas): Use `org-strip-protective-commas'. * lisp/org-exp.el (org-export-select-backend-specific-text): Use `org-strip-protective-commas'. * lisp/org-src.el (org-edit-src-code): Use `org-strip-protective-commas'. * lisp/org.el (org-strip-protective-commas): Single definition for this functionality.
-rw-r--r--lisp/ob.el6
-rw-r--r--lisp/org-exp.el12
-rw-r--r--lisp/org-src.el12
-rw-r--r--lisp/org.el16
4 files changed, 28 insertions, 18 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index 3616b0b..9f4d1cc 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -2236,8 +2236,10 @@ block but are passed literally to the \"example-block\"."
(defun org-babel-strip-protective-commas (body)
"Strip protective commas from bodies of source blocks."
- (when body
- (replace-regexp-in-string "^,#" "#" body)))
+ (with-temp-buffer
+ (insert body)
+ (org-strip-protective-commas (point-min) (point-max))
+ (buffer-string)))
(defun org-babel-script-escape (str &optional force)
"Safely convert tables into elisp lists."
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 2373613..9b06c5d 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -1761,17 +1761,7 @@ from the buffer."
beg-content end-content
`(org-protected t original-indentation ,ind org-native-text t))
;; strip protective commas
- (save-excursion
- (save-match-data
- (goto-char beg-content)
- (let ((front-line (save-excursion
- (re-search-forward
- "[^[:space:]]" end-content t)
- (goto-char (match-beginning 0))
- (current-column))))
- (while (re-search-forward "^[ \t]*\\(,\\)" end-content t)
- (when (= (current-column) front-line)
- (replace-match "" nil nil nil 1))))))
+ (org-strip-protective-commas beg-content end-content)
(delete-region (match-beginning 0) (match-end 0))
(save-excursion
(goto-char beg)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 675f89c..70f28f0 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -307,11 +307,13 @@ buffer."
(error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
(dolist (pair transmitted-variables)
(org-set-local (car pair) (cadr pair)))
- (when (eq major-mode 'org-mode)
- (goto-char (point-min))
- (while (re-search-forward "^," nil t)
- (if (eq (org-current-line) line) (setq total-nindent (1+ total-nindent)))
- (replace-match "")))
+ (if (eq major-mode 'org-mode)
+ (progn
+ (goto-char (point-min))
+ (while (re-search-forward "^," nil t)
+ (if (eq (org-current-line) line) (setq total-nindent (1+ total-nindent)))
+ (replace-match "")))
+ (org-strip-protective-commas (point-min) (point-max)))
(when markline
(org-goto-line (1+ (- markline begline)))
(org-move-to-column
diff --git a/lisp/org.el b/lisp/org.el
index 20a2867..0d06231 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5460,6 +5460,22 @@ will be prompted for."
'(font-lock-fontified t face font-lock-comment-face)))
(t nil))))))
+(defun org-strip-protective-commas (beg end)
+ "Strip protective commas between BEG and END in the current buffer."
+ (interactive "r")
+ (save-excursion
+ (save-match-data
+ (goto-char beg)
+ (let ((front-line (save-excursion
+ (re-search-forward
+ "[^[:space:]]" end t)
+ (goto-char (match-beginning 0))
+ (current-column))))
+ (while (re-search-forward "^[ \t]*\\(,\\)\\([*]\\|#\\+\\)" end t)
+ (goto-char (match-beginning 1))
+ (when (= (current-column) front-line)
+ (replace-match "" nil nil nil 1)))))))
+
(defun org-activate-angle-links (limit)
"Run through the buffer and add overlays to links."
(if (re-search-forward org-angle-link-re limit t)