diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-08-08 19:39:15 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-08-08 19:39:15 -0400 |
commit | 1d2e9a381e89ce14df3386d08f76f4012f202203 (patch) | |
tree | c57bf356c345e74b3b142f8605d0c3b3283d3083 | |
parent | a991bdf74dc90588121d54665ff405f9eb6f9da7 (diff) | |
download | org-link-edit-1d2e9a381e89ce14df3386d08f76f4012f202203.tar.gz |
slurp: Reduce new line stretches to single space
... instead of replacing each new line with a space.
-rw-r--r-- | org-link-edit.el | 4 | ||||
-rw-r--r-- | test-org-link-edit.el | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/org-link-edit.el b/org-link-edit.el index a303adf..915591a 100644 --- a/org-link-edit.el +++ b/org-link-edit.el @@ -155,7 +155,7 @@ If N is negative, slurp leading blobs instead of trailing blobs." (user-error "Not enough blobs after the link")) (point))) (let ((slurped (buffer-substring-no-properties end (point)))) - (setq slurped (replace-regexp-in-string "\n" " " slurped)) + (setq slurped (replace-regexp-in-string "\n+" " " slurped)) (when (and (= (length desc) 0) (string-match "^\\s-+\\(.*\\)" slurped)) (setq slurped (match-string 1 slurped))) @@ -200,7 +200,7 @@ If N is negative, slurp trailing blobs instead of leading blobs." (when (and (= (length desc) 0) (string-match "\\(.*\\)\\s-+$" slurped)) (setq slurped (match-string 1 slurped))) - (setq slurped (replace-regexp-in-string "\n" " " slurped)) + (setq slurped (replace-regexp-in-string "\n+" " " slurped)) (setq desc (concat slurped desc) beg (- beg (length slurped))) (delete-region (point) end) diff --git a/test-org-link-edit.el b/test-org-link-edit.el index e00288c..19d8c97 100644 --- a/test-org-link-edit.el +++ b/test-org-link-edit.el @@ -113,6 +113,15 @@ otherwise place the point at the beginning of the inserted text." website is" (org-link-edit-forward-slurp 1) (buffer-string)))) + ;; Collapse stretches of new lines. + (should + (string= + "\[\[http://orgmode.org/\]\[Org's website is\]\]" + (org-test-with-temp-text + "\[\[http://orgmode.org/\]\[Org's\]\] +\n\nwebsite\n\n\nis" + (org-link-edit-forward-slurp 2) + (buffer-string)))) ;; Slurp blob that has no whitespace. (should (string= @@ -204,6 +213,15 @@ website is" <point>\[\[http://orgmode.org/\]\[Org's website\]\]" (org-link-edit-backward-slurp 1) (buffer-string)))) + ;; Collapse stretches of new lines. + (should + (string= + "\[\[http://orgmode.org/\]\[Here is Org's website\]\]" + (org-test-with-temp-text + "Here\n\nis\n\n\n +<point>\[\[http://orgmode.org/\]\[Org's website\]\]" + (org-link-edit-backward-slurp 2) + (buffer-string)))) ;; Slurp blob that has no whitespace. (should (string= |