summaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2013-12-21 16:27:01 -0500
committerKyle Meyer <kyle@kyleam.com>2013-12-21 16:27:01 -0500
commitbd16be9f023fd948dfcca41005edbccbec3e7db4 (patch)
tree18bff0b4a1d93bc6894be2bbf61f2a32d8094395 /init
parent79378ebab1ca679cc5bde30e4a4805a46750e2b2 (diff)
downloademacs.d-bd16be9f023fd948dfcca41005edbccbec3e7db4.tar.gz
Function for exporting wrapped text
Diffstat (limited to 'init')
-rw-r--r--init/km-func.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/init/km-func.el b/init/km-func.el
index 7ac814b..536abc3 100644
--- a/init/km-func.el
+++ b/init/km-func.el
@@ -189,3 +189,35 @@ KILLARG."
(start-process "ext-term" bufname km/terminal)))
(define-key external-map "t" 'km/open-external-terminal)
+
+(defun km/export-wrapped-text (arg)
+ "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, export is restricted to the region. If ARG
+is non-nil, the region is copied with `x-select-text'."
+ (interactive "P")
+ (let ((wrapped-buffer (get-buffer-create "*Wrapped export*"))
+ beg end)
+ (if (region-active-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)
+ (unfill-paragraph)
+ (forward-line 1))
+ (when arg
+ (x-select-text (buffer-substring-no-properties (point-min) (point-max))))))
+
+;; http://www.emacswiki.org/emacs/UnfillParagraph
+(defun unfill-paragraph ()
+ "Takes a multi-line paragraph and makes it into a single line of text."
+ (interactive)
+ (let ((fill-column (point-max)))
+ (fill-paragraph nil)))