summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-editing.el25
-rw-r--r--lisp/init-external.el27
-rw-r--r--lisp/init-general.el2
-rw-r--r--lisp/init-text.el53
4 files changed, 54 insertions, 53 deletions
diff --git a/lisp/init-editing.el b/lisp/init-editing.el
index 0131a56..c7be657 100644
--- a/lisp/init-editing.el
+++ b/lisp/init-editing.el
@@ -71,6 +71,31 @@ special case.
(forward-line -1)
(delete-blank-lines))))
+(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).
+
+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*")))
+ (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/narrow-to-comment-heading ()
"Narrow to the current comment heading subtree.
diff --git a/lisp/init-external.el b/lisp/init-external.el
index 9063402..24725da 100644
--- a/lisp/init-external.el
+++ b/lisp/init-external.el
@@ -298,4 +298,31 @@ This affects only sites in the `simple-query' format."
(define-key km/external-map "j" 'km/webjump)
+
+;;; Other
+
+(defun km/columnify-file (delim)
+ "Separate current file on DELIM using column program.
+
+By default, DELIM is set to \",\". With a single prefix argument,
+use whitespace as the delimiter. With two prefix arguments,
+prompt for a delimiter.
+
+If a columnified buffer already exists, just switch to it."
+ (interactive (list (cond ((not current-prefix-arg) ",")
+ ((> (prefix-numeric-value current-prefix-arg) 4)
+ (read-string "Delimiter: "))
+ (t nil))))
+ (unless buffer-file-name
+ (user-error "Buffer not visiting a file"))
+ (let* ((output-buffer-name (concat "*cols: " (buffer-name) "*"))
+ (output-buffer (get-buffer output-buffer-name))
+ (fname (file-relative-name buffer-file-name))
+ (args (cons "--table"
+ (and delim (list "--separator" delim)))))
+ (unless output-buffer
+ (setq output-buffer (get-buffer-create output-buffer-name))
+ (apply #'call-process "column" fname output-buffer nil args))
+ (switch-to-buffer output-buffer)))
+
(provide 'init-external)
diff --git a/lisp/init-general.el b/lisp/init-general.el
index 36cbfaa..1882fb7 100644
--- a/lisp/init-general.el
+++ b/lisp/init-general.el
@@ -31,6 +31,8 @@
(add-hook 'after-save-hook
'executable-make-buffer-file-executable-if-script-p)
+(add-hook 'text-mode-hook 'turn-on-auto-fill)
+
;; Taken from
;; http://milkbox.net/note/single-file-master-emacs-configuration/.
(defmacro after (mode &rest body)
diff --git a/lisp/init-text.el b/lisp/init-text.el
deleted file mode 100644
index 6ee95ac..0000000
--- a/lisp/init-text.el
+++ /dev/null
@@ -1,53 +0,0 @@
-
-(add-hook 'text-mode-hook 'turn-on-auto-fill)
-
-(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).
-
-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*")))
- (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.
-
-By default, DELIM is set to \",\". With a single prefix argument,
-use whitespace as the delimiter. With two prefix arguments,
-prompt for a delimiter.
-
-If a columnified buffer already exists, just switch to it."
- (interactive (list (cond ((not current-prefix-arg) ",")
- ((> (prefix-numeric-value current-prefix-arg) 4)
- (read-string "Delimiter: "))
- (t nil))))
- (unless buffer-file-name
- (user-error "Buffer not visiting a file"))
- (let* ((output-buffer-name (concat "*cols: " (buffer-name) "*"))
- (output-buffer (get-buffer output-buffer-name))
- (fname (file-relative-name buffer-file-name))
- (args (cons "--table"
- (and delim (list "--separator" delim)))))
- (unless output-buffer
- (setq output-buffer (get-buffer-create output-buffer-name))
- (apply #'call-process "column" fname output-buffer nil args))
- (switch-to-buffer output-buffer)))
-
-(provide 'init-text)