Permalink
Browse files

Make coding-hook a real hook instead of a defun.

  • Loading branch information...
1 parent cd73bce commit b2ffdf12fe905fcd0359726efbc217d971e9ca8c @technomancy committed Mar 11, 2009
Showing with 39 additions and 18 deletions.
  1. +23 −11 starter-kit-defuns.el
  2. +1 −1 starter-kit-js.el
  3. +10 −5 starter-kit-lisp.el
  4. +3 −0 starter-kit-misc.el
  5. +2 −1 starter-kit-ruby.el
View
@@ -62,18 +62,30 @@ Symbols matching the text at point are put first in the completion list."
(position (cdr (assoc selected-symbol name-and-pos))))
(goto-char position))))
-(defun coding-hook ()
- "Enable things that are convenient across all coding buffers."
- (set (make-local-variable 'comment-auto-fill-only-comments) t)
+;;; These belong in coding-hook:
+
+(defun local-column-number-mode ()
(make-local-variable 'column-number-mode)
- (column-number-mode t)
- (setq save-place t)
- (auto-fill-mode) ;; in comments only
- (if window-system (hl-line-mode t))
- (pretty-lambdas)
- ;; TODO: this breaks in js2-mode!
- ;;(if (functionp 'idle-highlight) (idle-highlight))
- )
+ (column-number-mode t))
+
+(defun local-comment-auto-fill ()
+ (set (make-local-variable 'comment-auto-fill-only-comments) t)
+ (auto-fill-mode t))
+
+(defun turn-on-hl-line-mode ()
+ (if window-system (hl-line-mode t)))
+
+(defun turn-on-save-place-mode ()
+ (setq save-place t))
+
+(add-hook 'coding-hook 'local-column-number-mode)
+(add-hook 'coding-hook 'local-comment-auto-fill)
+(add-hook 'coding-hook 'turn-on-hl-line-mode)
+(add-hook 'coding-hook 'pretty-lambdas)
+
+(defun run-coding-hook ()
+ "Enable things that are convenient across all coding buffers."
+ (run-hooks coding-hook))
(defun untabify-buffer ()
(interactive)
View
@@ -20,7 +20,7 @@
(defun js-lambda () (interactive) (insert "function () {\n}")
(backward-char 5))
- (add-hook 'js2-mode-hook 'coding-hook)
+ (add-hook 'js2-mode-hook 'run-coding-hook)
(define-key js2-mode-map (kbd "C-c l") 'js-lambda)
(define-key js2-mode-map "\C-\M-h" 'backward-kill-word)
View
@@ -25,9 +25,10 @@
;;; Emacs Lisp
-(add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
-(add-hook 'emacs-lisp-mode-hook 'coding-hook)
+(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
+(add-hook 'emacs-lisp-mode-hook 'run-coding-hook)
(add-hook 'emacs-lisp-mode-hook 'esk-remove-elc-on-save)
+(add-hook 'emacs-lisp-mode-hook 'idle-highlight)
(defun esk-remove-elc-on-save ()
"If you're saving an elisp file, likely the .elc is no longer valid."
@@ -42,7 +43,9 @@
;;; Clojure
-(add-hook 'clojure-mode-hook 'coding-hook)
+(add-hook 'clojure-mode-hook 'run-coding-hook)
+(add-hook 'clojure-mode-hook 'idle-highlight)
+
(font-lock-add-keywords 'clojure-mode
'(("(\\|)" . 'esk-paren-face)))
@@ -51,13 +54,15 @@
;;; Scheme
-(add-hook 'scheme-mode-hook 'coding-hook)
+(add-hook 'scheme-mode-hook 'run-coding-hook)
+(add-hook 'scheme-mode-hook 'idle-highlight)
(font-lock-add-keywords 'scheme-mode
'(("(\\|)" . 'esk-paren-face)))
;;; Common Lisp
-(add-hook 'lisp-mode-hook 'coding-hook)
+(add-hook 'lisp-mode-hook 'run-coding-hook)
+(add-hook 'lisp-mode-hook 'idle-highlight)
(font-lock-add-keywords 'lisp-mode
'(("(\\|)" . 'esk-paren-face)))
View
@@ -71,6 +71,9 @@
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook 'turn-on-flyspell)
+(defvar coding-hook nil
@penryu

penryu Jun 11, 2011

What does this defvar do, other than provide documentation for the hook's purpose? Why defvar it AFTER it's had function named hooked to it?

@technomancy

technomancy Jun 11, 2011

Owner

It's just for documentation; you're right.

+ "Hook that gets run on activation of any programming mode.")
+
(defalias 'yes-or-no-p 'y-or-n-p)
(random t) ;; Seed the random-number generator
View
@@ -52,7 +52,8 @@ exec-to-string command, but it works and seems fast"
(delete-region (point-min) (point-max))))))
(ad-activate 'ruby-do-run-w/compilation)))
-(add-hook 'ruby-mode-hook 'coding-hook)
+(add-hook 'ruby-mode-hook 'run-coding-hook)
+(add-hook 'ruby-mode-hook 'idle-highlight)
;;; Flymake

0 comments on commit b2ffdf1

Please sign in to comment.