From: Ian Kelling Date: Mon, 24 Jun 2019 01:58:00 +0000 (-0400) Subject: ditch org for init, various improvements X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=87395fc29e64efbbef5c52bb0ac905cea46e6698;p=dot-emacs ditch org for init, various improvements --- diff --git a/dev.org b/dev.org deleted file mode 100644 index 75c5e45..0000000 --- a/dev.org +++ /dev/null @@ -1,36 +0,0 @@ -Things in development in this separate file, because -we recompile / reparse my-init.org whenever it changes, -and since it's pretty big, it's a bit annoying. - -We need at least one of these, even a blank one to avoid error on startup. -#+begin_src emacs-lisp -(ivy-mode 1) -(add-hook 'text-mode-hook (lambda () (auto-fill-mode t))) -(require 'counsel) -(setq counsel-find-file-at-point t) -#+end_src - - -#+begin_src sh -;; M-3 = test key -(global-set-key (kbd "M-3") 'my-as-off) -(setq x 5) - -#+end_src - -* ido -#+begin_src emacs-lisp -(require 'ido) -;; easier to read with just spaces as separator -(setf (nth 2 ido-decorations) " ") -;; note, at one point I liked this, but I don't now. -;;(setq ido-max-prospects 20) - -;; using counsel/ivy instead -;;(ido-mode t) -;; sets read-file-name-function, and read-buffer-function to ido. -;; searching through the emacs source code, it seems this is used -;; very few if any places. -;;(ido-everywhere t) - -#+end_src diff --git a/init-notes.org b/ian-notes.org similarity index 75% rename from init-notes.org rename to ian-notes.org index af7bad9..e976bac 100644 --- a/init-notes.org +++ b/ian-notes.org @@ -1,3 +1,6 @@ +#+title: My Personal Init Customization +#+OPTIONS: toc:nil num:nil ^:nil + * python disabled due to long load time todo: get smart-operator to work todo, checkout https://github.com/python-rope/ropemacs refactoring python, @@ -1503,3 +1506,389 @@ web-mode is competing package and actively developed, so i'm using that instead resizing a window horizontally with the mouse should be allowed in more places * TODO try using / making abbreviations + +* TODO move over to ivy, ditch ido + +* key binds. keep at end of file +this should come at the end because it depends on key maps being +created in earlier sections. + +** emacs keys notes +commands not needed in ido mode and their replacement in ido mode +spell check fix -> use current pattern and start new one +narrow -> create subdirectory +org-cycle -> M-s search recently used directory +vert split Window -> create file instead of select match +delete-other-windows -> open dired buffer +delete current window -> delete buffer/file +find file -> search within all subdirectories + +forward/back error + +buffer select -> toggle find file / buffer +up/down -> next/previous history +forward/back -> ido-forward/back + + +right keyboard attributes: movement, involve typing words +left keyboard attributes: non-typing universal non-movement + + + + +todo +fix global unpop mark ring +setup helm +learn cedet and projectile and helm +setup key for pop-global-mark +try out C-M-\ indent region +set quoted insert to some obscure keybind +make currently overrided M-u uppercase word into something obscure +remember mode +bind shell-command to something better +investigate tags +investigate keys in isearch mode and find file mode +try out occur. M-s o +investigate programming modes. M-g n/b next/previous error. gdb? +investigate org mode keys +learn version control +learn mail +check out imenu +bind capitalize-word to something obscure +sentance/paragraph movement/marking should be swapped with sexp/paren movement based on mode +bind fill-paragraph to something obscure +setup linewise paste +install magit (git control) +magpie expansion provides a completion key for acronym expansion based on buffer text +learn ediff +universal google +figure out auto-indent +learn eshell and prelude settings for it +combine register prefix and c-x prefix +note: remember to think of mouse & foot pedals +commands to change: select other window: C-x o. + +** named commands +*** gdb +gdb-many-windows +*** tramp sudo +/ssh:host|sudo:host: +when in the same session, you can then do: +/sudo:root@host: + +*** org insert table row +[org-shiftmetadown/up] +*** toggle line continuation / truncation / wrap + toggle-truncate-lines +*** auto-save on/off + my-as-on/my-as-off +*** toggle menu bar +menu-bar-mode +*** show abbreviations +list-abbrevs + +*** rename-file-and-buffer +*** ediff-buffers +*** refill-mode +automatically balance a paragraph with newlines +*** executable-make-buffer-file-executable-if-script-p +make a script executable +*** (setq lazy-highlight-cleanup nil) +keep search highlight on after search is done +*** auto-revert-tail-mode +tail a file +*** what-line +*** linum-mode +line numbers + +*** sgml-pretty-print +format xml in nxml-mode +*** visual-line-mode +toggle word wrap. +** compound commands +*** C-xc +exit0 +*** C-x s +save file +*** C-x e +eval last sexp +*** C-c - +[org insert table horizontal line or create list] +*** C-x tab +indent/dedent region + +*** C-x * +[calc-dispatch] +*** C-x = +[point information] +*** C-x d +[dired] +*** C-xb +[ibuffer] + +*** C-x r c +rectangular clear, replace area with whitespace +** gnus +searching overview. +3 types: +ingroup searching +nnir searching with notmuch, specific group (not sure if it can do multiple) +search all groups with mairix +*** a] +compose new message +*** C-c C-c] +send message +*** s] +save newsrc file, alterations to groups. +*** g] +gnus refresh / get new +*** m] +gnus new message +*** F] +gnus quoted reply all +*** e] +gnus draft edit message +*** delete] +gnus delete draft +#+begin_src emacs-lisp +(add-hook 'gnus-startup-hook + (lambda () + (define-key gnus-summary-mode-map (kbd "") 'gnus-summary-delete-article))) +#+end_src + +*** b] +mairix search +#+begin_src emacs-lisp +(add-hook 'gnus-startup-hook + (lambda () + (define-key gnus-group-mode-map "b" 'nnmairix-search) + (define-key gnus-summary-mode-map "b" 'nnmairix-search))) +#+end_src +*** B m] +move message, or messages in region +*** #] +mark article, move with B m +*** B delete] +gnus delete draft +*** / plus x a / b] +search current group (or see info manual for more groups), +using the gnus native search (its slow, do a notmuch or mairix search instead) +x= extra (ie. to) +todo; send in patch to make author search to in sent folder +a = author +/ = subject +b = body +see C-h m for a full list +*** G G ] +do a nnir notmuch search, for the group on the current line +*** A T ] +jump to thread from nnir group + +*** marks] +! = saved for later +E = expired +M-& apply process mark to a non-process mark command +*** S D e] +edit as new +*** T k / C-M-k +maybe rebind this to a shorter keybind, like del +gnus-summary-kill-thread +** message mode +*** C-ck] +discard message +** notmuch +*** space] +notmuch advance to next message/thread + +** readline / bash / .inputrc +*** C-m +[--------] +terminal crap, duplicate of enter + +** isearch +*** C-w +paste word/char under cursor into isearch +*** M-n/p +next/previous isearch history +*** C-o +*** m-r + +** icomplete +*** C-. C-, +icomplete-forward/backward-completions + +** info +*** [, ] +forward / previous node, descend/ascend tree as needed +*** x +Info-follow-nearest-node + +m, f, n, p or ^ command, depending on where you click. +** auto-complete +*** S-return +select next completion candidate +ac-expand +** agenda +*** t] +agenda cycle todo state +** org +*** C-c / t] +make just todo items visible +*** S- +org-shifttab global visibility cycle / move table cell +*** C-cs] +schedule todo item +*** C-cx p] +org set property +*** C-c -] +org insert horizontal line +*** C-cq] + org tag +** calc +i'd like to drill these sometime when I have space in my head, or I +plan to use calc. +*** space +[enter input to the stack, or duplicate top stack item] +*** C-M-i +[cycle 3 elements on stack] +*** tab +[cycle 2 elements on stack] +*** n +[negate] +*** _ +[begin negative number] +*** / +[reciprocal] +*** x +[calc named command] +*** M-delete +[delete 2nd from top of stack] +*** C-u [-]0-9 +[0=whole stack, 1-9=that many, -1-9=that element] +*** delete +[remove from the top of the stack] +*** ' +[algebraic mode. infix expressions are calculated when input to the stack] +*** m a +[auto algebraic mode] +*** $,$$,$$$ +[top x of stack reference] +*** s s/t/r/u +[store to variable: store, top, retrieve, unstore. the quick variables 0-9 don't need s prefix] +*** U/D +[undo/redo] +*** t p/n/]/y +[trail prev/next/end/yankh] +*** ` +[calc edit mode, to edit the top of stack] + +* keybind tables + + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | left primary | C- | M- | C-M- | C-S- | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | 2 | copy-symbol | shell-cd-to-file | --- | | + | 3 | dot-mode-execute | | recenter-top-bottom | | + | q | org-cycle, comint previous arg | org-archive-to-archive-sibling | quoted-insert | | + | w | goto-t.org | org-clock-in | | | + | e | copy-line | org-clock-in-last | | | + | r | isearch-backward | org-clock-out | | | + | a | copy-all | | | | + | s | C-x prefix | | split-window-vertically | | + | d | C-c prefix | | swap buffer | | + | f | kill-whole-line | print-var-at-point | kill rest of line | | + | g | other-window / cancel | abort-recursive-edit | gnus | | + | z | undo-tree-undo | | | | + | x | kill-region | append-next-kill | append-next-kill | | + | c | copy | org-capture | copy-to-register | | + | v | yank | insert-register | yank pop | | + | b | delete-other-windows | isearch-backward-current-symbol | isearch-current-symbol | | + | tab | yas-insert-snippet | indent line | | | + | delete | kill-symbol | | kill-sexp | | + | left-arrow | compile | | org-shiftup | | + | right-arrow | paste selection | | org-shiftdown | | + | backspace | backward-kill-symbol | | backward-kill-sexp | | + | f7 | | | | | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | right primary | C- | M- | C-M- | C-S- | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | * | split-window-horizontally | | calc-dispatch | | + | 9 | delete-window-or-exit | kill-buffer-and-window | kill client buffer | | + | u | universal-argument | | search-keybind | | + | i | ----- | | query-replace-regexp | | + | o | occur | | counsel-imenu | | + | p | move-mouse-to-point | | delete-horizontal-space | | + | j | pop-to-mark | previous-error | register prefix | | + | k | jump to register | next-error | man | | + | l | ivy-switch-buffer | | move cursor top bottom mid | | + | ; | comment-dwim | comment-dwim | comment-current-line-dwim | | + | m | | | recursive grep | | + | , | counsel-find-file | | find-file-in-project | | + | . | recentf-ido-find-file | | - | | + | / | join lines | | copy-variable | | + | 8 | calc-embedded-word | | | | + | up-arrow | back defun/headline | | | winner undo | + | down-arrow | forward dfun/headline | | toggle-mark-activation | smex-major-mode-commands | + | lbracket | ---- | | scroll-right | | + | rbracket | fill-paragraph | | scroll-left | | + | return | newline next line | non-indented newline | open newline on previous line | | + | space | org-edit-special | | spell check word | | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | left secondary | C- | M- | C-M- | C-S- | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | = | | | | | + | 1 | | | | | + | 4 | | | widen | | + | 5 | | | | | + | tab-key | query-replace | | | | + | t | org change todo state | | org insert timestamp | | + | home | start of buffer | | | | + | end | end of buffer | | | | + | f9 | | | | | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | right secondary | C- | M- | C-M- | C-S- | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + | 6 | save-buffers-kill-emacs | | insert-small-copyright | | + | 7 | | | insert-full-copyright | | + | 0 | text-scale-reset | | insert-apache | | + | - | | | org-edit-src-exit | | + | y | undo-tree-redo | | | | + | \ | sr-speedbar-toggle | | mark-defun | | + | h | help-prefix | | | | + | ' | eval-expression | | | | + | n | unpop-to-mark-command | | narrow-to-region | | + | rshift | | | | | + | escape | find-tag | | | | + |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| + +* keybind notes +common keys, which would be better off doing swaps than rebinds: +c-x prefix -> c-s +c-c prefix -> c-d +yank c-y -> c-c +search c-s -> kp-add +kill line c-k -> c-f +undo c-_ -> c-z +set-mark-command c-@ -> kp-enter +quoted-insert c-q -> c-m-q +recenter-top-bottom c-l -> c-m-3 +kill-region c-w -> c-x + +commands to make less accessible +narrow-to-defun/subtree -> M-2 maybe +occur + +command to make more accessible, ... + + +* TESTING / DEVELOPMENT AREA + +(defun comint-send-string (process string) + "Like `process-send-string', but also does extra bookkeeping for Comint mode." + (if process + (with-current-buffer (if (processp process) + (process-buffer process) + (get-buffer process)) + (comint-snapshot-last-prompt)) + (comint-snapshot-last-prompt)) + (process-send-string process string)) diff --git a/init.el b/init.el index f83922d..43384fe 100644 --- a/init.el +++ b/init.el @@ -70,26 +70,13 @@ ;; todo, set this var in my-init.org and use it instead ;; of .emacs.d (setq init-dir ,(file-name-directory load-file-name)) + ;; previously, i was doing byte-recompile-directory, but + ;; now i just have one init file (unless (equal (user-uid) 0) ; don't make root owned files - (byte-recompile-directory init-dir)) - ;; (byte-recompile-directory init-dir 0) ; with the 0, - ;; compile .el files that have no .elc file already - - ;; this must be loaded first to avoid an error: void-function(cl-member) - (require 'cl) - ;; added org-habit, org-drill, org-mobile from the defaults - ;; disabled because I'm not using org-drill, and I see - ;; this error on startup of emacs server, - ;; which might be nothing but meh, - ;; File mode specification error: (void-function org-drill-add-cloze-fontification) - - (require 'org) - ;; (setq org-modules (quote (org-bbdb org-bibtex org-docview org-gnus - ;; org-info org-jsinfo org-irc org-mew - ;; org-mhe org-rmail org-vm org-wl org-w3m - ;; org-habit org-drill org-mobile))) + (byte-recompile-file (concat init-dir "myinit.el"))) + (load-file (expand-file-name "myinit.el" init-dir)) - (org-babel-load-file (expand-file-name "my-init.org" init-dir)) - (org-babel-load-file (expand-file-name "dev.org" init-dir)))) + + )) ;;init.el ends here diff --git a/my-init.org b/my-init.org deleted file mode 100644 index 12a02fc..0000000 --- a/my-init.org +++ /dev/null @@ -1,2411 +0,0 @@ -#+title: My Personal Init Customization -#+OPTIONS: toc:nil num:nil ^:nil - - - -* key binds. keep at end of file -this should come at the end because it depends on key maps being -created in earlier sections. - -** emacs keys notes -commands not needed in ido mode and their replacement in ido mode -spell check fix -> use current pattern and start new one -narrow -> create subdirectory -org-cycle -> M-s search recently used directory -vert split Window -> create file instead of select match -delete-other-windows -> open dired buffer -delete current window -> delete buffer/file -find file -> search within all subdirectories - -forward/back error - -buffer select -> toggle find file / buffer -up/down -> next/previous history -forward/back -> ido-forward/back - - -right keyboard attributes: movement, involve typing words -left keyboard attributes: non-typing universal non-movement - - - - -todo -fix global unpop mark ring -setup helm -learn cedet and projectile and helm -setup key for pop-global-mark -try out C-M-\ indent region -set quoted insert to some obscure keybind -make currently overrided M-u uppercase word into something obscure -remember mode -bind shell-command to something better -investigate tags -investigate keys in isearch mode and find file mode -try out occur. M-s o -investigate programming modes. M-g n/b next/previous error. gdb? -investigate org mode keys -learn version control -learn mail -check out imenu -bind capitalize-word to something obscure -sentance/paragraph movement/marking should be swapped with sexp/paren movement based on mode -bind fill-paragraph to something obscure -setup linewise paste -install magit (git control) -magpie expansion provides a completion key for acronym expansion based on buffer text -learn ediff -universal google -figure out auto-indent -learn eshell and prelude settings for it -combine register prefix and c-x prefix -note: remember to think of mouse & foot pedals -commands to change: select other window: C-x o. -** prefix keybind changes -#+begin_src emacs-lisp - - - ; prefix key binds. - ; good info http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/ - ; rebinding the prefix keys are tricky. apparently, some modes ignore any redefinition of a prefix key and use it explicitly, - ; so you have to dig into their key maps and redo things. - ; There are 2 simpler alternatives which have their own downsides. - ; One is cua mode, which I do not like because it smashes 2 keybinds onto 1 and limits what you can do. - ; The other is keyboard-translate, which translates the key presses before anything else. - ; The downside is that it translates them when you aren't using them as a prefix. - ; Since the swaps I'm using are all very accessible, the only downside is some mental jugling when reading docs etc about these keybinds. - - ; I've seen this as an another suggestion, it was a total fail. The prefix command took over both keys. - ; (define-key key-translation-map [f12] "\C-c") - ; (define-key key-translation-map "\C-c" [left]) - - - ;idea to remove the hook later since it is only needed at startup. - ; did not work however, and there is not a real need to fix it, so I did not investigate - ;(defun removeSwapHook () - ; (remove-hook 'buffer-list-update-hook 'myKeySwap) - ; (remove-hook 'change-major-mode-hook 'removeSwapHook)) - ;(add-hook 'change-major-mode-hook 'removeSwapHook) - - - ; went through almost all the relevant standard hooks, - ; this overcomes a known bug that (keyboard-translate) does not get applied when running emacs daemon - (add-hook 'buffer-list-update-hook (lambda () (interactive) - (keyboard-translate ?\C-x ?\C-s) - (keyboard-translate ?\C-s ?\C-x) - (keyboard-translate ?\C-c ?\C-d) - (keyboard-translate ?\C-d ?\C-c))) - - - - ; these all don't work - ; don't know why this doesn't error but reversing the keys does - ;(keyboard-translate ?\t ?\M-\t) - ;(keyboard-translate [M-tab] [tab]) - ; from what i can tell, it wants to use a keyboard-translate-table, - ; which is a char table, which is a vector indexed by chars, - ; and mod+tab is not a char (it has too many bits), it is an integer - ; it actually says it can hold vectors or strings, but that it is obsolete to do so - ;(characterp ?\M-a) - ;(characterp ?\C-a) - - - -#+end_src - -** named commands -*** gdb -gdb-many-windows -*** tramp sudo -/ssh:host|sudo:host: -when in the same session, you can then do: -/sudo:root@host: - -*** org insert table row -[org-shiftmetadown/up] -*** toggle line continuation / truncation / wrap - toggle-truncate-lines -*** auto-save on/off - my-as-on/my-as-off -*** toggle menu bar -menu-bar-mode -*** show abbreviations -list-abbrevs - -*** rename-file-and-buffer -*** ediff-buffers -*** refill-mode -automatically balance a paragraph with newlines -*** executable-make-buffer-file-executable-if-script-p -make a script executable -*** (setq lazy-highlight-cleanup nil) -keep search highlight on after search is done -*** auto-revert-tail-mode -tail a file -*** trash-file-and-buffer -#+begin_src emacs-lisp -(defun trash-file-and-buffer () - "Removes file connected to current buffer and kills buffer." - (interactive) - (let ((filename (buffer-file-name)) - (buffer (current-buffer)) - (name (buffer-name))) - (if (not (and filename (file-exists-p filename))) - (error "Buffer '%s' is not visiting a file!" name) - (delete-file filename) - (kill-buffer buffer) - (message "File '%s' successfully removed" filename)))) - -#+end_src -*** what-line -*** linum-mode -line numbers - -*** sgml-pretty-print -format xml in nxml-mode -*** visual-line-mode -toggle word wrap. -** compound commands -*** C-xc -exit0 -*** C-x s -save file -*** C-x e -eval last sexp -*** C-x u -[undo-tree-visualize] -*** C-j u/U -[undo-tree save/restore state via register] -*** C-c - -[org insert table horizontal line or create list] -*** C-x tab -indent/dedent region - -[shift-left and shift-right are default for indenting by tab stop, -and they are only defined as lambdas so I copy them here -to use with up and down. -#+begin_src emacs-lisp -;; condition cuz emacs24 release doesn't have this yet -(when (boundp 'indent-rigidly-map) - (define-key indent-rigidly-map (kbd "") - (lambda (beg end) (interactive "r") - (let* ((current (indent-rigidly--current-indentation beg end)) - (next (indent--next-tab-stop current))) - (indent-rigidly beg end (- next current))))) - - (define-key indent-rigidly-map (kbd "") - (lambda (beg end) (interactive "r") - (let* ((current (indent-rigidly--current-indentation beg end)) - (next (indent--next-tab-stop current 'prev))) - (indent-rigidly beg end (- next current)))))) -#+end_src -*** C-x * -[calc-dispatch] -*** C-x = -[point information] -*** C-x d -[dired] -*** C-xb -[ibuffer] -#+begin_src emacs-lisp - (global-set-key (kbd "C-x C-b") 'ibuffer) -#+end_src - -*** C-x r c -rectangular clear, replace area with whitespace -** gnus -searching overview. -3 types: -ingroup searching -nnir searching with notmuch, specific group (not sure if it can do multiple) -search all groups with mairix -*** a] -compose new message -*** C-c C-c] -send message -*** s] -save newsrc file, alterations to groups. -*** g] -gnus refresh / get new -*** m] -gnus new message -*** F] -gnus quoted reply all -*** e] -gnus draft edit message -*** delete] -gnus delete draft -#+begin_src emacs-lisp -(add-hook 'gnus-startup-hook - (lambda () - (define-key gnus-summary-mode-map (kbd "") 'gnus-summary-delete-article))) -#+end_src - -*** b] -mairix search -#+begin_src emacs-lisp -(add-hook 'gnus-startup-hook - (lambda () - (define-key gnus-group-mode-map "b" 'nnmairix-search) - (define-key gnus-summary-mode-map "b" 'nnmairix-search))) -#+end_src -*** B m] -move message, or messages in region -*** #] -mark article, move with B m -*** B delete] -gnus delete draft -*** / plus x a / b] -search current group (or see info manual for more groups), -using the gnus native search (its slow, do a notmuch or mairix search instead) -x= extra (ie. to) -todo; send in patch to make author search to in sent folder -a = author -/ = subject -b = body -see C-h m for a full list -*** G G ] -do a nnir notmuch search, for the group on the current line -*** A T ] -jump to thread from nnir group - -*** marks] -! = saved for later -E = expired -M-& apply process mark to a non-process mark command -*** S D e] -edit as new -*** T k / C-M-k -maybe rebind this to a shorter keybind, like del -gnus-summary-kill-thread -** message mode -*** C-ck] -discard message -** notmuch -*** space] -notmuch advance to next message/thread - -** readline / bash / .inputrc -*** C-m -[--------] -#+begin_src emacs-lisp -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map "\C-m" nil))) -#+end_src -terminal crap, duplicate of enter - -** isearch -*** C-w -paste word/char under cursor into isearch -*** M-n/p -next/previous isearch history -*** C-o -isearch-occur - Activate occur easily inside isearch - from starter-kit -#+begin_src emacs-lisp -(define-key isearch-mode-map (kbd "C-o") - (lambda () (interactive) - (let ((case-fold-search isearch-case-fold-search)) - (occur (if isearch-regexp - isearch-string - (regexp-quote isearch-string)))))) -#+end_src -*** m-r -#+begin_src emacs-lisp -(defun my-isearch-toggle-regexp () - (interactive) - (isearch-toggle-regexp) - (cond (isearch-regexp - (global-set-key (kbd "C-r") 'isearch-backward-regexp) - (define-key global-map (kbd "") 'isearch-forward-regexp) - (define-key global-map (kbd "") 'isearch-forward-regexp)) - (t - (global-set-key (kbd "C-r") 'isearch-backward) - (define-key global-map (kbd "") 'isearch-forward) - (define-key global-map (kbd "") 'isearch-forward)))) -(define-key isearch-mode-map (kbd "M-r") 'my-isearch-toggle-regexp) - #+end_src - -** icomplete -*** C-. C-, -icomplete-forward/backward-completions - -** info -*** [, ] -forward / previous node, descend/ascend tree as needed -*** x -Info-follow-nearest-node -#+begin_src emacs-lisp -(define-key Info-mode-map "x" 'Info-follow-nearest-node) -#+end_src -m, f, n, p or ^ command, depending on where you click. -** auto-complete -*** S-return -select next completion candidate -ac-expand -** agenda -*** t] -agenda cycle todo state -** org -*** C-c / t] -make just todo items visible -*** S- -org-shifttab global visibility cycle / move table cell -*** C-cs] -schedule todo item -*** C-cx p] -org set property -*** C-c -] -org insert horizontal line -*** C-cq] - org tag -** calc -i'd like to drill these sometime when I have space in my head, or I -plan to use calc. -*** space -[enter input to the stack, or duplicate top stack item] -*** C-M-i -[cycle 3 elements on stack] -*** tab -[cycle 2 elements on stack] -*** n -[negate] -*** _ -[begin negative number] -*** / -[reciprocal] -*** x -[calc named command] -*** M-delete -[delete 2nd from top of stack] -*** C-u [-]0-9 -[0=whole stack, 1-9=that many, -1-9=that element] -*** delete -[remove from the top of the stack] -*** ' -[algebraic mode. infix expressions are calculated when input to the stack] -*** m a -[auto algebraic mode] -*** $,$$,$$$ -[top x of stack reference] -*** s s/t/r/u -[store to variable: store, top, retrieve, unstore. the quick variables 0-9 don't need s prefix] -*** U/D -[undo/redo] -*** t p/n/]/y -[trail prev/next/end/yankh] -*** ` -[calc edit mode, to edit the top of stack] - -** single/special keys -*** tab -isearch -#+begin_src emacs-lisp -(define-key isearch-mode-map (kbd "") 'isearch-query-replace) -#+end_src -*** f12 -isearch-forward -#+begin_src emacs-lisp -;; explained in http://stackoverflow.com/questions/7411920/how-to-bind-search-and-search-repeat-to-c-f-in-emacs -(global-set-key (kbd "") 'isearch-forward) -(global-set-key (kbd "") 'isearch-forward) -(define-key isearch-mode-map "\t" nil) -(define-key isearch-mode-map (kbd "") 'isearch-repeat-forward) -(define-key isearch-mode-map (kbd "") 'isearch-repeat-forward) -;; get rid of the standard completion binding, always use auto-complete -;; this didn't work very well -;;(global-set-key (kbd "TAB") 'auto-complete) -(define-key global-map [remap completion-at-point] 'auto-complete) - -#+end_src - -*** end - move-end-of-line -#+begin_src emacs-lisp -;; taken from emacs wiki, along with home function -;; http://www.emacswiki.org/emacs/BackToIndentationOrBeginning -(defun point-in-comment () - "Determine if the point is inside a comment" - (interactive) - (let ((syn (syntax-ppss))) - (and (nth 8 syn) - (not (nth 3 syn))))) -(defun end-of-code-or-line (arg) - "Move to end of line, or before start of comments depending on situation. - Toggle back and forth positions if we are already at one. - Comments are recognized in any mode that sets syntax-ppss - properly." - (interactive "P") - (when (catch 'bol - (let ((start (point)) - (bol (save-excursion - (beginning-of-line) - (point))) - (eol (progn (move-end-of-line arg) (point)))) - (while (point-in-comment) - (backward-char) - (when (= (point) bol) - (throw 'bol t))) - (throw 'bol (and (not (= eol start)) (>= start (point)))))) - (move-end-of-line arg))) - -(global-set-key (kbd "") 'end-of-code-or-line)(add-hook 'org-mode-hook (lambda () (define-key org-mode-map (kbd "") 'org-end-of-line))) -#+end_src - -*** home -back-to-indentation -#+begin_src emacs-lisp - (defun back-to-indentation-or-beginning () - (interactive) - (if (= (point) (progn (back-to-indentation) (point))) - (if (derived-mode-p 'org-mode) - (org-beginning-of-line) - (beginning-of-line)))) - (global-set-key (kbd "") 'back-to-indentation-or-beginning) - -#+end_src - -*** s-tab -indent-buffer -#+begin_src emacs-lisp -(global-set-key (kbd "") 'indent-buffer) -#+end_src -*** s-delete -send-shell -#+begin_src emacs-lisp - -(global-set-key (kbd "") 'send-shell) - -;; optional variables used by send-shell -(setq shell-send-yank-key nil) - -(defun repeat-shell () - (interactive) - "Repeat the last command in shell-mode, displaying the window if needed." - (let ((shell-buffer (get-buffer "*shell*"))) - (if shell-buffer - (buffer-window-show shell-buffer) - (let ((original-buffer (current-buffer))) - (funcall 'shell) - (setq shell-buffer (current-buffer)) - (switch-to-buffer original-buffer))) - (with-current-buffer shell-buffer - (goto-char (point-max)) - (call-interactively 'comint-previous-input) - ;; the t flag makes the buffer advance - (comint-send-input nil t)))) - -(setq compilation-filenames '("Makefile" "makefile")) - -(defun get-nearest-compilation-file () - "Search for the compilation file traversing up the directory tree." - (interactive) - (let ((dir default-directory) - (parent-dir (file-name-directory (directory-file-name default-directory))) - (nearest-compilation-file 'nil)) - (while (and (not (string= dir parent-dir)) - (not nearest-compilation-file)) - (dolist (filename compilation-filenames) - (setq file-path (concat dir filename)) - (when (file-readable-p file-path) - (setq nearest-compilation-file file-path))) - (setq dir parent-dir - parent-dir (file-name-directory (directory-file-name parent-dir)))) - nearest-compilation-file)) -(defun run () - (interactive) - "call run-fun if it is set, else run make if there is a makefile, -else save and repeat last shell command. -run-fun is meant to store file local variables, which show how to -do the main thing we want on this file, generally compile and -run. - -example of setting it in a file: -;; Local Variables: -;; run-fun: merge-test -;; End: " - (basic-save-buffer) - (if (and (boundp 'run-fun) run-fun) - (funcall run-fun) - (let ((makefile (get-nearest-compilation-file))) - (if (and makefile (stringp mode-name) (string= mode-name "C/l")) - (compile (format - "make -f %s" (get-nearest-compilation-file))) - (repeat-shell))))) - - -(defun send-shell () - (interactive) - (send-shell-buffer "*shell*" 'shell (kbd "C-v"))) - -(defun send-python () - (interactive) - (send-shell-buffer "*Python*" 'py-shell (kbd "C-v"))) - - -(defun send-shell-buffer (buffer-name &optional init shell-send-yank-key) - "Send current line or region to shell-mode buffer. -When in shell-mode, copy the current line to the -most recently visited visible window. - -SHELL-SEND-YANK-KEY: key to use instead -of yank to paste into recent window. This allows compatibility with -modes like org-mode which have their own yank function." - (if (string= (buffer-name) buffer-name) -;; this section is copied out of comint-send-input - (progn - (let ((proc (get-buffer-process (current-buffer)))) - (if (not proc) (user-error "Current buffer has no process") - (widen) - - (let* ((pmark (process-mark proc)) - (intxt (if (>= (point) (marker-position pmark)) - (progn (if comint-eol-on-send (end-of-line)) - (buffer-substring pmark (point))) - (let ((copy (funcall comint-get-old-input))) - (goto-char pmark) - (insert copy) - copy)))) - - (if (= (length intxt) 0) - (kill-new (comint-previous-matching-input-string "." 1)) - (kill-new intxt))))) - (kill-append "\n" nil) - (select-window (previous-window nil nil 'visible)) - (if (and (boundp 'shell-send-yank-key) shell-send-yank-key) - (call-interactively (global-key-binding shell-send-yank-key)) - (yank)) - (select-window (next-window nil nil 'visible))) - (let (start end) - (if mark-active - (setq start (mark) - end (point)) - (setq start (save-excursion (beginning-of-line) (point)) - end (save-excursion (end-of-line) (point))) - (let (line-move-visual) - (call-interactively 'next-line))) - (send-comint-input buffer-name start end init)))) - -;; supporting functions -(defun send-comint-input (buffer-name start end &optional init) - "Input the region to BUFFER-NAME, assuming it is a comint-derived buffer. - Show BUFFER-NAME if it is not show. - Call INIT if BUFFER-NAME does not exist." - (let ((input (filter-buffer-substring start end))) - (send-comint-string buffer-name input init))) - -(defun send-comint-string (buffer-name string &optional init) - "Input the string to BUFFER-NAME, assuming it is a comint-derived buffer. - Show BUFFER-NAME if it is not show. - Call INIT if BUFFER-NAME does not exist." - (let ((buffer (get-buffer buffer-name))) - (unless buffer - (message "nobuffer") - ;; save-excursion etc. don't work for (shell), so I do this instead - (if init (let ((original-buffer (current-buffer))) - (funcall init (and (boundp 'send-shell-buffer-name) send-shell-buffer-name)) - (switch-to-buffer original-buffer) - (setq buffer (get-buffer buffer-name))) - (error "No existing buffer found and no init function argument. "))) - (buffer-window-show buffer) - (with-current-buffer buffer - (let ((proc (get-buffer-process buffer))) - (goto-char (process-mark proc)) - (insert string) - (comint-send-input nil t))))) - -(defun buffer-window-show (&optional buffer action) - "Like temp-buffer-window-show, but removed stuff - relevant to it being temp or help." - (let (window frame) - (with-current-buffer buffer - (when (let ((window-combination-limit - ;; When `window-combination-limit' equals - ;; `temp-buffer' or `temp-buffer-resize' and - ;; `temp-buffer-resize-mode' is enabled in this - ;; buffer bind it to t so resizing steals space - ;; preferably from the window that was split. - (if (or (eq window-combination-limit 'temp-buffer) - (and (eq window-combination-limit - 'temp-buffer-resize) - temp-buffer-resize-mode)) - t - window-combination-limit))) - ;; debug - ;;(message "window-combination-limit") - ;;(print window-combination-limit) - (setq window (display-buffer buffer action))) - (setq frame (window-frame window)) - (unless (eq frame (selected-frame)) - (raise-frame frame)) - (setq minibuffer-scroll-window window) - (set-window-hscroll window 0) - ;; Return the window. - window)))) - - -;; when poping help, etc, allow reusing a window in a different frame if it is visible -;; figured this out after spending quite a while reading doc string for display-buffer -;; which is the main function which uses this. -;; it will use other vars or its arg to override this, -;; but those things are often nil. -;; aha moments in reading it: ACTION = (FUNCTION-or-FUNCTIONLIST ALIST) -;; FRAME adds an association to ACTION's alist, but it's not used if ACTION arg is nil. -(setq display-buffer-fallback-action `(,(car display-buffer-fallback-action) . '(reusable-frames . visible))) -;; stop splitting windows verticallly when I open a buffer or shell -(setq split-height-threshold nil) -#+end_src - -*** s-left arrow -shell -#+begin_src emacs-lisp -(global-set-key (kbd "") 'shell-wrap) -(global-set-key (kbd "") 'shell-wrap) -#+end_src -*** s-right arrow -previous-buffer -#+begin_src emacs-lisp -(global-set-key (kbd "") 'previous-buffer) -#+end_src -*** esc -*** return -new line - -#+begin_src emacs-lisp -;; todo, this doesn't set the keybind for the help minibuffer - - -(global-set-key (kbd "\r") 'indent-new-comment-line) - -;; don't use enter for autocomplete, we use tab or something -(define-key ac-completing-map (kbd "") nil) -(define-key ac-completing-map "\r" nil) - -(add-hook 'org-mode-hook - (lambda () - ;; copied from org-mode, replace org-enter with org-enter-indent -(org-defkey org-mode-map "\C-m" 'org-return-indent))) - - -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map "\r" nil) - (define-key comint-mode-map (kbd "") 'comint-send-input))) - -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map "\C-m" nil) - (define-key comint-mode-map "\C-d" nil))) - -#+end_src - -*** s-return -auto-correct-prev-word - #+begin_src emacs-lisp - (global-set-key (kbd "") 'flyspell-auto-correct-previous-word) -#+end_src - -*** down arrow -mark -#+begin_src emacs-lisp - (global-set-key (kbd "") 'set-mark-command) -#+end_src -*** s-down arrow -extended command -#+begin_src emacs-lisp - (global-set-key (kbd "") 'smex) -#+end_src -*** s-up arrow - -** mouse -*** mouse-2 mode line -mouse-delete-other-windows -*** C-mouse-2 mode line - mouse-split-window-horizontally -*** M-mouse-2 mode line -*** S-mouse-2 mode line -*** C-M-mouse-2 mode line -*** C-S-mouse2 mode line -*** mouse-3 mode line - mouse-delete-window -*** C-mouse-3 mode line -*** M-mouse-3 mode line -*** S-mouse-3 mode line -*** C-M-mouse-3 mode line -*** C-S-mouse-3 mode line -*** mouse-1 - set cursor/mark -*** C-mouse-1 -buffer list context menu -*** M-mouse-1 -*** S-mouse-1 -*** C-M-mouse-1 -*** C-S-mouse-1 -*** mouse-2 - paste -*** C-mouse-2 -*** M-mouse-2 -*** S-mouse-2 -*** C-M-mouse-2 -*** C-S-mouse-2 -*** mouse-3 -set-mark -#+begin_src emacs-lisp - (define-key global-map [down-mouse-3] 'mouse3-func) - (global-set-key [mouse-3] 'mouse3-set-mark) - (global-set-key [drag-mouse-3] 'mouse3-set-mark) -#+end_src -*** C-mouse-3 - global menu -*** M-mouse-3 -*** S-mouse-3 -*** C-M-mouse-3 -*** C-S-mouse-3 -*** mouse-9 -move-mouse-to-point -#+begin_src emacs-lisp - (global-set-key (kbd "") 'move-mouse-to-point) -#+end_src -*** C-mouse-9 -*** M-mouse-9 -*** S-mouse-9 -*** C-M-mouse-9 -*** C-S-mouse-9 -*** mouse-8 -*** C-mouse-8 -*** M-mouse-8 -*** S-mouse-8 -*** C-M-mouse-8 -*** C-S-mouse-8 -*** 1/kp-end -*** C-1/kp-end -*** M-1/kp-end -*** S-1/kp-end -*** C-M-1/kp-end -*** C-S-1/kp-end -*** 2/kp-down -*** C-2/kp-down -*** M-2/kp-down -smex -#+begin_src emacs-lisp -;; for when we have a standard keyboard which is not remapped -(global-set-key (kbd "M-2") 'smex) - -#+end_src - -*** S-2/kp-down -*** C-M-2/kp-down -*** C-S-2/kp-down -*** 3/kp-next -*** C-3/kp-next -*** M-3/kp-next -*** S-3/kp-next -*** C-M-3/kp-next -*** C-S-3/kp-next -*** 4/kp-left - indent-region -#+begin_src emacs-lisp - (global-set-key (kbd "") 'indent-region) -#+end_src -*** C-4/kp-left -*** M-4/kp-left -*** S-4/kp-left -*** C-M-4/kp-left -*** C-S-4/kp-left -*** 5/kp-begin - mark-defun -#+begin_src emacs-lisp - (global-set-key (kbd "") 'mark-defun) -#+end_src -*** C-5/kp-begin -*** M-5/kp-begin -*** S-5/kp-begin -*** C-M-5/kp-begin -*** C-S-5/kp-begin -*** 6/kp-right - ibuffer -#+begin_src emacs-lisp - (global-set-key (kbd "") 'ibuffer) -#+end_src -*** C-6/kp-right -*** M-6/kp-right -*** S-6/kp-right -*** C-M-6/kp-right -*** C-S-6/kp-right -*** 7/kp-home -*** C-7/kp-home -*** M-7/kp-home -*** S-7/kp-home -*** C-M-7/kp-home -*** C-S-7/kp-home -*** 8/kp-up -*** C-8/kp-up -*** M-8/kp-up -*** S-8/kp-up -*** C-M-8/kp-up -*** C-S-8/kp-up -*** 9/kp-prior - delete-horizontal-space -#+begin_src emacs-lisp - (global-set-key (kbd "") 'delete-horizontal-space) -#+end_src -*** C-9/kp-prior -*** M-9/kp-prior -*** S-9/kp-prior -*** C-M-9/kp-prior -*** C-S-9/kp-prior -*** 10/kp-insert -*** C-10/kp-insert -*** M-10/kp-insert -*** S-10/kp-insert -*** C-M-10/kp-insert -*** C-S-10/kp-insert -*** 11/kp-subtract -*** C-11/kp-subtract -*** M-11/kp-subtract -*** S-11/kp-subtract -*** C-M-11/kp-subtract -*** C-S-11/kp-subtract -*** 12/kp-add -*** C-12/kp-add -*** M-12/kp-add -*** S-12/kp-add -*** C-M-12/kp-add -*** C-S-12/kp-add -*** scroll - up/dn / scroll -on standard mouse, this scrolls, -because we have the accuracy to pick things up and -down easier, and because it is familiar. -*** C-scroll -cursor up/down fast -#+begin_src emacs-lisp -;; compiling warns that next-line should be called interactively, -;; but we would have to do something dumb, like give it a -;; vector of keys in order to supply the 8 argument -(defun down-fast () - (interactive) - (next-line 8)) -(defun up-fast () - (interactive) - (next-line -8)) - -(global-set-key (kbd "") 'up-fast) -(global-set-key (kbd "") 'down-fast) - -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map (kbd "") 'comint-previous-prompt) - (define-key comint-mode-map (kbd "") 'comint-next-prompt))) -#+end_src - -*** M-scroll -forward/back s-exp -#+begin_src emacs-lisp - (global-set-key (kbd "") 'backward-sexp) - (global-set-key (kbd "") 'forward-sexp) -#+end_src -*** S-scroll -expand/contract region -#+begin_src emacs-lisp -(global-set-key (kbd "") 'my-contract-region) -(global-set-key (kbd "") 'er/expand-region) -(global-set-key (kbd "") 'my-contract-region) -(global-set-key (kbd "") 'er/expand-region) -(global-set-key (kbd "") 'my-contract-region) -(global-set-key (kbd "") 'er/expand-region) - -(defun my-contract-region (arg) - (interactive "p") - (let ((current-prefix-arg '-)) - (call-interactively 'er/expand-region))) -#+end_src -*** C-M-scroll -scroll -background: I originally tried to make c-scroll be scroll -, but this made -for better compatibility with the standard mouse -#+begin_src emacs-lisp - (global-set-key (kbd "") 'mwheel-scroll) - (global-set-key (kbd "") 'mwheel-scroll) -; (require 'smooth-scroll) - ; (smooth-scroll-mode nil) - ; (global-set-key (kbd "") 'scroll-up-1) - ;(global-set-key (kbd "") 'scroll-down-1) -#+end_src -*** C-S-scroll -increase / decrease text size -#+begin_src emacs-lisp -(global-set-key (kbd "") 'text-scale-increase) -(global-set-key (kbd "") 'text-scale-decrease) -(global-set-key (kbd "") 'text-scale-increase) -(global-set-key (kbd "") 'text-scale-decrease) -(global-set-key (kbd "") 'text-scale-increase) -(global-set-key (kbd "") 'text-scale-decrease) -#+end_src -*** left-scroll -left/right -*** C-left-scroll -back / forward word -#+begin_src emacs-lisp - (global-set-key (kbd "") 'backward-symbol) - (global-set-key (kbd "") 'forward-symbol) - #+end_src -*** M-left-scroll ---- -unreachable -*** S-left-scroll ---- -unreachable -*** C-M-left-scroll ---- -unreachable -*** C-S-left-scroll ---- -unreachable -** left primary - -*** C-2 -copy-symbol -#+begin_src emacs-lisp -(global-unset-key (kbd "C-2")) -(defun copy-symbol (&optional arg) - "Copy symbol at point into kill-ring" - (interactive "P") - (kill-new (thing-at-point 'symbol))) - -(global-set-key (kbd "C-2") 'copy-symbol) -#+end_src -*** M-2 -shell-cd-to-file -#+begin_src emacs-lisp - -(defun shell-cd-to-file () - (interactive) - (let ((file (buffer-file-name))) - (if file - (send-comint-string "*shell*" - (concat "c " (file-name-directory file)) - 'shell) - (message "%s" "shell-cd-to-file: buffer has no file name")))) -(global-set-key (kbd "M-2") 'shell-cd-to-file) -#+end_src -*** C-M-2 ---- -#+begin_src emacs-lisp - (global-unset-key (kbd "C-M-2")) -#+end_src -*** C-S-2 -*** C-3 -dot-mode-execute -#+begin_src emacs-lisp -(global-set-key (kbd "C-3") 'dot-mode-execute) - #+end_src -*** M-3 -*** C-M-3 - recenter-top-bottom -#+begin_src emacs-lisp -(global-set-key (kbd "C-M-3") 'recenter-top-bottom) -#+end_src -*** C-S-3 -*** C-q -org-cycle, comint previous arg -#+begin_src emacs-lisp -(global-set-key (kbd "C-q") 'outline-cycle) -(add-hook 'org-mode-hook - (lambda () (define-key org-mode-map (kbd "C-q") 'org-cycle))) -(define-key widget-keymap (kbd "C-q") 'widget-forward) -(add-hook 'comint-mode-hook - (lambda () (define-key comint-mode-map (kbd "C-q") 'comint-insert-previous-argument))) -#+end_src -*** M-q -org-archive-to-archive-sibling -#+begin_src emacs-lisp -(global-set-key (kbd "M-q") 'org-archive-to-archive-sibling) -#+end_src -*** C-M-q -quoted-insert -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-q") 'quoted-insert) -#+end_src -*** C-S-q -*** C-w ---- -in terminal, it's ctrl-backspace, duplicate keybind. -*** M-w -org-clock-in -#+begin_src emacs-lisp -(global-set-key (kbd "M-w") 'org-clock-in) -#+end_src -*** C-M-w -*** C-S-w -*** C-e -copy-line -#+begin_src emacs-lisp -;; todo, make repeated calls to this append the kills -(defun copy-line (&optional arg) - "Copy lines (as many as prefix argument) in the kill ring. - Ease of use features: - - Move to start of next line. - - Appends the copy on sequential calls. - - Use newline as last char even on the last line of the buffer. - - If region is active, copy its lines." - (interactive "p") - (let ((beg (line-beginning-position)) - (end (line-end-position (or arg 1)))) - (when mark-active - (if (> (point) (mark)) - (setq beg (save-excursion (goto-char (mark)) (line-beginning-position))) - (setq end (save-excursion (goto-char (mark)) (line-end-position))))) - (if (eq last-command 'copy-line) - (kill-append (buffer-substring beg end) (< end beg)) - (kill-ring-save beg end))) - (kill-append "\n" nil) - ;; dun need cuz I have yank-better - ;;(beginning-of-line (or (and arg (1+ arg)) 2)) - (if (and arg (not (= 1 arg))) (message "%d lines copied" arg))) - -(global-set-key (kbd "C-e") 'copy-line) -#+end_src -*** M-e -org-clock-in-last -#+begin_src emacs-lisp -(global-set-key (kbd "M-e") 'org-clock-in-last) - #+end_src -*** C-M-e -*** C-S-e -*** C-r -isearch-backward -#+begin_src emacs-lisp -(global-set-key (kbd "C-r") 'isearch-backward) -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map (kbd "C-r") 'comint-history-isearch-backward-regexp))) -#+end_src -*** M-r -org-clock-out -#+begin_src emacs-lisp -(global-set-key (kbd "M-r") 'org-clock-out) -#+end_src -*** C-M-r -*** C-S-r -*** C-a -copy buffer - #+begin_src emacs-lisp -(defun copy-all () - "Copy entire buffer to clipboard" - (interactive) - (clipboard-kill-ring-save (point-min) (point-max))) -(global-set-key (kbd "C-a") 'copy-all) - #+end_src -*** M-a -macro record -#+begin_src emacs-lisp -(global-set-key (kbd "M-a") 'kmacro-start-macro-or-insert-counter) -#+end_src -*** C-M-a -macro end / call -#+begin_src emacs-lisp -(global-set-key (kbd "C-M-a") 'kmacro-end-or-call-macro) -(add-hook 'perl-mode-hook (lambda () (define-key perl-mode-map (kbd "C-M-a") nil))) -(add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-M-a") nil))) -(add-hook 'c++-mode-hook - (lambda () (define-key c++-mode-map (kbd "C-M-a") nil))) -(add-hook 'c-mode-hook - (lambda () (define-key c-mode-map (kbd "C-M-a") nil))) - - -#+end_src -*** C-S-a -*** C-s -c-x prefix - -*** M-s -*** C-M-s -split-window-vertically -#+begin_src emacs-lisp -(global-set-key (kbd "C-M-s") 'split-window-vertically) -#+end_src -*** C-S-s -*** C-d - C-c prefix -*** M-d -*** C-M-d -swap buffer across windows -from http://www.emacswiki.org/emacs/TransposeWindows -#+begin_src emacs-lisp -(setq swapping-buffer nil) -(setq swapping-window nil) -(defun swap-buffers-in-windows () - "Swap buffers between two windows" - (interactive) - (if (and swapping-window - swapping-buffer) - (let ((this-buffer (current-buffer)) - (this-window (selected-window))) - (if (and (window-live-p swapping-window) - (buffer-live-p swapping-buffer)) - (progn (switch-to-buffer swapping-buffer) - (select-window swapping-window) - (switch-to-buffer this-buffer) - (select-window this-window) - (message "Swapped buffers.")) - (message "Old buffer/window killed. Aborting.")) - (setq swapping-buffer nil) - (setq swapping-window nil)) - (progn - (setq swapping-buffer (current-buffer)) - (setq swapping-window (selected-window)) - (message "Buffer and window marked for swapping.")))) - -(global-set-key (kbd "C-M-d") 'swap-buffers-in-windows) -#+end_src -*** C-S-d -*** C-f] -kill-whole-line -#+begin_src emacs-lisp - (global-set-key (kbd "C-f") 'kill-whole-line-wrapper) - (defun kill-whole-line-wrapper (&optional arg) - "If we are at the end of the file, kill backwards instead of doing nothing." - (interactive "P") - (if (= (point) (point-max)) - (kill-whole-line -1) - (kill-whole-line arg))) -#+end_src -*** M-f] -print-var-at-point -#+begin_src emacs-lisp -(defun print-var-at-point () - (interactive) - (let ((v (variable-at-point))) - (if (symbolp v) - (message "%s: %s" v (symbol-value v)) - (message "no symbol found at point")))) -(global-set-key (kbd "M-f") 'print-var-at-point) -#+end_src - -*** C-M-f] -kill rest of line -#+begin_src emacs-lisp - - (add-hook 'org-mode-hook - (lambda () - (define-key org-mode-map (kbd "C-M-f") 'org-kill-line))) - - (global-set-key (kbd "C-M-f") 'kill-line) -#+end_src -*** C-S-f -*** C-g] -cancel / other window -#+begin_src emacs-lisp - (global-set-key (kbd "C-g") 'other-window) -#+end_src -*** M-g] -abort-recursive-edit -#+begin_src emacs-lisp - (global-set-key (kbd "M-g") 'abort-recursive-edit) -#+end_src -*** C-M-g] -gnus -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-g") 'mu4e) -#+end_src -*** C-S-g -*** C-z -#+begin_src emacs-lisp - (global-set-key (kbd "C-z") 'undo-tree-undo) -#+end_src -*** M-z -*** C-M-z] -*** C-S-z -*** C-x -kill-region -#+begin_src emacs-lisp - (global-set-key (kbd "C-s") 'kill-region) -#+end_src -*** M-x] -smex -#+begin_src emacs-lisp -(global-set-key (kbd "M-x") 'smex) -#+end_src -*** C-M-x] -cut-to-register -#+begin_src emacs-lisp -;; same args as copy-to-register -(defun cut-to-register (register start end &optional delete-flag region) - (interactive (list (register-read-with-preview "Cut to register: ") - (region-beginning) - (region-end) - current-prefix-arg - t)) - (copy-to-register register start end t region)) - -(global-set-key (kbd "C-M-x") 'cut-to-register) -#+end_src -*** C-S-x -*** C-c -copy -#+begin_src emacs-lisp -(global-set-key (kbd "C-d") 'kill-ring-save) -(add-hook 'c-mode-hook - (lambda () (define-key c-mode-map (kbd "C-d") nil))) -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map (kbd "C-d") nil))) -;; the base map is shared by many c-modes, like java -(add-hook 'c-mode-hook - (lambda () - (define-key c-mode-base-map "\C-d" nil) - (define-key c-mode-base-map (kbd "") 'c-electric-delete-forward))) - -#+end_src -*** M-c] -org-capture -#+begin_src emacs-lisp - (define-key global-map "\M-c" 'org-capture) -#+end_src -*** C-M-c] -copy-to-register -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-c") 'copy-to-register) -#+end_src -*** C-S-c -*** C-v -yank -#+begin_src emacs-lisp - (global-set-key (kbd "C-v") 'yank-better) - - - - (defun yank-better (arg) - "Paste, linewise if our kill ends with a newline. - I change the behavior of plain prefix. It makes it not do linewise paste, - because sometimes you want to yank pop and a linewise paste screws that up. - c-u with no number normally makes the point go before the yank. - That is pointless for me, as it would be just as easier and less - thought to pop the mark after yanking cuz it is set to before the mark." - (interactive "*P") - (if (and (not (equal arg '(4))) (string-suffix-p "\n" (current-kill 0 t))) - (beginning-of-line)) - (if (and (stringp mode-name) (string= mode-name "Org")) - (call-interactively 'org-yank) - (setq this-command 'yank) - (call-interactively 'yank (and (not (equal arg '(4))))))) - - (put 'yank-better 'delete-selection 'yank) -#+end_src -*** M-v] -insert-register -#+begin_src emacs-lisp - (global-set-key (kbd "M-v") 'insert-register) -#+end_src -*** C-M-v] -yank-pop -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-v") 'yank-pop) -#+end_src -*** C-S-v -*** C-b] -delete-other-windows -#+begin_src emacs-lisp - (global-set-key (kbd "C-b") 'delete-other-windows) -#+end_src -*** M-b] -isearch-backward-current-symbol -#+begin_src emacs-lisp - (global-set-key (kbd "M-b") 'isearch-backward-current-symbol) -#+end_src -*** C-M-b] -isearch-current-symbol - #+begin_src emacs-lisp -(global-set-key (kbd "C-M-b") 'isearch-current-symbol) -#+end_src -*** C-S-b -*** C-tab] ---- -in terminal, it's just TAB, duplicate keybind. -*** M-tab] ---- -in terminal it's duplicated of C-M-i -*** C-M-tab -*** C-S-tab -*** C-delete] -kill-symbol -#+begin_src emacs-lisp - (global-set-key (kbd "") 'kill-symbol) -(defun kill-symbol (arg) - (interactive "p") - (kill-region (point) (save-excursion (forward-symbol arg) (point)))) - -#+end_src -*** M-delete -*** C-M-delete] -kill-sexp -#+begin_src emacs-lisp - (global-set-key (kbd "") 'kill-sexp) -#+end_src -*** C-S-delete - -*** C-left-arrow] -compile / comint search -#+begin_src emacs-lisp -(defun set-p (var) - (and (bound-and-true-p var) - (not (eq var 'unset)))) -(global-set-key (kbd "C-(") 'run) - -;; make compile work from the gtags root dir -(defadvice compile (before pre-compile-advice activate) - (basic-save-buffer) - (when (set-p ggtags-project-root) - (setq-local compile-saved-dir default-directory) - (setq default-directory ggtags-project-root))) -(defadvice compile (after post-compile-advice activate) - (when (bound-and-true-p compile-saved-dir) - (setq default-directory compile-saved-dir))) - - -(add-hook 'c-mode-hook (lambda () (define-key c-mode-map (kbd "C-(") 'compile))) -(add-hook 'comint-mode-hook - (lambda () - (define-key isearch-mode-map (kbd "C-(") 'isearch-repeat-backward) - (define-key comint-mode-map (kbd "C-(") 'isearch-backward))) - -#+end_src -*** M-left-arrow -*** C-M-left-arrow] -org-shiftup -#+begin_src emacs-lisp - (add-hook 'org-mode-hook - (lambda () (define-key org-mode-map (kbd "C-M-(") 'org-shiftup))) -#+end_src -*** C-S-left-arrow -*** C-right-arrow] -keyboard-yank-primary -#+begin_src emacs-lisp -(defun keyboard-yank-primary () - (interactive) - (let ((mouse-yank-at-point t)) - (mouse-yank-primary nil))) -;; paste selection -(global-set-key (kbd "C-)") 'keyboard-yank-primary) ;; kinesis binding -(global-set-key (kbd "") 'keyboard-yank-primary) -#+end_src -*** M-right-arrow -*** C-M-right-arrow -#+begin_src emacs-lisp - (add-hook 'org-mode-hook - (lambda () (define-key org-mode-map (kbd "C-M-)") 'org-shiftdown))) -#+end_src -*** C-S-right-arrow -*** C-backspace] -backward-kill-symbol -#+begin_src emacs-lisp -(global-set-key (kbd "") 'backward-kill-symbol) -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map (kbd "") 'backward-kill-word))) -(defun backward-kill-symbol (arg) - (interactive "p") - (kill-region (point) (save-excursion (backward-symbol arg) (point)))) -#+end_src -*** M-backspace -*** C-M-backspace] -backward-kill-sexp -#+begin_src emacs-lisp - (global-set-key (kbd "") 'backward-kill-sexp) -#+end_src -*** C-S-backspace -*** C-f7 -*** M-f7 -*** C-M-f7 -*** C-S-f7 - -** right primary -*** C-*] -split-window-horizontally -#+begin_src emacs-lisp - (global-set-key (kbd "C-*") 'split-window-horizontally) -#+end_src -*** M-* -*** C-M-*] -calc-dispatch -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-*") 'calc-dispatch) -#+end_src -*** C-S-* -*** C-9] -delete-window-or-exit -#+begin_src emacs-lisp -(global-set-key (kbd "C-9") 'delete-window-or-exit) - -(defun delete-window-or-exit () - "Delete window or exit emacs." - (interactive) - (if (condition-case nil (delete-window) (error t)) - (if (or (boundp 'server-process) (> (length (frame-list)) 1)) - (progn (basic-save-buffer) (delete-frame)) - (save-buffers-kill-terminal t)))) -#+end_src -*** M-9] -kill-buffer - #+begin_src emacs-lisp -(defun kill-buffer-no-ido () -"kill-buffer, avoid the ido remapping" - (interactive) - (kill-buffer)) -(global-set-key (kbd "M-9") 'kill-buffer-no-ido) - #+end_src -strangely, in simple mode, this is overridden. -I found this map to override, but it didn't work, so it seems its being bound some other way. -I did a grep of the emacs sources, but couldn't find anything. -(define-key universal-argument-map [?9] nil) - -*** C-M-9] -end server edit - ,save & kill buffer if it was opened externally via emacsclient - - #+begin_src emacs-lisp -(defun server-edit-save () - (interactive) - (save-buffer) - (server-edit)) -(global-set-key (kbd "C-M-9") 'server-edit-save) - #+end_src -*** C-S-9 -*** C-u] -universal-argument -*** M-u -*** C-M-u] -search-keybind -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-u") 'search-keybind) - - (defun search-keybind (regexp &optional nlines) - (interactive (occur-read-primary-args)) - (save-excursion - (describe-bindings) - (set-buffer "*Help*") - (occur regexp) - (delete-windows-on "*Help*") - )) -#+end_src -*** C-S-u -*** C-i ------ -*** M-i -*** C-M-i] -query-replace-regexp -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-i") 'query-replace-regexp) - (add-hook 'flyspell-mode-hook - (lambda () (define-key flyspell-mode-map (kbd "C-M-i") nil))) -(add-hook 'text-mode-hook - (lambda () (define-key text-mode-map (kbd "C-M-i") nil))) - -#+end_src -*** C-S-i -*** C-o] -occur -#+begin_src emacs-lisp - (global-set-key (kbd "C-o") 'occur) -#+end_src -*** M-o -*** C-M-o] -counsel-imenu -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-o") 'counsel-imenu) -#+end_src -*** C-S-o -*** C-p] -move-mouse-to-point -#+begin_src emacs-lisp - (global-set-key (kbd "C-p") 'move-mouse-to-point) -#+end_src -*** M-p -*** C-M-p] -delete-horizontal-space -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-p") 'delete-horizontal-space) -#+end_src -*** C-S-p -*** C-j] -pop-to-mark -#+begin_src emacs-lisp -(defun my-pop-to-mark-command () - "Jump to mark, and pop a new position for mark off the ring. - \(Does not affect global mark ring\)." - (interactive) - (pop-to-mark-command) - (if (and (derived-mode-p 'org-mode) (outline-invisible-p)) - (org-show-context 'mark-goto))) - -(global-set-key (kbd "C-j") 'my-pop-to-mark-command) -(define-key ido-common-completion-map (kbd "C-j") 'ido-select-text) -(add-hook 'ido-setup-hook - (lambda () (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text))) -(add-hook 'lisp-interaction-mode-hook - (lambda () - (define-key lisp-interaction-mode-map (kbd "C-j") nil))) - -#+end_src -*** M-j] -previous-error -#+begin_src emacs-lisp - (global-set-key (kbd "M-j") 'previous-error) -#+end_src -*** C-M-j] - -register prefix -#+begin_src emacs-lisp -(define-key global-map (kbd "C-M-j") ctl-x-r-map) -(define-key ctl-x-r-map "m" 'kmacro-to-register) -#+end_src - -*** C-S-j -*** C-k] -jump-to-register -#+begin_src emacs-lisp - - (global-set-key (kbd "C-k") 'jump-to-register) -#+end_src -*** M-k] -next-error -#+begin_src emacs-lisp - (global-set-key (kbd "M-k") 'next-error) -#+end_src -*** C-M-k] -man -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-k") 'man) -#+end_src -*** C-S-k -*** C-l] -ivy-switch-buffer -#+begin_src emacs-lisp - (global-set-key (kbd "C-l") 'ivy-switch-buffer) -#+end_src -*** M-l - -*** C-M-l] -move cursor top bottom mid, comint clear screen -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-l") 'move-to-window-line-top-bottom) -#+end_src -*** C-S-l -*** C-;] -used in flyspell, not sure what for, otherwise unbound -*** M-; -comment-dwim -*** C-M-;] -comment-current-line-dwim -#+begin_src emacs-lisp - (defun comment-current-line-dwim () - "Comment or uncomment the current line." - (interactive) - (save-excursion - (push-mark (beginning-of-line) t t) - (end-of-line) - (comment-dwim nil)) - (move-beginning-of-line 2)) - (global-set-key (kbd "C-M-;") 'comment-current-line-dwim) -#+end_src -*** C-S-; -*** C-m] -*** M-m -*** C-M-m] -recursive grep -#+begin_src emacs-lisp - (define-key global-map (kbd "C-M-m") 'rgrep) -#+end_src -*** C-S-m -*** C-,] -counsel-find-file -#+begin_src emacs-lisp - (global-set-key (kbd "C-,") 'counsel-find-file) -(add-hook 'flyspell-mode-hook - (lambda () (define-key flyspell-mode-map (kbd "C-,") nil))) -#+end_src -*** M-, -*** C-M-,] -find-file-in-project - #+begin_src emacs-lisp - (global-set-key (kbd "C-M-,") 'find-file-in-project) -#+end_src -*** C-S-, -*** C-.] -find recent file -Taken from starter kit. -#+begin_src emacs-lisp - (defun recentf-ido-find-file () - "Find a recent file using Ido." - (interactive) - (let* ((file-assoc-list - (mapcar (lambda (x) - (cons (file-name-nondirectory x) - x)) - recentf-list)) - (filename-list - (remove-duplicates (mapcar #'car file-assoc-list) - :test #'string=)) - (filename (ido-completing-read "Choose recent file: " - filename-list - nil - t))) - (when filename - (find-file (cdr (assoc filename - file-assoc-list)))))) - - (add-hook 'flyspell-mode-hook - (lambda () (define-key flyspell-mode-map (kbd "C-.") nil))) - (define-key dot-mode-map (kbd "C-.") nil) - (global-set-key (kbd "C-.") 'recentf-ido-find-file) - (add-hook 'php-mode-hook - (lambda () (define-key php-mode-map (kbd "C-.") nil))) -#+end_src -*** M-. -*** C-M-. -- -#+begin_src emacs-lisp - (define-key dot-mode-map (kbd "C-M-.") nil) -;; (global-set-key (kbd "C-M-.") 'execute-extended-command) -#+end_src -*** C-S-. -*** C-/] -join lines -#+begin_src emacs-lisp - (defun vim-style-join-line () - (interactive) - (join-line '(4))) - (global-set-key (kbd "C-/") 'vim-style-join-line) -(define-key undo-tree-map (kbd "C-/") nil) -#+end_src -*** M-/ -*** C-M-/] -copy-buffer-file-name -#+begin_src emacs-lisp -;; haven't bound this atm, todo, maybe someday? -(defun copy-variable (variable) - (interactive - (let ((v (variable-at-point)) - (enable-recursive-minibuffers t) - val) - (setq val (completing-read (if (symbolp v) - (format - "Describe variable (default %s): " v) - "Describe variable: ") - obarray - (lambda (vv) - (or (get vv 'variable-documentation) - (and (boundp vv) (not (keywordp vv))))) - t nil nil - (if (symbolp v) (symbol-name v)))) - (list (if (equal val "") - v (intern val))))) - (kill-new (symbol-value variable))) - -(defun copy-buffer-file-name () - (interactive) - (let ((name (cond - ((derived-mode-p 'mu4e-view-mode) (mu4e-message-field-at-point :path)) - (t buffer-file-name)) - )) - (kill-new name) - (message name))) - - -(global-set-key (kbd "C-M-/") 'copy-buffer-file-name) - - -#+end_src -*** C-S-/ -*** C-8] -calc-embedded-word -#+begin_src emacs-lisp - (global-set-key (kbd "C-8") 'calc-embedded-word) -#+end_src -*** M-8 -*** C-M-8 -*** C-S-8 -*** C-up-arrow] -org prev headline -#+begin_src emacs-lisp - (define-key undo-tree-map "\C-_" nil) -;; disabled just because i don't want to accidentally hit it - (define-key global-map "\C-_" nil) - (global-set-key (kbd "") 'beginning-of-defun) - - (add-hook 'org-mode-hook - (lambda () - (define-key org-mode-map (kbd "\C-_") 'outline-previous-visible-heading))) - -#+end_src - - -*** M-up-arrow -*** C-M-up-arrow -*** C-S-up-arrow -winner undo -#+begin_src emacs-lisp - (global-set-key (kbd "") 'winner-undo) -#+end_src -*** C-down-arrow] -org next headline -#+begin_src emacs-lisp - (global-set-key (kbd "") 'end-of-defun) - - (add-hook 'org-mode-hook - (lambda () - (define-key org-mode-map (kbd "") 'outline-next-visible-heading))) - -#+end_src - - -*** M-down-arrow -*** C-M-down-arrow] -toggle-mark-activation -#+begin_src emacs-lisp - (defun toggle-mark-activation () - (interactive) - (if mark-active - (deactivate-mark t) - (activate-mark))) - - (global-set-key (kbd "") 'toggle-mark-activation) -#+end_src -winner redo -#+begin_src emacs-lisp - (global-set-key (kbd "") 'winner-redo) -#+end_src - -*** C-S-down-arrow] -m-x for major mode - #+begin_src emacs-lisp - (global-set-key (kbd "") 'smex-major-mode-commands) -#+end_src -*** C-lbracket ----- -*** M-lbracket -*** C-M-lbracket] -scroll-right -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-[") 'scroll-right) - #+end_src -*** C-S-lbracket -*** C-rbracket] -fill-paragraph -#+begin_src emacs-lisp - (global-set-key (kbd "C-]") 'fill-paragraph) -#+end_src -*** M-rbracket -*** C-M-rbracket] -scroll-left - #+begin_src emacs-lisp - (global-set-key (kbd "C-M-]") 'scroll-left) - #+end_src -*** C-S-rbracket -*** C-return] -newline-anywhere -#+begin_src emacs-lisp -(defun newline-anywhere () - "Add a newline from anywhere in the line." - (interactive) - (end-of-line) - (newline-and-indent)) -(global-set-key (kbd "") 'newline-anywhere) - -#+end_src -*** M-return] -plain newline -#+begin_src emacs-lisp -(defun plain-newline () -(interactive) -(insert "\n")) -(global-set-key (kbd "") 'plain-newline) -#+end_src - -*** C-M-return -#+begin_src emacs-lisp -(defun newline-anywhere-previous () - "Add a newline from anywhere in the line." - (interactive) - (forward-line -1) - (end-of-line) - (newline-and-indent)) -(global-set-key (kbd "") 'newline-anywhere-previous) -#+end_src -*** C-S-return -*** C-space] -org-edit-special -#+begin_src emacs-lisp -;; commented due to new keyboard needing ctrl-space for mark -;; (kbd "") does not work, (kbd "C-SPC") should work -;; (add-hook 'org-mode-hook -;; (lambda () -;; (define-key org-mode-map (kbd "C-SPC") 'org-edit-special) -;; ;; org-src-mode-map is broken in git version of emacs. -;; ;; temporarily use this for exiting edit-special mode. -;; (global-set-key (kbd "C-M--") 'org-edit-src-exit) -;; (define-key org-src-mode-map (kbd "C-SPC") 'org-edit-src-exit))) -#+end_src -*** M-space -*** C-M-space - before or under cursor -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-SPC") 'ispell-word) -#+end_src -*** C-S-space -** left secondary -*** C-= -*** M-= -*** C-M-= -*** C-S-= -*** C-1 -*** M-1 -*** C-M-1 -*** C-S-1 -*** C-4 -*** M-4 -*** C-M-4 -widen -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-4") 'widen) -#+end_src -*** C-S-4 -*** C-5 -*** M-5 -*** C-M-5 -*** C-S-5 -*** C-tab-key] -query-replace -#+begin_src emacs-lisp - - (global-set-key (kbd "") 'query-replace) -#+end_src -*** M-tab-key -*** C-M-tab-key -*** C-S-tab-key -*** C-t] -org cycle todo / toggle comint motion -#+begin_src emacs-lisp -(add-hook 'org-mode-hook - (lambda () - (define-key org-mode-map (kbd "C-t") 'org-todo))) - -(defun my-comint-previous-input (arg) - (interactive "*p") - (if (comint-after-pmark-p) - (comint-previous-input arg) - (forward-line -1))) - -(defun my-comint-next-input (arg) - (interactive "*p") - (if (comint-after-pmark-p) - (comint-next-input arg) - (forward-line))) - -(add-hook 'comint-mode-hook - (lambda () - (define-key comint-mode-map (kbd "C-t") 'comint-toggle-arrow-keys) - (define-key comint-mode-map (kbd "") 'my-comint-previous-input) - (define-key comint-mode-map (kbd "") 'my-comint-next-input))) - - -(defun comint-toggle-arrow-keys () - (interactive) - (toggle-arrow-keys comint-mode-map)) - -(setq-default comint-arrow-movement nil) -(defun toggle-arrow-keys (map) - (cond ((lookup-key map (kbd "")) - (setq-local comint-arrow-movement t) - (define-key map (kbd "") nil) - (define-key map (kbd "") nil)) - (t - (setq-local comint-arrow-movement nil) - (define-key map (kbd "") 'my-comint-previous-input) - (define-key map (kbd "") 'my-comint-next-input) - (goto-char (point-max))))) - -(eval-after-load "message" - '(define-key message-mode-map (kbd "C-t") 'mail-signature)) -#+end_src -Thanks for the update. I will be enjoying it. - -#+RESULTS: -: comint-toggle-arrow-keys -*** M-t -*** C-M-t] -org timestamp -#+begin_src emacs-lisp -(global-set-key (kbd "C-M-t") 'org-time-stamp-with-time) -#+end_src -*** C-S-t -*** C-home -start of buffer -*** M-home -*** C-M-home -*** C-S-home -*** C-end -end of buffer -*** M-end -*** C-M-end -*** C-S-end -*** C-f9 -*** M-f9 -*** C-M-f9 -*** C-S-f9 -** right secondary -*** C-6 -save-buffers-kill-emacs -#+begin_src emacs-lisp -(global-set-key (kbd "C-6") 'save-buffers-kill-emacs) -#+end_src -*** M-6 -*** C-M-6] - insert-small-copyright -#+begin_src emacs-lisp -(defun insert-small-copyright () - (interactive) - (beginning-of-line) - (let ((beg (point))) - (insert "Copyright (C) 2017 Ian Kelling\nThis program is under GPL v. 3 or later, see ") - (comment-region beg (point)))) - - (global-set-key (kbd "C-M-6") 'insert-small-copyright) -#+end_src -*** C-S-6 -*** C-7 -*** M-7 -*** C-M-7] -insert-full-copyright -#+begin_src emacs-lisp -(defun insert-full-copyright () - (interactive) - (beginning-of-line) - (let ((beg (point))) - (insert "Copyright (C) 2017 Ian Kelling\n") - (insert "\n") - (insert "This program is free software: you can redistribute it and/or modify\n") - (insert "it under the terms of the GNU General Public License as published by\n") - (insert "the Free Software Foundation, either version 3 of the License, or\n") - (insert "(at your option) any later version.\n") - (insert "\n") - (insert "This program is distributed in the hope that it will be useful,\n") - (insert "but WITHOUT ANY WARRANTY; without even the implied warranty of\n") - (insert "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") - (insert "GNU General Public License for more details.\n") - (insert "\n") - (insert "You should have received a copy of the GNU General Public License\n") - (insert "along with this program. If not, see .\n") - (comment-region beg (point)))) - -(global-set-key (kbd "C-M-7") 'insert-full-copyright) - -#+end_src -*** C-S-7 -*** C-0 -text-scale-reset -#+begin_src emacs-lisp -(defun text-scale-reset () - (interactive) - (text-scale-set 0)) -(global-set-key (kbd "C-0") 'text-scale-reset) -#+end_src -*** M-0 -*** C-M-0 -insert-apache -#+begin_src emacs-lisp -(defun insert-apache () - (interactive) - (beginning-of-line) - (let ((beg (point))) - (insert "Copyright (C) 2017 Ian Kelling\n") - (insert "\n") - (insert "Licensed under the Apache License, Version 2.0 (the \"License\");\n") - (insert "you may not use this file except in compliance with the License.\n") - (insert "You may obtain a copy of the License at\n") - (insert "\n") - (insert " http://www.apache.org/licenses/LICENSE-2.0\n") - (insert "\n") - (insert "Unless required by applicable law or agreed to in writing, software\n") - (insert "distributed under the License is distributed on an \"AS IS\" BASIS,\n") - (insert "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n") - (insert "See the License for the specific language governing permissions and\n") - (insert "limitations under the License.\n") - (comment-region beg (point)))) -(global-set-key (kbd "C-M-0") 'insert-apache) -#+end_src - -*** C-S-0 -*** C-- -*** M-- -*** C-M-- -org-edit-src-exit -*** C-S-- -*** C-y] - undo-tree-redo -#+begin_src emacs-lisp -(global-set-key (kbd "C-y") 'undo-tree-redo) -(add-hook 'org-mode-hook - (lambda () (define-key org-mode-map (kbd "C-y") nil))) -#+end_src - -*** M-y -*** C-M-y -*** C-S-y -*** C-\ -#+begin_src emacs-lisp - (global-set-key (kbd "C-\\") 'sr-speedbar-toggle) -#+end_src -*** M-\ -*** C-M-\] -mark-defun -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-\\") 'mark-defun) -#+end_src -*** C-S-\ -*** C-h -help-prefix - -*** M-h -*** C-M-h -*** C-S-h -*** C-' -eval-expression -#+begin_src emacs-lisp -(global-set-key (kbd "C-'") 'eval-expression) -#+end_src -*** M-' -*** C-M-' -*** C-S-' -*** C-n] -unpop to mark - #+begin_src emacs-lisp - (defun unpop-to-mark-command () - "Unpop off mark ring. Does nothing if mark ring is empty." - (interactive) - (when mark-ring - (let ((pos (marker-position (car (last mark-ring))))) - (if (not (= (point) pos)) - (goto-char pos) - (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring)) - (set-marker (mark-marker) pos) - (setq mark-ring (nbutlast mark-ring)) - (goto-char (marker-position (car (last mark-ring)))))))) - - (global-set-key (kbd "C-n") 'unpop-to-mark-command) -#+end_src -*** M-n -*** C-M-n] -narrow-to-region -#+begin_src emacs-lisp - (global-set-key (kbd "C-M-n") 'narrow-to-region) -#+end_src -*** C-S-n -*** C-rshift -*** M-rshift -*** C-M-rshift -*** C-S-rshift -*** C-escape] - find-tag - :ID: a6dd7e4c-1831-4493-bbfd-557dc2f9c856 - :CUSTOM_ID: 6901fa1b-c827-4525-b24b-bdb8fe5f638b - - - - - - - - - :END: -find-tag -#+begin_src emacs-lisp - (global-set-key (kbd "") 'find-tag) -#+end_src -*** M-escape -*** C-M-escape -*** C-S-escape -* keybind table src -not necessary to have at the end, but its convenient to have it next -to its output. - #+NAME: keybind-table-generator -#+BEGIN_SRC emacs-lisp :results silent -(defun org-custom-id-get (&optional pom create prefix) - "Get the CUSTOM_ID property of the entry at point-or-marker POM. - If POM is nil, refer to the entry at point. - If the entry does not have a CUSTOM_ID, the function returns nil. - However, when CREATE is non nil, create an ID if none is present already. - PREFIX will be passed through to `org-id-new'. - In any case, the CUSTOM_ID of the entry is returned." - (org-with-point-at pom - (let ((id (org-entry-get nil "CUSTOM_ID"))) - (cond - ((and id (stringp id) (string-match "\\S-" id)) - id) - (create - (setq id (org-id-new prefix)) - (org-entry-put pom "CUSTOM_ID" id) - (org-id-add-location id (buffer-file-name (buffer-base-buffer))) - id))))) - -(defun get-title() - (interactive) - (let ((title (plist-get (cadr (org-element-at-point)) ':title))) - ;; remove brackets from [title] - ;; I was at one point using org-drill for spaces repitition, - ;; and enclosed question and answer by 2 sets of brackets. - (string-match "[^[ ][^]]*" title) - (setq title (match-string 0 title)) - (print title) - title)) - - -(defun org-dblock-write:keybind-dblock (arg) - (let (output) - (save-excursion - (goto-char (org-find-entry-with-id "beginning-of-keybind-table-data")) - (let* ((table-level (org-current-level)) - (keybind-level (1+ table-level)) - (prefixes (list "C-M-S-" "C-M-" "C-S-" "M-S-" "M-" "C-" "S-")) - table-title - previous-prefixes - ) - (while (>= (org-current-level) table-level) - (setq table-title (get-title)) - (outline-next-heading) - (let (found-prefixes - found-all-prefixes) - ;; go through the first few elements of the table to find out what column headings aka prefixes it should have - (save-excursion - (while (not found-all-prefixes) - (let ((prefixes-copy prefixes) - current-prefix - found-prefix) - (while (and prefixes-copy (not found-prefix)) - (setq current-prefix (car prefixes-copy)) - (when (and (> (length (get-title)) (length current-prefix)) - (string= (substring (get-title) 0 (length current-prefix)) current-prefix)) - (setq found-prefix t)) - (setq prefixes-copy (cdr prefixes-copy))) - (unless found-prefix - (setq current-prefix "")) - (if (and found-prefixes (string= (car (last found-prefixes)) current-prefix)) - (setq found-all-prefixes t) - (push current-prefix found-prefixes))) - (outline-next-heading))) - (setq found-prefixes (reverse found-prefixes)) - - ;; start a new table or repeat the prefixes in the current table - - (if (or (not previous-prefixes) (equal previous-prefixes found-prefixes)) - (setq output (concat output "|-|\n| ")) - (setq output (concat output "|-|\n\n|-|\n| "))) - (setq output (concat output table-title " | ")) - (setq previous-prefixes found-prefixes) - - ;; add the prefixes - (dolist (prefix found-prefixes) - (setq output (concat output prefix "|"))) - (setq output (concat output "\n|-|\n")) - - - (let (subtree-end) - (while (>= (org-current-level) keybind-level) - (dotimes (i (length found-prefixes)) - ;; add keybind name - (when (= i 0) - (setq output (concat output "| " (substring (get-title) (length (car found-prefixes))) " | "))) - ;; add keybinds by searching for regex [keybind] to the start of the next heading - (save-excursion - (outline-next-heading) - (setq subtree-end (point))) - ;; skip over scheduled line - - ;; see comment after source block to understand this regex - (re-search-forward "^\\s-*\\([^*: ].*?$\\)" subtree-end t) - (let ((m (match-string 1))) - (when m - (setq output (concat output "[[#" (org-custom-id-get (point) 'create) "][" m "]]"))) - (setq output (concat output " | "))) - ;; advance to next keybind - (outline-next-heading)) - (setq output (concat output "\n")) - )))))) - (setq output (concat output "|-|")) - (insert output)) - (org-table-map-tables 'org-table-align 'quietly)) - - -#+END_SRC - after source block due to bad parsing of comments in non emacs lisp mode - some easily forgotten regex elements. whitespace: \\s- - non-greedy star: *? - subexpression for close bracket char or nothing: \\(\\]\\|\\) - -* keybind tables -:LOGBOOK: -CLOCK: [2016-11-28 Mon 10:59]--[2016-11-28 Mon 10:59] => 0:00 -:END: -dunno why but it takes doing ctrl-c twice to update this - #+BEGIN: keybind-dblock - |---------------------+------------------------| - | single/special keys | | - |---------------------+------------------------| - | tab key | [[#6c10a716-1d8e-4ce4-8e26-64468f19c17a][isearch]] | - | tab | [[#51ece189-1840-41a1-8ca0-19f9a0481895][isearch-forward]] | - | end | [[#00d589b7-2b8e-494c-b761-3afefebe6ec6][move-end-of-line]] | - | home | [[#7800e455-c3f6-4a8f-8907-b2292449ab67][back-to-indentation]] | - | s-tab | [[#3072901e-5cf3-4d6e-9ac8-3ef64a5f6ad2][indent-buffer]] | - | s-delete | [[#e53728b6-054d-4443-a03e-6cf02d13724d][send-shell]] | - | s-left arrow | [[#d8c473ac-5507-4a6b-9e5a-46558c17b09f][shell]] | - | s-right arrow | [[#cbae2b27-ff95-4b12-88e0-e1a0f7705db6][previous-buffer]] | - | esc | | - | return | [[#fab6adea-ed20-45ab-a0a3-776c68d5c3a5][new line]] | - | s-return | [[#c433c837-24fa-45e1-8991-a4d380550ea0][auto-correct-prev-word]] | - | down arrow | [[#7a868484-9c63-4a73-abda-7751cb2c02be][mark]] | - | s-down arrow | [[#097b97e0-8ad8-40f7-8388-c4ace1706b38][extended command]] | - | s-up arrow | | - |---------------------+------------------------| - - |-------------------+----------------------------+---------------------------------+--------------------+---------------+-------------+-------------| - | mouse | | C- | M- | S- | C-M- | C-S- | - |-------------------+----------------------------+---------------------------------+--------------------+---------------+-------------+-------------| - | mouse-2 mode line | [[#69aaa631-6fb5-4beb-b2d8-c0f3d92c0a98][mouse-delete-other-windows]] | [[#501479ab-e1e2-497e-bd86-071f8afa3378][mouse-split-window-horizontally]] | | | | | - | mouse-3 mode line | [[#917a1844-8c38-4f31-8616-50fc81334f2c][mouse-delete-window]] | | | | | | - | mouse-1 | [[#4e60e2e4-8c2f-4450-8060-2d793ede530c][set cursor/mark]] | [[#b661f84f-57df-4095-9dc1-d1a876a53ee5][buffer list context menu]] | | | | | - | mouse-2 | [[#086b0b50-054f-462d-92fa-b27852f887b0][paste]] | | | | | | - | mouse-3 | [[#0481632e-9c50-4328-9365-c4b5bf967b66][set-mark]] | [[#9623c78f-7705-4cbe-a990-c24eb1067377][global menu]] | | | | | - | mouse-9 | [[#efaec161-b279-4129-86fd-b410430926e4][move-mouse-to-point]] | | | | | | - | mouse-8 | | | | | | | - | 1/kp-end | | | | | | | - | 2/kp-down | | | [[#50db5a06-452e-491f-875b-3de936a4d04a][smex]] | | | | - | 3/kp-next | | | | | | | - | 4/kp-left | [[#c44d0f65-9502-4cc6-9642-96d907f6b093][indent-region]] | | | | | | - | 5/kp-begin | [[#2458c6bc-7113-4d4b-bbdf-206e1cb842a7][mark-defun]] | | | | | | - | 6/kp-right | [[#3b79bc58-6067-43bd-9471-9d592744a25a][ibuffer]] | | | | | | - | 7/kp-home | | | | | | | - | 8/kp-up | | | | | | | - | 9/kp-prior | [[#a3b51adb-4405-4d9f-9b88-a8faa479fbe7][delete-horizontal-space]] | | | | | | - | 10/kp-insert | | | | | | | - | 11/kp-subtract | | | | | | | - | 12/kp-add | | | | | | | - | scroll | [[#33433f0f-5b0e-46ba-8452-d2a51e54769b][up/dn / scroll]] | [[#38c594ca-1d13-441b-833c-ad47b27e7073][cycle recent buffers]] | [[#e1e2e253-450d-4620-af9e-78d378f49ad5][forward/back s-exp]] | [[#945cbcda-9a5a-4a9f-ad5c-4ede9a43656e][expand region]] | [[#10bc56d0-a6fe-4e2e-a287-1d280358ad1c][scroll]] | [[#fc79fff3-259e-416a-a62a-c237b30ade28][zoom]] | - | left-scroll | [[#d2d5c5c7-f0de-4e08-953b-d41d3e282ba7][left/right]] | [[#7bb95aa5-381e-454a-a6c6-aaeec728db08][back / forward word]] | [[#3aeb5be7-6026-42f6-a65b-b00799e44642][winner undo redo]] | [[#ca5cdcd4-b3da-4d7b-86ab-4c7c0ac2caf7][---]] | [[#7f7103f5-2488-46a6-8530-6d8a558e6eff][unreachable]] | [[#7b4f1f49-6d93-4210-a30c-8278d6e63655][unreachable]] | - |-------------------+----------------------------+---------------------------------+--------------------+---------------+-------------+-------------| - - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | left primary | C- | M- | C-M- | C-S- | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | 2 | [[#b7db9f5c-f31d-45fb-ac70-eb3ef9369d3d][copy-symbol]] | [[#53ecfda2-d9f6-4882-b7a2-9b3c859e3bcb][shell-cd-to-file]] | [[#33c4996d-92bc-4df0-b005-11553677be13][---]] | | - | 3 | [[#401f56ff-6aba-4156-b128-f449b18c27af][dot-mode-execute]] | | [[#eb0cc3a8-b62e-4a24-9f84-cc8e854f91dd][recenter-top-bottom]] | | - | q | [[#679fd3cd-c43b-409c-be36-4175a5f27cd3][org-cycle, comint previous arg]] | [[#9a186632-7b04-4af7-b7de-eaec87daf315][org-archive-to-archive-sibling]] | [[#1f5e9b63-7ce0-445c-a426-b41839585d38][quoted-insert]] | | - | w | [[#20005b6d-9a9d-4b58-882c-7ce860c7a395][goto-t.org]] | [[#9531a0da-269f-4359-9124-e83fbf61a92f][org-clock-in]] | | | - | e | [[#11e8f541-f0a0-4058-883a-98bd1e7b8c4d][copy-line]] | [[#74d0ed51-ddb5-488e-bf55-0f033916e319][org-clock-in-last]] | | | - | r | [[#5088a8b2-a772-4660-a3b6-b8cca7099da6][isearch-backward]] | [[#8fe64424-1f11-4086-84b3-07c2af210c1c][org-clock-out]] | | | - | a | [[#d57dd0ac-2251-44af-b232-30f8a2b0b198][copy-all]] | [[#77987ef8-6a18-4123-8ede-77bc766aa2aa][kmacro-start-macro-or-in...]] | [[#dd2c225e-2d18-4b95-bc30-765163a5e368][kmacro-end-or-call-macro]] | | - | s | [[#f26dd0f5-0655-485f-8c76-e6dfc6abd947][C-x prefix]] | | [[#290ea04a-be99-416a-a95f-458045a91c93][split-window-vertically]] | | - | d | [[#b699614a-9994-4fe7-b2c6-f0fe81b7ad2b][C-c prefix]] | | [[#d9f48fbe-0a32-4133-93fb-f43ff6ab0037][swap buffer]] | | - | f | [[#2695ed8a-e0d3-4e84-8688-98e3c50723b0][kill-whole-line]] | [[#869f0aec-c739-4fb7-8e3a-8b55ab637765][print-var-at-point]] | [[#e7e4dd0b-418f-48ee-b366-9e733e3bec61][kill rest of line]] | | - | g | [[#a58a1eda-43ed-437e-b483-5c312e0754a7][other-window / cancel]] | [[#a287d720-4419-4546-8262-1f377bb158d2][abort-recursive-edit]] | [[#327e18af-30b7-47e5-aa53-5f678788b4c1][gnus]] | | - | z | [[#5c30ce7e-8bc6-45bf-b9b1-5c75334a3e27][undo-tree-undo]] | | | | - | x | [[#ec1403d3-528e-41b1-a195-5563bc93e124][kill-region]] | [[#bb7c95d5-dd97-439d-bf1f-cdac98d11543][append-next-kill]] | [[#47cc90e3-335f-4c44-9f39-b732e5440664][append-next-kill]] | | - | c | [[#400f06e1-8e45-443c-8d7b-3d1bb1176aab][copy]] | [[#7a265014-1e9c-4639-ad1d-26b3416379a8][org-capture]] | [[#503e0beb-6fda-4e94-9678-d58bd3cbbc8e][copy-to-register]] | | - | v | [[#16411f68-7fe0-49e8-9a73-212471594f9e][yank]] | [[#fe04fffa-6f85-483a-b329-938531109c35][insert-register]] | [[#c559e9ea-1218-4ccb-9c3a-74cbac4be220][yank pop]] | | - | b | [[#3090fb11-9a11-47e5-bc98-080ebd250d37][delete-other-windows]] | [[#c18b9197-3d52-45a6-9d20-50d18fe1e7a7][isearch-backward-current-symbol]] | [[#e9dd549f-d031-418a-a0d5-30cf85e91c37][isearch-current-symbol]] | | - | tab | [[#928505cb-707c-47ba-af54-5ae1df2ee07d][yas-insert-snippet]] | [[#64f91d86-afa9-4500-8d7d-ce8b2668726b][indent line]] | | | - | delete | [[#e3d8653e-2282-4e3a-a4f5-29211ba2e647][kill-symbol]] | | [[#d9664937-d61c-4cc8-89c6-7f2182655c20][kill-sexp]] | | - | left-arrow | [[#601c8172-f9b7-4e36-88ab-c66c2911b4d7][compile]] | | [[#91ddc121-db27-4f1c-a9ec-a4d29b96a7d2][org-shiftup]] | | - | right-arrow | [[#5f66f60b-adcd-45dc-86b2-5d1225e2455c][paste selection]] | | [[#fc2147b4-a19a-4fde-bb53-e7ac28f0bfa1][org-shiftdown]] | | - | backspace | [[#96f90a00-2260-4340-ae03-f4a86bd65502][backward-kill-symbol]] | | [[#606b0991-7431-4a8a-a909-b872e104cc88][backward-kill-sexp]] | | - | f7 | | | | | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | right primary | C- | M- | C-M- | C-S- | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | * | [[#045c374c-b03e-42cb-b274-0f30c81fe3f3][split-window-horizontally]] | | [[#05cf6230-9263-4fd4-9812-4f32009eed46][calc-dispatch]] | | - | 9 | [[#43d14154-2722-4ba5-b547-1b78c6274ebf][delete-window-or-exit]] | [[#ed93f5b8-2c7f-46f8-8d84-2e10d9bc8f87][kill-buffer-and-window]] | [[#37ef629b-fdbc-4d0b-bfa0-335eb1d408ee][kill client buffer]] | | - | u | [[#327992c0-6eba-4935-aec1-49871c2a8619][universal-argument]] | | [[#7af825b1-92d8-4d5d-aaa1-8b4b466ea2e0][search-keybind]] | | - | i | [[#3124e200-1d6e-4ad2-9a36-0d03e1e7dc38][-----]] | | [[#b2cc7cdd-c177-4ef2-af43-28ca7a338fda][query-replace-regexp]] | | - | o | [[#b87a2c8a-7eb3-4661-9b28-589d14206c41][occur]] | | [[#d30ac3cd-1963-4bd0-8052-98e12b6524b0][counsel-imenu]] | | - | p | [[#d84de055-e92e-478d-bb39-bc39acfa1586][move-mouse-to-point]] | | [[#08e65732-2fb1-4a78-9d18-cee87eb867a7][delete-horizontal-space]] | | - | j | [[#ca1ce86b-dcea-45c1-9a8e-dd4f306776e8][pop-to-mark]] | [[#b92414e2-0d5b-4576-8fa5-5e7f1e32819a][previous-error]] | [[#8fe7cac2-ab1a-4b39-aced-10c5e0157e68][register prefix]] | | - | k | [[#eb1c2360-bfd4-4d5c-b789-11b5ca5ba475][jump to register]] | [[#9061b192-735a-4273-ae36-993e6fad9205][next-error]] | [[#e1d768be-6b9b-4322-931f-3e570376ae15][man]] | | - | l | [[#137995db-ee30-4738-90e2-54dcd5cadcf2][ivy-switch-buffer]] | | [[#56fcff3b-ffd9-4280-a226-4b58558906b8][move cursor top bottom mid]] | | - | ; | [[#150bef9a-3faa-4c72-a176-88c3be56f612][comment-dwim]] | [[#211e76d9-d89a-4cc6-abce-69397d456fda][comment-dwim]] | [[#17035e1e-bbe6-44a6-ad54-6a39b04feac3][comment-current-line-dwim]] | | - | m | | | [[#9a6a1998-4ed6-485e-9b2d-c36a42d7ec1a][recursive grep]] | | - | , | [[#e4f617b2-d3f1-47e4-ae7f-2d64c4fd47b9][counsel-find-file]] | | [[#e0691924-11e1-48d2-abee-27945a409676][find-file-in-project]] | | - | . | [[#6e97b7f1-c5cf-48bb-9c09-db1950dc1eae][recentf-ido-find-file]] | | [[#824d422c-67b6-4d68-af11-6a2135e528f5][-]] | | - | / | [[#941a7fa8-84b9-434d-89a0-1487385ec479][join lines]] | | [[#37f67593-4f60-4d3b-9aad-6c9bc4882443][copy-variable]] | | - | 8 | [[#45644cfa-d408-4a69-a97a-545ef46ba656][calc-embedded-word]] | | | | - | up-arrow | [[#2dade04a-8ac7-483c-8675-5268af6eca2b][back defun/headline]] | | | [[#572d6618-471a-43c7-8a50-3f5e56f45cd7][winner undo]] | - | down-arrow | [[#a1f25c12-3523-45bd-9bf5-62bf3cd5ca43][forward dfun/headline]] | | [[#57a09286-94c6-4b9f-953a-7368743f95ec][toggle-mark-activation]] | [[#9c87093b-7e30-44fb-83c9-c1b176074a5d][smex-major-mode-commands]] | - | lbracket | [[#9d9916dd-3280-47dd-aab1-cd28d5ebfe15][----]] | | [[#c10b53e9-657c-48f4-8afb-cad0e709bcd6][scroll-right]] | | - | rbracket | [[#21b38c6b-3a46-4a08-8eca-d44abb148287][fill-paragraph]] | | [[#095c3d97-bc49-419a-a8c0-c7a21d46d980][scroll-left]] | | - | return | [[#db6e4c41-c048-4bef-b0c9-e129464c056d][newline next line]] | [[#10b2591a-5628-46ee-b395-682e91efcb83][non-indented newline]] | [[#1fc4f025-719f-4866-a9ab-23b30e4581b1][open newline on previous line]] | | - | space | [[#b7d5a893-3045-4968-a150-cb813fddfe9e][org-edit-special]] | | [[#47b5912e-edc7-42ec-841b-f0e202b7f593][spell check word]] | | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | left secondary | C- | M- | C-M- | C-S- | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | = | | | | | - | 1 | | | | | - | 4 | | | [[#2d4de3c9-9e0c-4ab4-89e3-e41bfed3c9a7][widen]] | | - | 5 | | | | | - | tab-key | [[#2f527321-7f78-421b-b0c4-6fc810da0246][query-replace]] | | | | - | t | [[#3bcdf4a3-f33c-4dad-ba94-e4fd3775eca6][org change todo state]] | | [[#47c64b9c-346d-45ad-8c38-865fe22d31a6][org insert timestamp]] | | - | home | [[#1919659a-b466-4519-9276-8bf06a916066][start of buffer]] | | | | - | end | [[#0a7bd629-cbcc-4761-8fe2-cc9370b985a4][end of buffer]] | | | | - | f9 | | | | | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | right secondary | C- | M- | C-M- | C-S- | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - | 6 | [[#e44e584b-d925-4036-9ad5-a90d02e74bef][save-buffers-kill-emacs]] | | [[#da73de75-0914-4f48-81d5-9b408433b14b][insert-small-copyright]] | | - | 7 | | | [[#a68c6b8e-9911-475e-ab35-e239771fe881][insert-full-copyright]] | | - | 0 | [[#96ae2fcc-3a0c-40c4-aef8-06aff3fd42be][text-scale-reset]] | | [[#0e7f83a5-600e-4016-af98-95904300c016][insert-apache]] | | - | - | | | [[#6febc7ea-9cc7-488c-af34-538b8e69633b][org-edit-src-exit]] | | - | y | [[#97aee7f1-3647-4602-a65a-45e8a3aa3a7c][undo-tree-redo]] | | | | - | \ | [[#69005926-08ab-4adc-a163-44fed609cc95][sr-speedbar-toggle]] | | [[#27045e96-59a3-45b4-b0ff-6247aa5ed47e][mark-defun]] | | - | h | [[#3c5f241f-fc62-459d-ab85-6b7c1fb04801][help-prefix]] | | | | - | ' | [[#9f252721-a2d5-46c6-b268-8ed597256229][eval-expression]] | | | | - | n | [[#65ac9206-1a67-48dc-8b72-26d763d7bf2b][unpop-to-mark-command]] | | [[#34fb8fbd-42dc-46b0-8c3c-c7e51edc9687][narrow-to-region]] | | - | rshift | | | | | - | escape | [[#da8bae21-a7be-45de-8027-1b26e6285e40][find-tag]] | | | | - |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------| - #+END: - - -* keybind notes -common keys, which would be better off doing swaps than rebinds: -c-x prefix -> c-s -c-c prefix -> c-d -yank c-y -> c-c -search c-s -> kp-add -kill line c-k -> c-f -undo c-_ -> c-z -set-mark-command c-@ -> kp-enter -quoted-insert c-q -> c-m-q -recenter-top-bottom c-l -> c-m-3 -kill-region c-w -> c-x - -commands to make less accessible -narrow-to-defun/subtree -> M-2 maybe -occur - -command to make more accessible, ... - - -* TESTING / DEVELOPMENT AREA - -(defun comint-send-string (process string) - "Like `process-send-string', but also does extra bookkeeping for Comint mode." - (if process - (with-current-buffer (if (processp process) - (process-buffer process) - (get-buffer process)) - (comint-snapshot-last-prompt)) - (comint-snapshot-last-prompt)) - (process-send-string process string)) - - diff --git a/myinit.el b/myinit.el index 2e1f383..5c5d102 100644 --- a/myinit.el +++ b/myinit.el @@ -15,6 +15,40 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . +;;; Weird package bug workaround + + +;; without this, when installing a package, this message happens +;; +;; custom-handle-keyword: Unknown keyword :group +;; +;; but when i lookup the function, i get the following, and if +;; I evaluate it, the error goes away. so I think the real +;; definition is happening somewhere else + +(defun custom-handle-keyword (symbol keyword value type) + "For customization option SYMBOL, handle KEYWORD with VALUE. +Fourth argument TYPE is the custom option type." + (if purify-flag + (setq value (purecopy value))) + (cond ((eq keyword :group) + (custom-add-to-group value symbol type)) + ((eq keyword :version) + (custom-add-version symbol value)) + ((eq keyword :package-version) + (custom-add-package-version symbol value)) + ((eq keyword :link) + (custom-add-link symbol value)) + ((eq keyword :load) + (custom-add-load symbol value)) + ((eq keyword :tag) + (put symbol 'custom-tag value)) + ((eq keyword :set-after) + (custom-add-dependencies symbol value)) + (t + (error "Unknown keyword %s" keyword)))) + + ;;; misc emacs documentation ;;;; how to find auto-saved files that need recovering @@ -135,7 +169,7 @@ ;;; things that should be at the beginning ;; todo, evaluating this manually disables debug on error instead of toggling it -;;(toggle-debug-on-error) ;uncomment to help debug and catch errors +(toggle-debug-on-error) ;uncomment to help debug and catch errors ;; packages installed from package manager: i pretty much prioritize repos this way: gnu, then melpa, then marmalade. @@ -193,11 +227,6 @@ (setq custom-file "~/.emacs.d/custom.el") (load custom-file 'noerror) -;; undo tree stuff -;; more resilient undo-tree-history if we have their locations set up front. -(setq undo-tree-history-directory-alist '(("." . "~/.undo-tree-history"))) -;; Undo in region just happens accidentally, and throws me off, and it's been buggy in the past -(setq undo-tree-enable-undo-in-region nil) ;;; abreviations @@ -497,9 +526,8 @@ A non-nil CURRENT-ONLY argument means save only current buffer." ;;; bbdb ;; based on bbdb manual -;; also has instructions to initialize upon launching gnus, etc -;; but I figure try this to make sure everything works all the time first -(require 'bbdb) +;; also has instructions to integrate with gnus, + (bbdb-initialize 'message) ;; recommended by gnus, @@ -509,18 +537,19 @@ A non-nil CURRENT-ONLY argument means save only current buffer." (setq message-kill-buffer-on-exit t) -;; based on emacs24-starter-kit -(setq bbdb-offer-save 'auto - bbdb-notice-auto-save-file t - bbdb-expand-mail-aliases t - bbdb-canonicalize-redundant-nets-p t - bbdb-complete-name-allow-cycling t) ;; use d instead (add-hook 'bbdb-mode-hook - (lambda () (define-key bbdb-mode-map (kbd "C-k") nil))) + (lambda () (define-key bbdb-mode-map (kbd "C-k") nil)) + ;; based on emacs24-starter-kit + (setq bbdb-offer-save 'auto + bbdb-notice-auto-save-file t + bbdb-expand-mail-aliases t + bbdb-canonicalize-redundant-nets-p t + bbdb-complete-name-allow-cycling t) + ) -(require 'bbdb-csv-import) +;;(require 'bbdb-csv-import) ;;; bookmark settings ; save bookmarks whenever they are changed instead of just when emacs quits @@ -560,12 +589,16 @@ A non-nil CURRENT-ONLY argument means save only current buffer." (defun toggle-night () (interactive) (cond ((equal (car custom-enabled-themes) 'naquadah) - (override-theme 'occidental)) + (override-theme 'leuven)) (t (override-theme 'naquadah)))) -;; for a long time i used leuven plus this, but it doesn't like dark terminal -;;(custom-set-faces `(default ((t (:background "#F6F6F0"))))) -(override-theme 'occidental) + + +;; in the leuven theme file, i made this change. will need to remake it +;; on package updates. I could fork, but its a pretty simple change +;; < `(default ((,class (:foreground "#333333" :background "#FFFFFF")))) +;; > `(default ((,class (:foreground "#333333" :background "#F6F6F0")))) +(override-theme 'leuven) ;; disable color thing with this: @@ -1056,10 +1089,10 @@ https://fsf.org | https://gnu.org (add-hook 'haskell-mode-hook (lambda () (define-key haskell-mode-map (kbd "C-(") - (lambda () (interactive) - (basic-save-buffer) - (haskell-compile) - (run-with-timer .3 nil 'repeat-shell))))) + (lambda () (interactive) + (basic-save-buffer) + (haskell-compile) + (run-with-timer .3 nil 'repeat-shell))))) (add-hook 'haskell-cabal-mode-hook (lambda () (define-key haskell-cabal-mode-map (kbd "C-(") 'haskell-compile))) @@ -1233,7 +1266,7 @@ https://fsf.org | https://gnu.org ;;(add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode)) (require 'outshine) -(add-hook 'outline-minor-mode-hook 'outshine-hook-function) +(add-hook 'outline-minor-mode-hook 'outshine-mode) (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode) (add-hook 'sh-mode-hook 'outline-minor-mode) @@ -1464,6 +1497,14 @@ https://fsf.org | https://gnu.org (setq tramp-default-method "ssh") ;;; misc general settings +(ivy-mode 1) +(add-hook 'text-mode-hook (lambda () (auto-fill-mode t))) +(setq counsel-find-file-at-point t) + +;; easier to read with just spaces as separator +(setf (nth 2 ido-decorations) " ") + + ;; https://www.emacswiki.org/emacs/FillParagraph ;; make list items start paragraphs. (setq paragraph-start "\f\\|[ \t]*$\\|[ \t]*[-+*] ") @@ -1721,7 +1762,6 @@ Go to the next directory based on where the cursor is." (dot-mode . "") (yas-global-mode . "") (yas-minor-mode . "") - (undo-tree-mode . "") (volatile-highlights-mode . "") (highlight-symbol-mode . "") ;; Major modes @@ -1791,6 +1831,14 @@ Go to the next directory based on where the cursor is." (y (cdr pos))) (set-mouse-position (selected-frame) x y))) +;;;; keybinds for wow mouse + +(global-set-key (kbd "") 'move-mouse-to-point) +(global-set-key (kbd "") 'indent-region) +(global-set-key (kbd "") 'mark-defun) +(global-set-key (kbd "") 'ibuffer) +(global-set-key (kbd "") 'delete-horizontal-space) + ;;; org mode ;; todo work on org-cycle-emulate-tab @@ -2129,22 +2177,6 @@ indent yanked text (with prefix arg don't indent)." (setq TeX-parse-self t) -;;; undo tree - -;; undo-tree checks for minor modes which override -;; its minor mode keymap, and sets global keybinds if -;; that happens. this will prevent that, but I have no -;; reason to do that, so it is commented. -;; (defun undo-tree-overridden-undo-bindings-p () nil) - -;; todo, send patch undo-tree-visualize should scroll with the scroll key, instead of just pgup pgdn (aka next/prior) -(global-undo-tree-mode) -;; disabled due to bug, something like unknown entry in undo tree canary -;; (setq undo-tree-auto-save-history t) -(setq undo-outer-limit 100000000 ; per undo command - undo-limit 500000000 ; undo history limit - undo-strong-limit 600000000) ; undo history limit plus some extra - ;;; visible mark mode @@ -2215,6 +2247,19 @@ indent yanked text (with prefix arg don't indent)." erc-track-switch-direction 'importance) +;;; named commands +(defun rm-file-and-buffer () + "Removes file connected to current buffer and kills buffer." + (interactive) + (let ((filename (buffer-file-name)) + (buffer (current-buffer)) + (name (buffer-name))) + (if (not (and filename (file-exists-p filename))) + (error "Buffer '%s' is not visiting a file!" name) + (delete-file filename) + (kill-buffer buffer) + (message "File '%s' successfully removed" filename)))) + ;;; persistent registers ;; This needs to be at the end, because I visit a file, thus setting a ;; mode, and the mode hook needs to be setup before that. @@ -2229,3 +2274,1295 @@ indent yanked text (with prefix arg don't indent)." (?x (file . ,"/a/x.txt")) )) (set-register (car r) (cadr r))) + +(setq undo-outer-limit 100000000 ; per undo command + undo-limit 500000000 ; undo history limit + undo-strong-limit 600000000) ; undo history limit plus some extra + +;;; keybinds + +;;;; misc +(global-set-key (kbd "C-x C-b") 'ibuffer) + + +;; isearch-occur +;; Activate occur easily inside isearch +;; from starter-kit + +(define-key isearch-mode-map (kbd "C-o") + (lambda () (interactive) + (let ((case-fold-search isearch-case-fold-search)) + (occur (if isearch-regexp + isearch-string + (regexp-quote isearch-string)))))) + + +(defun my-isearch-toggle-regexp () + (interactive) + (isearch-toggle-regexp) + (cond (isearch-regexp + (global-set-key (kbd "C-r") 'isearch-backward-regexp) + (define-key global-map (kbd "") 'isearch-forward-regexp)) + (t + (global-set-key (kbd "C-r") 'isearch-backward) + (define-key global-map (kbd "") 'isearch-forward)))) +(define-key isearch-mode-map (kbd "M-r") 'my-isearch-toggle-regexp) + + +(define-key Info-mode-map "x" 'Info-follow-nearest-node) + + +;;;; single/special keys +;;;;; tab - isearch +(define-key isearch-mode-map (kbd "") 'isearch-query-replace) + +;;;;; f12 - isearch-forward +;; explained in http://stackoverflow.com/questions/7411920/how-to-bind-search-and-search-repeat-to-c-f-in-emacs +(global-set-key (kbd "") 'isearch-forward) +(global-set-key (kbd "") 'isearch-forward) +(define-key isearch-mode-map "\t" nil) +(define-key isearch-mode-map (kbd "") 'isearch-repeat-forward) +(define-key isearch-mode-map (kbd "") 'isearch-repeat-forward) +;; get rid of the standard completion binding, always use auto-complete +;; this didn't work very well +;;(global-set-key (kbd "TAB") 'auto-complete) +(define-key global-map [remap completion-at-point] 'auto-complete) + +;;;;; end - move-end-of-line +;; taken from emacs wiki, along with home function +;; http://www.emacswiki.org/emacs/BackToIndentationOrBeginning +(defun point-in-comment () + "Determine if the point is inside a comment" + (interactive) + (let ((syn (syntax-ppss))) + (and (nth 8 syn) + (not (nth 3 syn))))) +(defun end-of-code-or-line (arg) + "Move to end of line, or before start of comments depending on situation. + Toggle back and forth positions if we are already at one. + Comments are recognized in any mode that sets syntax-ppss + properly." + (interactive "P") + (when (catch 'bol + (let ((start (point)) + (bol (save-excursion + (beginning-of-line) + (point))) + (eol (progn (move-end-of-line arg) (point)))) + (while (point-in-comment) + (backward-char) + (when (= (point) bol) + (throw 'bol t))) + (throw 'bol (and (not (= eol start)) (>= start (point)))))) + (move-end-of-line arg))) + +(global-set-key (kbd "") 'end-of-code-or-line)(add-hook 'org-mode-hook (lambda () (define-key org-mode-map (kbd "") 'org-end-of-line))) + +;;;;; home - back-to-indentation +(defun back-to-indentation-or-beginning () + (interactive) + (if (= (point) (progn (back-to-indentation) (point))) + (if (derived-mode-p 'org-mode) + (org-beginning-of-line) + (beginning-of-line)))) +(global-set-key (kbd "") 'back-to-indentation-or-beginning) + +;;;;; s-tab - indent-buffer +(global-set-key (kbd "") 'indent-buffer) +;;;;; s-delete - send-shell + +(global-set-key (kbd "") 'send-shell) + +;; optional variables used by send-shell +(setq shell-send-yank-key nil) + +(defun repeat-shell () + (interactive) + "Repeat the last command in shell-mode, displaying the window if needed." + (let ((shell-buffer (get-buffer "*shell*"))) + (if shell-buffer + (buffer-window-show shell-buffer) + (let ((original-buffer (current-buffer))) + (funcall 'shell) + (setq shell-buffer (current-buffer)) + (switch-to-buffer original-buffer))) + (with-current-buffer shell-buffer + (goto-char (point-max)) + (call-interactively 'comint-previous-input) + ;; the t flag makes the buffer advance + (comint-send-input nil t)))) + +(setq compilation-filenames '("Makefile" "makefile")) + +(defun get-nearest-compilation-file () + "Search for the compilation file traversing up the directory tree." + (interactive) + (let ((dir default-directory) + (parent-dir (file-name-directory (directory-file-name default-directory))) + (nearest-compilation-file 'nil)) + (while (and (not (string= dir parent-dir)) + (not nearest-compilation-file)) + (dolist (filename compilation-filenames) + (setq file-path (concat dir filename)) + (when (file-readable-p file-path) + (setq nearest-compilation-file file-path))) + (setq dir parent-dir + parent-dir (file-name-directory (directory-file-name parent-dir)))) + nearest-compilation-file)) +(defun run () + (interactive) + "call run-fun if it is set, else run make if there is a makefile, +else save and repeat last shell command. +run-fun is meant to store file local variables, which show how to +do the main thing we want on this file, generally compile and +run. + +example of setting it in a file: +;; Local Variables: +;; run-fun: merge-test +;; End: " + (basic-save-buffer) + (if (and (boundp 'run-fun) run-fun) + (funcall run-fun) + (let ((makefile (get-nearest-compilation-file))) + (if (and makefile (stringp mode-name) (string= mode-name "C/l")) + (compile (format + "make -f %s" (get-nearest-compilation-file))) + (repeat-shell))))) + + +(defun send-shell () + (interactive) + (send-shell-buffer "*shell*" 'shell (kbd "C-v"))) + +(defun send-python () + (interactive) + (send-shell-buffer "*Python*" 'py-shell (kbd "C-v"))) + + +(defun send-shell-buffer (buffer-name &optional init shell-send-yank-key) + "Send current line or region to shell-mode buffer. +When in shell-mode, copy the current line to the +most recently visited visible window. + +SHELL-SEND-YANK-KEY: key to use instead +of yank to paste into recent window. This allows compatibility with +modes like org-mode which have their own yank function." + (if (string= (buffer-name) buffer-name) + ;; this section is copied out of comint-send-input + (progn + (let ((proc (get-buffer-process (current-buffer)))) + (if (not proc) (user-error "Current buffer has no process") + (widen) + + (let* ((pmark (process-mark proc)) + (intxt (if (>= (point) (marker-position pmark)) + (progn (if comint-eol-on-send (end-of-line)) + (buffer-substring pmark (point))) + (let ((copy (funcall comint-get-old-input))) + (goto-char pmark) + (insert copy) + copy)))) + + (if (= (length intxt) 0) + (kill-new (comint-previous-matching-input-string "." 1)) + (kill-new intxt))))) + (kill-append "\n" nil) + (select-window (previous-window nil nil 'visible)) + (if (and (boundp 'shell-send-yank-key) shell-send-yank-key) + (call-interactively (global-key-binding shell-send-yank-key)) + (yank)) + (select-window (next-window nil nil 'visible))) + (let (start end) + (if mark-active + (setq start (mark) + end (point)) + (setq start (save-excursion (beginning-of-line) (point)) + end (save-excursion (end-of-line) (point))) + (let (line-move-visual) + (call-interactively 'next-line))) + (send-comint-input buffer-name start end init)))) + +;; supporting functions +(defun send-comint-input (buffer-name start end &optional init) + "Input the region to BUFFER-NAME, assuming it is a comint-derived buffer. + Show BUFFER-NAME if it is not show. + Call INIT if BUFFER-NAME does not exist." + (let ((input (filter-buffer-substring start end))) + (send-comint-string buffer-name input init))) + +(defun send-comint-string (buffer-name string &optional init) + "Input the string to BUFFER-NAME, assuming it is a comint-derived buffer. + Show BUFFER-NAME if it is not show. + Call INIT if BUFFER-NAME does not exist." + (let ((buffer (get-buffer buffer-name))) + (unless buffer + (message "nobuffer") + ;; save-excursion etc. don't work for (shell), so I do this instead + (if init (let ((original-buffer (current-buffer))) + (funcall init (and (boundp 'send-shell-buffer-name) send-shell-buffer-name)) + (switch-to-buffer original-buffer) + (setq buffer (get-buffer buffer-name))) + (error "No existing buffer found and no init function argument. "))) + (buffer-window-show buffer) + (with-current-buffer buffer + (let ((proc (get-buffer-process buffer))) + (goto-char (process-mark proc)) + (insert string) + (comint-send-input nil t))))) + +(defun buffer-window-show (&optional buffer action) + "Like temp-buffer-window-show, but removed stuff + relevant to it being temp or help." + (let (window frame) + (with-current-buffer buffer + (when (let ((window-combination-limit + ;; When `window-combination-limit' equals + ;; `temp-buffer' or `temp-buffer-resize' and + ;; `temp-buffer-resize-mode' is enabled in this + ;; buffer bind it to t so resizing steals space + ;; preferably from the window that was split. + (if (or (eq window-combination-limit 'temp-buffer) + (and (eq window-combination-limit + 'temp-buffer-resize) + temp-buffer-resize-mode)) + t + window-combination-limit))) + ;; debug + ;;(message "window-combination-limit") + ;;(print window-combination-limit) + (setq window (display-buffer buffer action))) + (setq frame (window-frame window)) + (unless (eq frame (selected-frame)) + (raise-frame frame)) + (setq minibuffer-scroll-window window) + (set-window-hscroll window 0) + ;; Return the window. + window)))) + + +;; when poping help, etc, allow reusing a window in a different frame if it is visible +;; figured this out after spending quite a while reading doc string for display-buffer +;; which is the main function which uses this. +;; it will use other vars or its arg to override this, +;; but those things are often nil. +;; aha moments in reading it: ACTION = (FUNCTION-or-FUNCTIONLIST ALIST) +;; FRAME adds an association to ACTION's alist, but it's not used if ACTION arg is nil. +(setq display-buffer-fallback-action `(,(car display-buffer-fallback-action) . '(reusable-frames . visible))) +;; stop splitting windows verticallly when I open a buffer or shell +(setq split-height-threshold nil) + +;;;;; s-left arrow - shell +(global-set-key (kbd "") 'shell-wrap) +(add-hook 'org-mode-hook + (lambda () + (define-key org-mode-map (kbd "") nil))) + +;;;;; s-right arrow - keyboard-yank-primary +(defun keyboard-yank-primary () + (interactive) + (let ((mouse-yank-at-point t)) + (mouse-yank-primary nil))) +;; paste selection +(global-set-key (kbd "") 'keyboard-yank-primary) +(add-hook 'org-mode-hook + (lambda () + (define-key org-mode-map (kbd "") nil))) +;;;;; esc + ; todo, test out if this can be used +;;;;; return - new line + +;; todo, this doesn't set the keybind for the help minibuffer + + +(global-set-key (kbd "\r") 'indent-new-comment-line) + +;; don't use enter for autocomplete, we use tab or something +(define-key ac-completing-map (kbd "") nil) +(define-key ac-completing-map "\r" nil) + +(add-hook 'org-mode-hook + (lambda () + ;; copied from org-mode, replace org-enter with org-enter-indent + (org-defkey org-mode-map "\C-m" 'org-return-indent))) + + +(add-hook 'comint-mode-hook + (lambda () + (define-key comint-mode-map "\r" nil) + (define-key comint-mode-map (kbd "") 'comint-send-input))) + +(add-hook 'comint-mode-hook + (lambda () + (define-key comint-mode-map "\C-m" nil) + (define-key comint-mode-map "\C-d" nil))) + +;;;;; s-return - auto-correct-prev-word +(global-set-key (kbd "") 'flyspell-auto-correct-previous-word) +;; kp-enter is shift return in terminal +(global-set-key (kbd "") 'flyspell-auto-correct-previous-word) + +;;;;; s-down arrow - my-contract-region +(global-set-key (kbd "") 'my-contract-region) +;;;;; c-up/down move 8 lines + +;; compiling warns that next-line should be called interactively, +;; but we would have to do something dumb, like give it a +;; vector of keys in order to supply the 8 argument +(defun down-fast () + (interactive) + (next-line 8)) +(defun up-fast () + (interactive) + (next-line -8)) + +(global-set-key (kbd "") 'up-fast) +(global-set-key (kbd "") 'down-fast) + +;;;;; c-scroll comint prev/next prompt + +(add-hook 'comint-mode-hook + (lambda () + (define-key comint-mode-map (kbd "") 'comint-previous-prompt) + (define-key comint-mode-map (kbd "") 'comint-next-prompt))) +;;;;; m-scroll prev/next sexp +(global-set-key (kbd "") 'backward-sexp) +(global-set-key (kbd "") 'forward-sexp) +;;;;; S-scroll expand/contract region +(global-set-key (kbd "") 'my-contract-region) +(global-set-key (kbd "") 'er/expand-region) +(global-set-key (kbd "") 'my-contract-region) +(global-set-key (kbd "") 'er/expand-region) + +(defun my-contract-region (arg) + (interactive "p") + (let ((current-prefix-arg '-)) + (call-interactively 'er/expand-region))) + +;; todo: define c-m scroll. i manually set to normal scrolling, i dunno why + + +;;;;; c-s-scroll scale text + +(global-set-key (kbd "") 'text-scale-increase) +(global-set-key (kbd "") 'text-scale-decrease) +(global-set-key (kbd "") 'text-scale-increase) +(global-set-key (kbd "") 'text-scale-decrease) +(global-set-key (kbd "") 'text-scale-increase) +(global-set-key (kbd "") 'text-scale-decrease) + + +;;;;; s-up arrow er/expand-region +(global-set-key (kbd "") 'er/expand-region) +;;;;; c-left/right move symbol + +(global-set-key (kbd "") 'backward-symbol) +(global-set-key (kbd "") 'forward-symbol) + +;;;; left primary + +;;;;; C-2 copy-symbol + +(global-unset-key (kbd "C-2")) +(defun copy-symbol (&optional arg) + "Copy symbol at point into kill-ring" + (interactive "P") + (kill-new (thing-at-point 'symbol))) + +(global-set-key (kbd "C-2") 'copy-symbol) + +;;;;; M-2 shell-cd-to-file + + +(defun shell-cd-to-file () + (interactive) + (let ((file (buffer-file-name))) + (if file + (send-comint-string "*shell*" + (concat "c " (file-name-directory file)) + 'shell) + (message "%s" "shell-cd-to-file: buffer has no file name")))) +(global-set-key (kbd "M-2") 'shell-cd-to-file) + +;;;;; C-M-2 --- + ; todo. whats going on here? +(global-unset-key (kbd "C-M-2")) + +;;;;; C-3 dot-mode-execute + +(global-set-key (kbd "C-3") 'dot-mode-execute) + +;;;;; C-M-3 recenter-top-bottom + +(global-set-key (kbd "C-M-3") 'recenter-top-bottom) + +;;;;; C-q org-cycle, comint previous arg + +(global-set-key (kbd "C-q") 'bicycle-cycle) +(add-hook 'org-mode-hook + (lambda () (define-key org-mode-map (kbd "C-q") 'org-cycle))) +(define-key widget-keymap (kbd "C-q") 'widget-forward) +(add-hook 'comint-mode-hook + (lambda () (define-key comint-mode-map (kbd "C-q") 'comint-insert-previous-argument))) + +;;;;; M-q org-archive-to-archive-sibling + +(global-set-key (kbd "M-q") 'org-archive-to-archive-sibling) + +;;;;; C-M-q quoted-insert + +(global-set-key (kbd "C-M-q") 'quoted-insert) + +;;;;; C-w --- +;; in terminal, it's ctrl-backspace, duplicate keybind. +;;;;; M-w org-clock-in + +(global-set-key (kbd "M-w") 'org-clock-in) + +;;;;; C-e copy-line + +;; todo, make repeated calls to this append the kills +(defun copy-line (&optional arg) + "Copy lines (as many as prefix argument) in the kill ring. + Ease of use features: + - Move to start of next line. + - Appends the copy on sequential calls. + - Use newline as last char even on the last line of the buffer. + - If region is active, copy its lines." + (interactive "p") + (let ((beg (line-beginning-position)) + (end (line-end-position (or arg 1)))) + (when mark-active + (if (> (point) (mark)) + (setq beg (save-excursion (goto-char (mark)) (line-beginning-position))) + (setq end (save-excursion (goto-char (mark)) (line-end-position))))) + (if (eq last-command 'copy-line) + (kill-append (buffer-substring beg end) (< end beg)) + (kill-ring-save beg end))) + (kill-append "\n" nil) + ;; dun need cuz I have yank-better + ;;(beginning-of-line (or (and arg (1+ arg)) 2)) + (if (and arg (not (= 1 arg))) (message "%d lines copied" arg))) + +(global-set-key (kbd "C-e") 'copy-line) + +;;;;; M-e org-clock-in-last + +(global-set-key (kbd "M-e") 'org-clock-in-last) + +;;;;; C-r isearch-backward + +(global-set-key (kbd "C-r") 'isearch-backward) +(add-hook 'comint-mode-hook + (lambda () + (define-key comint-mode-map (kbd "C-r") 'comint-history-isearch-backward-regexp))) + +;;;;; M-r org-clock-out + +(global-set-key (kbd "M-r") 'org-clock-out) + +;;;;; C-a copy buffer + +(defun copy-all () + "Copy entire buffer to clipboard" + (interactive) + (clipboard-kill-ring-save (point-min) (point-max))) +(global-set-key (kbd "C-a") 'copy-all) + +;;;;; C-s - c-x prefix + ; prefix key binds. + ; good info http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/ + ; rebinding the prefix keys are tricky. apparently, some modes ignore any redefinition of a prefix key and use it explicitly, + ; so you have to dig into their key maps and redo things. + ; There are 2 simpler alternatives which have their own downsides. + ; One is cua mode, which I do not like because it smashes 2 keybinds onto 1 and limits what you can do. + ; The other is keyboard-translate, which translates the key presses before anything else. + ; The downside is that it translates them when you aren't using them as a prefix. + ; Since the swaps I'm using are all very accessible, the only downside is some mental jugling when reading docs etc about these keybinds. + + ; I've seen this as an another suggestion, it was a total fail. The prefix command took over both keys. + ; (define-key key-translation-map [f12] "\C-c") + ; (define-key key-translation-map "\C-c" [left]) + + + ;idea to remove the hook later since it is only needed at startup. + ; did not work however, and there is not a real need to fix it, so I did not investigate + ;(defun removeSwapHook () + ; (remove-hook 'buffer-list-update-hook 'myKeySwap) + ; (remove-hook 'change-major-mode-hook 'removeSwapHook)) + ;(add-hook 'change-major-mode-hook 'removeSwapHook) + + + ; went through almost all the relevant standard hooks, + ; this overcomes a known bug that (keyboard-translate) does not get applied when running emacs daemon + (add-hook 'buffer-list-update-hook (lambda () (interactive) + (keyboard-translate ?\C-x ?\C-s) + (keyboard-translate ?\C-s ?\C-x) + (keyboard-translate ?\C-c ?\C-d) + (keyboard-translate ?\C-d ?\C-c))) + + + + ; these all don't work + ; don't know why this doesn't error but reversing the keys does + ;(keyboard-translate ?\t ?\M-\t) + ;(keyboard-translate [M-tab] [tab]) + ; from what i can tell, it wants to use a keyboard-translate-table, + ; which is a char table, which is a vector indexed by chars, + ; and mod+tab is not a char (it has too many bits), it is an integer + ; it actually says it can hold vectors or strings, but that it is obsolete to do so + ;(characterp ?\M-a) + ;(characterp ?\C-a) + +;;;;; C-M-s - split-window-vertically + +(global-set-key (kbd "C-M-s") 'split-window-vertically) + +;;;;; C-d - C-c prefix +;;;;; C-M-d - swap buffer across windows +;; from http://www.emacswiki.org/emacs/TransposeWindows + +(setq swapping-buffer nil) +(setq swapping-window nil) +(defun swap-buffers-in-windows () + "Swap buffers between two windows" + (interactive) + (if (and swapping-window + swapping-buffer) + (let ((this-buffer (current-buffer)) + (this-window (selected-window))) + (if (and (window-live-p swapping-window) + (buffer-live-p swapping-buffer)) + (progn (switch-to-buffer swapping-buffer) + (select-window swapping-window) + (switch-to-buffer this-buffer) + (select-window this-window) + (message "Swapped buffers.")) + (message "Old buffer/window killed. Aborting.")) + (setq swapping-buffer nil) + (setq swapping-window nil)) + (progn + (setq swapping-buffer (current-buffer)) + (setq swapping-window (selected-window)) + (message "Buffer and window marked for swapping.")))) + +(global-set-key (kbd "C-M-d") 'swap-buffers-in-windows) + +;;;;; C-f] - kill-whole-line + +(global-set-key (kbd "C-f") 'kill-whole-line-wrapper) +(defun kill-whole-line-wrapper (&optional arg) + "If we are at the end of the file, kill backwards instead of doing nothing." + (interactive "P") + (if (= (point) (point-max)) + (kill-whole-line -1) + (kill-whole-line arg))) + +;;;;; M-f - print-var-at-point + +(defun print-var-at-point () + (interactive) + (let ((v (variable-at-point))) + (if (symbolp v) + (message "%s: %s" v (symbol-value v)) + (message "no symbol found at point")))) +(global-set-key (kbd "M-f") 'print-var-at-point) + + +;;;;; C-M-f - kill rest of line + + +(add-hook 'org-mode-hook + (lambda () + (define-key org-mode-map (kbd "C-M-f") 'org-kill-line))) + +(global-set-key (kbd "C-M-f") 'kill-line) +;;;;; C-g - cancel / other window + +(global-set-key (kbd "C-g") 'other-window) + +;;;;; M-g - abort-recursive-edit + +(global-set-key (kbd "M-g") 'abort-recursive-edit) + +;;;;; C-M-g - gnus + +(global-set-key (kbd "C-M-g") 'mu4e) + +;;;;; C-z - undo-only + +(global-set-key (kbd "C-z") 'undo-only) + +;;;;; C-x - kill-region + +(global-set-key (kbd "C-s") 'kill-region) + +;;;;; M-x - smex + +(global-set-key (kbd "M-x") 'smex) + +;;;;; C-M-x - cut-to-register + +;; same args as copy-to-register +(defun cut-to-register (register start end &optional delete-flag region) + (interactive (list (register-read-with-preview "Cut to register: ") + (region-beginning) + (region-end) + current-prefix-arg + t)) + (copy-to-register register start end t region)) + +(global-set-key (kbd "C-M-x") 'cut-to-register) + +;;;;; C-c - copy + +(global-set-key (kbd "C-d") 'kill-ring-save) +(add-hook 'c-mode-hook + (lambda () (define-key c-mode-map (kbd "C-d") nil))) +(add-hook 'comint-mode-hook + (lambda () + (define-key comint-mode-map (kbd "C-d") nil))) +;; the base map is shared by many c-modes, like java +(add-hook 'c-mode-hook + (lambda () + (define-key c-mode-base-map "\C-d" nil) + (define-key c-mode-base-map (kbd "") 'c-electric-delete-forward))) + + +;;;;; M-c - org-capture + +(define-key global-map "\M-c" 'org-capture) + +;;;;; C-M-c - copy-to-register + +(global-set-key (kbd "C-M-c") 'copy-to-register) + +;;;;; C-v - yank + +(global-set-key (kbd "C-v") 'yank-better) + + + +(defun yank-better (arg) + "Paste, linewise if our kill ends with a newline. + I change the behavior of plain prefix. It makes it not do linewise paste, + because sometimes you want to yank pop and a linewise paste screws that up. + c-u with no number normally makes the point go before the yank. + That is pointless for me, as it would be just as easier and less + thought to pop the mark after yanking cuz it is set to before the mark." + (interactive "*P") + (if (and (not (equal arg '(4))) (string-suffix-p "\n" (current-kill 0 t))) + (beginning-of-line)) + (if (and (stringp mode-name) (string= mode-name "Org")) + (call-interactively 'org-yank) + (setq this-command 'yank) + (call-interactively 'yank (and (not (equal arg '(4))))))) + +(put 'yank-better 'delete-selection 'yank) + +;;;;; M-v - insert-register + +(global-set-key (kbd "M-v") 'insert-register) + +;;;;; C-M-v - yank-pop + +(global-set-key (kbd "C-M-v") 'yank-pop) + +;;;;; C-b - delete-other-windows + +(global-set-key (kbd "C-b") 'delete-other-windows) + +;;;;; M-b - isearch-backward-current-symbol + +(global-set-key (kbd "M-b") 'isearch-backward-current-symbol) + +;;;;; C-M-b - isearch-current-symbol + +(global-set-key (kbd "C-M-b") 'isearch-current-symbol) + +;;;;; C-tab - --- +;; in terminal, it's just TAB, duplicate keybind. +;;;;; M-tab - --- +;; in terminal it's duplicated of C-M-i +;;;;; C-delete - kill-symbol + +(global-set-key (kbd "") 'kill-symbol) +(defun kill-symbol (arg) + (interactive "p") + (kill-region (point) (save-excursion (forward-symbol arg) (point)))) + + +;;;;; C-M-delete - kill-sexp + +(global-set-key (kbd "") 'kill-sexp) + +;;;;; C-left-arrow - compile / comint search + +(defun set-p (var) + (and (bound-and-true-p var) + (not (eq var 'unset)))) +(global-set-key (kbd "C-(") 'run) + +;; make compile work from the gtags root dir +(defadvice compile (before pre-compile-advice activate) + (basic-save-buffer) + (when (set-p ggtags-project-root) + (setq-local compile-saved-dir default-directory) + (setq default-directory ggtags-project-root))) +(defadvice compile (after post-compile-advice activate) + (when (bound-and-true-p compile-saved-dir) + (setq default-directory compile-saved-dir))) + + +(add-hook 'c-mode-hook (lambda () (define-key c-mode-map (kbd "C-(") 'compile))) +(add-hook 'comint-mode-hook + (lambda () + (define-key isearch-mode-map (kbd "C-(") 'isearch-repeat-backward) + (define-key comint-mode-map (kbd "C-(") 'isearch-backward))) + + +;;;;; C-M-left-arrow - org-shiftup + +(add-hook 'org-mode-hook + (lambda () (define-key org-mode-map (kbd "C-M-(") 'org-shiftup))) + +;;;;; C-right-arrow - forward-symbol +;;;;; C-M-right-arrow - org-shiftdown +(add-hook 'org-mode-hook +(lambda () (define-key org-mode-map (kbd "C-M-)") 'org-shiftdown))) + +;;;;; C-backspace - backward-kill-symbol + +(global-set-key (kbd "") 'backward-kill-symbol) +(add-hook 'comint-mode-hook + (lambda () + (define-key comint-mode-map (kbd "") 'backward-kill-word))) +(defun backward-kill-symbol (arg) + (interactive "p") + (kill-region (point) (save-excursion (backward-symbol arg) (point)))) + +;;;;; C-M-backspace - backward-kill-sexp + +(global-set-key (kbd "") 'backward-kill-sexp) + +;;;; right primary +;;;;; C-* - split-window-horizontally + +(global-set-key (kbd "C-*") 'split-window-horizontally) + +;;;;; C-M-* - calc-dispatch + +(global-set-key (kbd "C-M-*") 'calc-dispatch) + +;;;;; C-9 - delete-window-or-exit + +(global-set-key (kbd "C-9") 'delete-window-or-exit) + +(defun delete-window-or-exit () + "Delete window or exit emacs." + (interactive) + (if (condition-case nil (delete-window) (error t)) + (if (or (boundp 'server-process) (> (length (frame-list)) 1)) + (progn (basic-save-buffer) (delete-frame)) + (save-buffers-kill-terminal t)))) + +;;;;; M-9 - kill-buffer + +(defun kill-buffer-no-ido () + "kill-buffer, avoid the ido remapping" + (interactive) + (kill-buffer)) +(global-set-key (kbd "M-9") 'kill-buffer-no-ido) + +;; strangely, in simple mode, this is overridden. +;; I found this map to override, but it didn't work, so it seems its being bound some other way. +;; I did a grep of the emacs sources, but couldn't find anything. +;; (define-key universal-argument-map [?9 nil) + +;;;;; C-M-9 - end server edit +;; save & kill buffer if it was opened externally via emacsclient + + + (defun server-edit-save () + (interactive) + (save-buffer) + (server-edit)) + (global-set-key (kbd "C-M-9") 'server-edit-save) + +;;;;; C-u - universal-argument +;;;;; C-M-u - search-keybind + + (global-set-key (kbd "C-M-u") 'search-keybind) + + (defun search-keybind (regexp &optional nlines) + (interactive (occur-read-primary-args)) + (save-excursion + (describe-bindings) + (set-buffer "*Help*") + (occur regexp) + (delete-windows-on "*Help*") + )) + +;;;;; C-i - ----- +;;;;; C-M-i - query-replace-regexp + + (global-set-key (kbd "C-M-i") 'query-replace-regexp) + (add-hook 'flyspell-mode-hook + (lambda () (define-key flyspell-mode-map (kbd "C-M-i") nil))) + (add-hook 'text-mode-hook + (lambda () (define-key text-mode-map (kbd "C-M-i") nil))) + + +;;;;; C-o - occur + + (global-set-key (kbd "C-o") 'occur) + +;;;;; C-M-o - counsel-imenu + + (global-set-key (kbd "C-M-o") 'counsel-imenu) + +;;;;; C-p - move-mouse-to-point + + (global-set-key (kbd "C-p") 'move-mouse-to-point) + +;;;;; C-M-p - delete-horizontal-space + + (global-set-key (kbd "C-M-p") 'delete-horizontal-space) + +;;;;; C-j - pop-to-mark + + (defun my-pop-to-mark-command () + "Jump to mark, and pop a new position for mark off the ring. + \(Does not affect global mark ring\)." + (interactive) + (pop-to-mark-command) + (if (and (derived-mode-p 'org-mode) (outline-invisible-p)) + (org-show-context 'mark-goto))) + + (global-set-key (kbd "C-j") 'my-pop-to-mark-command) + (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text) + (add-hook 'ido-setup-hook + (lambda () (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text))) + (add-hook 'lisp-interaction-mode-hook + (lambda () + (define-key lisp-interaction-mode-map (kbd "C-j") nil))) + + +;;;;; M-j - previous-error + + (global-set-key (kbd "M-j") 'previous-error) + +;;;;; C-M-j - register prefix + + (define-key global-map (kbd "C-M-j") ctl-x-r-map) + (define-key ctl-x-r-map "m" 'kmacro-to-register) + + +;;;;; C-k - jump-to-register + + + (global-set-key (kbd "C-k") 'jump-to-register) + +;;;;; M-k - next-error + + (global-set-key (kbd "M-k") 'next-error) + +;;;;; C-M-k - man + + (global-set-key (kbd "C-M-k") 'man) + +;;;;; C-l - ivy-switch-buffer + + (global-set-key (kbd "C-l") 'ivy-switch-buffer) + +;;;;; C-M-l - move cursor top bottom mid, comint clear screen + + (global-set-key (kbd "C-M-l") 'move-to-window-line-top-bottom) + +;;;;; C-; - used in flyspell, not sure what for, otherwise unbound +;;;;; M-; - comment-dwim +;;;;; C-M-; - comment-current-line-dwim + + (defun comment-current-line-dwim () + "Comment or uncomment the current line." + (interactive) + (save-excursion + (push-mark (beginning-of-line) t t) + (end-of-line) + (comment-dwim nil)) + (move-beginning-of-line 2)) + (global-set-key (kbd "C-M-;") 'comment-current-line-dwim) + +;;;;; C-M-m - recursive grep + + (define-key global-map (kbd "C-M-m") 'rgrep) + +;;;;; C-, - ounsel-find-file + + (global-set-key (kbd "C-,") 'counsel-find-file) + (add-hook 'flyspell-mode-hook + (lambda () (define-key flyspell-mode-map (kbd "C-,") nil))) + +;;;;; C-M-, - ind-file-in-project + + (global-set-key (kbd "C-M-,") 'find-file-in-project) + +;;;;; C-. - find recent file +;; Taken from starter kit. + + (defun recentf-ido-find-file () + "Find a recent file using Ido." + (interactive) + (let* ((file-assoc-list + (mapcar (lambda (x) + (cons (file-name-nondirectory x) + x)) + recentf-list)) + (filename-list + (remove-duplicates (mapcar #'car file-assoc-list) + :test #'string=)) + (filename (ido-completing-read "Choose recent file: " + filename-list + nil + t))) + (when filename + (find-file (cdr (assoc filename + file-assoc-list)))))) + + (add-hook 'flyspell-mode-hook + (lambda () (define-key flyspell-mode-map (kbd "C-.") nil))) + (define-key dot-mode-map (kbd "C-.") nil) + (global-set-key (kbd "C-.") 'recentf-ido-find-file) + (add-hook 'php-mode-hook + (lambda () (define-key php-mode-map (kbd "C-.") nil))) + +;;;;; C-M-. - - + + (define-key dot-mode-map (kbd "C-M-.") nil) + ;; (global-set-key (kbd "C-M-.") 'execute-extended-command) + +;;;;; C-/ - join lines + + (defun vim-style-join-line () + (interactive) + (join-line '(4))) + (global-set-key (kbd "C-/") 'vim-style-join-line) + +;;;;; C-M-/ - copy-buffer-file-name + + ;; haven't bound this atm, todo, maybe someday? + (defun copy-variable (variable) + (interactive + (let ((v (variable-at-point)) + (enable-recursive-minibuffers t) + val) + (setq val (completing-read (if (symbolp v) + (format + "Describe variable (default %s): " v) + "Describe variable: ") + obarray + (lambda (vv) + (or (get vv 'variable-documentation) + (and (boundp vv) (not (keywordp vv))))) + t nil nil + (if (symbolp v) (symbol-name v)))) + (list (if (equal val "") + v (intern val))))) + (kill-new (symbol-value variable))) + + (defun copy-buffer-file-name () + (interactive) + (let ((name (cond + ((derived-mode-p 'mu4e-view-mode) (mu4e-message-field-at-point :path)) + (t buffer-file-name)) + )) + (kill-new name) + (message name))) + + + (global-set-key (kbd "C-M-/") 'copy-buffer-file-name) + + + +;;;;; C-8 - calc-embedded-word + + (global-set-key (kbd "C-8") 'calc-embedded-word) + +;;;;; C-up-arrow - org prev headline + + ;; disabled just because i don't want to accidentally hit it + (define-key global-map "\C-_" nil) + (global-set-key (kbd "") 'beginning-of-defun) + + (add-hook 'org-mode-hook + (lambda () + (define-key org-mode-map (kbd "\C-_") 'outline-previous-visible-heading))) + + + + +;;;;; C-S-up-arrow - winner undo + + (global-set-key (kbd "") 'winner-undo) + +;;;;; C-down-arrow - org next headline + + (global-set-key (kbd "") 'end-of-defun) + + (add-hook 'org-mode-hook + (lambda () + (define-key org-mode-map (kbd "") 'outline-next-visible-heading))) + + + + +;;;;; C-M-down-arrow - toggle-mark-activation + + (defun toggle-mark-activation () + (interactive) + (if mark-active + (deactivate-mark t) + (activate-mark))) + + (global-set-key (kbd "") 'toggle-mark-activation) + +;;;;; C-S-down-arrow winner redo + + (global-set-key (kbd "") 'winner-redo) + + +;;;;; C-S-down-arrow - m-x for major mode + + (global-set-key (kbd "") 'smex-major-mode-commands) + +;;;;; C-lbracket - ---- +;;;;; C-M-lbracket - scroll-right + + (global-set-key (kbd "C-M-[") 'scroll-right) + +;;;;; C-rbracket - fill-paragraph + + (global-set-key (kbd "C-]") 'fill-paragraph) + +;;;;; C-M-rbracket - scroll-left + + (global-set-key (kbd "C-M-]") 'scroll-left) + +;;;;; C-return - newline-anywhere + + (defun newline-anywhere () + "Add a newline from anywhere in the line." + (interactive) + (end-of-line) + (newline-and-indent)) + (global-set-key (kbd "") 'newline-anywhere) + + +;;;;; M-return - plain newline + + (defun plain-newline () + (interactive) + (insert "\n")) + (global-set-key (kbd "") 'plain-newline) + + +;;;;; C-M-return - newline-anywhere-previous +(defun newline-anywhere-previous () + "Add a newline from anywhere in the line." + (interactive) + (forward-line -1) + (end-of-line) + (newline-and-indent)) +(global-set-key (kbd "") 'newline-anywhere-previous) + +;;;;; C-space - org-edit-special + +;; commented due to new keyboard needing ctrl-space for mark +;; (kbd "") does not work, (kbd "C-SPC") should work +;; (add-hook 'org-mode-hook +;; (lambda () +;; (define-key org-mode-map (kbd "C-SPC") 'org-edit-special) +;; ;; org-src-mode-map is broken in git version of emacs. +;; ;; temporarily use this for exiting edit-special mode. +;; (global-set-key (kbd "C-M--") 'org-edit-src-exit) +;; (define-key org-src-mode-map (kbd "C-SPC") 'org-edit-src-exit))) + +;;;;; C-M-space - before or under cursor + +(global-set-key (kbd "C-M-SPC") 'ispell-word) +;;;; left secondary +;;;;; C-M-4 - widen + +(global-set-key (kbd "C-M-4") 'widen) + +;;;;; C-tab-key - query-replace + + +(global-set-key (kbd "") 'query-replace) + +;;;;; C-t - org cycle todo / toggle comint motion + +(add-hook 'org-mode-hook + (lambda () + (define-key org-mode-map (kbd "C-t") 'org-todo))) + +(defun my-comint-previous-input (arg) + (interactive "*p") + (if (comint-after-pmark-p) + (comint-previous-input arg) + (forward-line -1))) + +(defun my-comint-next-input (arg) + (interactive "*p") + (if (comint-after-pmark-p) + (comint-next-input arg) + (forward-line))) + +(add-hook 'comint-mode-hook + (lambda () + (define-key comint-mode-map (kbd "C-t") 'comint-toggle-arrow-keys) + (define-key comint-mode-map (kbd "") 'my-comint-previous-input) + (define-key comint-mode-map (kbd "") 'my-comint-next-input))) + + +(defun comint-toggle-arrow-keys () + (interactive) + (toggle-arrow-keys comint-mode-map)) + +(setq-default comint-arrow-movement nil) +(defun toggle-arrow-keys (map) + (cond ((lookup-key map (kbd "")) + (setq-local comint-arrow-movement t) + (define-key map (kbd "") nil) + (define-key map (kbd "") nil)) + (t + (setq-local comint-arrow-movement nil) + (define-key map (kbd "") 'my-comint-previous-input) + (define-key map (kbd "") 'my-comint-next-input) + (goto-char (point-max))))) + +(eval-after-load "message" + '(define-key message-mode-map (kbd "C-t") 'mail-signature)) + + +;;;;; C-M-t - org timestamp + +(global-set-key (kbd "C-M-t") 'org-time-stamp-with-time) + +;;;;; C-home - start of buffer +;;;;; C-end - end of buffer +;;;; right secondary +;;;;; C-6 - save-buffers-kill-emacs + +(global-set-key (kbd "C-6") 'save-buffers-kill-emacs) + +;;;;; C-M-6 - insert-small-copyright + +(defun insert-small-copyright () + (interactive) + (beginning-of-line) + (let ((beg (point))) + (insert "Copyright (C) 2017 Ian Kelling\nThis program is under GPL v. 3 or later, see ") + (comment-region beg (point)))) + +(global-set-key (kbd "C-M-6") 'insert-small-copyright) + +;;;;; C-M-7 - insert-full-copyright + +(defun insert-full-copyright () + (interactive) + (beginning-of-line) + (let ((beg (point))) + (insert "Copyright (C) 2017 Ian Kelling\n") + (insert "\n") + (insert "This program is free software: you can redistribute it and/or modify\n") + (insert "it under the terms of the GNU General Public License as published by\n") + (insert "the Free Software Foundation, either version 3 of the License, or\n") + (insert "(at your option) any later version.\n") + (insert "\n") + (insert "This program is distributed in the hope that it will be useful,\n") + (insert "but WITHOUT ANY WARRANTY; without even the implied warranty of\n") + (insert "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") + (insert "GNU General Public License for more details.\n") + (insert "\n") + (insert "You should have received a copy of the GNU General Public License\n") + (insert "along with this program. If not, see .\n") + (comment-region beg (point)))) + +(global-set-key (kbd "C-M-7") 'insert-full-copyright) + + +;;;;; C-0 - text-scale-reset + +(defun text-scale-reset () + (interactive) + (text-scale-set 0)) +(global-set-key (kbd "C-0") 'text-scale-reset) + +;;;;; C-M-0 - insert-apache + +(defun insert-apache () + (interactive) + (beginning-of-line) + (let ((beg (point))) + (insert "Copyright (C) 2017 Ian Kelling\n") + (insert "\n") + (insert "Licensed under the Apache License, Version 2.0 (the \"License\");\n") + (insert "you may not use this file except in compliance with the License.\n") + (insert "You may obtain a copy of the License at\n") + (insert "\n") + (insert " http://www.apache.org/licenses/LICENSE-2.0\n") + (insert "\n") + (insert "Unless required by applicable law or agreed to in writing, software\n") + (insert "distributed under the License is distributed on an \"AS IS\" BASIS,\n") + (insert "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n") + (insert "See the License for the specific language governing permissions and\n") + (insert "limitations under the License.\n") + (comment-region beg (point)))) +(global-set-key (kbd "C-M-0") 'insert-apache) + + +;;;;; C-M-- - org-edit-src-exit +;;;;; C-y - undo + +(global-set-key (kbd "C-y") 'undo) +(add-hook 'org-mode-hook + (lambda () (define-key org-mode-map (kbd "C-y") nil))) + + +;;;;; C-\ - sr-speedbar-toggle +(global-set-key (kbd "C-\\") 'sr-speedbar-toggle) + +;;;;; C-M-\ - mark-defun + +(global-set-key (kbd "C-M-\\") 'mark-defun) + +;;;;; C-h - help-prefix + +;;;;; C-' - val-expression + +(global-set-key (kbd "C-'") 'eval-expression) + +;;;;; C-n - unpop to mark + +(defun unpop-to-mark-command () + "Unpop off mark ring. Does nothing if mark ring is empty." + (interactive) + (when mark-ring + (let ((pos (marker-position (car (last mark-ring))))) + (if (not (= (point) pos)) + (goto-char pos) + (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring)) + (set-marker (mark-marker) pos) + (setq mark-ring (nbutlast mark-ring)) + (goto-char (marker-position (car (last mark-ring)))))))) + +(global-set-key (kbd "C-n") 'unpop-to-mark-command) + +;;;;; C-M-n - narrow-to-region + +(global-set-key (kbd "C-M-n") 'narrow-to-region) + +;;;;; C-escape - find-tag + +(global-set-key (kbd "") 'find-tag)