Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

Commit

Permalink
slurp: Reduce new line stretches to single space
Browse files Browse the repository at this point in the history
... instead of replacing each new line with a space.
  • Loading branch information
kyleam committed Aug 8, 2015
1 parent a991bdf commit 1d2e9a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions org-link-edit.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test-org-link-edit.el
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down

0 comments on commit 1d2e9a3

Please sign in to comment.