summaryrefslogtreecommitdiff
path: root/lisp/init-editing.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-12-14 02:27:36 -0500
committerKyle Meyer <kyle@kyleam.com>2014-12-14 02:27:36 -0500
commit54567a4380b21d4dd5ee30a536669fc59130ec99 (patch)
treef637ef54cb9359899647f108947a1eda92c0ec93 /lisp/init-editing.el
parent0ea9f73242d0139aaca58695c059e31748a002f9 (diff)
downloademacs.d-54567a4380b21d4dd5ee30a536669fc59130ec99.tar.gz
Add command fill-surrounding-indented
Diffstat (limited to 'lisp/init-editing.el')
-rw-r--r--lisp/init-editing.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/lisp/init-editing.el b/lisp/init-editing.el
index 0c0d692..1842ebb 100644
--- a/lisp/init-editing.el
+++ b/lisp/init-editing.el
@@ -31,6 +31,38 @@
(let ((fill-column (point-max)))
(fill-paragraph nil)))
+(defun km/fill-surrounding-indented ()
+ "Fill current line with all surrounding lines of same indentation.
+This is like `fill-individual-paragraphs', but 1) it acts only on
+a single paragraph at point, not all paragraphs in a region, and
+2) it doesn't treat lines with the following structure as a
+special case.
+
+ foo> This line with extra indentation starts
+ foo> a paragraph that continues on more lines."
+ (interactive)
+ (save-excursion
+ (let ((orig-point (point))
+ (level (current-indentation))
+ beg end)
+ (beginning-of-line)
+ (while (and (not beg) (not (bobp)))
+ (forward-line -1)
+ (when (or (/= level (current-indentation))
+ (looking-at "^\\s-*$"))
+ (forward-line)
+ (setq beg (point))))
+ (goto-char orig-point)
+ (beginning-of-line)
+ (while (and (not end) (not (eobp)))
+ (forward-line)
+ (when (or (/= level (current-indentation))
+ (looking-at "^\\s-*$"))
+ (forward-line -1)
+ (end-of-line)
+ (setq end (point))))
+ (fill-region (or beg (point-min)) (or end (point-max))))))
+
(define-key search-map "s" 'query-replace)
(define-key search-map "S" 'replace-string)
(define-key search-map "r" 'query-replace-regexp)
@@ -141,6 +173,7 @@ and '<<<' mark the bounds of the narrowed region.
(global-set-key (kbd "C-;") 'er/expand-region)
(define-key km/editing-map "i" 'indent-relative)
+(define-key km/editing-map "f" 'km/fill-surrounding-indented)
(electric-indent-mode -1)