diff options
author | Kyle Meyer <kyle@kyleam.com> | 2017-03-31 20:03:09 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2017-03-31 20:03:09 -0400 |
commit | be1a29b2534290051b855493286b8011fba884c8 (patch) | |
tree | 6bd48c66dc873c2ec7cffd61ba7e00788e90e8e4 /lisp | |
parent | 23a6abef8c26704cce184477d2503b3f61148d68 (diff) | |
download | emacs.d-be1a29b2534290051b855493286b8011fba884c8.tar.gz |
Add strip-comment-lines command
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/km-editing.el | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lisp/km-editing.el b/lisp/km-editing.el index 34f7130..c4ec954 100644 --- a/lisp/km-editing.el +++ b/lisp/km-editing.el @@ -104,6 +104,26 @@ XSELECT is non-nil, copy the region with `x-select-text'." (buffer-substring-no-properties (point-min) (point-max))))) (pop-to-buffer wrapped-buffer))) +;;;###autoload +(defun km/strip-comment-lines (beg end) + "Export text to a new buffer, removing commented lines. +Any line starting with `comment-start' is considered a commented +line. Text is limited to BEG and END, as defined by the active +region. If there is no region, the whole buffer is used." + (interactive (if (use-region-p) + (list (region-beginning) (region-end)) + (list (point-min) (point-max)))) + (let ((comment-char (or comment-start + (user-error "No comment character is defined"))) + (text (buffer-substring-no-properties beg end))) + (with-current-buffer (get-buffer-create + (concat "*" (buffer-name) " - no comments*")) + (erase-buffer) + (insert text) + (goto-char (point-min)) + (flush-lines (concat "^" (regexp-quote comment-char) ".*$")) + (pop-to-buffer (current-buffer))))) + (defun km/delete-comment-lines (orig-buf) (let ((comment-char (with-current-buffer orig-buf comment-start))) |