I want to create a table in org-mode and use it in Ditaa The following function is created to replace “^+-” to “|-” and similarly, “^-+\s-*” to “-|”.
Surprisingly, this does not work.
(defun ditaa-to-table (begin end)
"Replace “^\+-” to “|-” in region; Replace “-\+\s-*$” to “-|”"
"I want to create a table in org-mode and use it in Ditaa"
"org-mode uses |- and -| for the row/cell delimiter at the extremes of the line, while Ditaa uses +- and -+"
(interactive "r")
(save-restriction
(narrow-to-region begin end)
(goto-char (point-min))
(while (search-forward-regexp "^\s-*\+-" nil t) (replace-match "|-" nil t))
(goto-char (point-min))
(while (search-forward-regexp "-\+\s-*$" nil t) (replace-match "-|" nil t))
))
If I use,
(while (search-forward-regexp "\+-" nil t) (replace-match "|-" nil t)) ;; works
works, But once I add the "^\s-*" char to mark the start-of-line, it stops working.
Similarly, basic one works, but once the "\s-*$" is added, it stops working
(while (search-forward-regexp "-\+" nil t) (replace-match "-|" nil t)) ;; works
(while (search-forward-regexp "-\+\s-*$" nil t) (replace-match "-|" nil t)) ;; does not work
I tried posix-search-forward also, and it does not work.
\s
with[:space:]
. Re-Builder helped me build the right RegExp that can be used in the function.