Change argnames, update all calls

This commit is contained in:
Kashish Sharma 2015-11-27 05:01:14 +05:30
parent d547f002f5
commit 0a20ea979c
7 changed files with 110 additions and 87 deletions

View File

@ -43,8 +43,10 @@
;; extend functions to ask for paths, with path history, and default ;; extend functions to ask for paths, with path history, and default
;; path being directory of current file? ;; path being directory of current file?
(cp-global-set-many-keys (cp-set-keys
:bindings
`((,(kbd "C-x C-a C-h") cp-adb-push-this-file) `((,(kbd "C-x C-a C-h") cp-adb-push-this-file)
(,(kbd "C-x C-a C-d") cp-adb-pull-and-ediff))) (,(kbd "C-x C-a C-d") cp-adb-pull-and-ediff)))
(defun cp-dired-adb-push-marked () (defun cp-dired-adb-push-marked ()
(interactive)) (interactive))

View File

@ -12,26 +12,29 @@
(kill-line 0)) (kill-line 0))
(global-set-key (kbd "C-u") 'cp-kill-line-0) (global-set-key (kbd "C-u") 'cp-kill-line-0)
;; whole-line-or-region
(global-set-key (kbd "C-y") 'whole-line-or-region-yank)
(global-set-key (kbd "M-w") 'whole-line-or-region-kill-ring-save)
(global-unset-key (kbd "C-x C-r")) (global-unset-key (kbd "C-x C-r"))
(global-set-key (kbd "C-x C-r C-i") 'string-insert-rectangle) (cp-set-keys
(global-set-key (kbd "C-x C-r C-r") 'replace-rectangle) :bindings
(global-set-key (kbd "C-x C-r C-k") 'kill-rectangle) ;; whole-line-or-region
`((,(kbd "C-y") whole-line-or-region-yank)
(,(kbd "M-w") whole-line-or-region-kill-ring-save)
(,(kbd "C-x C-r C-i") string-insert-rectangle)
(,(kbd "C-x C-r C-r") replace-rectangle)
(,(kbd "C-x C-r C-k") kill-rectangle)
;; A better solution would be to hack kill-line/kill-visual-line to ;; A better solution would be to hack kill-line/kill-visual-line to
;; kill the region if a region is active. The flexibility of those ;; kill the region if a region is active. The flexibility of those
;; functions is very desirable - you can delete from point to line ;; functions is very desirable - you can delete from point to line
;; end, clear a line to enter some other text on it (C-a C-k/"a k"), ;; end, clear a line to enter some other text on it (C-a C-k/"a k"),
;; or delete one or more whole lines (C-1 C-k/"1 k" or C-<num> ;; or delete one or more whole lines (C-1 C-k/"1 k" or C-<num>
;; C-k/"<num> k"). ;; C-k/"<num> k").
(global-set-key (kbd "C-S-k") 'whole-line-or-region-kill-region) (,(kbd "C-S-k") whole-line-or-region-kill-region)
(global-set-key (kbd "C-,") 'backward-paragraph)
(global-set-key (kbd "C-.") 'forward-paragraph) (,(kbd "C-,") backward-paragraph)
(global-set-key (kbd "C-<") 'beginning-of-buffer) (,(kbd "C-.") forward-paragraph)
(global-set-key (kbd "C->") 'end-of-buffer) (,(kbd "C-<") beginning-of-buffer)
(global-set-key (kbd "C-;") 'delete-horizontal-space) (,(kbd "C->") end-of-buffer)
(,(kbd "C-;") delete-horizontal-space)))
;; open-line should always move to the beginning of the current line ;; open-line should always move to the beginning of the current line
;; first, so one can run it anywhere. I also want it to indent it to ;; first, so one can run it anywhere. I also want it to indent it to
@ -74,7 +77,8 @@
;;;; I like the transpose commands ;;;; I like the transpose commands
(global-unset-key (kbd "C-t")) (global-unset-key (kbd "C-t"))
(cp-global-set-many-keys (cp-set-keys
:bindings
`((,(kbd "C-t C-c") transpose-chars) `((,(kbd "C-t C-c") transpose-chars)
(,(kbd "C-t C-w") transpose-words) (,(kbd "C-t C-w") transpose-words)
(,(kbd "C-t C-l") transpose-lines) (,(kbd "C-t C-l") transpose-lines)

View File

@ -20,9 +20,10 @@
" "
erc-timestamp-format-right nil erc-timestamp-format-right nil
erc-join-buffer 'bury) erc-join-buffer 'bury)
(cp-define-many-keys
erc-mode-map (global-unset-key (kbd "C-x e"))
`((,(kbd "C-x e r") 'erc-server-reconnect)))
(global-set-key (kbd "C-x e r") 'erc-server-reconnect)
(require 'rcirc) (require 'rcirc)
(setq (setq

View File

@ -30,12 +30,14 @@
(message "At deepest level.")) (message "At deepest level."))
(backward-char)) (backward-char))
(cp-global-set-many-keys (cp-set-keys
:bindings
`((,(kbd "C-c C-i") 'LilyPond-info) `((,(kbd "C-c C-i") 'LilyPond-info)
(,(kbd "M-]") 'cp-toggle-selective-display))) (,(kbd "M-]") 'cp-toggle-selective-display)))
(cp-define-many-keys (cp-set-keys
LilyPond-mode-map :keymap LilyPond-mode-map
:bindings
`((,(kbd "M-p") cp-backward-def) `((,(kbd "M-p") cp-backward-def)
(,(kbd "M-n") cp-forward-def) (,(kbd "M-n") cp-forward-def)
(,(kbd "M-P") cp-upper-level) (,(kbd "M-P") cp-upper-level)

View File

@ -14,7 +14,8 @@
(interactive) (interactive)
(find-tag (find-tag-default))) (find-tag (find-tag-default)))
(cp-global-set-many-keys (cp-set-keys
:bindings
`((,(kbd "M-t M-t") find-tag-no-prompt-other-window) `((,(kbd "M-t M-t") find-tag-no-prompt-other-window)
(,(kbd "M-t M-g") find-tag-no-prompt) (,(kbd "M-t M-g") find-tag-no-prompt)
(,(kbd "M-t M-p") pop-tag-mark) (,(kbd "M-t M-p") pop-tag-mark)
@ -33,7 +34,8 @@
;;;; mark ring ;;;; mark ring
;;;; Other custom keys ;;;; Other custom keys
(cp-global-set-many-keys (cp-set-keys
:bindings
`((,(kbd "C-x C-1") delete-other-windows) `((,(kbd "C-x C-1") delete-other-windows)
(,(kbd "C-x C-2") split-window-below) (,(kbd "C-x C-2") split-window-below)
(,(kbd "C-x C-3") split-window-right) (,(kbd "C-x C-3") split-window-right)
@ -42,6 +44,7 @@
(,(kbd "C-`") point-to-register) (,(kbd "C-`") point-to-register)
(,(kbd "C-'") jump-to-register) (,(kbd "C-'") jump-to-register)
(,(kbd "C-x C-d") dired-jump))) (,(kbd "C-x C-d") dired-jump)))
(require 'dired) (require 'dired)
(define-key dired-mode-map (kbd "b") 'dired-up-directory) (define-key dired-mode-map (kbd "b") 'dired-up-directory)
(add-hook 'dired-mode-hook 'visual-line-mode) (add-hook 'dired-mode-hook 'visual-line-mode)

View File

@ -11,8 +11,9 @@
;; (global-set-key (kbd "C-x C-p") 'paredit-mode) ;; (global-set-key (kbd "C-x C-p") 'paredit-mode)
;; (cp-define-many-keys ;; (cp-set-keys
;; paredit-mode-map ;; :keymap paredit-mode-map
;; :bindings
;; `((,(kbd "C-p") paredit-backward-down) ;; `((,(kbd "C-p") paredit-backward-down)
;; (,(kbd "C-n") paredit-forward-up) ;; (,(kbd "C-n") paredit-forward-up)
;; (,(kbd "C-b") paredit-backward) ;; (,(kbd "C-b") paredit-backward)
@ -38,8 +39,9 @@
;; (,(kbd "C-h") paredit-backward-delete) ;; (,(kbd "C-h") paredit-backward-delete)
;; (,(kbd "C-w") paredit-backward-kill-word))) ;; (,(kbd "C-w") paredit-backward-kill-word)))
;; (cp-define-many-keys ;; (cp-set-keys
;; comint-mode-map ;; :keymap comint-mode-map
;; :bindings
;; `((,(kbd "C-d") paredit-forward-down) ;; `((,(kbd "C-d") paredit-forward-down)
;; (,(kbd "C-M-p") comint-previous-input) ;; (,(kbd "C-M-p") comint-previous-input)
;; (,(kbd "C-M-n") comint-next-input))) ;; (,(kbd "C-M-n") comint-next-input)))
@ -64,8 +66,9 @@
;; (sp-pair "(" nil :unless '(cp-point-after-colon-p)) ;; (sp-pair "(" nil :unless '(cp-point-after-colon-p))
;; non-lisp modes ;; non-lisp modes
(cp-define-many-keys (cp-set-keys
smartparens-mode-map :keymap smartparens-mode-map
:bindings
`((,(kbd ";") sp-comment) `((,(kbd ";") sp-comment)
(,(kbd "C-)") sp-forward-slurp-sexp) (,(kbd "C-)") sp-forward-slurp-sexp)
(,(kbd "C-(") sp-backward-slurp-sexp) (,(kbd "C-(") sp-backward-slurp-sexp)
@ -94,8 +97,9 @@
;; (define-key emacs-lisp-mode-map (kbd "C-n") 'sp-next-sexp) ;; (define-key emacs-lisp-mode-map (kbd "C-n") 'sp-next-sexp)
(defun cp-setup-lisp-keys () (defun cp-setup-lisp-keys ()
(cp-define-many-keys (cp-set-keys
smartparens-mode-map :keymap smartparens-mode-map
:bindings
`((,(kbd "C-M-b") nil) `((,(kbd "C-M-b") nil)
(,(kbd "C-M-f") nil) (,(kbd "C-M-f") nil)
(,(kbd "C-M-u") nil) (,(kbd "C-M-u") nil)
@ -132,8 +136,9 @@
(,(kbd "C-M-u") upcase-word) (,(kbd "C-M-u") upcase-word)
(,(kbd "C-M-d") sp-kill-word))) (,(kbd "C-M-d") sp-kill-word)))
(cp-define-many-keys (cp-set-keys
comint-mode-map :keymap comint-mode-map
:bindings
`((,(kbd "C-d") sp-down-sexp) `((,(kbd "C-d") sp-down-sexp)
(,(kbd "C-M-p") comint-previous-input) (,(kbd "C-M-p") comint-previous-input)
(,(kbd "C-M-n") comint-next-input)))) (,(kbd "C-M-n") comint-next-input))))

104
init.el
View File

@ -9,100 +9,102 @@
(add-to-list 'load-path "~/.emacs.d/contrapunctus/") (add-to-list 'load-path "~/.emacs.d/contrapunctus/")
(defun cp-global-set-many-keys (key-fn-alist) (defun cp-global-set-many-keys (bindings)
"A clean way to define many keys using `global-set-key.' "A clean way to define many keys using `global-set-key'.
KEY-FN-ALIST must be in the form `((,(kbd \"...\") FN) ...)" BINDINGS must be in the form `((,(kbd \"...\") FN) ...)"
(mapc (lambda (b) (mapc (lambda (b)
(global-set-key (car b) (cadr b))) (global-set-key (car b) (cadr b)))
key-fn-alist)) bindings))
(defun cp-define-many-keys (keymap key-fn-alist) (defun cp-define-many-keys (keymap bindings)
"A clean way to define many keys using `define-key.' "A clean way to define many keys using `define-key'.
KEYMAP must be a valid keymap. KEYMAP must be a valid keymap.
KEY-FN-ALIST must be in the form `((,(kbd \"...\") FN) ...)" BINDINGS must be in the form `((,(kbd \"...\") FN) ...)"
(mapc (lambda (b) (mapc (lambda (b)
(define-key keymap (car b) (cadr b))) (define-key keymap (car b) (cadr b)))
key-fn-alist)) bindings))
(defun cp-local-set-many-keys (key-fn-alist) (defun cp-local-set-many-keys (bindings)
"A clean way to define many keys using `local-set-key.' "A clean way to define many keys using `local-set-key'.
KEY-FN-ALIST must be in the form `((,(kbd \"...\") FN) ...)" BINDINGS must be in the form `((,(kbd \"...\") FN) ...)"
(mapc (lambda (b) (mapc (lambda (b)
(local-set-key (car b) (cadr b))) (local-set-key (car b) (cadr b)))
key-fn-alist)) bindings))
(require 'cl) (require 'cl)
(cl-defun cp-set-keys (&key key-fn-alist keymap-or-local unset) (cl-defun cp-set-keys (&key keymap unset bindings)
"A clean way to set/unset many keybindings. "A clean way to set/unset many keybindings.
KEY-FN-ALIST must be in the form `((,(kbd \"...\") FN) ...) BINDINGS specifies the functions and the keys they are to be
bound to. It must be an alist in the form -
`((,(kbd \"...\") FN) ...)
If KEYMAP-OR-LOCAL is 'global or not supplied, the binding is If KEYMAP is a symbol `global' or not supplied, the binding is
created by `global-set-key'. created by `global-set-key'.
If it is local, the binding is created by `local-set-key'. If it is a symbol `local', the binding is created by
Otherwise, it is assumed to be a keymap and the binding is created `local-set-key'.
with `define-key'. Otherwise, it is assumed to be a keymap and the binding is
created with `define-key'.
If UNSET is non-nil, unset keybinds as specified by KEYMAP-OR-LOCAL If UNSET is non-nil, unset keybinds as specified by KEYMAP
instead of setting them. If a keymap is specified, the key is unset instead of setting them. If a keymap is specified, the key is unset
by using define-key to set it to nil in the given keymap - by using define-key to set it to nil in the given keymap -
otherwise, global-unset-key or local-unset-key are used as otherwise, global-unset-key or local-unset-key are used as
applicable." applicable."
(let ((key-function (if (not unset) (let ((key-function (if (not unset)
(pcase keymap-or-local (pcase keymap
((or `global `nil) #'global-set-key) ((or `global `nil) #'global-set-key)
(`local #'local-set-key) (`local #'local-set-key)
(x #'define-key)) (x #'define-key))
(pcase keymap-or-local (pcase keymap
((or `global `nil) #'global-unset-key) ((or `global `nil) #'global-unset-key)
(`local #'local-unset-key) (`local #'local-unset-key)
(x #'define-key))))) (x #'define-key)))))
(if (eq key-function 'define-key) (if (eq key-function 'define-key)
(if unset (if unset
(mapc (lambda (b) (mapc (lambda (b)
(funcall key-function keymap-or-local (car b) nil)) (funcall key-function keymap (car b) nil))
key-fn-alist) bindings)
(mapc (lambda (b) (mapc (lambda (b)
(funcall key-function keymap-or-local (car b) (cadr b))) (funcall key-function keymap (car b) (cadr b)))
key-fn-alist)) bindings))
(if unset (if unset
(mapc (lambda (b) (mapc (lambda (b)
(funcall key-function (car b))) (funcall key-function (car b)))
key-fn-alist) bindings)
(mapc (lambda (b) (mapc (lambda (b)
(funcall key-function (car b) (cadr b))) (funcall key-function (car b) (cadr b)))
key-fn-alist))))) bindings)))))
;; tests ;; tests
(progn (cp-set-keys :keymap-or-local 'global (progn (cp-set-keys :keymap 'global ; not actually needed, e.g. see next call
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww))) :bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal 'erc (lookup-key (current-global-map) (kbd "<f6>"))) (and (equal 'erc (lookup-key (current-global-map) (kbd "<f6>")))
(equal 'eww (lookup-key (current-global-map) (kbd "<f7>"))))) (equal 'eww (lookup-key (current-global-map) (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local 'global (progn (cp-set-keys :unset t
:unset 'unset :bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal nil (lookup-key (current-global-map) (kbd "<f6>"))) (and (equal nil (lookup-key (current-global-map) (kbd "<f6>")))
(equal nil (lookup-key (current-global-map) (kbd "<f7>"))))) (equal nil (lookup-key (current-global-map) (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local emacs-lisp-mode-map (progn (cp-set-keys :keymap emacs-lisp-mode-map
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww))) :bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal 'erc (lookup-key emacs-lisp-mode-map (kbd "<f6>"))) (and (equal 'erc (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal 'eww (lookup-key emacs-lisp-mode-map (kbd "<f7>"))))) (equal 'eww (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local emacs-lisp-mode-map (progn (cp-set-keys :keymap emacs-lisp-mode-map
:unset 'unset :unset t
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww))) :bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f6>"))) (and (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal nil (lookup-key emacs-lisp-mode-map (kbd "<f7>"))))) (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local 'local (progn (cp-set-keys :keymap 'local
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww))) :bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal 'erc (lookup-key emacs-lisp-mode-map (kbd "<f6>"))) (and (equal 'erc (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal 'eww (lookup-key emacs-lisp-mode-map (kbd "<f7>"))))) (equal 'eww (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local 'local (progn (cp-set-keys :keymap 'local
:unset 'unset :unset t
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww))) :bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f6>"))) (and (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal nil (lookup-key emacs-lisp-mode-map (kbd "<f7>"))))) (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
;;;; UTF-8 magic ;;;; UTF-8 magic
(setq locale-coding-system 'utf-8) (setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8) (set-terminal-coding-system 'utf-8)
@ -192,7 +194,8 @@ applicable."
(global-unset-key (kbd "<f1> i")) (global-unset-key (kbd "<f1> i"))
(cp-global-set-many-keys (cp-set-keys
:bindings
`((,(kbd "M-<f2>") compile) `((,(kbd "M-<f2>") compile)
(,(kbd "<f2> p") grep) (,(kbd "<f2> p") grep)
(,(kbd "<f2> o") find-grep) (,(kbd "<f2> o") find-grep)
@ -217,8 +220,9 @@ applicable."
(,(kbd "<f1> i e") cp-info-lilyref) (,(kbd "<f1> i e") cp-info-lilyref)
(,(kbd "<f1> i r") cp-info-lilylearn))) (,(kbd "<f1> i r") cp-info-lilylearn)))
(cp-define-many-keys (cp-set-keys
Info-mode-map :keymap Info-mode-map
:bindings
`((,(kbd "b") Info-history-back) `((,(kbd "b") Info-history-back)
(,(kbd "f") Info-history-forward))) (,(kbd "f") Info-history-forward)))
@ -226,7 +230,8 @@ applicable."
;; More convenient Unicode keys ;; More convenient Unicode keys
(global-unset-key (kbd "M-[")) (global-unset-key (kbd "M-["))
(cp-global-set-many-keys (cp-set-keys
:bindings
`((,(kbd "M-[ a") ,(kbd "ä")) `((,(kbd "M-[ a") ,(kbd "ä"))
(,(kbd "M-[ A") ,(kbd "Ä")) (,(kbd "M-[ A") ,(kbd "Ä"))
(,(kbd "M-[ u") ,(kbd "ü")) (,(kbd "M-[ u") ,(kbd "ü"))
@ -286,8 +291,9 @@ applicable."
(global-set-key (kbd "<f5> o") 'org-mode) (global-set-key (kbd "<f5> o") 'org-mode)
;(setq org-M-RET-may-split-line 'nil) ;(setq org-M-RET-may-split-line 'nil)
(add-hook 'org-mode-hook 'org-display-inline-images) (add-hook 'org-mode-hook 'org-display-inline-images)
(cp-define-many-keys (cp-set-keys
org-mode-map :keymap org-mode-map
:bindings
`((,(kbd "C-,") nil) `((,(kbd "C-,") nil)
(,(kbd "M-n") org-metadown) (,(kbd "M-n") org-metadown)
(,(kbd "M-p") org-metaup) (,(kbd "M-p") org-metaup)