Clean up prelude-mode.

This commit is contained in:
Bozhidar Batsov 2013-03-07 13:09:13 +02:00
parent 00661efa2a
commit 64aa0ee0c5
2 changed files with 23 additions and 29 deletions

View file

@ -69,30 +69,19 @@
(buffer-substring (region-beginning) (region-end))
(read-string "Google: "))))))
(defun prelude-indent-rigidly-and-copy-to-clipboard (begin end indent)
"Copy the selected code region to the clipboard, indented according
to Markdown blockquote rules."
(let ((buffer (current-buffer)))
(defun prelude-indent-rigidly-and-copy-to-clipboard (begin end arg)
"Indent region between BEGIN and END by ARG columns and copy to clipboard."
(interactive "r\nP")
(let ((arg (or arg 4))
(buffer (current-buffer)))
(with-temp-buffer
(insert-buffer-substring-no-properties buffer begin end)
(indent-rigidly (point-min) (point-max) indent)
(indent-rigidly (point-min) (point-max) arg)
(clipboard-kill-ring-save (point-min) (point-max)))))
(defun prelude-indent-blockquote-and-copy-to-clipboard (begin end)
"Copy the selected code region to the clipboard, indented according
to markdown blockquote rules (useful to copy snippets to StackOverflow, Assembla, Github."
(interactive "r")
(prelude-indent-rigidly-and-copy-to-clipboard begin end 4))
(defun prelude-indent-nested-blockquote-and-copy-to-clipboard (begin end)
"Copy the selected code region to the clipboard, indented according
to markdown blockquote rules. Useful to add snippets under bullet points."
(interactive "r")
(prelude-indent-rigidly-and-copy-to-clipboard begin end 6))
(defun prelude-insert-empty-line ()
"Insert an empty line after the current line and positon
the curson at its beginning, according to the current mode."
"Insert an empty line after the current line.
Position the cursor at its beginning, according to the current mode."
(interactive)
(move-end-of-line nil)
(open-line 1)

View file

@ -31,6 +31,7 @@
;; Boston, MA 02110-1301, USA.
;;; Code:
(require 'easymenu)
(defvar prelude-mode-map
(let ((map (make-sparse-keymap)))
@ -50,11 +51,13 @@
(define-key map (kbd "C-c r") 'prelude-rename-file-and-buffer)
(define-key map (kbd "C-c t") 'prelude-visit-term-buffer)
(define-key map (kbd "C-c k") 'prelude-kill-other-buffers)
(define-key map (kbd "C-c TAB") 'prelude-indent-rigidly-and-copy-to-clipboard)
(define-key map (kbd "C-c h") 'helm-prelude)
map)
"Keymap for Prelude mode.")
(defun prelude-mode-add-menu ()
"Add a menu entry for `prelude-mode' under Tools."
(easy-menu-add-item nil '("Tools")
'("Prelude"
("Files"
@ -74,8 +77,7 @@
["Indent buffer" prelude-indent-buffer]
["Indent buffer or region" prelude-indent-buffer-or-region]
["Duplicate line or region" prelude-duplicate-current-line-or-region]
["Copy to clipboard as blockquote" prelude-indent-blockquote-and-copy-to-clipboard]
["Copy to clipboard as nested blockqoute" prelude-indent-nested-blockquote-and-copy-to-clipboard]
["Indent rigidly and copy to clipboard" prelude-indent-rigidly-and-copy-to-clipboard]
["Insert date" prelude-insert-date]
["Eval and replace" prelude-eval-and-replace])
@ -94,18 +96,11 @@
(easy-menu-add-item nil '("Tools") '("--") "Search Files (Grep)..."))
(defun prelude-mode-remove-menu ()
"Remove `prelude-mode' menu entry."
(easy-menu-remove-item nil '("Tools") "Prelude")
(easy-menu-remove-item nil '("Tools") "--"))
;; define minor mode
(define-globalized-minor-mode prelude-global-mode prelude-mode prelude-on)
(defun prelude-on ()
(prelude-mode +1))
(defun prelude-off ()
(prelude-mode -1))
(define-minor-mode prelude-mode
"Minor mode to consolidate Emacs Prelude extensions.
@ -118,5 +113,15 @@
;; on stop
(prelude-mode-remove-menu)))
(define-globalized-minor-mode prelude-global-mode prelude-mode prelude-on)
(defun prelude-on ()
"Turn on `prelude-mode'."
(prelude-mode +1))
(defun prelude-off ()
"Turn off `prelude-mode'."
(prelude-mode -1))
(provide 'prelude-mode)
;;; prelude-mode.el ends here