Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2017-10-24 09:53:47 +02:00
commit 96c7fd7541
2 changed files with 43 additions and 4 deletions

View File

@ -581,14 +581,15 @@ Escaping happens when a line starts with \"*\", \"#+\", \",*\" or
(interactive "r") (interactive "r")
(save-excursion (save-excursion
(goto-char end) (goto-char end)
(while (re-search-backward "^[ \t]*,?\\(\\*\\|#\\+\\)" beg t) (while (re-search-backward "^[ \t]*\\(,*\\(?:\\*\\|#\\+\\)\\)" beg t)
(save-excursion (replace-match ",\\1" nil nil nil 1))))) (save-excursion (replace-match ",\\1" nil nil nil 1)))))
(defun org-escape-code-in-string (s) (defun org-escape-code-in-string (s)
"Escape lines in string S. "Escape lines in string S.
Escaping happens when a line starts with \"*\", \"#+\", \",*\" or Escaping happens when a line starts with \"*\", \"#+\", \",*\" or
\",#+\" by appending a comma to it." \",#+\" by appending a comma to it."
(replace-regexp-in-string "^[ \t]*,?\\(\\*\\|#\\+\\)" ",\\1" s nil nil 1)) (replace-regexp-in-string "^[ \t]*\\(,*\\(?:\\*\\|#\\+\\)\\)" ",\\1"
s nil nil 1))
(defun org-unescape-code-in-region (beg end) (defun org-unescape-code-in-region (beg end)
"Un-escape lines between BEG and END. "Un-escape lines between BEG and END.
@ -597,7 +598,7 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
(interactive "r") (interactive "r")
(save-excursion (save-excursion
(goto-char end) (goto-char end)
(while (re-search-backward "^[ \t]*,?\\(,\\)\\(?:\\*\\|#\\+\\)" beg t) (while (re-search-backward "^[ \t]*,*\\(,\\)\\(?:\\*\\|#\\+\\)" beg t)
(save-excursion (replace-match "" nil nil nil 1))))) (save-excursion (replace-match "" nil nil nil 1)))))
(defun org-unescape-code-in-string (s) (defun org-unescape-code-in-string (s)
@ -605,7 +606,7 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
Un-escaping happens by removing the first comma on lines starting Un-escaping happens by removing the first comma on lines starting
with \",*\", \",#+\", \",,*\" and \",,#+\"." with \",*\", \",#+\", \",,*\" and \",,#+\"."
(replace-regexp-in-string (replace-regexp-in-string
"^[ \t]*,?\\(,\\)\\(?:\\*\\|#\\+\\)" "" s nil nil 1)) "^[ \t]*,*\\(,\\)\\(?:\\*\\|#\\+\\)" "" s nil nil 1))

View File

@ -443,5 +443,43 @@ This is a tab:\t.
(org-edit-special) (org-edit-special)
(prog1 foo (org-edit-src-exit)))))) (prog1 foo (org-edit-src-exit))))))
;;; Code escaping
(ert-deftest test-org-src/escape-code-in-string ()
"Test `org-escape-code-in-string' specifications."
;; Escape lines starting with "*" or "#+".
(should (equal ",*" (org-escape-code-in-string "*")))
(should (equal ",#+" (org-escape-code-in-string "#+")))
;; Escape lines starting with ",*" and ",#+". Number of leading
;; commas does not matter.
(should (equal ",,*" (org-escape-code-in-string ",*")))
(should (equal ",,#+" (org-escape-code-in-string ",#+")))
(should (equal ",,,*" (org-escape-code-in-string ",,*")))
(should (equal ",,,#+" (org-escape-code-in-string ",,#+")))
;; Indentation does not matter.
(should (equal " ,*" (org-escape-code-in-string " *")))
(should (equal " ,#+" (org-escape-code-in-string " #+")))
;; Do nothing on other cases.
(should (equal "a" (org-escape-code-in-string "a")))
(should (equal "#" (org-escape-code-in-string "#")))
(should (equal "," (org-escape-code-in-string ","))))
(ert-deftest test-org-src/unescape-code-in-string ()
"Test `org-unescape-code-in-string' specifications."
;; Unescape lines starting with ",*" or ",#+". Number of leading
;; commas does not matter.
(should (equal "*" (org-unescape-code-in-string ",*")))
(should (equal "#+" (org-unescape-code-in-string ",#+")))
(should (equal ",*" (org-unescape-code-in-string ",,*")))
(should (equal ",#+" (org-unescape-code-in-string ",,#+")))
;; Indentation does not matter.
(should (equal " *" (org-unescape-code-in-string " ,*")))
(should (equal " #+" (org-unescape-code-in-string " ,#+")))
;; Do nothing on other cases.
(should (equal "a" (org-unescape-code-in-string "a")))
(should (equal "#" (org-unescape-code-in-string "#")))
(should (equal "," (org-unescape-code-in-string ","))))
(provide 'test-org-src) (provide 'test-org-src)
;;; test-org-src.el ends here ;;; test-org-src.el ends here