From 36559674202c29386b994a2827ba8bfcf48e34ba Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 4 Feb 2013 21:32:40 +0100 Subject: [PATCH] Emacs: AWK snippets. Emacs: my-keys minor more is back and fixed. --- .emacs | 4 +++ .emacs.d/functions.el | 7 ++--- .emacs.d/main.el | 42 ++++++++++++++++--------- .emacs.d/modes.el | 1 - .emacs.d/snippets/awk-mode/.yas-parents | 1 + .emacs.d/snippets/awk-mode/do | 7 +++++ .emacs.d/snippets/awk-mode/else | 7 +++++ .emacs.d/snippets/awk-mode/for | 7 +++++ .emacs.d/snippets/awk-mode/forin | 7 +++++ .emacs.d/snippets/awk-mode/fun | 6 ++++ .emacs.d/snippets/awk-mode/gsub | 4 +++ .emacs.d/snippets/awk-mode/if | 7 +++++ .emacs.d/snippets/awk-mode/printf | 6 ++++ .emacs.d/snippets/awk-mode/while | 7 +++++ 14 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 .emacs.d/snippets/awk-mode/.yas-parents create mode 100644 .emacs.d/snippets/awk-mode/do create mode 100644 .emacs.d/snippets/awk-mode/else create mode 100644 .emacs.d/snippets/awk-mode/for create mode 100644 .emacs.d/snippets/awk-mode/forin create mode 100644 .emacs.d/snippets/awk-mode/fun create mode 100644 .emacs.d/snippets/awk-mode/gsub create mode 100644 .emacs.d/snippets/awk-mode/if create mode 100644 .emacs.d/snippets/awk-mode/printf create mode 100644 .emacs.d/snippets/awk-mode/while diff --git a/.emacs b/.emacs index 442a93c0..34143e29 100644 --- a/.emacs +++ b/.emacs @@ -14,5 +14,9 @@ (load "~/.emacs.d/plugins" nil t) (load "~/.emacs.d/theme" nil t) +;; We need to put it at the end to make sure it doesn't get itself overriden by +;; other minor modes. +(my-keys-minor-mode 1) + ;; End of file diff --git a/.emacs.d/functions.el b/.emacs.d/functions.el index f32be938..417cc0cf 100644 --- a/.emacs.d/functions.el +++ b/.emacs.d/functions.el @@ -54,7 +54,7 @@ frames with exactly two windows." (select-window first-win) (if this-win-2nd (other-window 1)))))) -(global-set-key [(control c) (|)] 'my-toggle-window-split) +(define-key my-keys-minor-mode-map [(control c) (|)] 'my-toggle-window-split) ;;============================================================================== ;; Duplicate line @@ -95,7 +95,7 @@ frames with exactly two windows." (next-line arg)) ;; Binding. -(global-set-key (kbd "C-c C-d") 'duplicate-line) +(define-key my-keys-minor-mode-map (kbd "C-c C-d") 'duplicate-line) ;;============================================================================== ;; Comment DWIM -- toggle comment line @@ -117,5 +117,4 @@ the line." (comment-dwim arg))) ;; Binding. -;; TODO: global key ? -(global-set-key "\M-;" 'comment-dwim-line) +(define-key my-keys-minor-mode-map "\M-;" 'comment-dwim-line) diff --git a/.emacs.d/main.el b/.emacs.d/main.el index 279c3318..847bbe82 100644 --- a/.emacs.d/main.el +++ b/.emacs.d/main.el @@ -2,6 +2,18 @@ ;; MAIN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; We use a minor mode to override global keys.To assign +;; global keys, you need to write +;; (define-key my-keys-minor-mode-map (kbd "C-i") 'some-function) +(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.") + +(define-minor-mode my-keys-minor-mode + "A minor mode so that my key settings override annoying major modes." + t " my-keys" 'my-keys-minor-mode-map) + +(add-hook 'minibuffer-setup-hook (lambda () (my-keys-minor-mode 0) ) ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Make questions less annoying (defalias 'yes-or-no-p 'y-or-n-p) @@ -12,22 +24,22 @@ (setq kill-whole-line t) ;; Modern scrolling -(global-set-key [next] - (lambda () (interactive) - (condition-case nil (scroll-up) - (end-of-buffer (goto-char (point-max)))))) +(define-key my-keys-minor-mode-map [next] + (lambda () (interactive) + (condition-case nil (scroll-up) + (end-of-buffer (goto-char (point-max)))))) -(global-set-key [prior] - (lambda () (interactive) - (condition-case nil (scroll-down) - (beginning-of-buffer (goto-char (point-min)))))) +(define-key my-keys-minor-mode-map [prior] + (lambda () (interactive) + (condition-case nil (scroll-down) + (beginning-of-buffer (goto-char (point-min)))))) ;; Line numbers (autoload 'linum-mode "linum" "toggle line numbers on/off" t) ;; (setq linum-format "%-4d ") (setq linum-format "%d ") (global-linum-mode 1) ;; FIXME: This may generate warnings with emacsclient. Bug? -(global-set-key (kbd "C-") 'linum-mode) ;; Toggle line numbers. +(define-key my-keys-minor-mode-map (kbd "C-") 'linum-mode) ;; Toggle line numbers. ;; Indentation ;(setq standard-indent 4) @@ -100,16 +112,16 @@ browse-url-browser-function 'browse-url-generic) ;; Window resize ;; TODO: Use more { and } to continue. -(global-set-key (kbd "C-x {") (lambda () (interactive) (shrink-window-horizontally 5))) -(global-set-key (kbd "C-x }") (lambda () (interactive) (enlarge-window-horizontally 5))) +(define-key my-keys-minor-mode-map (kbd "C-x {") (lambda () (interactive) (shrink-window-horizontally 5))) +(define-key my-keys-minor-mode-map (kbd "C-x }") (lambda () (interactive) (enlarge-window-horizontally 5))) ;; (define-key my-keys-minor-mode-map (kbd "S-C-") 'shrink-window) ;; (define-key my-keys-minor-mode-map (kbd "S-C-") 'enlarge-window) ;; Copy/Paste to/from clipboard. ;; FIXME: copying does not work. -(global-set-key (kbd "C-") (kbd "M-| xclip")) -(global-set-key (kbd "C-") (kbd "C-u M-! xclip -o")) -(global-set-key (kbd "C-") (kbd "C-u M-! xclip -o -selection clipboard")) +(define-key my-keys-minor-mode-map (kbd "C-") (kbd "M-| xclip")) +(define-key my-keys-minor-mode-map (kbd "C-") (kbd "C-u M-! xclip -o")) +(define-key my-keys-minor-mode-map (kbd "C-") (kbd "C-u M-! xclip -o -selection clipboard")) ;; query-replace-regex fix on terminals. -(global-set-key (kbd "C-M-y") 'query-replace-regexp) +(define-key my-keys-minor-mode-map (kbd "C-M-y") 'query-replace-regexp) diff --git a/.emacs.d/modes.el b/.emacs.d/modes.el index 3bbe2d9b..0c4f81f7 100644 --- a/.emacs.d/modes.el +++ b/.emacs.d/modes.el @@ -365,7 +365,6 @@ properly escaped with double-quotes in case it has spaces." ) (setq compilation-scroll-output t) (local-set-key "\C-c\C-c" 'python-my-compile) - (local-set-key "\C-c\C-d" 'duplicate-line) ) ) diff --git a/.emacs.d/snippets/awk-mode/.yas-parents b/.emacs.d/snippets/awk-mode/.yas-parents new file mode 100644 index 00000000..eed5b442 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/.yas-parents @@ -0,0 +1 @@ +text-mode diff --git a/.emacs.d/snippets/awk-mode/do b/.emacs.d/snippets/awk-mode/do new file mode 100644 index 00000000..7629765d --- /dev/null +++ b/.emacs.d/snippets/awk-mode/do @@ -0,0 +1,7 @@ +# name: do { ... } while (...) +# key: do +# -- +do +{ + $0 +} while (${1:condition}) \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/else b/.emacs.d/snippets/awk-mode/else new file mode 100644 index 00000000..032f0ab2 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/else @@ -0,0 +1,7 @@ +# name: else { ... } +# key: else +# -- +else +{ + $0 +} \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/for b/.emacs.d/snippets/awk-mode/for new file mode 100644 index 00000000..69127fa5 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/for @@ -0,0 +1,7 @@ +# name: for (...; ...; ...) { ... } +# key: for +# -- +for (${1:i = 0}; ${2:i < NF}; ${3:i++}) +{ + $0 +} \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/forin b/.emacs.d/snippets/awk-mode/forin new file mode 100644 index 00000000..76d28f28 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/forin @@ -0,0 +1,7 @@ +# name: for ( var in array ) statement +# key: forin +# -- +for ( ${1:var} in ${2:array}) +{ + $0 +} \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/fun b/.emacs.d/snippets/awk-mode/fun new file mode 100644 index 00000000..436755d3 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/fun @@ -0,0 +1,6 @@ +#name : type fun (args) { ... } +# -- +${1:name} (${2:args}) +{ + $0 +} \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/gsub b/.emacs.d/snippets/awk-mode/gsub new file mode 100644 index 00000000..55973659 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/gsub @@ -0,0 +1,4 @@ +# -*- mode: snippet -*- +# key: gsub +# -- +gsub ("${1:regex}" , "${2:subs}"${3:, s}) \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/if b/.emacs.d/snippets/awk-mode/if new file mode 100644 index 00000000..5c6a1210 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/if @@ -0,0 +1,7 @@ +# name: if (...) { ... } +# key: if +# -- +if (${1:condition}) +{ + $0 +} \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/printf b/.emacs.d/snippets/awk-mode/printf new file mode 100644 index 00000000..e7d93d86 --- /dev/null +++ b/.emacs.d/snippets/awk-mode/printf @@ -0,0 +1,6 @@ +# -*- mode: snippet -*- +# name: printf +# contributor: joaotavora +# key: printf +# -- +printf ("${1:%s}\\n"${1:$(if (string-match "%" text) "," "\)")}$2${1:$(if (string-match "%" text) "\)" "")} \ No newline at end of file diff --git a/.emacs.d/snippets/awk-mode/while b/.emacs.d/snippets/awk-mode/while new file mode 100644 index 00000000..398c6d2b --- /dev/null +++ b/.emacs.d/snippets/awk-mode/while @@ -0,0 +1,7 @@ +# name : while (...) { ... } +# key: while +# -- +while (${1:condition}) +{ + $0 +} \ No newline at end of file