From 54567a4380b21d4dd5ee30a536669fc59130ec99 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 14 Dec 2014 02:27:36 -0500 Subject: Add command fill-surrounding-indented --- lisp/init-editing.el | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lisp/init-editing.el') 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) -- cgit v1.2.3