Merge pull request #558 from hbin/operations-on-buffer-or-region

Operations for buffer or region
This commit is contained in:
Bozhidar Batsov 2014-05-31 12:38:15 +03:00
commit 1c319bb448
2 changed files with 34 additions and 4 deletions

View file

@ -163,7 +163,7 @@ point reaches the beginning or end of the buffer, stop there."
(interactive)
(indent-region (point-min) (point-max)))
(defun prelude-indent-region-or-buffer ()
(defun prelude-indent-buffer-or-region ()
"Indent a region if selected, otherwise the whole buffer."
(interactive)
(save-excursion
@ -291,11 +291,38 @@ there's a region, all lines that region covers will be duplicated."
(interactive)
(untabify (point-min) (point-max)))
(defun prelude-untabify-buffer-or-region ()
"Untabify a region if selected, otherwise the whole buffer."
(interactive)
(save-excursion
(if (region-active-p)
(progn
(untabify (region-beginning) (region-end))
(message "Untabify selected region."))
(progn
(prelude-untabify-buffer)
(message "Untabify buffer.")))))
(defun prelude-cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer."
(interactive)
(prelude-indent-buffer)
(prelude-untabify-buffer)
(prelude-indent-buffer)
(whitespace-cleanup))
(defun prelude-cleanup-buffer-or-region ()
"Cleanup a region if selected, otherwise the whole buffer."
(interactive)
(save-excursion
(if (region-active-p)
(progn
(untabify (region-beginning) (region-end))
(indent-region (region-beginning) (region-end))
(message "Cleanup selected region."))
(progn
(prelude-untabify-buffer)
(prelude-indent-buffer)
(message "Cleanup buffer."))))
(whitespace-cleanup))
(defun prelude-eval-and-replace ()

View file

@ -48,9 +48,9 @@
(define-key map [(control shift down)] 'move-text-down)
(define-key map [(meta shift up)] 'move-text-up)
(define-key map [(meta shift down)] 'move-text-down)
(define-key map (kbd "C-c n") 'prelude-cleanup-buffer)
(define-key map (kbd "C-c n") 'prelude-cleanup-buffer-or-region)
(define-key map (kbd "C-c f") 'prelude-recentf-ido-find-file)
(define-key map (kbd "C-M-\\") 'prelude-indent-region-or-buffer)
(define-key map (kbd "C-M-\\") 'prelude-indent-buffer-or-region)
(define-key map (kbd "C-M-z") 'prelude-indent-defun)
(define-key map (kbd "C-c u") 'prelude-view-url)
(define-key map (kbd "C-c e") 'prelude-eval-and-replace)
@ -95,6 +95,7 @@
("Buffers"
["Clean up buffer" prelude-cleanup-buffer]
["Clean up buffer or region" prelude-cleanup-buffer-or-region]
["Kill other buffers" prelude-kill-other-buffers])
("Editing"
@ -103,6 +104,8 @@
["Move line down" prelude-move-line-down]
["Indent buffer" prelude-indent-buffer]
["Indent buffer or region" prelude-indent-buffer-or-region]
["Untabify buffer" prelude-untabify-buffer]
["Untabify buffer or region" prelude-untabify-buffer-or-region]
["Duplicate line or region" prelude-duplicate-current-line-or-region]
["Indent rigidly and copy to clipboard" prelude-indent-rigidly-and-copy-to-clipboard]
["Insert date" prelude-insert-date]