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
;; 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-d") cp-adb-pull-and-ediff)))
(defun cp-dired-adb-push-marked ()
(interactive))

View File

@ -12,26 +12,29 @@
(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-set-key (kbd "C-x C-r C-i") 'string-insert-rectangle)
(global-set-key (kbd "C-x C-r C-r") 'replace-rectangle)
(global-set-key (kbd "C-x C-r C-k") 'kill-rectangle)
(cp-set-keys
:bindings
;; 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
;; kill the region if a region is active. The flexibility of those
;; 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"),
;; or delete one or more whole lines (C-1 C-k/"1 k" or C-<num>
;; C-k/"<num> k").
(global-set-key (kbd "C-S-k") 'whole-line-or-region-kill-region)
(global-set-key (kbd "C-,") 'backward-paragraph)
(global-set-key (kbd "C-.") 'forward-paragraph)
(global-set-key (kbd "C-<") 'beginning-of-buffer)
(global-set-key (kbd "C->") 'end-of-buffer)
(global-set-key (kbd "C-;") 'delete-horizontal-space)
;; 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
;; 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"),
;; or delete one or more whole lines (C-1 C-k/"1 k" or C-<num>
;; C-k/"<num> k").
(,(kbd "C-S-k") whole-line-or-region-kill-region)
(,(kbd "C-,") backward-paragraph)
(,(kbd "C-.") forward-paragraph)
(,(kbd "C-<") beginning-of-buffer)
(,(kbd "C->") end-of-buffer)
(,(kbd "C-;") delete-horizontal-space)))
;; 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
@ -74,7 +77,8 @@
;;;; I like the transpose commands
(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-w") transpose-words)
(,(kbd "C-t C-l") transpose-lines)

View File

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

View File

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

View File

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

View File

@ -11,8 +11,9 @@
;; (global-set-key (kbd "C-x C-p") 'paredit-mode)
;; (cp-define-many-keys
;; paredit-mode-map
;; (cp-set-keys
;; :keymap paredit-mode-map
;; :bindings
;; `((,(kbd "C-p") paredit-backward-down)
;; (,(kbd "C-n") paredit-forward-up)
;; (,(kbd "C-b") paredit-backward)
@ -38,8 +39,9 @@
;; (,(kbd "C-h") paredit-backward-delete)
;; (,(kbd "C-w") paredit-backward-kill-word)))
;; (cp-define-many-keys
;; comint-mode-map
;; (cp-set-keys
;; :keymap comint-mode-map
;; :bindings
;; `((,(kbd "C-d") paredit-forward-down)
;; (,(kbd "C-M-p") comint-previous-input)
;; (,(kbd "C-M-n") comint-next-input)))
@ -64,8 +66,9 @@
;; (sp-pair "(" nil :unless '(cp-point-after-colon-p))
;; non-lisp modes
(cp-define-many-keys
smartparens-mode-map
(cp-set-keys
:keymap smartparens-mode-map
:bindings
`((,(kbd ";") sp-comment)
(,(kbd "C-)") sp-forward-slurp-sexp)
(,(kbd "C-(") sp-backward-slurp-sexp)
@ -94,8 +97,9 @@
;; (define-key emacs-lisp-mode-map (kbd "C-n") 'sp-next-sexp)
(defun cp-setup-lisp-keys ()
(cp-define-many-keys
smartparens-mode-map
(cp-set-keys
:keymap smartparens-mode-map
:bindings
`((,(kbd "C-M-b") nil)
(,(kbd "C-M-f") nil)
(,(kbd "C-M-u") nil)
@ -132,8 +136,9 @@
(,(kbd "C-M-u") upcase-word)
(,(kbd "C-M-d") sp-kill-word)))
(cp-define-many-keys
comint-mode-map
(cp-set-keys
:keymap comint-mode-map
:bindings
`((,(kbd "C-d") sp-down-sexp)
(,(kbd "C-M-p") comint-previous-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/")
(defun cp-global-set-many-keys (key-fn-alist)
"A clean way to define many keys using `global-set-key.'
KEY-FN-ALIST must be in the form `((,(kbd \"...\") FN) ...)"
(defun cp-global-set-many-keys (bindings)
"A clean way to define many keys using `global-set-key'.
BINDINGS must be in the form `((,(kbd \"...\") FN) ...)"
(mapc (lambda (b)
(global-set-key (car b) (cadr b)))
key-fn-alist))
bindings))
(defun cp-define-many-keys (keymap key-fn-alist)
"A clean way to define many keys using `define-key.'
(defun cp-define-many-keys (keymap bindings)
"A clean way to define many keys using `define-key'.
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)
(define-key keymap (car b) (cadr b)))
key-fn-alist))
bindings))
(defun cp-local-set-many-keys (key-fn-alist)
"A clean way to define many keys using `local-set-key.'
KEY-FN-ALIST must be in the form `((,(kbd \"...\") FN) ...)"
(defun cp-local-set-many-keys (bindings)
"A clean way to define many keys using `local-set-key'.
BINDINGS must be in the form `((,(kbd \"...\") FN) ...)"
(mapc (lambda (b)
(local-set-key (car b) (cadr b)))
key-fn-alist))
bindings))
(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.
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'.
If it is local, the binding is created by `local-set-key'.
Otherwise, it is assumed to be a keymap and the binding is created
with `define-key'.
If it is a symbol `local', the binding is created by
`local-set-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
by using define-key to set it to nil in the given keymap -
otherwise, global-unset-key or local-unset-key are used as
applicable."
(let ((key-function (if (not unset)
(pcase keymap-or-local
(pcase keymap
((or `global `nil) #'global-set-key)
(`local #'local-set-key)
(x #'define-key))
(pcase keymap-or-local
(pcase keymap
((or `global `nil) #'global-unset-key)
(`local #'local-unset-key)
(x #'define-key)))))
(if (eq key-function 'define-key)
(if unset
(mapc (lambda (b)
(funcall key-function keymap-or-local (car b) nil))
key-fn-alist)
(funcall key-function keymap (car b) nil))
bindings)
(mapc (lambda (b)
(funcall key-function keymap-or-local (car b) (cadr b)))
key-fn-alist))
(funcall key-function keymap (car b) (cadr b)))
bindings))
(if unset
(mapc (lambda (b)
(funcall key-function (car b)))
key-fn-alist)
bindings)
(mapc (lambda (b)
(funcall key-function (car b) (cadr b)))
key-fn-alist)))))
bindings)))))
;; tests
(progn (cp-set-keys :keymap-or-local 'global
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(progn (cp-set-keys :keymap 'global ; not actually needed, e.g. see next call
:bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal 'erc (lookup-key (current-global-map) (kbd "<f6>")))
(equal 'eww (lookup-key (current-global-map) (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local 'global
:unset 'unset
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(progn (cp-set-keys :unset t
:bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal nil (lookup-key (current-global-map) (kbd "<f6>")))
(equal nil (lookup-key (current-global-map) (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local emacs-lisp-mode-map
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(progn (cp-set-keys :keymap emacs-lisp-mode-map
:bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal 'erc (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal 'eww (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local emacs-lisp-mode-map
:unset 'unset
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(progn (cp-set-keys :keymap emacs-lisp-mode-map
:unset t
:bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal nil (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local 'local
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(progn (cp-set-keys :keymap 'local
:bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal 'erc (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal 'eww (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
(progn (cp-set-keys :keymap-or-local 'local
:unset 'unset
:key-fn-alist `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(progn (cp-set-keys :keymap 'local
:unset t
:bindings `((,(kbd "<f6>") erc) (,(kbd "<f7>") eww)))
(and (equal nil (lookup-key emacs-lisp-mode-map (kbd "<f6>")))
(equal nil (lookup-key emacs-lisp-mode-map (kbd "<f7>")))))
;;;; UTF-8 magic
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
@ -192,7 +194,8 @@ applicable."
(global-unset-key (kbd "<f1> i"))
(cp-global-set-many-keys
(cp-set-keys
:bindings
`((,(kbd "M-<f2>") compile)
(,(kbd "<f2> p") grep)
(,(kbd "<f2> o") find-grep)
@ -217,8 +220,9 @@ applicable."
(,(kbd "<f1> i e") cp-info-lilyref)
(,(kbd "<f1> i r") cp-info-lilylearn)))
(cp-define-many-keys
Info-mode-map
(cp-set-keys
:keymap Info-mode-map
:bindings
`((,(kbd "b") Info-history-back)
(,(kbd "f") Info-history-forward)))
@ -226,7 +230,8 @@ applicable."
;; More convenient Unicode keys
(global-unset-key (kbd "M-["))
(cp-global-set-many-keys
(cp-set-keys
:bindings
`((,(kbd "M-[ a") ,(kbd "ä"))
(,(kbd "M-[ A") ,(kbd "Ä"))
(,(kbd "M-[ u") ,(kbd "ü"))
@ -286,8 +291,9 @@ applicable."
(global-set-key (kbd "<f5> o") 'org-mode)
;(setq org-M-RET-may-split-line 'nil)
(add-hook 'org-mode-hook 'org-display-inline-images)
(cp-define-many-keys
org-mode-map
(cp-set-keys
:keymap org-mode-map
:bindings
`((,(kbd "C-,") nil)
(,(kbd "M-n") org-metadown)
(,(kbd "M-p") org-metaup)