From b4dd55883fcf01081e8ff83dd96442267471ec6a Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 15 Oct 2011 13:04:02 +0300 Subject: [PATCH] added basic customization support --- init.el | 4 + modules/prelude-c.el | 17 +- modules/prelude-clojure.el | 13 +- modules/prelude-coffee.el | 12 +- modules/prelude-common-lisp.el | 40 ++++- modules/prelude-core.el | 5 + modules/prelude-editor.el | 9 ++ modules/prelude-emacs-lisp.el | 25 ++- modules/prelude-global-keybindings.el | 222 ++++++++++++++------------ modules/prelude-perl.el | 12 +- modules/prelude-ruby.el | 12 +- modules/prelude-ui.el | 72 ++++++--- 12 files changed, 297 insertions(+), 146 deletions(-) diff --git a/init.el b/init.el index d6625fb..6789854 100644 --- a/init.el +++ b/init.el @@ -33,6 +33,10 @@ ;;; Code: +(defgroup prelude nil + "Emacs Prelude" + :group 'convenience) + ;; On OS X Emacs doesn't use the shell PATH if it's not started from ;; the shell. If you're using homebrew modifying the PATH is essential. (if (string= system-type "darwin") diff --git a/modules/prelude-c.el b/modules/prelude-c.el index 58c525a..b864a4e 100644 --- a/modules/prelude-c.el +++ b/modules/prelude-c.el @@ -32,13 +32,24 @@ ;;; Code: +;; customize +(defgroup c nil + "Emacs Prelude C programming support" + :group 'prelude) + +(defcustom prelude-enable-c-hook t + "Enable Prelude's default C hook." + :type 'boolean + :group 'c) + (defun prelude-c-coding-hook () (setq c-basic-offset 4) (prelude-coding-hook)) -;; this will affect all modes derived from cc-mode, like -;; java-mode, php-mode, etc -(add-hook 'c-mode-common-hook 'prelude-c-coding-hook) +(when prelude-enable-c-hook + ;; this will affect all modes derived from cc-mode, like + ;; java-mode, php-mode, etc + (add-hook 'c-mode-common-hook 'prelude-c-coding-hook)) (provide 'prelude-c) diff --git a/modules/prelude-clojure.el b/modules/prelude-clojure.el index 78d1404..0b8221c 100644 --- a/modules/prelude-clojure.el +++ b/modules/prelude-clojure.el @@ -32,6 +32,16 @@ ;;; Code: +;; customize +(defgroup clojure nil + "Emacs Prelude Clojure programming support" + :group 'prelude) + +(defcustom prelude-enable-clojure-hook t + "Enable Prelude's Clojure hook." + :type 'boolean + :group 'clojure) + (require 'prelude-lisp) ;; To start SLIME in your Clojure project: @@ -39,7 +49,8 @@ ;; 2. Invoke M-x clojure-jack-in from a project (require 'clojure-mode) -(add-hook 'clojure-mode-hook 'prelude-lisp-coding-hook) +(when prelude-enable-clojure-hook + (add-hook 'clojure-mode-hook 'prelude-lisp-coding-hook)) (provide 'prelude-clojure) diff --git a/modules/prelude-coffee.el b/modules/prelude-coffee.el index a3e06e5..707ef99 100644 --- a/modules/prelude-coffee.el +++ b/modules/prelude-coffee.el @@ -32,6 +32,15 @@ ;;; Code: +(defgroup coffee nil + "Emacs Prelude CoffeeScript support" + :group 'prelude) + +(defcustom prelude-enable-coffee-hook t + "Enable Prelude's CoffeeScript's hook" + :type 'boolean + :group 'coffee) + (require 'coffee-mode) (defun prelude-coffee-mode-hook () @@ -64,7 +73,8 @@ (file-exists-p (coffee-compiled-file-name)) (coffee-cos-mode t))) -(add-hook 'coffee-mode-hook 'prelude-coffee-mode-hook) +(when prelude-enable-coffee-hook + (add-hook 'coffee-mode-hook 'prelude-coffee-mode-hook)) (provide 'prelude-coffee) diff --git a/modules/prelude-common-lisp.el b/modules/prelude-common-lisp.el index da9411e..96047d3 100644 --- a/modules/prelude-common-lisp.el +++ b/modules/prelude-common-lisp.el @@ -32,9 +32,30 @@ ;;; Code: +(defgroup common-lisp nil + "Prelude's Common Lisp support" + :group 'prelude) + +(defcustom prelude-start-slime-automatically t + "Start SLIME automatically the first time a .list file is opened." + :type 'boolean + :group 'common-lisp) + +(defcustom prelude-enable-common-lisp-hook t + "Enable Prelude's Common Lisp hook" + :type 'boolean + :group 'common-lisp) + +(defcustom prelude-load-common-lisp-slime-automatically nil + "Load Common Lisp's SLIME by default. Setting this to `t' is not a +very good idea if you're programming on occasion in both Clojure and +Common Lisp." + :type 'boolean + :group 'common-lisp) + (require 'prelude-lisp) -;; the SBCL configuration file is in Common Lisp +;; the SBCL configuration file is in Common Lisp (add-to-list 'auto-mode-alist '("\\.sbclrc$" . lisp-mode)) ;; Use SLIME from Quicklisp @@ -43,8 +64,7 @@ ;; Common Lisp support depends on SLIME being installed with Quicklisp (if (file-exists-p (expand-file-name "~/quicklisp/slime-helper.el")) (load (expand-file-name "~/quicklisp/slime-helper.el")) - (message "%s" "SLIME is not installed. Use Quicklisp to install it.")) - ) + (message "%s" "SLIME is not installed. Use Quicklisp to install it."))) ;; a list of alternative Common Lisp implementations that can be ;; used with SLIME. Note that their presence render @@ -58,17 +78,23 @@ (sbcl ("sbcl" "--noinform") :coding-system utf-8-unix))) ;; select the default value from slime-lisp-implementations -(setq slime-default-lisp 'sbcl) +(if (string= system-type "darwin") + ;; default to Clozure CL on OS X + (setq slime-default-lisp 'ccl) + ;; default to SBCL on Linux and Windows + (setq slime-default-lisp 'sbcl)) -(add-hook 'lisp-mode-hook 'prelude-lisp-coding-hook) -(add-hook 'slime-repl-mode-hook 'prelude-interactive-lisp-coding-hook) +(when prelude-enable-common-lisp-hook + (add-hook 'lisp-mode-hook 'prelude-lisp-coding-hook) + (add-hook 'slime-repl-mode-hook 'prelude-interactive-lisp-coding-hook)) ;; start slime automatically when we open a lisp file (defun prelude-start-slime () (unless (slime-connected-p) (save-excursion (slime)))) -(add-hook 'slime-mode-hook 'prelude-start-slime) +(when prelude-start-slime-automatically + (add-hook 'slime-mode-hook 'prelude-start-slime)) ;; Stop SLIME's REPL from grabbing DEL, ;; which is annoying when backspacing over a '(' diff --git a/modules/prelude-core.el b/modules/prelude-core.el index d628769..883632b 100644 --- a/modules/prelude-core.el +++ b/modules/prelude-core.el @@ -36,6 +36,11 @@ (require 'thingatpt) (require 'imenu) +;; customization +(defgroup core nil + "Emacs Prelude core" + :group 'prelude) + (defun prelude-add-subfolders-to-load-path (parent-dir) "Adds all first level `parent-dir' subdirs to the Emacs load path." diff --git a/modules/prelude-editor.el b/modules/prelude-editor.el index 45f1c60..17a94b8 100644 --- a/modules/prelude-editor.el +++ b/modules/prelude-editor.el @@ -32,6 +32,11 @@ ;;; Code: +;; customize +(defgroup editor nil + "Emacs Prelude Editor enhancements" + :group 'prelude) + ;; Emacs users obviously have little need for Command and Option keys, ;; but they do need Meta and Super (when (string= system-type "darwin") @@ -160,6 +165,10 @@ (require 'yasnippet) ;; not yasnippet-bundle (yas/initialize) +;; dispense of trailing whitespace once and for all +(add-hook 'before-save-hook + 'delete-trailing-whitespace) + ;; projectile is a project management mode (require 'projectile) (projectile-global-mode t) diff --git a/modules/prelude-emacs-lisp.el b/modules/prelude-emacs-lisp.el index 2052c27..ae0a354 100644 --- a/modules/prelude-emacs-lisp.el +++ b/modules/prelude-emacs-lisp.el @@ -32,17 +32,17 @@ ;;; Code: +(defgroup emacs-lisp nil + "Prelude support for Emacs Lisp" + :group 'prelude) + +(defcustom prelude-enable-emacs-lisp-hook t + "Enable Prelude's Emacs Lisp hook" + :type 'boolean + :group 'emacs-lisp) (require 'prelude-lisp) -(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) -(add-hook 'emacs-lisp-mode-hook 'prelude-remove-elc-on-save) - -(add-hook 'emacs-lisp-mode-hook 'prelude-lisp-coding-hook) - -(add-hook 'ielm-mode-hook 'prelude-interactive-lisp-coding-hook) -(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode) - (defun prelude-remove-elc-on-save () "If you're saving an elisp file, likely the .elc is no longer valid." (make-local-variable 'after-save-hook) @@ -51,6 +51,15 @@ (if (file-exists-p (concat buffer-file-name "c")) (delete-file (concat buffer-file-name "c")))))) +(when prelude-enable-emacs-lisp-hook + (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) + (add-hook 'emacs-lisp-mode-hook 'prelude-remove-elc-on-save) + + (add-hook 'emacs-lisp-mode-hook 'prelude-lisp-coding-hook) + + (add-hook 'ielm-mode-hook 'prelude-interactive-lisp-coding-hook) + (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)) + (define-key emacs-lisp-mode-map (kbd "M-.") 'find-function-at-point) (provide 'prelude-emacs-lisp) diff --git a/modules/prelude-global-keybindings.el b/modules/prelude-global-keybindings.el index 12f4493..2cf2a07 100644 --- a/modules/prelude-global-keybindings.el +++ b/modules/prelude-global-keybindings.el @@ -32,120 +32,132 @@ ;;; Code: -;; You know, like Readline. -(global-set-key (kbd "C-M-h") 'backward-kill-word) +(defcustom prelude-enable-additional-keybindings t + "Enable Prelude additional global keybindings" + :type 'boolean + :group 'prelude) -;; Align your code in a pretty way. -(global-set-key (kbd "C-x \\") 'align-regexp) +(defcustom prelude-disable-arrow-navigation t + "Disable arrow navigation" + :type 'boolean + :group 'prelude) -;; Perform general cleanup. -(global-set-key (kbd "C-c n") 'prelude-cleanup-buffer) +(when prelude-enable-additional-keybindings + ;; You know, like Readline. + (global-set-key (kbd "C-M-h") 'backward-kill-word) -;; Font size -(define-key global-map (kbd "C-+") 'text-scale-increase) -(define-key global-map (kbd "C--") 'text-scale-decrease) + ;; Align your code in a pretty way. + (global-set-key (kbd "C-x \\") 'align-regexp) -;; Jump to a definition in the current file. (This is awesome.) -(global-set-key (kbd "M-i") 'prelude-ido-goto-symbol) + ;; Perform general cleanup. + (global-set-key (kbd "C-c n") 'prelude-cleanup-buffer) -;; File finding -(global-set-key (kbd "C-x f") 'prelude-recentf-ido-find-file) -(global-set-key (kbd "C-c r") 'bury-buffer) -(global-set-key (kbd "M-`") 'file-cache-minibuffer-complete) + ;; Font size + (define-key global-map (kbd "C-+") 'text-scale-increase) + (define-key global-map (kbd "C--") 'text-scale-decrease) -;; Window switching. (C-x o goes to the next window) -(global-set-key (kbd "C-x O") (lambda () - (interactive) - (other-window -1))) ;; back one + ;; Jump to a definition in the current file. (This is awesome.) + (global-set-key (kbd "M-i") 'prelude-ido-goto-symbol) -;; Indentation help -(global-set-key (kbd "C-x ^") 'join-line) -(global-set-key (kbd "C-M-\\") 'prelude-indent-region-or-buffer) + ;; File finding + (global-set-key (kbd "C-x f") 'prelude-recentf-ido-find-file) + (global-set-key (kbd "C-c r") 'bury-buffer) + (global-set-key (kbd "M-`") 'file-cache-minibuffer-complete) -;; Start proced in a similar manner to dired -(global-set-key (kbd "C-x p") 'proced) - -;; Start eshell or switch to it if it's active. -(global-set-key (kbd "C-x m") 'eshell) - -;; Start a new eshell even if one is active. -(global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t))) - -;; Start a regular shell if you prefer that. -(global-set-key (kbd "C-x M-m") 'shell) - -;; If you want to be able to M-x without meta -(global-set-key (kbd "C-x C-m") 'execute-extended-command) - -;; Fetch the contents at a URL, display it raw. -(global-set-key (kbd "C-x C-h") 'prelude-view-url) - -;; A complementary binding to the apropos-command(C-h a) -(global-set-key (kbd "C-h A") 'apropos) - -;; Should be able to eval-and-replace anywhere. -(global-set-key (kbd "C-c e") 'prelude-eval-and-replace) - -;; Magit rules! -(global-set-key (kbd "C-x g") 'magit-status) - -;; Activate occur easily inside isearch -(define-key isearch-mode-map (kbd "C-o") - (lambda () (interactive) - (let ((case-fold-search isearch-case-fold-search)) - (occur (if isearch-regexp - isearch-string - (regexp-quote isearch-string)))))) - -;; cycle through buffers -(global-set-key (kbd "") 'bury-buffer) - -;; use hippie-expand instead of dabbrev -(global-set-key (kbd "M-/") 'hippie-expand) - -;; spell check Bulgarian text -(global-set-key (kbd "C-c B") - (lambda()(interactive) - (ispell-change-dictionary "bulgarian") - (flyspell-buffer))) - -;; replace buffer-menu with ibuffer -(global-set-key (kbd "C-x C-b") 'ibuffer) - -;; swap windows -(global-set-key (kbd "C-c s") 'prelude-swap-windows) - -;; duplicate the current line or region -(global-set-key (kbd "C-c d") 'prelude-duplicate-current-line-or-region) - -;; rename buffer & visited file -(global-set-key (kbd "C-c r") 'prelude-rename-file-and-buffer) - -;; open an ansi-term buffer -(global-set-key (kbd "C-x t") 'prelude-visit-term-buffer) - -;; toggle input method -(global-set-key (kbd "C-\\") 'prelude-toggle-bulgarian-input-method) - -;; search with google -(global-set-key (kbd "C-c g") 'prelude-google) - -;; toggle menu-bar visibility -(global-set-key (kbd "") 'menu-bar-mode) - -;; real Emacs hackers don't use the arrow keys -(global-set-key (kbd "") (lambda () - (interactive) - (message "Arrow key navigation is disabled. Use C-p instead."))) -(global-set-key (kbd "") (lambda () - (interactive) - (message "Arrow key navigation is disabled. Use C-n instead."))) -(global-set-key (kbd "") (lambda () - (interactive) - (message "Arrow key navigation is disabled. Use C-b instead."))) -(global-set-key (kbd "") (lambda () + ;; Window switching. (C-x o goes to the next window) + (global-set-key (kbd "C-x O") (lambda () (interactive) - (message "Arrow key navigation is disabled. Use C-f instead."))) + (other-window -1))) ;; back one + + ;; Indentation help + (global-set-key (kbd "C-x ^") 'join-line) + (global-set-key (kbd "C-M-\\") 'prelude-indent-region-or-buffer) + + ;; Start proced in a similar manner to dired + (global-set-key (kbd "C-x p") 'proced) + + ;; Start eshell or switch to it if it's active. + (global-set-key (kbd "C-x m") 'eshell) + + ;; Start a new eshell even if one is active. + (global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t))) + + ;; Start a regular shell if you prefer that. + (global-set-key (kbd "C-x M-m") 'shell) + + ;; If you want to be able to M-x without meta + (global-set-key (kbd "C-x C-m") 'execute-extended-command) + + ;; Fetch the contents at a URL, display it raw. + (global-set-key (kbd "C-x C-h") 'prelude-view-url) + + ;; A complementary binding to the apropos-command(C-h a) + (global-set-key (kbd "C-h A") 'apropos) + + ;; Should be able to eval-and-replace anywhere. + (global-set-key (kbd "C-c e") 'prelude-eval-and-replace) + + ;; Magit rules! + (global-set-key (kbd "C-x g") 'magit-status) + + ;; Activate occur easily inside isearch + (define-key isearch-mode-map (kbd "C-o") + (lambda () (interactive) + (let ((case-fold-search isearch-case-fold-search)) + (occur (if isearch-regexp + isearch-string + (regexp-quote isearch-string)))))) + + ;; cycle through buffers + (global-set-key (kbd "") 'bury-buffer) + + ;; use hippie-expand instead of dabbrev + (global-set-key (kbd "M-/") 'hippie-expand) + + ;; spell check Bulgarian text + (global-set-key (kbd "C-c B") + (lambda()(interactive) + (ispell-change-dictionary "bulgarian") + (flyspell-buffer))) + + ;; replace buffer-menu with ibuffer + (global-set-key (kbd "C-x C-b") 'ibuffer) + + ;; swap windows + (global-set-key (kbd "C-c s") 'prelude-swap-windows) + + ;; duplicate the current line or region + (global-set-key (kbd "C-c d") 'prelude-duplicate-current-line-or-region) + + ;; rename buffer & visited file + (global-set-key (kbd "C-c r") 'prelude-rename-file-and-buffer) + + ;; open an ansi-term buffer + (global-set-key (kbd "C-x t") 'prelude-visit-term-buffer) + + ;; toggle input method + (global-set-key (kbd "C-\\") 'prelude-toggle-bulgarian-input-method) + + ;; search with google + (global-set-key (kbd "C-c g") 'prelude-google) + + ;; toggle menu-bar visibility + (global-set-key (kbd "") 'menu-bar-mode)) + +(when prelude-disable-arrow-navigation + ;; real Emacs hackers don't use the arrow keys + (global-set-key (kbd "") (lambda () + (interactive) + (message "Arrow key navigation is disabled. Use C-p instead."))) + (global-set-key (kbd "") (lambda () + (interactive) + (message "Arrow key navigation is disabled. Use C-n instead."))) + (global-set-key (kbd "") (lambda () + (interactive) + (message "Arrow key navigation is disabled. Use C-b instead."))) + (global-set-key (kbd "") (lambda () + (interactive) + (message "Arrow key navigation is disabled. Use C-f instead.")))) (provide 'prelude-global-keybindings) diff --git a/modules/prelude-perl.el b/modules/prelude-perl.el index 18a98ff..54f62ce 100644 --- a/modules/prelude-perl.el +++ b/modules/prelude-perl.el @@ -32,6 +32,15 @@ ;;; Code: +(defgroup perl nil + "Emacs Prelude Perl support." + :group 'prelude) + +(defcustom prelude-enable-perl-hook t + "Enable Prelude's Perl hook" + :type 'boolean + :group 'perl) + ;; use cperl-mode instead of perl-mode (defalias 'perl-mode 'cperl-mode) @@ -56,7 +65,8 @@ (set-face-background 'cperl-hash-face nil) (setq cperl-invalid-face nil)) -(add-hook 'cperl-mode-hook 'prelude-cperl-mode-hook t) +(when prelude-enable-perl-hook + (add-hook 'cperl-mode-hook 'prelude-cperl-mode-hook t)) (provide 'prelude-perl) diff --git a/modules/prelude-ruby.el b/modules/prelude-ruby.el index 5888ee7..a1c7f2e 100644 --- a/modules/prelude-ruby.el +++ b/modules/prelude-ruby.el @@ -32,6 +32,15 @@ ;;; Code: +(defgroup ruby nil + "Emacs Prelude Ruby support" + :group 'prelude) + +(defcustom prelude-enable-ruby-hook t + "Enable Prelude's Ruby hook" + :type 'boolean + :group 'ruby) + ;; Rake files are ruby, too, as are gemspecs, rackup files, and gemfiles. (add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode)) (add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode)) @@ -63,7 +72,8 @@ (ruby-block-mode t) (local-set-key (kbd "C-h r") 'yari)) -(add-hook 'ruby-mode-hook 'prelude-ruby-mode-hook) +(when prelude-enable-ruby-hook + (add-hook 'ruby-mode-hook 'prelude-ruby-mode-hook)) (require 'haml-mode) (require 'scss-mode) diff --git a/modules/prelude-ui.el b/modules/prelude-ui.el index c59438a..ad33a23 100644 --- a/modules/prelude-ui.el +++ b/modules/prelude-ui.el @@ -33,34 +33,68 @@ ;;; Code: -;; the toolbar is just a waste of valuable screen estate -(tool-bar-mode -1) -;; the menu bar is mostly useless as well -;; but removing it under OS X doesn't make much sense -(unless (string= system-type "darwin") - (menu-bar-mode -1)) -;; the blinking cursor is nothing, but an annoyance -(blink-cursor-mode -1) +;; customization +(defgroup ui nil + "Emacs Prelude UI" + :group 'prelude) -;; disable startup screen -(setq inhibit-startup-screen t) +(defcustom prelude-use-minimalistic-ui t + "If set to true Prelude will dispense of most the UI that's mouse related - +menu bar, tool bar, etc" + :type 'boolean + :group 'ui) -;; nice scrolling -(setq scroll-margin 0 - scroll-conservatively 100000 - scroll-preserve-screen-position 1) +(defcustom prelude-use-smooth-scrolling t + "Overrides the default scrolling behavior with a much more common one." + :type 'boolean + :group 'ui) -;; mode line settings -(line-number-mode t) -(column-number-mode t) -(size-indication-mode t) +(defcustom prelude-use-default-prelude-theme t + "If set to true Prelude will load up its default theme (Zenburn), +instead of Emacs's default theme." + :type 'boolean + :group 'ui) + +(defcustom prelude-enhance-modeline t + "If set to true Prelude will augment the default modeline settings." + :type 'boolean + :group 'ui) + + +(when prelude-use-minimalistic-ui + ;; the toolbar is just a waste of valuable screen estate + (tool-bar-mode -1) + ;; the menu bar is mostly useless as well + ;; but removing it under OS X doesn't make much sense + (unless (string= system-type "darwin") + (menu-bar-mode -1)) + ;; the blinking cursor is nothing, but an annoyance + (blink-cursor-mode -1) + + ;; disable startup screen + (setq inhibit-startup-screen t)) + + +(when prelude-use-smooth-scrolling + ;; nice scrolling + (setq scroll-margin 0 + scroll-conservatively 100000 + scroll-preserve-screen-position 1)) + +(when prelude-enhance-modeline + ;; mode line settings + (line-number-mode t) + (column-number-mode t) + (size-indication-mode t)) ;; enable y/n answers (fset 'yes-or-no-p 'y-or-n-p) ;; custom Emacs 24 color themes support (add-to-list 'custom-theme-load-path (concat prelude-dir "themes/")) -(load-theme 'zenburn t) + +(when prelude-use-default-prelude-theme + (load-theme 'zenburn t)) (provide 'prelude-ui) ;;; prelude-ui.el ends here