Permalink
Browse files

Add buffer-local-set-key convenience function

  • Loading branch information...
1 parent 30acf9f commit 27acd5ed73c88ea58c5d7cb086012d2ffa7245b9 @magnars committed Jan 2, 2013
Showing with 17 additions and 0 deletions.
  1. +17 −0 defuns/buffer-defuns.el
View
@@ -2,6 +2,23 @@
(require 'imenu)
+(defvar buffer-local-mode nil)
+(make-variable-buffer-local 'buffer-local-mode)
+
+(defun mode-keymap (mode-sym)
+ (symbol-value (intern (concat (symbol-name mode-sym) "-map"))))
+
+(defun* buffer-local-set-key (key action)
+ (when buffer-local-mode
+ (define-key (mode-keymap buffer-local-mode)
+ key action)
+ (return-from set-key-buffer-local))
+ (let* ((mode-name-loc (gensym "-blm")))
+ (eval `(define-minor-mode ,mode-name-loc nil nil nil (make-sparse-keymap)))
+ (setq buffer-local-mode mode-name-loc)
+ (funcall mode-name-loc 1)
+ (define-key (mode-keymap mode-name-loc) key action)))
+
(defun create-scratch-buffer nil
"create a new scratch buffer to work in. (could be *scratch* - *scratchX*)"
(interactive)

0 comments on commit 27acd5e

Please sign in to comment.