From cc2836c4f6d4e439d84200d4fc65078ae4b1c1c7 Mon Sep 17 00:00:00 2001 From: Perry Kundert Date: Mon, 27 Feb 2012 12:49:00 -0700 Subject: [PATCH 1/2] Retain correct 8-character tabs, but avoid them for future indenting --- modules/prelude-editor.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/prelude-editor.el b/modules/prelude-editor.el index c9c0b31..3eb23be 100644 --- a/modules/prelude-editor.el +++ b/modules/prelude-editor.el @@ -43,8 +43,18 @@ (setq mac-command-modifier 'super) (setq mac-option-modifier 'meta)) -;; Death to the tabs! -(setq-default indent-tabs-mode nil) +;; Death to the tabs! However, tabs historically indent to the next +;; 8-character offset; specifying anything else will cause *mass* +;; confusion, as it will change the appearance of every existing file. +;; In some cases (python), even worse -- it will change the semantics +;; (meaning) of the program. +;; +;; Emacs modes typically provide a standard means to change the +;; indentation width -- eg. c-basic-offset: use that to adjust your +;; personal indentation width, while maintaining the style (and +;; meaning) of any files you load. +(setq-default indent-tabs-mode nil) ;; don't use tabs to indent +(setq-default tab-width 8) ;; but maintain correct appearance ;; delete the selection with a keypress (delete-selection-mode t) From 04b1fe44c330283a7cbe7038c6be275939c697f8 Mon Sep 17 00:00:00 2001 From: Perry Kundert Date: Mon, 27 Feb 2012 12:50:28 -0700 Subject: [PATCH 2/2] Convert all prelude-*-mode-hooks into actual hooks (allow add-hook) --- init.el | 2 +- modules/prelude-c.el | 16 ++++++++++------ modules/prelude-clojure.el | 8 +++++--- modules/prelude-coffee.el | 8 +++++--- modules/prelude-common-lisp.el | 4 ++-- modules/prelude-emacs-lisp.el | 16 ++++++++++------ modules/prelude-haskell.el | 8 +++++--- modules/prelude-js.el | 6 ++++-- modules/prelude-latex.el | 6 ++++-- modules/prelude-lisp.el | 8 ++++++-- modules/prelude-org.el | 6 ++++-- modules/prelude-perl.el | 6 ++++-- modules/prelude-programming.el | 20 +++++++++++++++----- modules/prelude-python.el | 8 +++++--- modules/prelude-ruby.el | 18 ++++++++++++------ modules/prelude-scheme.el | 2 +- personal/example_el | 18 ++++++++++++++++++ 17 files changed, 111 insertions(+), 49 deletions(-) create mode 100644 personal/example_el diff --git a/init.el b/init.el index 09e6601..35f4d96 100644 --- a/init.el +++ b/init.el @@ -99,7 +99,7 @@ by Prelude.") (when (file-exists-p prelude-personal-dir) (mapc 'load (directory-files prelude-personal-dir nil "^[^#].*el$"))) -(message "Emacs Prelude is ready to do thy bidding, Master, %s!" +(message "Emacs Prelude is ready to do thy bidding, Master %s!" (getenv "USER")) ;;; init.el ends here diff --git a/modules/prelude-c.el b/modules/prelude-c.el index ebc8e26..7cf821c 100644 --- a/modules/prelude-c.el +++ b/modules/prelude-c.el @@ -32,18 +32,22 @@ ;;; Code: -(defun prelude-c-mode-common-hook () +(defun prelude-c-mode-common-defaults () + (setq indent-tabs-mode t) (setq c-basic-offset 4)) +(setq prelude-c-mode-common-hook 'prelude-c-mode-common-defaults) + ;; this will affect all modes derived from cc-mode, like ;; java-mode, php-mode, etc -(add-hook 'c-mode-common-hook 'prelude-c-mode-common-hook) +(add-hook 'c-mode-common-hook (lambda () (run-hooks 'prelude-c-mode-common-hook))) -(defun prelude-makefile-mode-hook () - (setq indent-tabs-mode t) - (setq tab-width 4)) +(defun prelude-makefile-mode-defaults () + (setq indent-tabs-mode t)) -(add-hook 'makefile-mode-hook 'prelude-makefile-mode-hook) +(setq prelude-makefile-mode-hook 'prelude-makefile-mode-defaults) + +(add-hook 'makefile-mode-hook (lambda () (run-hook 'prelude-makefile-mode-hook))) (provide 'prelude-c) diff --git a/modules/prelude-clojure.el b/modules/prelude-clojure.el index 23f3bde..4aaaae6 100644 --- a/modules/prelude-clojure.el +++ b/modules/prelude-clojure.el @@ -39,10 +39,12 @@ ;; 2. Invoke M-x clojure-jack-in from a project (require 'clojure-mode) -(defun prelude-clojure-mode-hook () - (prelude-lisp-coding-hook)) +(defun prelude-clojure-mode-defaults () + (run-hooks 'prelude-lisp-coding-hook)) -(add-hook 'clojure-mode-hook 'prelude-clojure-mode-hook) +(setq prelude-clojure-mode-hook 'prelude-clojure-mode-defaults) + +(add-hook 'clojure-mode-hook (lambda () (run-hooks 'prelude-clojure-mode-hook))) (provide 'prelude-clojure) diff --git a/modules/prelude-coffee.el b/modules/prelude-coffee.el index a3e06e5..0def94d 100644 --- a/modules/prelude-coffee.el +++ b/modules/prelude-coffee.el @@ -34,8 +34,8 @@ (require 'coffee-mode) -(defun prelude-coffee-mode-hook () - "coffee-mode-hook" +(defun prelude-coffee-mode-defaults () + "coffee-mode-defaults" ;; CoffeeScript uses two spaces. (set (make-local-variable 'tab-width) 2) @@ -64,7 +64,9 @@ (file-exists-p (coffee-compiled-file-name)) (coffee-cos-mode t))) -(add-hook 'coffee-mode-hook 'prelude-coffee-mode-hook) +(setq prelude-coffee-mode-hook 'prelude-coffee-mode-defaults) + +(add-hook 'coffee-mode-hook (lambda () (run-hooks 'prelude-coffee-mode-hook))) (provide 'prelude-coffee) diff --git a/modules/prelude-common-lisp.el b/modules/prelude-common-lisp.el index b17ce7c..1ff0531 100644 --- a/modules/prelude-common-lisp.el +++ b/modules/prelude-common-lisp.el @@ -63,8 +63,8 @@ ;; 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) +(add-hook 'lisp-mode-hook (lambda () (run-hooks 'prelude-lisp-coding-hook))) +(add-hook 'slime-repl-mode-hook (lambda () (run-hooks 'prelude-interactive-lisp-coding-hook))) ;; start slime automatically when we open a lisp file (defun prelude-start-slime () diff --git a/modules/prelude-emacs-lisp.el b/modules/prelude-emacs-lisp.el index 1a55d8a..86e550a 100644 --- a/modules/prelude-emacs-lisp.el +++ b/modules/prelude-emacs-lisp.el @@ -42,20 +42,24 @@ (if (file-exists-p (concat buffer-file-name "c")) (delete-file (concat buffer-file-name "c")))))) -(defun prelude-emacs-lisp-mode-hook () - (prelude-lisp-coding-hook) +(defun prelude-emacs-lisp-mode-defaults () + (run-hooks 'prelude-lisp-coding-hook) (turn-on-eldoc-mode) (prelude-remove-elc-on-save) (rainbow-mode +1)) -(add-hook 'emacs-lisp-mode-hook 'prelude-emacs-lisp-mode-hook) +(setq prelude-emacs-lisp-mode-hook 'prelude-emacs-lisp-mode-defaults) + +(add-hook 'emacs-lisp-mode-hook (lambda () (run-hooks 'prelude-emacs-lisp-mode-hook))) ;; ielm is an interactive Emacs Lisp shell -(defun prelude-ielm-mode-hook () - (prelude-interactive-lisp-coding-hook) +(defun prelude-ielm-mode-defaults () + (run-hooks 'prelude-interactive-lisp-coding-hook) (turn-on-eldoc-mode)) -(add-hook 'ielm-mode-hook 'prelude-ielm-mode-hook) +(setq prelude-ielm-mode-hook 'prelude-ielm-mode-defaults) + +(add-hook 'ielm-mode-hook (lambda () (run-hooks 'prelude-ielm-mode-hook))) (define-key emacs-lisp-mode-map (kbd "M-.") 'find-function-at-point) diff --git a/modules/prelude-haskell.el b/modules/prelude-haskell.el index f64bd96..33e3a38 100644 --- a/modules/prelude-haskell.el +++ b/modules/prelude-haskell.el @@ -32,13 +32,15 @@ ;;; Code: -(defun prelude-haskell-mode-hook () - (prelude-prog-mode-hook) +(defun prelude-haskell-mode-defaults () + (run-hooks 'prelude-prog-mode-hook) ;; run manually; not derived from prog-mode (subword-mode +1) (turn-on-haskell-doc-mode) (turn-on-haskell-indentation)) -(add-hook 'haskell-mode-hook 'prelude-haskell-mode-hook) +(setq prelude-haskell-mode-hook 'prelude-haskell-mode-defaults) + +(add-hook 'haskell-mode-hook (lambda () (run-hooks 'prelude-haskell-mode-hook))) (provide 'prelude-haskell) diff --git a/modules/prelude-js.el b/modules/prelude-js.el index 70834ad..dbe765c 100644 --- a/modules/prelude-js.el +++ b/modules/prelude-js.el @@ -32,11 +32,13 @@ ;;; Code: -(defun prelude-js-mode-hook () +(defun prelude-js-mode-defaults () ;; electric-layout-mode doesn't play nice with js-mode (electric-layout-mode -1)) -(add-hook 'js-mode-hook 'prelude-js-mode-hook) +(setq prelude-js-mode-hook 'prelude-js-mode-defaults) + +(add-hook 'js-mode-hook (lambda () (run-hooks 'prelude-js-mode-hook))) (provide 'prelude-js) diff --git a/modules/prelude-latex.el b/modules/prelude-latex.el index 785fa84..329e1c8 100644 --- a/modules/prelude-latex.el +++ b/modules/prelude-latex.el @@ -52,11 +52,13 @@ ("PDF Viewer" "open %o") ("HTML Viewer" "open %o"))) -(defun prelude-latex-mode-hook () +(defun prelude-latex-mode-defaults () (turn-on-auto-fill) (abbrev-mode +1)) -(add-hook 'LaTeX-mode-hook 'prelude-latex-mode-hook) +(setq prelude-latex-mode-hook 'prelude-latex-mode-defaults) + +(add-hook 'LaTeX-mode-hook (lambda () (run-hooks 'prelude-latex-mode-hook))) (provide 'prelude-latex) diff --git a/modules/prelude-lisp.el b/modules/prelude-lisp.el index 5c37bb3..540c817 100644 --- a/modules/prelude-lisp.el +++ b/modules/prelude-lisp.el @@ -36,14 +36,18 @@ (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol) ;; a great lisp coding hook -(defun prelude-lisp-coding-hook () +(defun prelude-lisp-coding-defaults () (paredit-mode +1)) +(setq prelude-lisp-coding-hook 'prelude-lisp-coding-defaults) + ;; interactive modes don't need whitespace checks -(defun prelude-interactive-lisp-coding-hook () +(defun prelude-interactive-lisp-coding-defaults () (paredit-mode +1) (prelude-turn-off-whitespace)) +(setq prelude-interactive-lisp-coding-hook 'prelude-interactive-lisp-coding-defaults) + (provide 'prelude-lisp) ;;; prelude-lisp.el ends here diff --git a/modules/prelude-org.el b/modules/prelude-org.el index e3ccba0..d823eef 100644 --- a/modules/prelude-org.el +++ b/modules/prelude-org.el @@ -38,10 +38,12 @@ (global-set-key "\C-cb" 'org-iswitchb) (setq org-log-done t) -(defun prelude-org-mode-hook () +(defun prelude-org-mode-defaults () (electric-indent-mode -1)) -(add-hook 'org-mode-hook 'prelude-org-mode-hook) +(setq prelude-org-mode-hook 'prelude-org-mode-defaults) + +(add-hook 'org-mode-hook (lambda () (run-hooks 'prelude-org-mode-hook))) (provide 'prelude-org) diff --git a/modules/prelude-perl.el b/modules/prelude-perl.el index 18a98ff..7bf1c15 100644 --- a/modules/prelude-perl.el +++ b/modules/prelude-perl.el @@ -35,7 +35,7 @@ ;; use cperl-mode instead of perl-mode (defalias 'perl-mode 'cperl-mode) -(defun prelude-cperl-mode-hook () +(defun prelude-cperl-mode-defaults () (setq cperl-indent-level 4) (setq cperl-continued-statement-offset 8) ;; cperl-hairy affects all those variables, but I prefer @@ -56,7 +56,9 @@ (set-face-background 'cperl-hash-face nil) (setq cperl-invalid-face nil)) -(add-hook 'cperl-mode-hook 'prelude-cperl-mode-hook t) +(setq prelude-cperl-mode-hook 'prelude-cperl-mode-defaults) + +(add-hook 'cperl-mode-hook (lambda () (run-hooks 'prelude-cperl-mode-hook)) t) (provide 'prelude-perl) diff --git a/modules/prelude-programming.el b/modules/prelude-programming.el index 9906175..9c200c8 100644 --- a/modules/prelude-programming.el +++ b/modules/prelude-programming.el @@ -95,19 +95,29 @@ (require 'which-func) (which-func-mode 1) -(defun prelude-prog-mode-hook () +;; in Emacs 24 programming major modes generally derive from a common +;; mode named prog-mode; for others, we'll arrange for our mode +;; defaults function to run prelude-prog-mode-hook directly. To +;; augment and/or counteract these defaults your own function +;; to prelude-prog-mode-hook, using: +;; +;; (add-hook 'prelude-prog-mode-hook 'my-prog-mode-defaults t) +;; +;; (the final optional t sets the *append* argument) + +(defun prelude-prog-mode-defaults () "Default coding hook, useful with any programming language." (flyspell-prog-mode) (prelude-local-comment-auto-fill) (prelude-turn-on-whitespace) (prelude-turn-on-abbrev) (prelude-add-watchwords) - ;; keep the whitespace decent all the time + ;; keep the whitespace decent all the time (in this buffer) (add-hook 'before-save-hook 'whitespace-cleanup nil t)) -;; in Emacs 24 programming major modes generally derive -;; from a common mode named prog-mode -(add-hook 'prog-mode-hook 'prelude-prog-mode-hook) +(setq prelude-prog-mode-hook 'prelude-prog-mode-defaults) + +(add-hook 'prog-mode-hook (lambda () (run-hooks 'prelude-prog-mode-hook))) (provide 'prelude-programming) ;;; prelude-programming.el ends here diff --git a/modules/prelude-python.el b/modules/prelude-python.el index 61bcb07..68c34db 100644 --- a/modules/prelude-python.el +++ b/modules/prelude-python.el @@ -35,11 +35,13 @@ (require 'python) -(defun prelude-python-mode-hook () - (prelude-prog-mode-hook) +(defun prelude-python-mode-defaults () + (run-hooks 'prelude-prog-mode-hook) ;; run manually; not derived from prog-mode (electric-indent-mode -1)) -(add-hook 'python-mode-hook 'prelude-python-mode-hook) +(setq prelude-python-mode-hook 'prelude-python-mode-defaults) + +(add-hook 'python-mode-hook (lambda () (run-hooks 'prelude-python-mode-hook))) (provide 'prelude-python) diff --git a/modules/prelude-ruby.el b/modules/prelude-ruby.el index ac2d763..3a7a062 100644 --- a/modules/prelude-ruby.el +++ b/modules/prelude-ruby.el @@ -59,30 +59,36 @@ (require 'ruby-block) (require 'ruby-end) -(defun prelude-ruby-mode-hook () +(defun prelude-ruby-mode-defaults () (inf-ruby-keys) ;; turn off the annoying input echo in irb (setq comint-process-echoes t) (ruby-block-mode t) (local-set-key (kbd "C-h r") 'yari)) -(add-hook 'ruby-mode-hook 'prelude-ruby-mode-hook) +(setq prelude-ruby-mode-hook 'prelude-ruby-mode-defaults) + +(add-hook 'ruby-mode-hook (lambda () (run-hooks 'prelude-ruby-mode-hook))) (require 'haml-mode) (require 'scss-mode) -(defun prelude-css-mode-hook () +(defun prelude-css-mode-defaults () (setq css-indent-offset 2) (rainbow-mode +1)) -(add-hook 'css-mode-hook 'prelude-css-mode-hook) +(setq prelude-css-mode-hook 'prelude-css-mode-defaults) -(defun prelude-scss-mode-hook () +(add-hook 'css-mode-hook (lambda () (run-hooks 'prelude-css-mode-hook))) + +(defun prelude-scss-mode-defaults () (prelude-css-mode-hook) ;; turn off annoying auto-compile on save (setq scss-compile-at-save nil)) -(add-hook 'scss-mode-hook 'prelude-scss-mode-hook) +(setq prelude-scss-mode-hook 'prelude-scss-mode-defaults) + +(add-hook 'scss-mode-hook (lambda () (run-hooks 'prelude-scss-mode-hook))) ;; cucumber support (require 'feature-mode) diff --git a/modules/prelude-scheme.el b/modules/prelude-scheme.el index 5bcef52..fe0bda4 100644 --- a/modules/prelude-scheme.el +++ b/modules/prelude-scheme.el @@ -32,7 +32,7 @@ ;;; Code: -(add-hook 'scheme-mode-hook 'prelude-lisp-coding-hook) +(add-hook 'scheme-mode-hook (lambda () (run-hooks 'prelude-lisp-coding-hook))) (provide 'prelude-scheme) diff --git a/personal/example_el b/personal/example_el new file mode 100644 index 0000000..16b6603 --- /dev/null +++ b/personal/example_el @@ -0,0 +1,18 @@ + +;; example_el -- Rename to example.el to activate, and restart emacs + +;; Here are some examples of how to override the defaults for the +;; various prelude-emacs settings. To *append* to any of the +;; configurations attached to prelude-*-hooks, you can attach a +;; function to the appropriate hook: + +(add-hook 'prelude-prog-mode-hook + (lambda () + (prelude-turn-off-whitespace) + (remove-hook 'before-save-hook 'whitespace-cleanup)) t) + +;; For other global settings, just run the appropriate function; all +;; personal/*.el files will be evaluate after prelude-emacs is loaded. + +(global-hl-line-mode -1) +(blink-cursor-mode t)