summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-01-04 21:55:10 -0500
committerKyle Meyer <kyle@kyleam.com>2016-01-04 21:55:10 -0500
commit13c91ede13ff41869390092c4d6bd9d80d7e2eae (patch)
tree9b02232ad918087930d48d5fe651029edd8ca7b5
parentfe1e5fd9780291ac06e369dbdd7cbaad4c88a687 (diff)
downloademacs.d-13c91ede13ff41869390092c4d6bd9d80d7e2eae.tar.gz
export-wrapped-text: Clean up
-rw-r--r--lisp/init-text.el37
1 files changed, 18 insertions, 19 deletions
diff --git a/lisp/init-text.el b/lisp/init-text.el
index c4fbecc..6ee95ac 100644
--- a/lisp/init-text.el
+++ b/lisp/init-text.el
@@ -1,31 +1,30 @@
(add-hook 'text-mode-hook 'turn-on-auto-fill)
-(defun km/export-wrapped-text (arg)
+(defun km/export-wrapped-text (&optional xselect)
"Export the text in current buffer as wrapped text.
This is useful for preparing text in emacs and then exporting to
a wrapped buffer for pasting text (e.g., into a web form).
-If region is active, restrict export to the region. If ARG is
-non-nil, copy the region with `x-select-text'."
+With an active region, restrict export to this region. If
+XSELECT is non-nil, copy the region with `x-select-text'."
(interactive "P")
- (let ((wrapped-buffer (get-buffer-create "*Wrapped export*"))
- beg end)
- (if (use-region-p)
- (progn (setq beg (region-beginning))
- (setq end (region-end)))
- (setq beg (point-min))
- (setq end (point-max)))
- (copy-to-buffer wrapped-buffer beg end)
- (switch-to-buffer-other-window wrapped-buffer)
- (while (not (eobp))
- (forward-paragraph)
- (forward-line -1)
- (km/unfill-paragraph)
- (forward-line 1))
- (when arg
- (x-select-text (buffer-substring-no-properties (point-min) (point-max))))))
+ (let ((wrapped-buffer (get-buffer-create "*Wrapped export*")))
+ (apply #'copy-to-buffer wrapped-buffer
+ (if (use-region-p)
+ (list (region-beginning) (region-end))
+ (list (point-min) (point-max))))
+ (with-current-buffer wrapped-buffer
+ (while (not (eobp))
+ (forward-paragraph)
+ (forward-line -1)
+ (km/unfill-paragraph)
+ (forward-line 1))
+ (when xselect
+ (x-select-text
+ (buffer-substring-no-properties (point-min) (point-max)))))
+ (pop-to-buffer wrapped-buffer)))
(defun km/columnify-file (delim)
"Separate current file on DELIM using column program.