various updates, mail
[dot-emacs] / my-init.org
1 #+TITLE: My Personal Init Customization
2 #+OPTIONS: toc:nil num:nil ^:nil
3 * copyright
4 # Copyright (C) 2017 Ian Kelling
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 * things that should be at the beginning
20 #+begin_src emacs-lisp
21 ;; todo, evaluating this manually disables debug on error instead of toggling it
22 ;(toggle-debug-on-error) ;uncomment to help debug and catch errors
23
24
25 #+end_src
26
27
28 packages installed from package manager: i pretty much prioritize repos this way: gnu, then melpa, then marmalade.
29
30 package-activated-list:
31 ac-dabbrev ac-haskell-process ack-and-a-half alect-themes auctex bash-completion bbdb csv-mode cyberpunk-theme dot-mode expand-region f find-file-in-project flycheck foreign-regexp ggtags ghc gnuplot-mode goto-chg haskell-mode heroku-theme highlight-indentation highlight-symbol htmlize inf-ruby info+ inkpot-theme jedi auto-complete jedi-core epc ctable concurrent key-chord leuven-theme logstash-conf magit git-commit magit-popup misc-fns mouse+ naquadah-theme nginx-mode occidental-theme org paredit pcsv php-mode pkg-info epl popup py-autopep8 python-environment deferred python-info python-mode rainbow-mode rust-mode rw-hunspell s smartparens smex smooth-scroll sr-speedbar strings swiper ivy tabulated-list tangotango-theme thingatpt+ undo-tree vimrc-mode volatile-highlights web-mode with-editor dash async ws-butler yasnippet
32
33 alternate keyboards
34 #+begin_src emacs-lisp
35 ;; todo, figure out an easy way to disable this when using external keyboard
36 (if (display-graphic-p)
37 (setq
38 enter-key (kbd "<return>")
39 s-enter-key (kbd "<S-return>")
40 c-m-enter-key (kbd "<C-M-return>")
41 m-enter (kbd "<M-return>")
42 c-enter (kbd "<C-return>"))
43 (setq
44 enter-key (kbd "C-m")
45 s-enter-key (kbd "C-8")
46 c-m-enter-key (kbd "C-M-8")
47 m-enter (kbd "M-m")
48 c-enter (kbd "C-8")))
49
50 (setq tp (string= (system-name) "tp"))
51 (setq x200 (string= (system-name) "x2"))
52 (setq laptop-keyboard (or tp x200))
53 #+end_src
54
55 - Ubiquitous Packages which should be loaded on startup rather than
56 autoloaded on demand since they are likely to be used in every
57 session.
58 #+name: starter-kit-load-on-startup
59 #+begin_src emacs-lisp
60 (require 'saveplace)
61 (require 'ffap)
62 (require 'uniquify)
63 (require 'ansi-color)
64 (require 'recentf)
65
66 #+end_src
67
68
69 - Better to have a list of packages in here vs installed manually.
70 However, I install manually because sometimes there are two
71 versions and it is not necessarily easy to reconcile that.
72 #+begin_src emacs-lisp
73 ;; based on marmalage website front page.
74 (require 'package)
75
76 ;; little kit to help remove a down server
77 ;; (setq package-archives nil)
78
79 (add-to-list 'package-archives
80 '("marmalade" .
81 "http://marmalade-repo.org/packages/"))
82
83 (add-to-list 'package-archives
84 '("melpa" . "http://melpa.milkbox.net/packages/") t)
85 (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
86
87 ;; if this is a new machine/config, get package list
88 ;; not sure why we need it, but it is recommended in starter kit,
89 ;; and doesn't seem like a bad thing
90 (unless package-archive-contents (package-refresh-contents))
91
92 #+end_src
93
94
95 keep our init.el clean, by moving customization elisp to it's own file
96 #+name: m-x-customize-customizations
97 #+begin_src emacs-lisp
98 (setq custom-file "~/.emacs.d/custom.el")
99 (load custom-file 'noerror)
100 #+end_src
101
102 undo tree stuff
103 #+begin_src emacs-lisp
104 ;; more resilient undo-tree-history if we have their locations set up front.
105 (setq undo-tree-history-directory-alist '(("." . "~/.undo-tree-history")))
106 ;; Undo in region just happens accidentally, and throws me off, and it's been buggy in the past
107 (setq undo-tree-enable-undo-in-region nil)
108 #+end_src
109
110 * Stuff that I do not recommend that others use without reading,
111 understanding, and customizing themselves are
112
113 all mouse stuff disabled till i have time to figure it out again.
114 #+begin_src emacs-lisp :tangle no
115 (defun xterm-mouse-translate-1 (&optional extension)
116 (save-excursion
117 (let* ((event (xterm-mouse-event extension))
118 (ev-command (nth 0 event))
119 (ev-data (nth 1 event))
120 (ev-where (nth 1 ev-data))
121 (vec (vector event))
122 (is-down (string-match "down-" (symbol-name ev-command))))
123
124 (cond
125 ((null event) nil) ;Unknown/bogus byte sequence!
126 (is-down
127 (setf (terminal-parameter nil 'xterm-mouse-last-down) event)
128 vec)
129 (t
130 (let* ((down (terminal-parameter nil 'xterm-mouse-last-down))
131 (down-data (nth 1 down))
132 (down-where (nth 1 down-data)))
133 (setf (terminal-parameter nil 'xterm-mouse-last-down) nil)
134 (cond
135 ((null down)
136 ;; This is an "up-only" event. Pretend there was an up-event
137 ;; right before and keep the up-event for later.
138 (push event unread-command-events)
139 (vector (cons (intern (replace-regexp-in-string
140 "\\`\\([ACMHSs]-\\)*" "\\&down-"
141 (symbol-name ev-command) t))
142 (cdr event))))
143 ((equal ev-where down-where) vec)
144 (t
145 (let ((drag (if (symbolp ev-where)
146 0 ;FIXME: Why?!?
147 (list (intern (replace-regexp-in-string
148 "\\`\\([ACMHSs]-\\)*" "\\&drag-"
149 (symbol-name ev-command) t))
150 down-data ev-data))))
151 (if (null track-mouse)
152 (vector drag)
153 (push drag unread-command-events)
154 (vector (list 'mouse-movement ev-data))))))))))))
155
156 #+end_src
157 * how to find auto-saved files that need recovering
158 find a recently dated file in ~/.emacs.d/auto-save-list/, and see the files listed in it.
159 #file# is an auto-save file. It may or may not be different than the file is corresponds to.
160 If it is different, emacs will give a message about recovering it when you open it.
161
162
163
164 * TODO keybinds to remember
165
166 keys worth memorizing
167
168 c-2
169 c-m-3
170
171 s-return
172
173 in isearch, C-o
174 isearch-occur
175
176 org, C-c / t
177 make just todo items visible
178
179 C-mouse-1
180 buffer list menu
181
182 C-up/down
183 move up/down fast
184
185 M-right-scroll
186 forward/back sexp
187
188 C-M-right-scroll
189 scroll
190
191 C-S-scroll
192 change text size
193
194 how to control+left scroll on kinesis
195 right shift = control
196
197 C-left-scroll
198 forward/backward word
199
200 C-M-d
201 swap buffers across windows
202
203 shell-cd-to-file
204 M-2
205
206 * TODO add simpler keybind for make-frame-command
207 current one is C-x 5 2.
208
209 * TODO learn some more ivy mode stuff
210 * TODO declarative package installations,
211 with documentation.
212 * TODO shell mode reverse search hides 2nd+ line of multi-line result
213 * TODO figure out browsing files with broken nfs mount
214 causes emacs to freeze until I kill -9 it.
215 * TODO make a keybind to print var under cursor
216 and actually, putting the start of it in th emodeline might be cool
217 * TODO make recent files save periodically,
218 normally it just saves on exit, but half the time I don't exit cleanly
219 so they don't get saved, because I leave emacs running until it crashes
220 * TODO fix undo tree outside visible buffer bug
221 * TODO c-<delete> in shell mode should send over
222 previous line if current line is empty
223 * TODO make c-m-s be just a control key for easier use
224 * TODO try out avy mode for laptop
225 i used to have ace jump mode, but google says avy is better.
226 * TODO bind a in group mode of gnus to c-u a,
227 also, make a default for number of articles
228 * TODO make auto-complete be on by default in sql-mode
229 * TODO make an easy bind for open previous buffer
230 * TODO i think my autosave for sudo-edit might be too fast
231 it sometimes leaves #_asdfjasdf files littered
232 * TODO readline-compleste doesn't work when you cat a file without a newline,
233 and so the prompt is messed up. not sure exactly what needs to be in end, or if its anything
234 * TODO figure out how to paste a path into find file
235 probably have to use the old kind of find file
236 * TODO readline-complete doesn't escape special chars in filenames
237 * TODO readline-complete dev
238
239
240
241 ** misc fixes
242
243 bad code, the comment this relates to was removed, but not the comment
244 /* If waiting for this channel, arrange to return as
245 soon as no more input to be processed. No more
246 waiting. */
247
248
249 (status_notify): New arg WAIT_PROC. this is unused, this is a bug.
250 The change in status_notify's return is just passing more information
251 from what it did already. No changes at all inside this function.
252
253 * TODO consider whether to bind indent-for-tab-command
254 I removed it from m-tab for terminal compatibility.
255 It's the default tab command, which yasnippet replaces.
256 * TODO readline-complete: remove the hardcoded rlc-no-readline-hook
257 * TODO isearch doesn't automatically wrap in info
258 * TODO look into fixing shell mode reverse search
259 and why auto-complete dies
260 caveat is that it doesn't work well with certain unusual prompts, for example if $/# is not used at the end
261 see if we can load history, or reverse search with history commands
262 * TODO keybinds for s-delete/tab etc
263 * TODO fix bbdb info packaging in melpa
264 * TODO figure out why my emacs startup script doesn't work from dmenu
265 * TODO post idea to make customize group show function var names so we can read doc strings
266 * TODO report/fix bug that kill-whole-line doesn't work right with append kill
267 * TODO make bash keybind for copy paste interoperate with x windows
268 * TODO fix org stderr redirection
269 make this produce output of "ok"
270 #+begin_src sh
271 echo ok >&2
272
273 #+end_src
274 * TODO make ido keybinds better
275 * TODO fix indenting in org
276
277 (defun my-org-indent-region (start end)
278 "Indent region."
279 (interactive "r")
280 (save-excursion
281 (let ((line-end (org-current-line end)))
282 (goto-char start)
283 (while (< (org-current-line) line-end)
284 (cond ((org-in-src-block-p) (org-babel-do-in-edit-buffer (indent-according-to-mode)))
285 (t (call-interactively 'org-indent-line)))
286 (move-beginning-of-line 2)))))
287
288
289
290 org-indent-region is broken for source blocks
291 the above function works, but has several problems.
292 first: it should not have separate logic from org-indent-line
293 second: it runs way too slow, mainly the command
294 (org-babel-do-in-edit-buffer (indent-according-to-mode)))
295
296
297 * TODO figure out newline in prompt shell issue
298 setting this before readline-complete is loaded allows completion to work,
299 but auto-completion still fails. Need to debug readline-complete to figure this out.
300 (setq shell-prompt-pattern "^[^#$%>]*[#$]\n")
301 * TODO setup bind for find tag / lisp function at point
302
303 * TODO org-delete-char should also work for the delete/backspace keys!
304 fix and send patch
305
306 * TODO checkout projectile / graphene's project settings
307
308 * TODO check up on recent changes to 3rd party default configs
309 - last checked apr 24
310 https://github.com/eschulte/emacs24-starter-kit/commits/master
311
312 last checked mayish
313 https://github.com/bbatsov/prelude
314 - redefined mouse functions from this file
315
316 * TODO figure out how to setup emacs to format text nicely like thunderbird
317 * TODO it appears impossible make C-[ not be the same as escape
318 * TODO movement within info buffer after opening a link doesn't cancel isearch
319 leads to many frustrations
320 * TODO fix org resolve clock message. it is innacurate
321 i is not the same, becuase it does not make org realize there is an active clock
322
323 * TODO add apropos commands to help prefix, from
324 http://stackoverflow.com/questions/3124844/what-are-your-favorite-global-key-bindings-in-emacs
325 * TODO my autosave goes into an endless prompting loop
326 when running save buffer, and the buffer has been changed
327 outside of emacs
328 * TODO smart peren does not see ?\\) as a valid paren
329
330 * TODO why does org-end-of-line not go all the way to the end on a closed headline?
331 * TODO org makes random ... things, and delete right before them does ctrl-i
332 * TODO try mark word, which might be a useful keybind
333 * TODO fix org-cycle: it assumes which key it is bound to for its last alternative
334 * TODO checkout lisp-complete-symbol to augment auto-complete
335 * TODO emacs keylogger to optimize key binds
336 * TODO remap/investigate find tag, find tag at point
337 * TODO set key to cycle buffers by mode, example below
338
339 (defun cycle-buffer-by-mode (p-mode)
340 "Cycle buffers by mode name"
341 (interactive)
342 (dolist (buffer (buffer-list))
343 (with-current-buffer buffer
344 (when (buffer-live-p buffer)
345 (if (string-match p-mode mode-name) ;(regexp-quote p-mode)
346 (setq switch2buffer buffer)))))
347 (when (boundp 'switch2buffer)
348 (switch-to-buffer switch2buffer)))
349
350 And I have bound this to my F9 key
351
352 (global-set-key [f9] '(lambda () (interactive) (cycle-buffer-by-mode "Shell$")))
353
354 * TODO test out usefulness of forward/back sexp in different languages
355
356 * TODO major mode settings to check out in future
357 ** emacs24 starter kit
358 - Nxhtml -- utilities for web development
359 [[http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html][Nxhtml]] is a large package of utilities for web development and for
360 embedding multiple major modes in a single buffer.
361
362 Nxhtml is not installed in this version of the starter-kit by default,
363 for information on installing nxhtml see [[http://www.emacswiki.org/emacs/NxhtmlMode][EmacsWiki-Nxhtml]].
364
365 web-mode is competing package and actively developed, so i'm using that instead
366
367
368 (dolist (package '(yaml-mode js2-mode))
369 (unless (package-installed-p package)
370
371 - Associate modes with file extensions
372
373 (add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$" . diff-mode))
374 (add-to-list 'auto-mode-alist '("\\.css$" . css-mode))
375 (require 'yaml-mode)
376 (add-to-list 'auto-mode-alist '("\\.ya?ml$" . yaml-mode))
377 (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
378 (add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
379 (add-to-list 'auto-mode-alist '("\\.js\\(on\\)?$" . js2-mode))
380 ;; (add-to-list 'auto-mode-alist '("\\.xml$" . nxml-mode))
381
382 - clojure in starter-kit-lisp.org
383
384 - others = gnus, js, publish, perl, python, perl, ruby
385 they each have their own starter kit file.
386
387 - snippets for various modes other than org-mode
388
389 * TODO update yasnippet documentation
390 yas expand key customization is rediculously hard to figure out
391 and completely undocumented
392 * TODO fix org source indenting, send patch
393 * TODO check out bundling aka compiling yasnippet
394 * TODO try xml/html mode url func
395
396 (defun view-url ()
397 "Open a new buffer containing the contents of URL."
398 (interactive)
399 (let* ((default (thing-at-point-url-at-point))
400 (url (read-from-minibfer "URL: " default)))
401 (switch-to-buffer (url-retrieve-synchronously url))
402 (rename-buffer url t)
403 ;; TODO: switch to nxml/nxhtml mode
404 (cond ((search-forward "<?xml" nil t) (xml-mode))
405 ((search-forward "<html" nil t) (html-mode)))))
406
407 * TODO flyspell-buffer automatically
408
409 * TODO respond to ediff thread
410 * TODO fix horizontal mouse resizing
411 resizing a window horizontally with the mouse should be allowed in more places
412
413 * TODO try using / making abbreviations
414
415 * abbreviations
416 #+begin_src emacs-lisp
417
418 ;; turn on abbrev mode globally
419 (setq-default abbrev-mode t)
420
421 #+end_src
422 default abbreviation mode file is .emacs.d/abbrev_defs.
423 add-global-abbrev, add-mode-abbrev for expansion at point
424 if all else fails, edit the abbrev file
425
426 * auto-complete
427
428 #+begin_src emacs-lisp
429 ;; auto-completion in minibuffer
430 ;; disabled while I look for another alternative
431 ;;(icomplete-mode)
432
433 (require 'auto-complete-config)
434 (ac-config-default)
435
436
437 ;; complete after 1 char instead of default 2
438 (setq ac-auto-start 1)
439 (setq ac-delay 0.001)
440
441 (add-to-list 'ac-modes 'org-mode 'sql-mode)
442
443 (defun ac-common-setup ()
444 (add-to-list 'ac-sources 'ac-source-yasnippet))
445
446 ;; for org mode completion source taken from wiki.
447 ;; it did not work. no idea why. todo, investigate
448 ;; the ac-sources code is at http://www.emacswiki.org/emacs/AutoCompleteSources
449 ;; i've deleted it here so as to save space and not spam this file
450 ;;(defun my-ac-org-mode ()
451 ;; (setq ac-sources (append ac-sources '(ac-source-org))))
452
453
454 ;; this makes the org-self-insert command not do a flyspell spell check.
455 ;; low priority thing to look into sometime
456 (ac-flyspell-workaround)
457
458
459 (define-key ac-completing-map (kbd "<up>") nil)
460 (define-key ac-completing-map (kbd "<down>") nil)
461 (define-key ac-completing-map (kbd "<S-return>") 'ac-expand)
462 (define-key ac-completing-map "\t" 'ac-complete)
463 (define-key ac-completing-map (kbd "<tab>") 'ac-complete)
464
465
466
467 #+end_src
468 * auto-complete readline-complete
469 #+begin_src emacs-lisp
470
471 (add-to-list 'load-path "~/.emacs.d/src/readline-complete")
472 (require 'readline-complete)
473 ;; not sure how I made these, but I deleted, and
474 ;; it would be nice to make them again sometime
475 ;;(require 'src-loaddefs)
476
477 ;; disabled cuz broken
478 ;; redefining function in readline-complete so ac-complete only uses readline as a source
479 (defun ac-rlc-setup-sources ()
480 "Add me to shell-mode-hook!"
481 (setq ac-sources '(ac-source-shell)))
482 (add-hook 'shell-mode-hook 'ac-rlc-setup-sources)
483
484 ;; generally unnecessary, but why not
485 (setq explicit-shell-file-name "bash")
486
487 ;; readline-complete says to add this line.
488 ;; however, it messes up my procfs directory tracking hook
489 ;; because get-process doesn't notice the child shell.
490 ;; instead, I've removed export EMACS=t from
491 ;; comint-exec-1 (the function which initially sets it)
492 ;; by finding it in emacs sources and redefinind it here
493 ;; and done stty echo in my bashrc
494 ;;(setq explicit-bash-args '("-c" "export EMACS=; stty echo; bash"))
495
496 (setenv "EMACS" "")
497 (setq explicit-bash-args nil)
498 (setq comint-process-echoes t)
499 ;; default of 30 is way too slow. todo, consider pushing this upstream
500 (setq rlc-attempts 5)
501
502 (add-to-list 'ac-modes 'shell-mode)
503
504 ;; readline-complete recommends this (i assume this format),
505 ;; but greping finds no reference in emacs or my .emacs.d
506 ;; so I'm assuming it is for an older emacs
507 ;;(setq explicit-ssh-args '("-t"))
508
509 (add-hook 'shell-mode-hook
510 (lambda ()
511 (define-key shell-mode-map (kbd "<tab>") 'auto-complete)))
512
513
514 #+end_src
515 #+RESULTS:
516 : comint-exec-1
517
518 ** readline complete fix
519
520 I need this function here, where INSIDE_EMACS is replaced with RLC_INSIDE_EMACS.
521 #+begin_src emacs-lisp
522 ;; ian: last update 2017-1-7. update this periodically from upstream
523 ;; like when we do a major emacs update
524 (defun comint-exec-1 (name buffer command switches)
525 (let ((process-environment
526 (nconc
527 ;; If using termcap, we specify `emacs' as the terminal type
528 ;; because that lets us specify a width.
529 ;; If using terminfo, we specify `dumb' because that is
530 ;; a defined terminal type. `emacs' is not a defined terminal type
531 ;; and there is no way for us to define it here.
532 ;; Some programs that use terminfo get very confused
533 ;; if TERM is not a valid terminal type.
534 ;; ;; There is similar code in compile.el.
535 (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
536 (list "TERM=dumb" "TERMCAP="
537 (format "COLUMNS=%d" (window-width)))
538 (list "TERM=emacs"
539 (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))
540 (list (format "RLC_INSIDE_EMACS=%s,comint" emacs-version))
541 process-environment))
542 (default-directory
543 (if (file-accessible-directory-p default-directory)
544 default-directory
545 "/"))
546 proc decoding encoding changed)
547 (let ((exec-path (if (and command (file-name-directory command))
548 ;; If the command has slashes, make sure we
549 ;; first look relative to the current directory.
550 (cons default-directory exec-path) exec-path)))
551 (setq proc (apply 'start-file-process name buffer command switches)))
552 ;; Some file name handler cannot start a process, fe ange-ftp.
553 (unless (processp proc) (error "No process started"))
554 (let ((coding-systems (process-coding-system proc)))
555 (setq decoding (car coding-systems)
556 encoding (cdr coding-systems)))
557 ;; Even if start-file-process left the coding system for encoding data
558 ;; sent from the process undecided, we had better use the same one
559 ;; as what we use for decoding. But, we should suppress EOL
560 ;; conversion.
561 (if (and decoding (not encoding))
562 (setq encoding (coding-system-change-eol-conversion decoding 'unix)
563 changed t))
564 (if changed
565 (set-process-coding-system proc decoding encoding))
566 proc))
567
568 #+end_src
569
570 * auto save & backup
571 #+begin_src emacs-lisp
572 (setq auto-save-timeout 1) ; idle time before auto-save.
573
574 ;; main hook for my auto save
575 (add-hook 'auto-save-hook 'my-auto-save)
576 ;; additional hook to try to deal with emacs not auto-saving when a buffer isn't active
577 (add-hook 'window-configuration-change-hook 'my-auto-save)
578
579 (defun my-auto-save ()
580 (when (and
581 my-as
582 (buffer-file-name)
583 ;; mu4e has a bug right now, undo breaks when saving drafts
584 (not (string= (buffer-file-name) "*draft*"))
585 (buffer-modified-p)
586 (not (org-src-edit-buffer-p)))
587 (let (message-log-max)
588 ;; a bit of a hack to partially suppress the constant saving in the echo area
589 (with-temp-message ""
590 (basic-save-buffer)))))
591
592 (defun my-as-off ()
593 (interactive)
594 (setq my-as nil))
595
596 (defun my-as-off-local ()
597 (interactive)
598 (setq-local my-as nil))
599
600 (defun my-as-on ()
601 (interactive)
602 (setq my-as t))
603
604 (defun my-as-on-local ()
605 (interactive)
606 (setq-local my-as on))
607
608 ;; based on suggestion in the emacs docs, redefine these 2 functions
609 ;; to avoid prompt spamming the user when we do auto-save
610 (defun ask-user-about-supersession-threat (fn)
611 (discard-input)
612 (message
613 "File for %s has changed on disk outside of emacs. Auto-save is overwriting it, however
614 a backup is being created in case that is not what you intended." buffer-file-name)
615 (setq buffer-backed-up nil))
616
617 (defadvice ask-user-about-lock (before lock-deactivate-as activate)
618 (make-local-variable 'my-as)
619 (setq my-as nil)
620 (message "proper autosave has been turned off for this buffer because of lock file problem.
621 In this buffer, do M-x my-as-on to reenable"))
622
623 ;; todo, this doesn't work consistently to override the auto-save message
624 (defalias 'do-auto-save-original (symbol-function 'do-auto-save))
625 (defun do-auto-save (&optional no-message current-only)
626 "This function has been modified to wrap the original so that NO-MESSAGE
627 is always set to t, since we auto-save a lot, it spams otherwise.
628 The original doc string is as follows:
629
630 Auto-save all buffers that need it.
631 This is all buffers that have auto-saving enabled
632 and are changed since last auto-saved.
633 Auto-saving writes the buffer into a file
634 so that your editing is not lost if the system crashes.
635 This file is not the file you visited; that changes only when you save.
636 Normally we run the normal hook `auto-save-hook' before saving.
637
638
639 A non-nil NO-MESSAGE argument means do not print any message if successful.
640 A non-nil CURRENT-ONLY argument means save only current buffer."
641 (interactive)
642 (do-auto-save-original t current-only))
643
644 ;; enable MY auto-save
645 (my-as-on)
646
647 #+end_src
648
649
650 backups, separate from auto-save
651
652 #+begin_src emacs-lisp
653
654 ;; set backup file location
655 (setq backup-directory-alist '(("." . "~/.editor-backups")))
656 (setq auto-save-file-name-transforms
657 '((".*" "~/.editor-backups/" t)))
658
659 (setq version-control t ;; Use version numbers for backups
660 kept-new-versions 100
661 kept-old-versions 2
662 delete-old-versions t ;; delete old versions silently
663 ;; assume hard linked files are done on purpose, don't screw them up
664 backup-by-copying-when-linked t)
665
666 ;; todo, the time needs to be an integer, not a vector type thing
667 (defun constant-backup ()
668 "Backup conditioned on some time passing since last one.
669 Hooked into 'before-save-hook."
670 (cl-flet ((b-time (minutes)
671 (< last-backup-time
672 (- (current-time) (* 60 minutes)))))
673 (when (or (not (boundp 'last-backup-time)) (and (< (buffer-size) 10000000) (b-time 5)) (b-time 30))
674 (setq buffer-backed-up nil)
675 (setq-local last-backup-time (current-time)))))
676
677 ;; make a backup on auto-save, because the backup feature is not
678 ;; utilized with my-auto-save, only normal interactive save.
679 ;; todo, enable when fixed
680 ;;(add-hook 'before-save-hook 'constant-backup)
681
682 (add-hook 'auto-save-hook 'auto-save-size-limit)
683
684 (defun auto-save-size-limit ()
685 (when (and (not backup-inhibited) (> (buffer-size) 2000000))
686 (message "Backups disabled for this buffer due to size > 2 megs")
687 (make-local-variable 'backup-inhibited)
688 (setq backup-inhibited t)))
689
690 #+end_src
691
692
693
694 background:
695 the faq suggests to auto-save using
696 (setq auto-save-visited-file-name t)
697 and to toggle auto-saving in the current buffer, type `M-x auto-save-mode'
698
699 however, this is buggy.
700 it leaves around lock files, which can be disabled with
701 (setq create-lockfiles nil)
702 but it is also buggy on other things that appear to hook onto file saving
703 so i created my own function, which originally had bugs,
704 but new emacs version fixed all that, yay!.
705
706
707 ; not using, but here for documentation,
708 ; alternate way to enable and specify how long between autosaves.
709 ; number of input events between autosave.
710 ; lowest bound of functionality is actually about 15 input events
711 ;(setq auto-save-interval
712 ** todo keep an eye out for why/when and fix the fact that normal auto-save files are being made soemtimes
713 they are #filename#
714 seems they are created
715
716 * bbdb
717 #+begin_src emacs-lisp
718 ;; based on bbdb manual
719 ;; also has instructions to initialize upon launching gnus, etc
720 ;; but I figure try this to make sure everything works all the time first
721 (require 'bbdb)
722 (bbdb-initialize 'message)
723
724 ;; recommended by gnus,
725 ;; but seems like it could be good to have set for other stuff
726 (setq user-full-name "Ian Kelling"
727 user-mail-address "ian@iankelling.org")
728 ;; general email setting? recommended by mu4e
729 (setq message-kill-buffer-on-exit t)
730
731
732 ;; based on emacs24-starter-kit
733 (setq bbdb-offer-save 'auto
734 bbdb-notice-auto-save-file t
735 bbdb-expand-mail-aliases t
736 bbdb-canonicalize-redundant-nets-p t
737 bbdb-complete-name-allow-cycling t)
738
739 ;; use d instead
740 (add-hook 'bbdb-mode-hook
741 (lambda () (define-key bbdb-mode-map (kbd "C-k") nil)))
742
743 (add-to-list 'load-path "~/.emacs.d/src/bbdb-csv-import")
744 (require 'bbdb-csv-import)
745
746 #+end_src
747
748 * bookmark settings
749 #+begin_src emacs-lisp
750 ; save bookmarks whenever they are changed instead of just when emacs quits
751 (setq bookmark-save-flag 1)
752 ; increase bookmark context size for better functionality
753 (setq bookmark-search-size 2000)
754 #+end_src
755 * c-like settings
756 #+begin_src emacs-lisp
757 ;; change last thing from gnu.
758 ;; notably this avoids brace indent after if, and 4 space indent
759 (setq c-default-style '((java-mode . "java")
760 (awk-mode . "awk")
761 (other . "stroustrup")))
762 ;; for emacs itself, use
763 ;; (setq c-default-style '((java-mode . "java")
764 ;; (awk-mode . "awk")
765 ;; (other . "gnu")))
766 ;; (setq-default c-basic-offset 2)
767 #+end_src
768 * color theme
769
770 A Theme builder is available at http://elpa.gnu.org/themes/ along with
771 a list of pre-built themes at http://elpa.gnu.org/themes/view.html and
772 themes are available through ELPA.
773
774
775 interesting light themes
776
777
778 #+begin_src emacs-lisp
779 (defun override-theme (arg)
780 (interactive)
781 (while custom-enabled-themes
782 (disable-theme (car custom-enabled-themes)))
783 (load-theme arg t))
784 (setq color-theme-is-global t)
785
786 (defun toggle-night ()
787 (interactive)
788 (cond ((equal (car custom-enabled-themes) 'naquadah)
789 ;; background off white to be better on the eyes. took this
790 ;; color from gitweb.
791 (custom-set-faces `(default ((t (:background "#F6F6F0")))))
792 (override-theme 'leuven))
793 (t
794 ;; revert previous background change
795 (custom-set-faces `(default ((t (:background nil)))))
796 (override-theme 'naquadah))))
797
798 (custom-set-faces `(default ((t (:background "#F6F6F0")))))
799 (override-theme 'leuven) ;; org mode features, with monitor darkened. part of org-mode i think
800
801
802 ;; disable color thing with this:
803 ;;(disable-theme (car custom-enabled-themes))
804
805 ;; decent dark themes
806
807 ;;(override-theme 'tangotango)
808 ;;(override-theme 'deeper-blue)
809 ;;(override-theme 'tango-dark)
810 ;;(override-theme 'tsdh-dark)
811
812 ;;(override-theme 'heroku)
813 ;;(override-theme 'inkpot) ;; part of inkpot-theme package
814 ;;(override-theme 'naquadah) ; org mode features, part of naquadah-theme package
815 ;;(override-theme 'spolsky) ;; part of sublime-themes package
816 ;;(override-theme 'twilight-anti-bright) ;; from twilight-anti-bright-theme package
817
818 ;; interesting but not usable colors
819 ;;(override-theme 'cyberpunk) ; cool org mode features, from cyberpunk-theme package
820 ;;(override-theme 'wombat) ; cursor not visible enough. from a wombat package, not sure which
821 ;;(override-theme 'misterioso) ; cursor not visible enough
822
823
824
825 ;;decent light themes
826 ;;(override-theme 'alect-light) ; theres a -alt version, don't see a dif. could use this without dimming. from alect-something package
827 ;;(override-theme 'occidental) ; from occidental-theme package
828
829
830 ;;color-theme is deprecated in emacs 24.
831
832 ;; theme packages i tried then removed:
833 ;; ignored ones that didn't use the new theme engine
834
835 ;;66 packages (zenburn-theme-2.1, zen-and-art-theme-1.0.1, waher-theme-20130917.7, ujelly-theme-1.0.35, twilight-theme-1.0.0, twilight-bright-theme-20130605.143, twilight-anti-bright-theme-20120713.316, tronesque-theme-1.3, tron-theme-12, toxi-theme-0.1.0, tommyh-theme-1.2, tango-2-theme-1.0.0, sunny-day-theme-20131203.1250, sublime-themes-20140117.323, subatomic-theme-20131011.1048, soothe-theme-0.3.16, soft-morning-theme-20131211.1342, soft-charcoal-theme-20130924.1206, sea-before-storm-theme-0.3, purple-haze-theme-20130929.1751, phoenix-dark-pink-theme-20130905.941, phoenix-dark-mono-theme-20130306.1215, pastels-on-dark-theme-0.3, obsidian-theme-20130920.937, nzenburn-theme-20130513, noctilux-theme-20131019.31, mustang-theme-20130920.939, monokai-theme-0.0.10, molokai-theme-20130828.0, late-night-theme-0.0, jujube-theme-0.1, ir-black-theme-20130302.2355, gruvbox-theme-20131229.1458, gruber-darker-theme-0.6, grandshell-theme-20140118.1003, github-theme-0.0.3, gandalf-theme-0.1, flatland-theme-20131204.858, django-theme-20131022.202, deep-thought-theme-0.1.1, dakrone-theme-20131212.1159, colorsarenice-theme-20131128.1106, color-theme-wombat+-0.0.2, color-theme-wombat-0.0.1, color-theme-twilight-0.1, color-theme-tango-0.0.2, color-theme-solarized-20120301, color-theme-sanityinc-solarized-2.25, color-theme-railscasts-0.0.2, color-theme-monokai-0.0.5, color-theme-molokai-0.1, color-theme-ir-black-1.0.1, color-theme-heroku-1.0.0, color-theme-github-0.0.3, color-theme-eclipse-0.0.2, color-theme-dpaste-0.0.1, color-theme-dawn-night-1.0, color-theme-colorful-obsolescence-0.0.1, color-theme-cobalt-0.0.2, color-theme-20080305.34, clues-theme-20130908.801, busybee-theme-20130920.942, bubbleberry-theme-0.1.2, assemblage-theme-20130715.621, anti-zenburn-theme-20140104.1542, ample-zen-theme-0.2)
836
837
838
839 #+end_src
840
841 * yasnippet
842 cd ~/.emacs.d/src
843 git clone --recursive https://github.com/capitaomorte/yasnippet
844 touch snippets/.yas-make-groups
845
846 This all makes it so I can look through the default snippets
847 in the menu bar, but they don't show up elsewhere, because they are
848 mostly things I don't want.
849
850 #+begin_src emacs-lisp
851
852 (require 'yasnippet)
853 ;; this needs to be before yas-global-mode
854 (setq yas-snippet-dirs (list "~/.emacs.d/snippets"))
855 (yas-global-mode 1)
856
857 (setq
858 yas-also-auto-indent-first-line t
859 yas-choose-tables-first t
860 yas-use-menu (quote full)
861 ;; this sets ido-prompt as first function
862 yas-prompt-functions
863 '(yas-ido-prompt yas-dropdown-prompt yas-x-prompt yas-completing-prompt yas-no-prompt))
864
865 ;; todo, explore this option for wrapping region
866 ;; '(yas/wrap-around-region t))
867
868 #+end_src
869
870 #+RESULTS:
871 | yas-ido-prompt | yas-dropdown-prompt | yas-x-prompt | yas-completing-prompt | yas-no-prompt |
872
873 * cross session settings
874 #+begin_src emacs-lisp
875
876 ;; Save a list of recent files visited.
877 (recentf-mode 1)
878 (setq recentf-max-saved-items 200
879 recentf-max-menu-items 15)
880
881
882 (setq save-place t
883 save-place-version-control 'nospecial
884 save-place-limit 40000
885 save-place-file "~/.emacs.d/places")
886
887
888
889 ;; savehist keeps track of some history
890 ;; search entries
891 (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring)
892 ;; save every minute
893 savehist-autosave-interval 60
894 ;; keep the home clean
895 savehist-file "~/.emacs.d/.savehist")
896 (savehist-mode 1)
897
898 #+end_src
899
900 * ediff
901 #+begin_src emacs-lisp
902 ;; ediff-buffers is the main command to use
903
904 ;; ediff - don't start another frame for the control panel
905 ;; unfortunately, this doesn't allow me to use 2 frames for the diff buffers
906 ;; so disable this temporarily with the next line if you want that
907 ;; sometime I should setup 2 functions to explicitly do each type
908 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
909 ;;(setq ediff-window-setup-function 'ediff-setup-windows-default)
910
911 ;; do side by side diffs
912 (setq ediff-split-window-function 'split-window-horizontally)
913
914
915 #+end_src
916
917
918
919 Things I tried which didn't work, which intuitively I think should work better: I can open the second diff buffer in a new frame, and close it's window in the first frame after starting ediff, but when I hit n to go to the next diff, it restores the window in the first frame. Another thing I tried is to open 2 new frames and set them up as I want. However, if I try to open the *Ediff Control Panel* buffer in a different window from its original one, my mouse jumps to one of the diff frames, or if that isn't visible, the buffer just hangs until I select the original ediff control panel window. This seems like a bug to me. I am using a very recent development version of emacs.
920
921 * dired
922 #+begin_src emacs-lisp
923
924 ;; dired - reuse current buffer by pressing 'a'
925 (put 'dired-find-alternate-file 'disabled nil)
926 #+end_src
927
928 * mu4e
929 [[info:org#External links]]
930 [[info:mu4e#Keybindings]]
931
932 alsot tried notmuch, it had some glitches, and it's config
933 has a list of folders which i'd rather not publish, so it's config is archived.
934
935 #+begin_src emacs-lisp
936 ;;(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e")
937 (require 'mu4e)
938 (setq send-mail-function (quote sendmail-send-it) ;; common to gnus also
939 mu4e-maildir "/m/4e"
940 ;; use the standard imap folders
941 mu4e-sent-folder "/Sent"
942 mu4e-drafts-folder "/Drafts"
943 mu4e-trash-folder "/Trash"
944 ;; standard imap folder is /Archive, but I've set this to /Junk,
945 ;; because I don't manually archive individual messages, and mu4e
946 ;; is lacking a button to move to the spam folder "Junk", and I
947 ;; want one to train spamassassin better. Note: It calls
948 ;; archiving "refiling", so it's bound to r.
949 mu4e-refile-folder "/Junk"
950 ;; reindex new mail this often in seconds
951 ;; show addresses instead of just names
952 mu4e-view-show-addresses t
953 mu4e-use-fancy-chars t
954 mu4e-confirm-quit nil
955 mu4e-headers-leave-behavior 'apply ;; dont ask, do whatever was marked
956 mu4e-headers-fields (delq (assoc :mailing-list mu4e-headers-fields) mu4e-headers-fields)
957 ;; a bit faster than the default 500. trying out the default for now
958 ;;mu4e-headers-results-limit 80
959
960 ;; looking up the list of maildirs when doing jo from summary
961 ;; can take a few seconds if we have a ton of messages.
962 ;; Only take that time for the first lookup.
963 ;; if we add a new maildir, just restart mu4e for it to be in that list.
964 mu4e-cache-maildir-list t
965 ;; default is 8, way too small for my big monitors
966 mu4e-headers-visible-lines 50
967 )
968
969 ;; fucks up reading unread bookmark. when that is fixed, enable it
970 ;; (setq mu4e-update-interval 60)
971
972
973 ;; this file includes setting up my email addresses, which are not public,
974 ;; including
975 ;; mu4e-user-mail-address-list
976 ;; and a function
977 ;; inspired by mu4e info manual, search for mu4e-compose-pre-hook.
978 (load "/p/c/mu4e.el")
979
980 ;; it's implemented in mu4e, but not in the actions list for
981 ;; some reason.
982 (add-to-list 'mu4e-view-actions
983 '("browser view" . mu4e-action-view-in-browser) t)
984 (setq mu4e-maildir-shortcuts
985 '( ("/INBOX" . ?i)
986 ("/github" . ?g)
987 ("/zroe" . ?z)
988 ("/Drafts" . ?d)
989 ("/Sent" . ?d)
990 ))
991
992 ;; normally, you would add to this, but we want to
993 ;; modify unread messages. the first 4 are defined by default.
994 (setq mu4e-bookmarks
995 `( ,(make-mu4e-bookmark
996 :name "Unread messages"
997 :query "flag:unread AND NOT flag:trashed AND NOT maildir:/Junk AND NOT maildir:/fwfw"
998 :key ?u)
999 ,(make-mu4e-bookmark
1000 :name "Today's messages"
1001 :query "date:today..now"
1002 :key ?t)
1003 ,(make-mu4e-bookmark
1004 :name "Last 7 days"
1005 :query "date:7d..now"
1006 :key ?w)
1007 ,(make-mu4e-bookmark
1008 :name "Messages with images"
1009 :query "mime:image/*"
1010 :key ?p))
1011 )
1012
1013
1014 (defun mu4e-action-msgs-by-this-sender (msg)
1015 "In header view, view messages by the sender of the message under point."
1016 (let ((from (mu4e-message-field msg :from)))
1017 (unless from
1018 (mu4e-error "No from header for this message"))
1019 ;; from is structured like: (("Anacron" . "root@x2.lan"))
1020 (mu4e-headers-search (concat "f:" (cdar from)))))
1021
1022 (add-to-list 'mu4e-headers-actions
1023 '("from this sender" . mu4e-action-msgs-by-this-sender) t)
1024 (add-to-list 'mu4e-view-actions
1025 '("from this sender" . mu4e-action-msgs-by-this-sender) t)
1026 #+end_src
1027
1028
1029
1030 * disabled but saved for documentation purposes
1031 :PROPERTIES:
1032 :header-args: :tangle no
1033 :END:
1034
1035 ** ido keybinds
1036 *** C-j
1037 ido-find-file create file
1038 *** //]
1039 ido goto root
1040 *** C-k]
1041 ido kill buffer/file
1042 *** C-d]
1043 ido open dired buffer
1044 *** M-d]
1045 ido search within all subdirectories
1046 *** M-m]
1047 ido create subdirectory
1048 *** M-s]
1049 ido search recently used directories
1050 *** M-n/p]
1051 ido next/previous recently used directory
1052 *** C-s]
1053 **** TODO implement this keybind, normally ctrl-space
1054 ido use current pattern and start a new one
1055
1056
1057 ** indent settings for git's perl code
1058 don't have a way to set this automatically or a good place to put this
1059 #+begin_src emacs-lisp
1060 (setq
1061 perl-indent-level 8
1062 perl-continued-statement-offset 8
1063 perl-continued-brace-offset -8
1064 perl-brace-offset 0
1065 perl-brace-imaginary-offset 0
1066 indent-tabs-mode t
1067 )
1068 #+end_src
1069 ** org mode website
1070
1071 #+begin_src emacs-lisp
1072 ;; use org-publish-current-project with a project file open
1073 (setq org-publish-project-alist
1074 '(("org"
1075 :base-directory "/a/h/src"
1076 :publishing-directory "/a/h/output"
1077 :base-extension "org"
1078 ;;:publishing-function org-org-publish-to-org
1079 :publishing-function org-html-publish-to-html
1080 :preserve-breaks t
1081 :html-postamble "Everything here is <a rel=\"license\"
1082 href=\"http://creativecommons.org/licenses/by-sa/4.0/\"><img
1083 alt=\"Creative Commons License\" style=\"border-width:0\"
1084 src=\"http://i.creativecommons.org/l/by-sa/4.0/80x15.png\" /></a>"
1085 :html-head "<link rel=\"stylesheet\"
1086 href=\"style.css\"
1087 type=\"text/css\"/>"
1088 :htmlized-source t)
1089 ("othersrc"
1090 :base-directory "/a/h/src"
1091 :base-extension "css\\|el\\|"
1092 :publishing-directory "/a/h/output"
1093 :publishing-function org-publish-attachment)
1094 ("other"
1095 :base-directory "/a/h/other"
1096 :base-extension ".*"
1097 :publishing-directory "/a/h/output"
1098 :publishing-function org-publish-attachment)))
1099 ;; default is xhtml-strict. don't really care, but this is more common
1100 (setq org-html-doctype "html4-strict")
1101
1102 ;; this is needed for worg
1103 ;; todo: for my own site, I need to define the css in a separate file
1104 ;; in order to use this setting. see the variable help for info
1105 (setq org-export-htmlize-output-type t)
1106
1107
1108 #+end_src
1109
1110 ** bash-completion
1111 #+begin_src emacs-lisp
1112 ;; this eventually gets set in
1113 ;; comint-dynamic-complete-functions
1114 ;; (car comint-dynamic-complete-functions)
1115 (autoload 'bash-completion-dynamic-complete "bash-completion"
1116 "BASH completion hook")
1117 (add-hook 'shell-dynamic-complete-functions
1118 'bash-completion-dynamic-complete)
1119
1120 ;; this appears useless, but was in the recommended init code
1121 (add-hook 'shell-command-complete-functions
1122 'bash-completion-dynamic-complete)
1123
1124 (defun ac-rlc-setup-sources ()
1125 "Add me to shell-mode-hook!"
1126 (setq ac-sources '(ac-source-shell)))
1127 (add-hook 'shell-mode-hook 'ac-rlc-setup-sources)
1128
1129 #+end_src
1130
1131 ** misc stuff
1132 It is an awesome mode for keyboard navigation.
1133 However, using the mouse takes less thought and works as well
1134
1135 #+begin_src emacs-lisp
1136
1137
1138 ;; whitespace-mode config. minimal for bad whitespace
1139 ;(setq whitespace-line-column 80) ; for style of lines-tail, but I have it disabled
1140 (setq whitespace-style '(face tabs empty trailing))
1141 ;to enable whitespace mode
1142 (whitespace-mode +1)
1143
1144
1145
1146 (defun org-set-mark-command (arg)
1147 "Do set-mark-command and then org-show-context if the point
1148 moves to invisible text."
1149 (interactive "P")
1150 (let ((initial-point (point)))
1151 (setq this-command 'set-mark-command)
1152 (set-mark-command (arg))
1153 (if (and (not (= (point) initial-point))
1154 (or (outline-invisible-p) (org-invisible-p2)))
1155 (org-show-context 'mark-goto))))
1156
1157 (defun org-exchange-point-and-mark (&optional arg)
1158 (interactive "P")
1159 (let ((initial-point (point)))
1160 (exchange-point-and-mark)
1161 (if (and (not (= (point) initial-point))
1162 (or (outline-invisible-p) (org-invisible-p2)))
1163 (org-show-context 'mark-goto))))
1164
1165
1166 (defun toggle-mode-line ()
1167 "Toggle mode line on and off."
1168 (interactive)
1169 (if mode-line-format
1170 (progn (setq my-saved-mode-line-format mode-line-format)
1171 (setq mode-line-format nil))
1172 (setq mode-line-format my-saved-mode-line-format))
1173 (force-mode-line-update))
1174 (toggle-mode-line)
1175 (global-set-key (kbd "M-m") 'toggle-mode-line)
1176 (add-hook 'after-change-major-mode-hook
1177 (lambda () (setq my-saved-mode-line-format mode-line-format)
1178 (setq mode-line-format nil)))
1179
1180
1181 #+end_src
1182
1183 ** Copy mode-line to the top
1184 #+begin_src emacs-lisp
1185 ;; Copy mode-line to the top
1186 (setq-default header-line-format mode-line-format
1187 mode-line-format nil)
1188 ;; copied the mode-line theme into the header theme, else it is unreadable
1189 ;; this goes after loading the theme
1190 (let ((class '((class color) (min-colors 89))))
1191 (custom-theme-set-faces
1192 'leuven
1193 `(header-line ((,class (:box (:line-width 1 :color "#1A2F54") :foreground "#85CEEB" :background "#335EA8"))))))
1194
1195 #+end_src
1196
1197 ** tab bindings for when I wanted to make tab be for search
1198 #+begin_src emacs-lisp
1199
1200 (define-key emacs-lisp-mode-map (kbd "<tab>") nil)
1201 (define-key button-buffer-map "\t" nil)
1202 (define-key button-buffer-map (kbd "f") 'forward-button)
1203 (define-key Info-mode-map "\t" nil)
1204 (define-key widget-keymap "\t" nil)
1205 (define-key widget-keymap (kbd "<tab>") nil)
1206
1207 (add-hook 'compilation-mode-hook (lambda ()
1208 (define-key compilation-mode-map (kbd "<tab>") nil)
1209 (define-key compilation-mode-map "\t" nil)))
1210
1211 ;; unbind c-i for yas. it already separately binds <tab>
1212 (add-hook 'yas-minor-mode-hook (lambda ()
1213 (define-key yas-minor-mode-map "\t" nil)))
1214
1215 (add-hook 'haskell-interactive-mode-hook
1216 (lambda ()
1217 (define-key haskell-interactive-mode-map "\t" nil)
1218 (define-key haskell-interactive-mode-map (kbd "<tab>") 'haskell-interactive-mode-tab)))
1219
1220 (define-key minibuffer-local-must-match-map "\t" nil)
1221 (define-key minibuffer-local-must-match-map (kbd "<tab>") 'minibuffer-complete)
1222 (define-key minibuffer-local-completion-map (kbd "<tab>") 'minibuffer-complete)
1223 (define-key minibuffer-local-completion-map "\t" 'minibuffer-complete)
1224
1225 (add-hook 'ido-setup-hook
1226 (lambda()
1227 (define-key ido-completion-map (kbd "<tab>") 'ido-complete)
1228 (define-key ido-completion-map "\t" nil)))
1229
1230 #+end_src
1231
1232 ** kill buffer and window
1233 #+begin_src emacs-lisp
1234 (defun kill-buffer-and-window ()
1235 "Close the current window and kill the buffer it's visiting."
1236 (interactive)
1237 (progn
1238 (kill-buffer)
1239 (delete-window)))
1240 #+end_src
1241 ** sending multiple commands to a comint buffer
1242 without waiting for commands to finish is unreliable.
1243 seems like 1 in 100 times, an invisible command to restore prompt didn't work
1244 #+begin_src emacs-lisp
1245 (setq shell-unset-prompt "unset PROMPT_COMMAND; unset PS1")
1246 (setq shell-set-prompt "PROMPT_COMMAND=prompt_command")
1247
1248 (if (boundp 'shell-unset-prompt)
1249 (send-invisible-string proc shell-unset-prompt))
1250 (if (boundp 'shell-set-prompt)
1251 (send-invisible-string proc shell-set-prompt))
1252
1253
1254 (defun send-invisible-string (proc string)
1255 "Like send-invisible, but non-interactive"
1256 (comint-snapshot-last-prompt)
1257 (funcall comint-input-sender proc string))
1258
1259 #+end_src
1260
1261
1262
1263
1264 ** org-mode auto-complete source
1265
1266 todo, someday take a look at this. it is broken.
1267
1268 ;(defvar ac-source-eshell-pcomplete
1269 ; '((candidates . (pcomplete-completions))))
1270 ;(defun ac-complete-eshell-pcomplete ()
1271 ; (interactive)
1272 ; (auto-complete '(ac-source-eshell-pcomplete)))
1273
1274 ;(add-hook 'org-mode-hook (lambda () (setq ac-sources (cons 'ac-source-eshell-pcomplete ac-sources))))
1275 ;(add-to-list 'ac-modes 'eshell-mode)
1276
1277
1278 ** gnus nice unicode
1279
1280
1281 this looks nice, but it lags gnus just a bit
1282 #+begin_src emacs-lisp
1283
1284 (defun gnus-pretty-chars-setup ()
1285 (when window-system
1286 (setq gnus-sum-thread-tree-indent " "
1287 gnus-sum-thread-tree-root "● "
1288 gnus-sum-thread-tree-false-root "◯ "
1289 gnus-sum-thread-tree-single-indent "◎ "
1290 gnus-sum-thread-tree-leaf-with-other "├─► "
1291 gnus-sum-thread-tree-vertical "│"
1292 gnus-sum-thread-tree-single-leaf "╰─► ")))
1293 ;; dunno why, but this didn't work just setting on startup
1294 (add-hook 'gnus-startup-hook 'gnus-pretty-chars-setup)
1295
1296 #+end_src
1297
1298 ** misc
1299 #+begin_src emacs-lisp
1300
1301 ;; this makes more ergonomic sense, since our eyes are mostly on the left,
1302 ;; but after using it a while, it's too much cognitive dissonance that
1303 ;; every other program has it on the right
1304 ;;(set-scroll-bar-mode 'left)
1305
1306
1307
1308 ; todo, is this require things necessary?
1309 ; (require 'flyspell)
1310
1311
1312
1313 ; whenever M-tab is completion, swap it with tab
1314 ;(define-key emacs-lisp-mode-map (kbd "<tab>") 'completion-at-point)
1315 ;(define-key emacs-lisp-mode-map (kbd "C-M-i") 'indent-for-tab-command)
1316 ;(define-key lisp-interaction-mode-map (kbd "<tab>") 'completion-at-point)
1317 ;(define-key lisp-interaction-mode-map (kbd "C-M-i") 'indent-for-tab-command)
1318 ;the global tab keyind. for some reason this totally screws up mini-buffer tab.
1319 ; disabled until I actually find myself using this, and find a fix for the above problem
1320 ;(global-set-key (kbd "<tab>") 'complete-symbol)
1321
1322
1323 ; todo, make my custom overlays have an underline if they are
1324 ; overriding a paren matching overlay
1325 ; make right click set the mark
1326 ; make search tab do completion instead of meta-tab
1327 ; in isearch, move C-y to C-v
1328 ; in isearch, move c-s to c-f
1329
1330 ; some testing to figure out the underlining when paren highlight conflicts
1331 ; (let ((extra-overlays (overlays-at (1+ end-point))))
1332 ; (when extra-overlays (print extra-overlays)))
1333
1334
1335
1336
1337 ; commented out because it messes up yank-pop.
1338 ; todo, fix it someday
1339 ; make yank linewise if it ends in a newline
1340 ;(defadvice yank (before linewise-yank-advice activate)
1341 ; (let ((arg (ad-get-arg 0)))
1342 ; (when (string-match "\n[ \t]*$" (current-kill (cond
1343 ;; ((listp arg) 0)
1344 ;; ((eq arg '-) -2)
1345 ;; (t (1- arg))) t))
1346 ;; (move-beginning-of-line nil))))
1347
1348
1349
1350 ; todo, look into augmenting auto-complete with hippie expand.
1351 ; starter kit has some hippie expand settings to look into:
1352 ; (when (boundp 'hippie-expand-try-functions-list)
1353 ; (delete 'try-expand-line hippie-expand-try-functions-list)
1354 ; (delete 'try-expand-list hippie-expand-try-functions-list))
1355
1356
1357 ;; hippie expand is dabbrev expand on steroids
1358 ;(setq hippie-expand-try-functions-list '(try-expand-dabbrev
1359 ; try-expand-dabbrev-all-buffers
1360 ; try-expand-dabbrev-from-kill
1361 ; try-complete-file-name-partially
1362 ; try-complete-file-name
1363 ; try-expand-all-abbrevs
1364 ; try-expand-list
1365 ; try-expand-line
1366 ; try-complete-lisp-symbol-partially
1367 ; try-complete-lisp-symbol))
1368 ;; use hippie-expand instead of dabbrev
1369 ;(global-set-key (kbd "M-/") 'hippie-expand)
1370
1371
1372 ; commented because i haven't had time to check it out yet
1373 ;; shorter aliases for ack-and-a-half commands
1374 ;(defalias 'ack 'ack-and-a-half)
1375 ;(defalias 'ack-same 'ack-and-a-half-same)
1376 ;(defalias 'ack-find-file 'ack-and-a-half-find-file)
1377 ;(defalias 'ack-find-file-same 'ack-and-a-half-find-file-same)
1378
1379
1380
1381
1382 ; todo. take a look at fixing this
1383 ;delete-old-versions t ; fix description in http://www.emacswiki.org/emacs/ForceBackups
1384
1385
1386
1387
1388 ;; prelude uses paredit mode.
1389 ;; paredit has some useful stuff but also annoying stuff.
1390 ;; if I ever do a ton of lisp coding, I should look into it
1391
1392
1393
1394
1395
1396
1397 ; random notes and example code
1398
1399
1400 ; usefull thing
1401 ;(map 'list #'list tabSwapKeys (reverse (getBinds tabSwapKeys)))
1402
1403 ; example of getting keymap info
1404 ;(car (car (minor-mode-key-binding (kbd "C-/") t)))
1405 ;(cdr (car (minor-mode-key-binding (kbd "C-/") t)))
1406 ;(global-key-binding (kbd "C-M-i") t)
1407 ;(minor-mode-key-binding (kbd "<tab>") t)
1408 ;(local-key-binding (kbd "C-M-i") t)
1409 ;(current-minor-mode-maps)
1410 ;(cdr (assq 'undo-tree-mode minor-mode-map-alist))
1411
1412
1413 ; center on incremental search, instead of being at top or bottom of screen.
1414 ; i'm hoping that setting Isearch Allow Scroll is good enough to fix this annoyance
1415 ;from http://stackoverflow.com/questions/11052678/emacs-combine-iseach-forward-and-recenter-top-bottom
1416
1417 ;example of constant definition of an overlay and propreries
1418 ;(defface mouse-flash-position '((t (:background "Yellow")))
1419 ; "*Face used to highlight mouse position temporarily."
1420 ; :group 'mouse)
1421 ;(defface mouse-flash-position '((t (:background "Yellow")))
1422 ; "*Face used to highlight mouse position temporarily."
1423 ; :group 'mouse)
1424 ;(defconst mouse-flash-posn-overlay
1425 ; ;; Create and immediately delete, to get "overlay in no buffer".
1426 ; (let ((ol (make-overlay (point-min) (point-max))))
1427 ; ;(delete-overlay ol)
1428 ; ;(overlay-put ol 'face 'mouse-flash-position)
1429 ; (overlay-put ol 'mouse-face 'mouse-flash-position)
1430 ; (overlay-put ol 'priority 1000000)
1431 ; ol)
1432 ; "Overlay to highlight current mouse position.")
1433
1434
1435 ;tip, put the last interactive command as elisp on the kill ring:
1436 ;C-x <ESC> <ESC> C-a C-k C-g
1437
1438 ; example of overlay testing
1439 ;(setq foo (make-overlay 2 3 nil t nil))
1440 ;(setq foo2 (make-overlay 3 4 nil t nil))
1441 ;(overlay-put foo 'face '(:background "red3" :foreground "black"))
1442 ;(overlay-put foo2 'face '(:background "red1" :foreground "black"))
1443 ;(overlay-put foo 'face 'visible-mark-face)
1444 ;(overlay-put foo 'face visible-mark-face2)
1445
1446
1447 #+end_src
1448
1449
1450 ** SQL
1451
1452 disabled, as I haven't used it in a long time. I think it was good for learning some sql stuff.
1453 #+begin_src emacs-lisp :tangle no
1454 (require 'sqlup-mode)
1455 (add-hook 'sql-mode-hook 'sqlup-mode)
1456 (add-hook 'sql-interactive-mode-hook 'sqlup-mode)
1457
1458 (setq sql-product 'postgres)
1459 #+end_src
1460
1461
1462 ** icomplete
1463 #+begin_src emacs-lisp
1464 ;; without this, on partial completion return would exit the minibuffer, and i had to
1465 ;; keep typing out letters do a full completion before pressing enter.
1466 ;; super annoying. So I picked ctrl-j as a free key to put exit,
1467 ;; but in practice, I would just use ctrl-g to quit. Anyways,
1468 ;; ivy is doing all the minibuffer stuff, so removed this as it's
1469 ;; unused, so it can't cause any problems in future
1470 (when (boundp 'icomplete-minibuffer-map)
1471 (define-key icomplete-minibuffer-map (kbd "C-j") 'exit-minibuffer)
1472 (define-key icomplete-minibuffer-map (kbd "<return>")
1473 'minibuffer-force-complete-and-exit))
1474
1475
1476 #+end_src
1477 * elisp settings
1478 #+begin_src emacs-lisp
1479 ; when manually evaluating lisp, go into debugger on error
1480 (setq eval-expression-debug-on-error t)
1481 ;reminder of useful var: debug-on-error
1482 #+end_src
1483
1484
1485
1486
1487
1488 * gnus
1489
1490 good info http://www.emacswiki.org/emacs/GnusTutorial
1491 good info http://www.emacs.uniyar.ac.ru/doc/em24h/emacs183.htm
1492
1493 searching / accessing old mailing list messages:
1494 http://wiki.list.org/display/DOC/How+do+I+make+the+archives+searchable
1495 3 options suggested. nabble is very good, and you can even reply directly from their web interface with your own email
1496 address.
1497 google with site:example.com/archive works
1498 However, it has the downside of relying on a 3rd party running unreleased software.
1499 mail-archive.com and gmane.org search do not work.
1500
1501 Some lists mirror to a newsgroup via gmane, and then mirror the newsgroup via a google group, which has good search
1502 ability, and you can post via the newsgroup.
1503
1504 Downsides of nabble/google. Doesn't integrate with normal email programs, and lock in. They store and show you what you
1505 have and haven't read, what messages you've sent, etc. migrating that data to a normal mail program is undocumented and
1506 unsupported.
1507
1508 mailmans normal public archives are a bit obfuscated, but there is also a "private" archive, available to subscribers,
1509 which is not obfuscated, and can be easily imported to your local email program.
1510 you have to sub and log in to the web interfact to access it, and then the url is unpublished, but follows a format,
1511 which is documented in a few places around the web like
1512 https://mail.python.org/pipermail/mailman-users/2005-September/046757.html
1513 its form is:
1514 https://lists.fedorahosted.org/mailman/private/hyperkitty-devel.mbox/hyperkitty-devel.mbox
1515 http://www.example.com/mailman/private/<listname>.mbox/<listname>.mbox
1516 if you copy the url after logging in, and pass it to this function, it will print the transformed url
1517 lurl() { local x="${1#*/options/}"; x="${x%%/*}.mbox"; echo "${1%/mailman/*}/mailman/private/$x/$x"; }
1518
1519 Then you can download that url. Actually downloading the url is something firefox doesn't make the easiest out of the box.
1520 Here are some options:
1521 - paste in the url bar, the save the page
1522 as a file after it loads.
1523 - use downthemall extension or similar and paste the url in it.
1524 - put it in an html page as
1525 a link (or a small javascript program which will display input as a link), then right click and save as.
1526 wget won't work because you need to have (i assume) the authorization cookie mailman gives your browser
1527
1528 people have written various tools to de-obfuscate the normal public archives and sometimes import them to a mail
1529 program. It seems they were not aware of the private archive. However, these tools are probably still useful to automate
1530 things. None of them has a lot of usage, so I decided it was not worth the risk of hitting bugs vs doing a few extra clicks.
1531
1532 this was the most interesting one I found within a few minutes of googling.
1533 https://github.com/wcdolphin/mailman-downloader
1534
1535 Once you have an mbox file, there are rather straightforward ways to get it into any mail program, but I will cover
1536 gnus, which I use and is a bit tricky.
1537
1538 gnus has a native search (limited, too slow for body text searches), and external search engine integration.
1539 gnus manual recommends converting to maildir for searching local mail, but importing lots of maildir messages to gnus
1540 takes 10+ minutes, so scratch that option. it suggests 2 alternate options
1541 mairix. for mbox, it doesn't integrate 100% with gnus, it copies the search results to a mbox
1542 and tells gnus to make a group of that mbox and display it. This means the read state won't be persistent, but otherwise
1543 works great.
1544
1545 local imap server which will use the mbox and provide search.
1546 dovecot is modular, theres a dovecot-common which uses recommends to install i guess it's most used modules. Its
1547 description is completely not useful. Anyways, I'm not sure if there is any benefit to installing this over just the
1548 module we need.
1549 pi dovecot-imapd
1550
1551 dovecot by default also makes a an inbox folder based on the normal local mail location /var/mail/<username>
1552 those locations are adjustable and well documented via the var mail_location in
1553 /etc/dovecot/conf.d/10-mail.conf
1554 I forward my local mail, didn't see immediately how to turn off the inbox, but it will always be empty, so I left as
1555 is. you could make the var be empty, which apparently has the same effect.
1556
1557 Originally just linked the default location ~/.mail, but I changed to altering the config since ~/.mail since it seems
1558 other things like postfix use that location
1559
1560 based on http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html
1561 other links that poped up contained outdated, innacurate information
1562 http://sachachua.com/blog/2008/05/geek-how-to-use-offlineimap-and-the-dovecot-mail-server-to-read-your-gmail-in-emacs-efficiently/
1563 http://www.emacswiki.org/emacs/JamesFerguson
1564 http://www.sanityinc.com/articles/read-mailing-lists-in-emacs-over-imap/
1565
1566 Within emacs you can move messages between mbox and maildir etc, which is a nice flexibility.
1567
1568
1569
1570 doc group for mbox:
1571 in gnus, do gnus-group-make-doc-group (G f in groups buffer) and point to the file
1572
1573 info about groups created within gnus is stored in ~/.newsrc.eld
1574 also stored is a duplication of what email messages are read/unread,
1575 what newsgroups are subsribed to and read/unread,
1576 probably more stuff, everything that gnus saves.
1577
1578
1579 searching the body of the messages, i cut off after a few minutes.
1580 i can grep the file in just a couple seconds
1581
1582
1583 random side note
1584 we can also get mbox from gmane
1585 http://notmuchmail.org/howto/#index7h2
1586
1587
1588 gnus can't search mboxes except with its builtin search which is extremely slow. mairix can do mbox files from the command
1589 line, but not from within gnus, but from mairix.el, which can then open the results in gnus
1590
1591 mbox can be converted to maildir easily, but gnus loads lots of maildir messages extremely slow. it parses all the
1592 headers and generates a nov file for each.
1593
1594 nnfolder-generate-active-file
1595
1596 to reset things, when changing mail group. I duno all the proper way, but it works to delete
1597 ~/Mail ~/.newsrc.eld ~/.dribble (or something)
1598
1599
1600 ** mail sources vs select methods background
1601 I found this very confusing when first reading through the manual. "mail sources" is a term that does not simply mean
1602 sources of mail, it is much narrower for gnus. sources of mail can be either "mail sources" or select methods. Mail
1603 sources will move mail to ~/Mail (not sure what format), and split it into groups according to variables. You can use
1604 "mail sources" for maildir / imap, but those can also be read via select methods, which do not move the mail from their
1605 location, but use them in their native format. This is what I want to do, and I can simply ignore mail
1606 sources. Confusing terminology is that "fetching mail" "scanning mail", lots of things mail doesn't mean all mail, it
1607 means specifically from "mail sources". The words "articles" and "news" is used in connection with select methods, aka my actual mail.
1608
1609
1610
1611 ** caching background
1612
1613 caching:
1614 there is also ~/News/cache, filled with a bunch of articles, like 300 megs. can't figure out why.
1615 Grepped for caching in the manual, found 2 main things.
1616 cache is for 2 purposes. to cache locally, and to keep articles from expiring, called persistence
1617 gnus-use-cache, which puts things if they are
1618 gnus-cache-enter-articles
1619 things go in cache when they are marked certain ways by default, ticked and dormant
1620 and read articles are moved out of the cache
1621 still no idea why i have a bunch in the cache, but I set a var so that my mail won't get cached
1622 I'm gonna delete the cache, and check on it later see what exactly is going in there
1623 And of course, I moved ~/News to my encrypted drive and symlinked it
1624
1625
1626 * haskell
1627 :LOGBOOK:
1628 :END:
1629
1630 useful comint-shell mode commands. If not prefaced with *, it means it is not in the haskell custom repl
1631 *todo: setup haskell c-t toggle arrow keys
1632 tab completion
1633 C-q insert prev arg
1634 C-( history search
1635 c-m-left/right move to next/prev prompts
1636 *c-enter, multi-line input
1637 *s-delete, send input across windows. (i can implement this)
1638 *c-m-l clear screen
1639 *haskell-process-interrupt, c-cc terminate job (i can implement this maybe)
1640
1641 nice bash/readline functions missing in comint:
1642 yank-nth-arg
1643 operate-get-next
1644 menu-complete
1645
1646 usefull comint commands:
1647 c-cl : list historic command in temp buffer
1648 C-c C-o comint-delete-output
1649 comint-restore-input, todo: put this on a randomish c-c key
1650
1651
1652
1653 todo:
1654 checkout haskell repl functions:
1655 c-cv haskell-check, hlint
1656 C-M-q prog-indent-sexp
1657 c-c. haskell-mode-format-imports
1658 C-c M-/ haskell-doc-check-active
1659 haskell-process-generate-tags
1660 haskell-process-cabal-build
1661 haskell-cabal-command.. or something
1662 haskell-process-restart
1663 C-h v haskell-process-log
1664 C-h v haskell-process-show-debug-tips
1665
1666 various not immediately useful functions:
1667 haskell-process-add-dependency
1668 haskell-process-touch-buffer
1669 haskell-process-cd
1670 haskell-process-unignore
1671 haskell-process-reload-devel-main
1672
1673
1674 rebind
1675 home: C-a haskell-interactive-mode-beginning
1676 c-return: C-j haskell-interactive-mode-newline-indent
1677 up/down: <C-down> haskell-interactive-mode-history-next
1678
1679 todo haskell mode better binds for:
1680 'haskell-process-load-file
1681 'haskell-process-do-type
1682 'haskell-process-do-info
1683 'inferior-haskell-send-decl
1684
1685
1686 commands which don't work in haskell-interactive-mode(hi) vs inferior-haskell-mode(ih, default)
1687 functions not in hi:
1688 inferior-haskell-find-definition, use tags instead
1689 inferior-haskell-find-haddock, todo, test if this works
1690
1691 redefined ih to hi
1692 switch-to-haskell -> 'haskell-interactive-switch
1693 haskell-process-load-file -> inferior-haskell-load-file
1694 haskell-process-do-type -> inferior-haskell-type
1695 switch-to-haskell -> haskell-interactive-switch
1696 inferior-haskell-load-file -> 'haskell-process-load-file
1697
1698
1699 haskell-mode installation from source, based on its readme
1700 in the git directory,
1701 make all
1702
1703 #+begin_src emacs-lisp
1704
1705
1706
1707 ;; remove default option to not link the file
1708 (setq haskell-compile-command "ghc -Wall -ferror-spans -fforce-recomp %s")
1709 (add-hook 'haskell-indentation-mode-hook
1710 (lambda ()
1711 (define-key haskell-indentation-mode-map [?\C-d] nil)
1712 (define-key haskell-indentation-mode-map
1713 (kbd "<deletechar>")
1714 'haskell-indentation-delete-char)))
1715
1716 ;;copied from haskell-mode docs in order to use the new, better, nondefault
1717 ;;interactive mode.
1718 (eval-after-load "haskell-mode"
1719 '(progn
1720 (define-key haskell-mode-map (kbd "C-x C-d") nil)
1721 (define-key haskell-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)
1722 (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-file)
1723 (define-key haskell-mode-map (kbd "C-c C-b") 'haskell-interactive-switch)
1724 (define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
1725 (define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
1726 (define-key haskell-mode-map (kbd "C-c M-.") nil)
1727 (define-key haskell-mode-map (kbd "C-c C-d") nil)))
1728
1729 ;; ghc-mod install http://www.mew.org/~kazu/proj/ghc-mod/en/emacs.html
1730 ;; todo, try this out
1731 ;; (autoload 'ghc-init "ghc" nil t)
1732 ;;(add-hook 'haskell-mode-hook (lambda () (ghc-init) (flymake-mode)))
1733
1734
1735
1736 (add-to-list 'load-path "~/.emacs.d/src/ghci-completion")
1737 ;; from the package readme for ghci-completion
1738 (require 'ghci-completion)
1739 (add-hook 'inferior-haskell-mode-hook 'turn-on-ghci-completion)
1740
1741
1742 ;; disable some rebinds. they are set to appropriate keys in the keybinds section
1743 (eval-after-load "haskell-mode"
1744 '(progn
1745 (define-key haskell-mode-map (kbd "C-a") 'nil)
1746 (define-key haskell-mode-map (kbd "C-j") 'nil)))
1747
1748 (defun pretty-lambdas-haskell ()
1749 (font-lock-add-keywords
1750 nil `((,(concat "(?\\(" (regexp-quote "\\") "\\)")
1751 (0 (progn (compose-region (match-beginning 1) (match-end 1)
1752 ,(make-char 'greek-iso8859-7 107))
1753 nil))))))
1754 ;; from haskell-mode manual
1755 (add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan)
1756 (when (window-system)
1757 (add-hook 'haskell-mode-hook 'pretty-lambdas-haskell))
1758
1759 ;; added from haskell-mode website install instructions
1760 ;(load "/usr/share/emacs/site-lisp/haskell-mode/haskell-site-file")
1761 (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
1762 ;;the three indentation modules are mutually exclusive - add at most one. Trying out the "most advanced"
1763 (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
1764 ;;(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
1765 ;;(add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent)
1766
1767
1768 ;; todo, set this to some other key
1769 ;; (local-set-key (kbd "C-e") 'my-haskell-load-and-run)
1770
1771 (defun my-haskell-load-and-run ()
1772 "Loads and runs the current Haskell file."
1773 (interactive)
1774 (let ((start-buffer (current-buffer)))
1775 (inferior-haskell-load-and-run inferior-haskell-run-command)
1776 (sleep-for 0 100)
1777 (end-of-buffer)
1778 (pop-to-buffer start-buffer)))
1779
1780 ;; show haskell function in mode line
1781 ;; todo, this broke after updating emacs
1782 ;;(eval-after-load "which-func"
1783 ;; '(add-to-list 'which-func-modes 'haskell-mode))
1784
1785
1786
1787 (add-hook 'interactive-haskell-mode-hook 'ac-haskell-process-setup)
1788 (add-hook 'haskell-interactive-mode-hook 'ac-haskell-process-setup)
1789 (eval-after-load "auto-complete"
1790 '(add-to-list 'ac-modes 'haskell-interactive-mode))
1791
1792 (add-hook 'haskell-mode-hook
1793 (lambda () (define-key haskell-mode-map (kbd "C-(")
1794 (lambda () (interactive)
1795 (basic-save-buffer)
1796 (haskell-compile)
1797 (run-with-timer .3 nil 'repeat-shell)))))
1798 (add-hook 'haskell-cabal-mode-hook
1799 (lambda () (define-key haskell-cabal-mode-map (kbd "C-(") 'haskell-compile)))
1800
1801
1802
1803 (add-hook 'haskell-interactive-mode-hook
1804 (lambda ()
1805 (define-key haskell-interactive-mode-map "\r" nil)
1806 (define-key haskell-interactive-mode-map (kbd "<return>") 'haskell-interactive-mode-return)))
1807 (add-hook 'haskell-indentation-mode-hook (lambda () (define-key haskell-indentation-mode-map "\r" nil)))
1808
1809
1810
1811 (add-hook 'haskell-interactive-mode-hook
1812 (lambda ()
1813 (define-key haskell-interactive-mode-map (kbd "<C-M-return>") 'haskell-interactive-mode-newline-indent)))
1814
1815 #+end_src
1816
1817 #+RESULTS:
1818 | (lambda nil (define-key haskell-interactive-mode-map (kbd <C-M-return>) (quote haskell-interactive-mode-newline-indent))) | (lambda nil (define-key haskell-interactive-mode-map \n nil) (define-key haskell-interactive-mode-map (kbd <return>) (quote haskell-interactive-mode-return))) | ac-haskell-process-setup |
1819
1820 * isearch
1821 #+begin_src emacs-lisp
1822 (setq
1823 isearch-allow-scroll t
1824 search-ring-update t) ;; dont start an edit when going to previous search
1825
1826 (defun isearch-yank-regexp (regexp)
1827 "Pull REGEXP into search regexp."
1828 (let ((isearch-regexp nil)) ;; Dynamic binding of global.
1829 (isearch-yank-string regexp))
1830 (isearch-search-and-update))
1831
1832 (defun isearch-yank-symbol (&optional partialp backward)
1833 "Put symbol at current point into search string.
1834
1835 If PARTIALP is non-nil, find all partial matches."
1836 (interactive "P")
1837
1838 (let (from to bound sym)
1839 (setq sym
1840 ; this block taken directly from find-tag-default
1841 ; we couldn't use the function because we need the internal from and to values
1842 (when (or (progn
1843 ;; Look at text around `point'.
1844 (save-excursion
1845 (skip-syntax-backward "w_") (setq from (point)))
1846 (save-excursion
1847 (skip-syntax-forward "w_") (setq to (point)))
1848 (> to from))
1849 ;; Look between `line-beginning-position' and `point'.
1850 (save-excursion
1851 (and (setq bound (line-beginning-position))
1852 (skip-syntax-backward "^w_" bound)
1853 (> (setq to (point)) bound)
1854 (skip-syntax-backward "w_")
1855 (setq from (point))))
1856 ;; Look between `point' and `line-end-position'.
1857 (save-excursion
1858 (and (setq bound (line-end-position))
1859 (skip-syntax-forward "^w_" bound)
1860 (< (setq from (point)) bound)
1861 (skip-syntax-forward "w_")
1862 (setq to (point)))))
1863 (buffer-substring-no-properties from to)))
1864 (cond ((null sym)
1865 (message "No symbol at point"))
1866 ((null backward)
1867 (goto-char (1+ from)))
1868 (t
1869 (goto-char (1- to))))
1870 (isearch-search)
1871 (if partialp
1872 (isearch-yank-string sym)
1873 (isearch-yank-regexp
1874 (concat "\\_<" (regexp-quote sym) "\\_>")))))
1875
1876 (defun isearch-current-symbol (&optional partialp)
1877 "Incremental search forward with symbol under point.
1878
1879 Prefixed with \\[universal-argument] will find all partial
1880 matches."
1881 (interactive "P")
1882 (let ((start (point)))
1883 (isearch-forward-regexp nil 1)
1884 (isearch-yank-symbol partialp)))
1885 ;; todo, make this
1886
1887 (defun isearch-backward-current-symbol (&optional partialp)
1888 "Incremental search backward with symbol under point.
1889
1890 Prefixed with \\[universal-argument] will find all partial
1891 matches."
1892 (interactive "P")
1893 (let ((start (point)))
1894 (isearch-backward-regexp nil 1)
1895 (isearch-yank-symbol partialp)))
1896
1897
1898
1899 ; lets look through emacs starter kit before we throw this out.
1900
1901
1902 ; automatically wrap to the top of the buffer when isearch fails
1903 (defadvice isearch-search (after isearch-no-fail activate)
1904 (unless isearch-success
1905 (ad-disable-advice 'isearch-search 'after 'isearch-no-fail)
1906 (ad-activate 'isearch-search)
1907 (isearch-repeat (if isearch-forward 'forward))
1908 (ad-enable-advice 'isearch-search 'after 'isearch-no-fail)
1909 (ad-activate 'isearch-search)))
1910
1911 ;; Activate occur easily inside isearch
1912 (define-key isearch-mode-map (kbd "C-o")
1913 (lambda () (interactive)
1914 (let ((case-fold-search isearch-case-fold-search))
1915 (occur (if isearch-regexp
1916 isearch-string
1917 (regexp-quote isearch-string))))))
1918
1919
1920 #+end_src
1921
1922 * lisp / elisp mode setings
1923 #+begin_src emacs-lisp
1924
1925 (add-hook 'emacs-lisp-mode-hook 'starter-kit-remove-elc-on-save)
1926 (defun starter-kit-remove-elc-on-save ()
1927 "If you're saving an elisp file, likely the .elc is no longer valid."
1928 (make-local-variable 'after-save-hook)
1929 (add-hook 'after-save-hook
1930 (lambda ()
1931 (if (file-exists-p (concat buffer-file-name "c"))
1932 (delete-file (concat buffer-file-name "c"))))))
1933
1934
1935 (defun emacs-lisp-mode-defaults ()
1936 ;; checkdoc has an annoying feature that wants a header and footer
1937 ;; in every elisp buffer as if they all were packages
1938 ;; todo, see if there is a way
1939 ;; to make checkdoc usable instead of just disabling it as I do here
1940 (if (boundp 'flycheck-checkers)
1941 (setq flycheck-checkers (remove 'emacs-lisp-checkdoc flycheck-checkers)))
1942 (eldoc-mode 1))
1943 (add-hook 'emacs-lisp-mode-hook 'emacs-lisp-mode-defaults)
1944
1945 (define-key lisp-mode-map (kbd "<M-up>") 'backward-up-list)
1946 (define-key lisp-mode-map (kbd "<M-down>") 'down-list)
1947 (define-key emacs-lisp-mode-map (kbd "<M-up>") 'backward-up-list)
1948 (define-key emacs-lisp-mode-map (kbd "<M-down>") 'down-list)
1949 (define-key emacs-lisp-mode-map (kbd "<M-escape>") 'find-function-at-point)
1950
1951 ;; interactive modes don't need whitespace checks
1952 (defun interactive-lisp-coding-defaults ()
1953 (whitespace-mode -1))
1954 (setq prelude-interactive-lisp-coding-hook 'prelude-interactive-lisp-coding-defaults)
1955
1956
1957 ;; ielm is an interactive Emacs Lisp shell
1958 (defun ielm-mode-defaults ()
1959 (run-hooks 'prelude-interactive-lisp-coding-hook)
1960 (turn-on-eldoc-mode))
1961 (add-hook 'ielm-mode-hook 'ielm-mode-defaults)
1962
1963 #+end_src
1964
1965
1966 * java eclim
1967
1968 based on https://github.com/senny/emacs-eclim
1969
1970
1971 eclim: eclipse completion, searching, validation, etc inside emacs
1972 install
1973 #+begin_src sh :tangle no
1974 cd ~/opt
1975 git clone git://github.com/ervandew/eclim.git
1976 cd eclim
1977 pi ant
1978 ant -Declipse.home=/a/opt/eclipse
1979 #+end_src
1980
1981
1982 currently makes emacs hang a bunch. dunno why. just using eclipse instead
1983 #+begin_src emacs-lisp :tangle no
1984 (require 'eclim)
1985 (global-eclim-mode)
1986
1987 ;; just do java
1988 (setq eclim-accepted-file-regexps
1989 '("\\.java"))
1990
1991 (custom-set-variables
1992 '(eclim-eclipse-dirs '("/a/opt/eclipse"))
1993 '(eclim-executable "/a/opt/eclipse/eclim"))
1994
1995 (setq help-at-pt-display-when-idle t)
1996 (setq help-at-pt-timer-delay 0.1)
1997 (help-at-pt-set-timer)
1998
1999 ;; dunno if this line is needed
2000 (require 'eclimd)
2001 (setq eclimd-default-workspace "/a/bin/eclipse-workspace")
2002
2003 ;;add the emacs-eclim source
2004 (require 'ac-emacs-eclim-source)
2005 (add-hook 'java-mode-hook 'ac-emacs-eclim-java-setup)
2006
2007 #+end_src
2008
2009 #+RESULTS:
2010 | ac-emacs-eclim-java-setup |
2011
2012 * mediawiki
2013 #+begin_src emacs-lisp
2014
2015 (add-to-list 'load-path "~/.emacs.d/src/mediawiki-el")
2016 (eval-after-load "mediawiki"
2017 '(progn
2018 (remove-hook 'outline-minor-mode-hook 'mediawiki-outline-magic-keys)
2019 (add-hook 'mediawiki-mode-hook
2020 (lambda () (define-key mediawiki-mode-map (kbd "C-(") 'mediawiki-save-reload)))
2021
2022 ;; mediawiki mode has a bug that it will claim an edit conflict unless you reload after saving.
2023 ;; I also like to save with no edit summary for previewing on my local mw instance
2024 (defun mediawiki-save-reload ()
2025 (interactive)
2026 (and (mediawiki-save "") (mediawiki-reload)))))
2027 #+end_src
2028 * modes with little configuration needed
2029 #+begin_src emacs-lisp
2030
2031 ;;(require 'dtrt-indent)
2032 ;;(setq dtrt-indent-mode t)
2033
2034 (setq css-indent-offset 2)
2035
2036 (load-file "/a/h/iank-mod.el")
2037
2038 (add-to-list 'load-path "/a/opt/ws-butler")
2039
2040 (require 'ws-butler)
2041 (ws-butler-global-mode)
2042
2043
2044
2045 (require 'nginx-mode)
2046 ;;The mode should automatically activate for files called nginx.conf and files under /etc/nginx - if not, you can add something like this to your init file:
2047 ;;(add-to-list 'auto-mode-alist '("/etc/nginx/sites-available/.*" . nginx-mode))
2048
2049 ;; todo, put this on a hook with prog mode
2050 ;;(highlight-indentation-mode 1)
2051
2052 (add-hook 'auto-revert-tail-mode-hook
2053 (lambda ()
2054 (when (string=
2055 buffer-file-name
2056 "/var/log/cloudman/development/cm-service.log")
2057 (setq-local prev-auto-revert-max 0)
2058 ;; set buffer-local hook
2059 (add-hook 'after-revert-hook 'tail-colorize nil t))))
2060 (defun tail-colorize ()
2061 (ansi-color-apply-on-region prev-auto-revert-max (point-max))
2062 (setq-local prev-auto-revert-max (point-max)))
2063
2064
2065 ;; gnu global
2066 (require 'ggtags)
2067 (add-hook 'c-mode-common-hook
2068 (lambda () (ggtags-mode 1)
2069 (setq c-label-minimum-indentation 0)))
2070
2071 ;; specific to my unusual keybind setup, you may want to
2072 ;; pick different keys
2073 (define-key ggtags-mode-map (kbd "C-M-o") 'ggtags-find-tag-dwim)
2074 (define-key ggtags-mode-map (kbd "C-M-m") 'ggtags-grep)
2075
2076 (defun gtags-update-single(filename)
2077 "Update Gtags database for changes in a single file"
2078 (interactive)
2079 (start-process "update-gtags" "update-gtags" "bash" "-c" (concat "cd " ggtags-project-root " ; gtags --single-update " filename )))
2080
2081 (defun gtags-update-current-file()
2082 (interactive)
2083 (let ((rel-filename (replace-regexp-in-string
2084 ggtags-project-root "."
2085 (buffer-file-name (current-buffer)))))
2086 (gtags-update-single rel-filename)))
2087
2088 (defun gtags-update-hook()
2089 "Update GTAGS file incrementally upon saving a file"
2090 (when (and ggtags-mode ggtags-project-root)
2091 (gtags-update-current-file)))
2092
2093 (add-hook 'after-save-hook 'gtags-update-hook)
2094
2095 ;; i'd like to make some elisp which modifies a keymap to remove
2096 ;; all binds which don't match a predicate.
2097 ;; I tried setting a keymap to a new keymap,
2098 ;; but that didn't register as functional.
2099 ;; so I'd need to modify the list in place.
2100
2101 (require 'magit)
2102
2103
2104 ;; colorize hex colors: use rainbow mode
2105
2106
2107 ;; message mode prompted me on first message.
2108 ;; a function which describes options then sets this
2109 ;; the other options were to use smtp directly or pass to another mail client
2110 ;; here we use the standard sendmail interface, which I use postfix for
2111 (setq send-mail-function (quote sendmail-send-it))
2112
2113 (add-to-list 'load-path "~/.emacs.d/src/spray")
2114 (require 'spray)
2115 (global-set-key (kbd "C-M-w") 'spray-mode)
2116 ;; remember, h/l = move. f/s = faster/slower, space = pause, all others quit
2117
2118 ;; delete active selection with self-insert commands
2119 (delete-selection-mode t)
2120
2121 ;; Transparently open compressed files
2122 (auto-compression-mode t)
2123
2124 ;; Highlight matching parenthesesq when the pointq is on them.
2125 ;; not needed since smart paren mode?
2126 ;; (show-paren-mode 1)
2127
2128
2129 ;; not documented, but looking at the source, I find this
2130 ;; stops me from being asked what command on every C-c-c
2131 ;; when doing a latex document.
2132 (setq TeX-command-force "LaTeX")
2133
2134 ;; dot mode, repeats last action
2135 (require 'dot-mode)
2136 (add-hook 'find-file-hooks 'dot-mode-on)
2137
2138
2139 ;; clean up obsolete buffers automatically at midnight
2140 (require 'midnight)
2141
2142
2143 ;; disabled because it takes 400ms on startup
2144 ;; ;; emacs regexes are too limited.
2145 ;; (require 'foreign-regexp)
2146 ;; ;; perl is most powerful, but javascript is pretty close and
2147 ;; ;; I'd rather know javascript stuff than perl
2148 ;; (custom-set-variables
2149 ;; '(foreign-regexp/regexp-type 'javascript) ;; Choose by your preference.
2150 ;; '(reb-re-syntax 'foreign-regexp)) ;; Tell re-builder to use foreign regexp.
2151 ;; ;; it would be nice to add documentation to do this for more commands to that package
2152 ;; ;; disabled because it's too slow. but I'd still m-x it for advanced replacements
2153 ;; ;;(define-key global-map [remap isearch-forward-regexp] 'foreign-regexp/isearch-forward)
2154
2155
2156 ;; saner regex syntax
2157 (require 're-builder)
2158 (setq reb-re-syntax 'string)
2159
2160
2161 ;; use shift + arrow keys to switch between visible buffers
2162 ;; todo, set these keys to something else
2163 (require 'windmove)
2164 (windmove-default-keybindings)
2165
2166
2167 ;; show the name of the current function definition in the modeline
2168 (require 'which-func)
2169 (setq which-func-modes t)
2170 (which-function-mode 1)
2171
2172
2173 ;; enable winner-mode to manage window configurations
2174 (winner-mode +1)
2175
2176 ;; meaningful names for buffers with the same name
2177 (require 'uniquify)
2178 (setq uniquify-buffer-name-style 'forward
2179 uniquify-separator "/"
2180 ;; for sdx work. until I figure out a better way.
2181 ;; maybe something like projectile can do it,
2182 ;; or hacking around the status bar
2183 uniquify-min-dir-content 2
2184 uniquify-after-kill-buffer-p t ; rename after killing uniquified
2185 uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
2186
2187
2188 ;; makefiles require tabs
2189 ;; todo: find a makefile indent function that works,
2190 ;; best I could find is this one which means don't indent at all
2191 ;;
2192 (add-hook 'makefile-mode-hook
2193 (lambda ()
2194 (setq indent-tabs-mode t)
2195 (setq indent-line-function (lambda () 'no-indent))))
2196
2197
2198 ;; todo, turn on auto-fill just for txt files
2199 ;;(add-hook 'text-mode-hook 'turn-on-auto-fill)
2200 (add-hook 'text-mode-hook 'turn-on-flyspell)
2201
2202
2203 ;; auto indent shell script comments
2204 (setq sh-indent-comment t)
2205
2206 ;; random extra highlights
2207 (require 'volatile-highlights)
2208 (volatile-highlights-mode t)
2209
2210
2211 ;; make help buffers smaller when it makes sense
2212 (temp-buffer-resize-mode 1)
2213
2214
2215 (require 'info+)
2216 ;; based on suggestions in info+.el, I also installed misc-fns, strings, and thingatpt+
2217 ;; remove some bad keybinds from info+
2218 (define-key Info-mode-map [mouse-4] nil)
2219 (define-key Info-mode-map [mouse-5] nil)
2220
2221
2222 (require 'smooth-scroll)
2223 ;; long gnus summary buffers lags too much with this,
2224 ;; but I like it enough to leave it enabled by default
2225 ;; and crank up the step size to be faster
2226 ;; and it doesn't have a way to enable it only for certain modes etc.
2227 ;; todo sometime, make it work for certain modes only
2228 (smooth-scroll-mode t)
2229 ;; its too slow with the default of 2
2230 (setq smooth-scroll/vscroll-step-size 7)
2231 ;; sublimity doesn't work as good going fast by default
2232 ;; smooth-scrolling.el, does not do smooth scrolling. its about cursor location
2233
2234
2235 (setq sh-here-document-word "'EOF'")
2236
2237 (setq tramp-default-method "ssh")
2238 #+end_src
2239 * misc general settings
2240
2241 #+begin_src emacs-lisp
2242
2243 (setq vc-follow-symlinks t)
2244
2245 ;; give us a shell to start instead of scratch
2246 ;;(setq initial-buffer-choice (lambda () (new-shell)))
2247
2248 ;; disable this nasty function, as I always use a gui
2249 (defun suspend-frame() (interactive))
2250
2251 ;; Seed the random-number generator
2252 (random t)
2253
2254 ;; easier to remember than keybinds
2255 (defalias 'scrypt 'mml-secure-message-encrypt-pgpmime)
2256 (defalias 'sign 'mml-secure-message-sign-pgpmime)
2257 (defun encrypt ()
2258 (interactive)
2259 (mml-secure-message-encrypt-pgpmime 'dontsign))
2260
2261 ;; don't highlight the region.
2262 (set-face-background 'region nil)
2263
2264 ;; this fixes save error for python example code
2265 (define-coding-system-alias 'UTF-8 'utf-8)
2266
2267 ;; i don't use frame titles, but if I ever do
2268 ;; this starter kit setting is probably good
2269 (if window-system (setq frame-title-format '(buffer-file-name "%f" ("%b"))))
2270
2271 (set-terminal-coding-system 'utf-8)
2272 (set-keyboard-coding-system 'utf-8)
2273 (prefer-coding-system 'utf-8)
2274
2275 ;; remove ugly 3d box feature
2276 (set-face-attribute 'mode-line nil :box nil)
2277
2278 (add-to-list 'default-frame-alist
2279 '(font . "DejaVu Sans Mono-11"))
2280 ; the default will jump 2 sizes.
2281 (setq text-scale-mode-step 1.1)
2282 (setq font-lock-maximum-decoration t
2283 inhibit-startup-message t
2284 transient-mark-mode t
2285 delete-by-moving-to-trash t
2286 shift-select-mode nil
2287 truncate-partial-width-windows nil
2288 uniquify-buffer-name-style 'forward
2289 oddmuse-directory "~/.emacs.d/oddmuse"
2290 echo-keystrokes 0.1
2291 mark-ring-max 160
2292 sort-fold-case t ; case insensitive line sorting
2293 global-mark-ring-max 1000
2294 ;; the visible bell seems to lag the ui
2295 ;;visible-bell t
2296 ;; turn off audible bell
2297 ;; https://www.emacswiki.org/emacs/AlarmBell
2298 ring-bell-function 'ignore
2299 case-replace nil
2300 revert-without-query '(".*")
2301 ;; don't pause display code on input.
2302 ;; smoother display performance at slight cost of input performance
2303 redisplay-dont-pause t
2304 font-lock-maximum-decoration t) ; probably default and not necesary
2305
2306
2307 (setq-default indent-tabs-mode nil ;; don't use tabs to indent
2308 cursor-type 'box
2309 fill-column 72
2310
2311 ;; wrap at word boundaries instead of mid-word
2312 word-wrap t
2313 imenu-auto-rescan t
2314 indicate-empty-lines t) ; mark end of buffer
2315
2316
2317 (blink-cursor-mode '(-4))
2318 (menu-bar-mode -1)
2319 (tool-bar-mode -1)
2320
2321
2322 ;; enable various commands
2323 (put 'narrow-to-region 'disabled nil)
2324 (put 'narrow-to-page 'disabled nil)
2325 (put 'narrow-to-defun 'disabled nil)
2326 (put 'upcase-region 'disabled nil)
2327 (put 'downcase-region 'disabled nil)
2328 (put 'scroll-left 'disabled nil)
2329 ;; these from graphene, haven't read about them yet
2330 (put 'ido-complete 'disabled nil)
2331 (put 'ido-exit-minibuffer 'disabled nil)
2332 (put 'dired-find-alternate-file 'disabled nil)
2333 (put 'autopair-newline 'disabled nil)
2334
2335
2336
2337 ;;disable and minimize various prompts/messages
2338 (fset 'yes-or-no-p 'y-or-n-p)
2339 (setq confirm-nonexistent-file-or-buffer nil
2340 inhibit-startup-message t
2341 inhibit-startup-echo-area-message t
2342 inhibit-startup-screen t
2343 compilation-read-command nil ;; just don't compile with unsafe file local vars
2344 kill-buffer-query-functions (remq 'process-kill-buffer-query-function
2345 kill-buffer-query-functions))
2346
2347
2348 ;; exit without bothering me
2349 ;; http://stackoverflow.com/questions/2706527/make-emacs-stop-asking-active-processes-exist-kill-them-and-exit-anyway/2708042#2708042
2350 (add-hook 'comint-exec-hook
2351 (lambda () (set-process-query-on-exit-flag (get-buffer-process (current-buffer)) nil)))
2352 ;; based on save-buffers-kill-emacs help string, don't ask about clients when exiting
2353 ;; apparently this would need to be in some later hook. dunno where is best, but this works
2354 (defadvice save-buffers-kill-emacs (before no-client-prompt-advice activate)
2355 (setq kill-emacs-query-functions (delq 'server-kill-emacs-query-function kill-emacs-query-functions)))
2356
2357
2358
2359 ;; (custom-set-faces
2360 ;; ;; setting header-line-format to " " as a hack for a top margin the oly thning I could find to do a top margin
2361 ;; '(header-line ((t (:background "default" :foreground "default" :overline nil :underline nil))))
2362 ;; ;; don't highlight the region
2363 ;; '(region ((t nil))))
2364 (setq-default header-line-format " ")
2365
2366
2367 (setq initial-scratch-message nil)
2368 #+end_src
2369
2370
2371 vertical margin background.
2372 google turned up: http://lists.gnu.org/archive/html/help-gnu-emacs/2014-03/msg00544.html
2373 the xresource doesn't work for me, probably an xmonad thing.
2374
2375 figured out I needed to customize the header line face. To find the face, M-x list-faces-display or just google / search
2376 info,
2377 then M-x customize-face
2378 header-line
2379 unchecked some stuff so that it inherits from default.
2380
2381 * misc function definitions
2382 #+begin_src emacs-lisp
2383
2384
2385
2386
2387
2388 (defun next-backup-dir ()
2389 "In a directory listing from rsync -n,
2390 Go to the next directory based on where the cursor is."
2391 (interactive)
2392 (let* ((start-col (current-column))
2393 (end-col (progn (skip-chars-forward "^/\n") (current-column)))
2394 (dir (progn
2395 (beginning-of-line 1)
2396 (buffer-substring-no-properties (point) (+ (point) end-col)))))
2397 (message dir)
2398 (forward-line 1)
2399 (while (and (not (eobp))
2400 (string= dir (buffer-substring-no-properties (point) (+ (point) end-col))))
2401 (forward-line 1))
2402 (forward-char-same-line start-col)))
2403 ;; copy paste this for fast keybind
2404 ;;(local-set-key (kbd "<kp-enter>"))
2405
2406
2407 (defun goto-buffer-or-find-file (file-name)
2408 "If buffer is with FILE-NAME exists, go to it, else open the file using full path."
2409 (interactive)
2410 (let ((b (get-buffer (file-name-nondirectory file-name))))
2411 (if b
2412 (switch-to-buffer b)
2413 (find-file file-name))))
2414
2415
2416
2417
2418 ;; todo, i think this is broken. perhaps the last goto-char is not accounting for buffer or something
2419 (defun unpop-global-mark ()
2420 "Unpop off global mark ring. Does nothing if mark ring is empty."
2421 (interactive)
2422 (when global-mark-ring
2423 (setq global-mark-ring (cons (copy-marker (mark-marker)) global-mark-ring))
2424 (let ((lm (car (last global-mark-ring))))
2425 (set-marker (mark-marker) (marker-position lm) (marker-buffer lm)))
2426 (when (null (mark t)) (ding))
2427 (setq global-mark-ring (nbutlast global-mark-ring))
2428 (goto-char (marker-position (mark-marker)))))
2429
2430 (defun indent-buffer ()
2431 "Indents the entire buffer."
2432 (interactive)
2433 (cond ((derived-mode-p 'org-mode)
2434 (org-indent-region (point-min) (point-max)))
2435 ((derived-mode-p 'python-mode)
2436 (py-autopep8))
2437 (t
2438 (indent-region (point-min) (point-max)))))
2439
2440
2441 ;; TODO doesn't work with uniquify
2442 (defun rename-file-and-buffer ()
2443 "Renames current buffer and file it is visiting."
2444 (interactive)
2445 (let ((name (buffer-name))
2446 (filename (buffer-file-name)))
2447 (if (not (and filename (file-exists-p filename)))
2448 (message "Buffer '%s' is not visiting a file!" name)
2449 (let ((new-name (read-file-name "New name: " filename)))
2450 (cond ((get-buffer new-name)
2451 (message "A buffer named '%s' already exists!" new-name))
2452 (t
2453 (rename-file name new-name 1)
2454 (rename-buffer new-name)
2455 (set-visited-file-name new-name)
2456 (set-buffer-modified-p nil)))))))
2457
2458
2459
2460 (defun sudo-edit (&optional arg)
2461 (interactive "P")
2462 (if (or arg (not buffer-file-name))
2463 (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
2464 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
2465
2466
2467
2468 (defun backward-symbol (arg)
2469 (interactive "p")
2470 (forward-symbol (- arg)))
2471
2472 #+end_src
2473
2474 * mode line
2475 #+begin_src emacs-lisp
2476
2477 ; -----------------------------
2478 ; fixing up the mode line
2479 ; modified from mastering emacs blog
2480 ; ----------------------------
2481
2482 (defvar mode-line-cleaner-alist
2483 `((auto-complete-mode . "")
2484 (yas/minor-mode . "")
2485 (paredit-mode . "")
2486 (auto-fill-function . "")
2487 (eldoc-mode . "")
2488 (abbrev-mode . "")
2489 (flyspell-mode . "")
2490 (glasses-mode . "")
2491 (dot-mode . "")
2492 (yas-global-mode . "")
2493 (yas-minor-mode . "")
2494 (undo-tree-mode . "")
2495 (volatile-highlights-mode . "")
2496 (highlight-symbol-mode . "")
2497 ;; Major modes
2498 (lisp-interaction-mode . "λ")
2499 (hi-lock-mode . "")
2500 (python-mode . "Py")
2501 (emacs-lisp-mode . "EL")
2502 (nxhtml-mode . "nx"))
2503 "Alist for `clean-mode-line'.
2504
2505 When you add a new element to the alist, keep in mind that you
2506 must pass the correct minor/major mode symbol and a string you
2507 want to use in the modeline *in lieu of* the original.")
2508
2509
2510 (defun clean-mode-line ()
2511 (interactive)
2512 (loop for cleaner in mode-line-cleaner-alist
2513 do (let* ((mode (car cleaner))
2514 (mode-str (cdr cleaner))
2515 (old-mode-str (cdr (assq mode minor-mode-alist))))
2516 (when old-mode-str
2517 (setcar old-mode-str mode-str))
2518 ;; major mode
2519 (when (eq mode major-mode)
2520 (setq mode-name mode-str)))))
2521
2522 ; disabled
2523 ; (add-hook 'after-change-major-mode-hook 'clean-mode-line)
2524
2525
2526 ;;; alias the new `flymake-report-status-slim' to
2527 ;;; `flymake-report-status'
2528 (defalias 'flymake-report-status 'flymake-report-status-slim)
2529 (defun flymake-report-status-slim (e-w &optional status)
2530 "Show \"slim\" flymake status in mode line."
2531 (when e-w
2532 (setq flymake-mode-line-e-w e-w))
2533 (when status
2534 (setq flymake-mode-line-status status))
2535 (let* ((mode-line " Φ"))
2536 (when (> (length flymake-mode-line-e-w) 0)
2537 (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
2538 (setq mode-line (concat mode-line flymake-mode-line-status))
2539 (setq flymake-mode-line mode-line)
2540 (force-mode-line-update)))
2541
2542
2543 (add-hook 'after-change-major-mode-hook (lambda ()
2544
2545 (setq mode-line-mule-info nil
2546 mode-line-position nil
2547 mode-line-modes nil))) ; todo, make only flymake status show up
2548
2549 #+end_src
2550
2551 * mouse related
2552 ** settings
2553 #+begin_src emacs-lisp
2554 (setq focus-follows-mouse t
2555 mouse-autoselect-window t
2556 xterm-mouse-mode t)
2557 #+end_src
2558 ** move-mouse-to-point
2559 todo, this is buggy with multiple windows open.
2560 #+begin_src emacs-lisp
2561 (defun move-mouse-to-point ()
2562 (interactive)
2563 (let* ((pos (posn-col-row (posn-at-point)))
2564 (x (+ (car pos) 2)) ; no idea why this is off by 1-2
2565 (y (cdr pos)))
2566 (set-mouse-position (selected-frame) x y)))
2567 #+end_src
2568 ** cursor highlight
2569 disabled until fixed
2570 #+begin_src emacs-lisp :tangle no
2571 (defun mouse-follow-cursor ()
2572 ;(if (not (equal this-command last-command)) (print this-command))
2573 ;debug
2574 ; (print this-command)
2575 (when (and this-command (not (string= this-command "show-pointer")))
2576 (let* ((pos (posn-col-row (posn-at-point)))
2577 (x (1+ (car pos))) ; no idea why this is off by 1
2578 (y (cdr pos)))
2579 (setq ignore-mouse-visibility t)
2580 (set-mouse-position (selected-frame) x y))
2581 ;(sleep-for 0 100)
2582 (frame-make-pointer-invisible)))
2583
2584 ; (when this-command
2585 ; (if (string= this-command "show-pointer")
2586 ; (frame-make-pointer-visible)
2587 ;))
2588
2589
2590
2591 (defun show-pointer ()
2592 (interactive)
2593 (if ignore-mouse-visibility
2594 (setq ignore-mouse-visibility nil)
2595 ; (print "visible")
2596 (frame-make-pointer-visible)))
2597
2598 (setq ignore-mouse-visibility t)
2599 ; disabled
2600 ; (global-set-key (kbd "<mouse-movement>") 'show-pointer)
2601
2602 ; (add-hook 'post-command-hook 'mouse-follow-cursor t)
2603
2604
2605 ; status. working, except that all scroll wheel actions send a mouse-movement command before doing their actual command, which makes the pointer flicker.
2606 ; this is just an artifact of xbindkeys. when i do my own mouse chip, it will fix this.
2607
2608 ; we could set track-mouse to nil, then do the command, then set it back. i like that idea a bit better.
2609 ; we could do the same thing in the other case of ignore-mouse-visibility.
2610
2611 ; there are also other issues, it doesn't work with changing buffers on a split screen.
2612 ; i think a good idea along with this would be for the cursor to follow the mouse all the time.
2613 ; i have done code for that in my mouse 1 function,
2614 ; i just need to read it again and try it out.
2615
2616
2617
2618
2619 ; this does not take care of scrolling,
2620 ; a post-command hook function below does,
2621 ; but it breaks when the frame is split.
2622 ; the bug is specifically in mouse-pixel-position
2623 ; todo, fix this eventually
2624 (defun mouse-highlight-event (event)
2625 (interactive "e")
2626 (when (or (not event) (mouse-movement-p event)
2627 (memq (car-safe event) '(switch-frame select-window)))
2628 (let ((pos (posn-point (event-end event))))
2629 (if (eq (overlay-buffer mouse-hi-ov) (current-buffer))
2630 (move-overlay mouse-hi-ov pos (1+ pos))
2631 (delete-overlay mouse-hi-ov)
2632 (setq mouse-hi-ov
2633 (make-overlay pos (1+ pos)))
2634 (overlay-put mouse-hi-ov
2635 'insert-in-front-hooks (list 'mouse-hi-modification))
2636 (overlay-put mouse-hi-ov 'priority 1001))
2637 (cond ((save-excursion (goto-char pos) (eolp))
2638 (overlay-put mouse-hi-ov 'face nil)
2639 (overlay-put mouse-hi-ov 'before-string
2640 (propertize
2641 " "
2642 'cursor t
2643 'face 'mouse-cursor-face)))
2644 (t
2645 (overlay-put mouse-hi-ov 'face 'mouse-cursor-face)
2646 (overlay-put mouse-hi-ov 'before-string nil))))))
2647
2648
2649 ; overlay changed hook function
2650 (defun mouse-hi-modification (ov timing beginning end &optional length)
2651 "Make an overlay of length 1 not expand when text is inserted at the front."
2652 (when timing
2653 (let ((start (overlay-start ov)))
2654 (move-overlay ov start (1+ start)))))
2655
2656
2657
2658
2659 (defun mouse-hi-command-hook ()
2660 ; not sure if I need to deal with case of a nil mouse position in some unforseen situation.
2661 (let ((x-y (cdr (mouse-pixel-position))))
2662 (when (wholenump (car x-y))
2663 (let ((pos (posn-point (posn-at-x-y (car x-y) (cdr x-y) nil t))))
2664 (when pos
2665 (if (eq (overlay-buffer mouse-hi-ov) (current-buffer))
2666 (move-overlay mouse-hi-ov pos (1+ pos))
2667 (delete-overlay mouse-hi-ov)
2668 (setq mouse-hi-ov
2669 (make-overlay pos (1+ pos)))
2670
2671 (overlay-put mouse-hi-ov 'priority 1001))
2672 (cond ((save-excursion (goto-char pos) (eolp))
2673
2674 (overlay-put mouse-hi-ov 'face nil)
2675 (overlay-put mouse-hi-ov 'before-string
2676 (propertize
2677 " "
2678 'cursor t
2679 'face 'mouse-cursor-face)))
2680 (t
2681 (overlay-put mouse-hi-ov 'face 'mouse-cursor-face)
2682 (overlay-put mouse-hi-ov 'before-string nil))))))))
2683 ; (pcase-let ((`(,_ ,x . ,y) (mouse-pixel-position)))
2684 ; (posn-point (posn-at-x-y x y)))))
2685 ; equivalent of above to find pos. todo, learn about the above syntax
2686
2687 (setq mouse-hi-ov (make-overlay 1 1))
2688 (delete-overlay mouse-hi-ov)
2689 ; initialized overlay
2690 ; temporarily set to nil instead of t because it is broken and
2691 ; also has a bug that makes emacs not remember the column when
2692 ; doing up and down movements.
2693 ; it also messes up yas/insert-snippet, dunno why.
2694 ; i should test out whether it is something in the post-command hook
2695 ; (setq track-mouse t)
2696 ;(add-hook 'post-command-hook 'mouse-hi-command-hook)
2697
2698 ;(mouse-hi-command-hook)
2699 ;(setq debug-on-error nil)
2700
2701 #+end_src
2702 ** mouse 1 drag func
2703
2704 disabled as it breaks in newer emacs versions with this error, when
2705 clicking on info links
2706
2707 "and: Symbol's function definition is void: mouse--remap-link-click-p"
2708
2709 #+begin_src emacs-lisp :tangle no
2710
2711 ; Copied from mouse.el and modified.
2712 ; my modifications have comments prefaced by "ian"
2713 (defun mouse-drag-track (start-event &optional
2714 do-mouse-drag-region-post-process)
2715 "Track mouse drags by highlighting area between point and cursor.
2716 The region will be defined with mark and point.
2717 DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
2718 `mouse-drag-region'."
2719 (mouse-minibuffer-check start-event)
2720 (setq mouse-selection-click-count-buffer (current-buffer))
2721 ; ian. removed as unneeded since I don't use TMM
2722 ;(deactivate-mark)
2723 (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
2724 (original-window (selected-window))
2725 ;; We've recorded what we needed from the current buffer and
2726 ;; window, now let's jump to the place of the event, where things
2727 ;; are happening.
2728 (_ (mouse-set-point start-event))
2729 (echo-keystrokes 0)
2730 (start-posn (event-start start-event))
2731 (start-point (posn-point start-posn))
2732 (start-window (posn-window start-posn))
2733 (start-window-start (window-start start-window))
2734 (start-hscroll (window-hscroll start-window))
2735 (bounds (window-edges start-window))
2736 (make-cursor-line-fully-visible nil)
2737 (top (nth 1 bounds))
2738 (bottom (if (window-minibuffer-p start-window)
2739 (nth 3 bounds)
2740 ;; Don't count the mode line.
2741 (1- (nth 3 bounds))))
2742 (on-link (and mouse-1-click-follows-link
2743 ;; Use start-point before the intangibility
2744 ;; treatment, in case we click on a link inside
2745 ;; intangible text.
2746 (mouse-on-link-p start-posn)))
2747 (click-count (1- (event-click-count start-event)))
2748 (remap-double-click (and on-link
2749 (eq mouse-1-click-follows-link 'double)
2750 (= click-count 1)))
2751 ;; Suppress automatic hscrolling, because that is a nuisance
2752 ;; when setting point near the right fringe (but see below).
2753 (auto-hscroll-mode-saved auto-hscroll-mode)
2754 (auto-hscroll-mode nil)
2755 moved-off-start event end end-point)
2756
2757 (setq mouse-selection-click-count click-count)
2758 ;; In case the down click is in the middle of some intangible text,
2759 ;; use the end of that text, and put it in START-POINT.
2760 (if (< (point) start-point)
2761 (goto-char start-point))
2762 (setq start-point (point))
2763 (if remap-double-click
2764 (setq click-count 0))
2765
2766 ;; Activate the region, using `mouse-start-end' to determine where
2767 ;; to put point and mark (e.g., double-click will select a word).
2768 (setq transient-mark-mode
2769 (if (eq transient-mark-mode 'lambda)
2770 '(only)
2771 (cons 'only transient-mark-mode)))
2772 (delete-overlay mouse-hi-ov) ; ian, added this.
2773
2774 (let ((range (mouse-start-end start-point start-point click-count)))
2775 (push-mark (nth 0 range) t t)
2776 (goto-char (nth 1 range)))
2777
2778 ;; Track the mouse until we get a non-movement event.
2779 (track-mouse
2780 (while (progn
2781 (setq event (read-event))
2782 (or (mouse-movement-p event)
2783 (memq (car-safe event) '(switch-frame select-window))))
2784 (unless (memq (car-safe event) '(switch-frame select-window))
2785 ;; Automatic hscrolling did not occur during the call to
2786 ;; `read-event'; but if the user subsequently drags the
2787 ;; mouse, go ahead and hscroll.
2788 (let ((auto-hscroll-mode auto-hscroll-mode-saved))
2789 (redisplay))
2790 (setq end (event-end event)
2791 end-point (posn-point end))
2792 ;; Note whether the mouse has left the starting position.
2793 (unless (eq end-point start-point)
2794 (setq moved-off-start t))
2795 (if (and (eq (posn-window end) start-window)
2796 (integer-or-marker-p end-point))
2797 (mouse--drag-set-mark-and-point start-point
2798 end-point click-count)
2799 (let ((mouse-row (cdr (cdr (mouse-position)))))
2800 (cond
2801 ((null mouse-row))
2802 ((< mouse-row top)
2803 (mouse-scroll-subr start-window (- mouse-row top)
2804 nil start-point))
2805 ((>= mouse-row bottom)
2806 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
2807 nil start-point))))))
2808 (visible-mark-move-overlays))) ; ian, added this
2809
2810
2811 ;; Handle the terminating event if possible.
2812 (when (consp event)
2813 ;; Ensure that point is on the end of the last event.
2814 (when (and (setq end-point (posn-point (event-end event)))
2815 (eq (posn-window end) start-window)
2816 (integer-or-marker-p end-point)
2817 (/= start-point end-point))
2818 (mouse--drag-set-mark-and-point start-point
2819 end-point click-count))
2820
2821 ;; Find its binding.
2822 (let* ((fun (key-binding (vector (car event))))
2823 (do-multi-click (and (> (event-click-count event) 0)
2824 (functionp fun)
2825 (not (memq fun '(mouse-set-point
2826 mouse-set-region))))))
2827 (if (and (/= (mark) (point))
2828 (not do-multi-click))
2829
2830 ;; If point has moved, finish the drag.
2831 (let* (last-command this-command)
2832 (and mouse-drag-copy-region
2833 do-mouse-drag-region-post-process
2834 (let (deactivate-mark)
2835 (copy-region-as-kill (mark) (point)))))
2836
2837 ;; Otherwise, run binding of terminating up-event.
2838 (if do-multi-click
2839 (goto-char start-point)
2840 (deactivate-mark)
2841 (unless moved-off-start
2842 ;; ian: poping the mark is a poor choice of behavior.
2843 ;; we should delete the mark instead.
2844 ;; The first way I found to delete it is to pop it first
2845 (pop-mark)
2846 (setq mark-ring (nbutlast mark-ring))))
2847
2848 (when (and (functionp fun)
2849 (= start-hscroll (window-hscroll start-window))
2850 ;; Don't run the up-event handler if the window
2851 ;; start changed in a redisplay after the
2852 ;; mouse-set-point for the down-mouse event at
2853 ;; the beginning of this function. When the
2854 ;; window start has changed, the up-mouse event
2855 ;; contains a different position due to the new
2856 ;; window contents, and point is set again.
2857 (or end-point
2858 (= (window-start start-window)
2859 start-window-start)))
2860
2861 (when (and on-link
2862 (= start-point (point))
2863 (mouse--remap-link-click-p start-event event))
2864
2865 ;; If we rebind to mouse-2, reselect previous selected
2866 ;; window, so that the mouse-2 event runs in the same
2867 ;; situation as if user had clicked it directly. Fixes
2868 ;; the bug reported by juri@jurta.org on 2005-12-27.
2869 (if (or (vectorp on-link) (stringp on-link))
2870 (setq event (aref on-link 0))
2871 (select-window original-window)
2872 (setcar event 'mouse-2)
2873 ;; If this mouse click has never been done by the
2874 ;; user, it doesn't have the necessary property to be
2875 ;; interpreted correctly.
2876 (put 'mouse-2 'event-kind 'mouse-click)))
2877 (push event unread-command-events)))))))
2878 #+end_src
2879
2880 ** mouse 3
2881 #+begin_src emacs-lisp :tangle no
2882
2883
2884 (defun mouse3-range-mark (start click click-count)
2885 (let* ((range (mouse-start-end start click click-count))
2886 (beg (nth 0 range))
2887 (end (nth 1 range)))
2888 (cond ((<= click start)
2889 (set-mark beg))
2890 (t
2891 (set-mark end))))
2892 (visible-mark-move-overlays))
2893
2894
2895 (defun mouse3-set-mark (event)
2896 "in development"
2897 (interactive "e")
2898 (mouse-minibuffer-check event)
2899 ;; Use event-end in case called from mouse-drag-region.
2900 ;; If EVENT is a click, event-end and event-start give same value.
2901 (set-mark (posn-point (event-end event)))
2902 (visible-mark-move-overlays))
2903
2904
2905 (defun mouse3-func (start-event)
2906 "in development"
2907 (interactive "e")
2908
2909 (run-hooks 'mouse-leave-buffer-hook)
2910
2911 (mouse-minibuffer-check start-event)
2912 (setq mouse-selection-click-count-buffer (current-buffer))
2913 (push-mark (posn-point (event-end start-event)))
2914
2915 (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
2916 (original-window (selected-window))
2917 ;; We've recorded what we needed from the current buffer and
2918 ;; window, now let's jump to the place of the event, where things
2919 ;; are happening.
2920 ;(_ (mouse-set-point start-event)) ; ian: commented, replaced
2921 (echo-keystrokes 0)
2922 (start-posn (event-start start-event))
2923 (start-point (posn-point start-posn))
2924 (start-window (posn-window start-posn))
2925 (start-window-start (window-start start-window))
2926 (start-hscroll (window-hscroll start-window))
2927 (bounds (window-edges start-window))
2928 (make-cursor-line-fully-visible nil)
2929 (top (nth 1 bounds))
2930 (bottom (if (window-minibuffer-p start-window)
2931 (nth 3 bounds)
2932 ;; Don't count the mode line.
2933 (1- (nth 3 bounds))))
2934 (click-count (1- (event-click-count start-event)))
2935 ;; Suppress automatic hscrolling, because that is a nuisance
2936 ;; when setting point near the right fringe (but see below).
2937 (auto-hscroll-mode-saved auto-hscroll-mode)
2938 (auto-hscroll-mode nil)
2939 moved-off-start event end end-point)
2940
2941 (setq mouse-selection-click-count click-count)
2942 ;; In case the down click is in the middle of some intangible text,
2943 ;; use the end of that text, and put it in START-POINT.
2944 (if (< (mark) start-point) ; ian: change point to the mark
2945 (set-mark start-point)
2946 (visible-mark-move-overlays))
2947 (setq start-point (mark))
2948
2949 (delete-overlay mouse-hi-ov) ; ian, added this.
2950
2951 ;; Activate the region, using `mouse-start-end' to determine where
2952 ;; to put point and mark (e.g., double-click will select a word).
2953 (let ((range (mouse-start-end start-point start-point click-count)))
2954 (set-mark (nth 1 range)))
2955 (visible-mark-move-overlays)
2956
2957
2958 ;; Track the mouse until we get a non-movement event.
2959 (track-mouse
2960
2961 (while (progn
2962 (setq event (read-event))
2963 (or (mouse-movement-p event)
2964 (memq (car-safe event) '(switch-frame select-window))))
2965 (unless (memq (car-safe event) '(switch-frame select-window))
2966
2967 ;; Automatic hscrolling did not occur during the call to
2968 ;; `read-event'; but if the user subsequently drags the
2969 ;; mouse, go ahead and hscroll.
2970 (let ((auto-hscroll-mode auto-hscroll-mode-saved))
2971 (redisplay))
2972 (setq end (event-end event)
2973 end-point (posn-point end))
2974 ;; Note whether the mouse has left the starting position.
2975
2976 (unless (eq end-point start-point)
2977 (setq moved-off-start t))
2978 (if (and (eq (posn-window end) start-window)
2979 (integer-or-marker-p end-point))
2980 (mouse3-range-mark start-point end-point click-count); ian, set mark
2981
2982 ; do scrolling if needed
2983 (let ((mouse-row (cdr (cdr (mouse-position)))))
2984 (cond
2985 ((null mouse-row))
2986 ((< mouse-row top)
2987 (mouse-scroll-subr start-window (- mouse-row top)
2988 nil start-point))
2989 ((>= mouse-row bottom)
2990 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
2991 nil start-point))))))))
2992
2993 ;; Handle the terminating event if possible.
2994 (when (consp event)
2995 ;; Ensure that point is on the end of the last event.
2996 (when (and (setq end-point (posn-point (event-end event)))
2997 (eq (posn-window end) start-window)
2998 (integer-or-marker-p end-point)
2999 (/= start-point end-point))
3000 ;(mouse--drag-set-mark-and-point start-point ; ian, set mark
3001 ;end-point click-count))
3002 (mouse3-range-mark start-point end-point click-count)); ian, set mark
3003
3004 ;; Find its binding.
3005 (let* ((fun (key-binding (vector (car event))))
3006 (do-multi-click (and (> (event-click-count event) 0)
3007 (functionp fun)
3008 (not (memq fun '(mouse3-set-mark))))))
3009 (if (and (/= end-point start-point)
3010 (not do-multi-click))
3011
3012 ;; If point has moved, finish the drag.
3013 (let* (last-command this-command)
3014 (and mouse-drag-copy-region
3015 do-mouse-drag-region-post-process
3016 (let (deactivate-mark)
3017 (copy-region-as-kill (mark) (point)))))
3018
3019 ;; Otherwise, run binding of terminating up-event.
3020 (when do-multi-click
3021 (set-mark start-point)) ; ian, change this. why?
3022 (visible-mark-move-overlays)
3023
3024
3025 (when (and (functionp fun)
3026 (= start-hscroll (window-hscroll start-window))
3027 ;; Don't run the up-event handler if the window
3028 ;; start changed in a redisplay after the
3029 ;; mouse-set-point for the down-mouse event at
3030 ;; the beginning of this function. When the
3031 ;; window start has changed, the up-mouse event
3032 ;; contains a different position due to the new
3033 ;; window contents, and point is set again.
3034 (or end-point
3035 (= (window-start start-window)
3036 start-window-start)))
3037
3038 (push event unread-command-events)))))))
3039
3040 #+end_src
3041
3042
3043
3044
3045
3046 * org mode
3047
3048 #+begin_src emacs-lisp
3049
3050 ;; todo work on org-cycle-emulate-tab
3051
3052 ;; todo, this doesn't work for a non-standard keybind
3053 ;;(setq org-special-ctrl-k t)
3054
3055 ;; todo, generally fix org mode keys
3056 ;; todo, org-mark-element, unbdind from M-h, bind to mark defun key
3057
3058 (org-babel-do-load-languages
3059 'org-babel-load-languages
3060 '((emacs-lisp . t)
3061 (sh . t)))
3062
3063 ;; make shell work like interactive bash shell
3064 (setq org-babel-default-header-args:sh
3065 '((:results . "output") (:shebang . "#!/bin/bash -l")))
3066
3067 ;; my patch to output stderr
3068 (setq org-babel-use-error-buffer nil)
3069
3070 ;
3071 ;; org-mode manual suggests these, but I haven't used them.
3072 ;;(global-set-key "\C-cl" 'org-store-link)
3073 ;;(global-set-key "\C-ca" 'org-agenda)
3074 ;; this got in the way of a haskell mode command
3075 ;;(global-set-key "\C-cb" 'org-iswitchb)
3076
3077
3078
3079 ;; org-src-tab-acts-natively t ; broken option. using next instead, todo fix
3080
3081 (setq org-src-fontify-natively t ; make babel blocks nice
3082 org-adapt-indentation nil
3083 org-src-preserve-indentation t
3084 ;; The most basic logging is to keep track of when a TODO item was finished.
3085 org-log-done 'time
3086 ;; use a drawer to keep the logs tidy
3087 org-log-into-drawer t
3088 org-extend-today-until 0
3089 org-startup-truncated nil
3090 org-clock-persist t
3091 org-clock-mode-line-total 'today
3092 ;; global STYLE property values for completion
3093 org-global-properties (quote (("STYLE_ALL" . "habit")))
3094 org-special-ctrl-a/e t ;; home and end work special in headlines
3095 org-completion-use-ido t
3096 org-catch-invisible-edits 'smart)
3097
3098 ;; non universally recommended settings
3099 (setq
3100 org-default-notes-file (concat org-directory "/a/t.org")
3101 org-agenda-files (quote ("/a/t.org"))
3102 org-mobile-directory "/p/org-mobile"
3103 org-mobile-inbox-for-pull "/p/from-mobile.org"
3104 org-directory "/p")
3105
3106 ;; modeilne populated from (org-clock-get-clocked-time)
3107 ;; which is populated from the var org-clock-total-time
3108 ;; which is populated by a function which starts from (org-clock-get-sum-start)
3109 ;;
3110
3111 (org-clock-persistence-insinuate)
3112
3113
3114 (defun time-to-org-day (time)
3115 (round (time-to-number-of-days
3116 (time-subtract time (list 0 (* 3600 org-extend-today-until) 0)))))
3117
3118
3119 (defun my-org-confirm-babel-evaluate (lang body)
3120 (not (or (string= (buffer-file-name) "/a/t.org")
3121 (string= (buffer-file-name) "/home/ian/.emacs.d/my-init.org")
3122 )))
3123 (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
3124
3125
3126 (defun org-time-stamp-with-time (arg)
3127 (interactive "P")
3128 ;; '(4) is the argument passed by universal prefix
3129 (org-time-stamp (if arg arg '(4)) t))
3130
3131 (defun ian-org-work-time ()
3132 (interactive)
3133 (save-excursion
3134 (set-buffer "t.org")
3135 (goto-char (org-find-entry-with-id "ian-identifier-1"))
3136 (org-clock-in)))
3137
3138 (defun ian-org-idle-time ()
3139 (interactive)
3140 (save-excursion
3141 (goto-char (org-find-entry-with-id "ian-identifier-2"))
3142 (set-buffer "t.org")
3143 (org-clock-in)))
3144
3145
3146
3147 ;; based on http://stackoverflow.com/questions/3758139/variable-pitch-for-org-mode-fixed-pitch-for-tables
3148 ;; keywords: proportional font, monospace
3149
3150 (defun variable-pitch-on ()
3151 (variable-pitch-mode 1))
3152 (add-hook 'fundamental-mode-hook 'variable-pitch-on)
3153 (add-hook 'org-mode-hook 'variable-pitch-on)
3154 (add-hook 'text-mode-hook 'variable-pitch-on)
3155
3156 (set-face-attribute 'org-table nil :family (face-attribute 'fixed-pitch :family))
3157 (set-face-attribute 'org-code nil :family (face-attribute 'fixed-pitch :family))
3158 (set-face-attribute 'org-formula nil :family (face-attribute 'fixed-pitch :family))
3159 (set-face-attribute 'org-link nil :family (face-attribute 'fixed-pitch :family))
3160 (set-face-attribute 'org-block nil :family (face-attribute 'fixed-pitch :family))
3161 (set-face-attribute 'org-date nil :family (face-attribute 'fixed-pitch :family))
3162
3163
3164 (defun remove-org-binds ()
3165 (define-key org-mode-map (kbd "<M-return>") nil)
3166 (define-key org-mode-map (kbd "C-'") nil)
3167 (define-key org-mode-map (kbd "C-y") nil)
3168 (define-key org-mode-map (kbd "<C-return>") nil)
3169 (define-key org-mode-map (kbd "<C-M-kp-enter>") nil)
3170 (define-key org-mode-map (kbd "C-,") nil)
3171 (define-key org-mode-map (kbd "C-M-m") nil)
3172 (define-key org-mode-map (kbd "C-k") nil)
3173 (define-key org-mode-map (kbd "C-j") nil)
3174 (define-key org-mode-map (kbd "C-M-i") nil)
3175 (define-key org-mode-map (kbd "C-M-t") nil)
3176 (define-key org-mode-map (kbd "M-a") 'nil)
3177 (define-key org-mode-map (kbd "C-a") nil)
3178 (define-key org-mode-map (kbd "M-e") nil)
3179 (define-key org-mode-map (kbd "C-e") nil)
3180 (define-key org-mode-map (kbd "C-3") nil)
3181 (define-key org-mode-map (kbd "<M-left>") nil)
3182 (define-key org-mode-map (kbd "<M-right>") nil)
3183 (define-key org-mode-map (kbd "<S-return>") nil)
3184 (define-key org-mode-map (kbd "<tab>") nil)
3185 (define-key org-mode-map (kbd "<C-S-down>") nil)
3186 (define-key org-mode-map (kbd "<C-S-up>") nil)
3187 (define-key org-mode-map (kbd "<S-down>") nil)
3188 (define-key org-mode-map (kbd "<S-up>") nil)
3189 (define-key org-mode-map "\t" nil))
3190 (add-hook 'org-mode-hook 'remove-org-binds)
3191
3192 #+end_src
3193
3194
3195 * org drill
3196
3197
3198 #+begin_src emacs-lisp :tangle no
3199
3200 (setq
3201 ;; account actual time, not just scheduled time
3202 org-drill-adjust-intervals-for-early-and-late-repetitions-p t
3203
3204 ;; still show leeches, but warn
3205 org-drill-leech-method (quote warn)
3206 ;; increased from default 20
3207 org-drill-maximum-duration 60
3208 ;; especially when starting, I want to drill hard
3209 org-drill-maximum-items-per-session nil
3210 ;; don't prompt to save buffer, auto-save will do that
3211 org-drill-save-buffers-after-drill-sessions-p nil
3212 ;; this one deals with varying difficulty items better
3213 ;; sm2 is similar, but more simplistic
3214 org-drill-spaced-repetition-algorithm (quote simple8)
3215 )
3216 #+end_src
3217 ;; todo, make the prompting text reflect this number.
3218 ;; org-drill-failure-quality
3219
3220 * os specific settings
3221
3222 disabled cuz I have none yet
3223 #+begin_src emacs-lisp :tangle no
3224 (cond ((eq system-type 'darwin))
3225 ((eq system-type 'gnu/linux))
3226 ((eq system-type 'windows-nt))
3227 (t ))
3228 #+end_src
3229
3230
3231 * prog-mode-defaults
3232
3233 #+begin_src emacs-lisp
3234
3235
3236 (defun prog-mode-defaults ()
3237 "Default coding hook, useful with any programming language."
3238 ;; so that I can do completion before the dialog pops up
3239 (local-set-key (kbd "<tab>") 'auto-complete)
3240 ;; todo, this is causing error message on loading file, prolly not working
3241 ;;(flycheck-mode +1)
3242 (setq ac-sources (delq 'ac-source-dictionary ac-sources))
3243 (highlight-symbol-mode)
3244 (make-local-variable 'column-number-mode)
3245 ;; this says do autofilling using newcomment.el. The "only" is a misnomer.
3246 (set (make-local-variable 'comment-auto-fill-only-comments) t)
3247 (column-number-mode t)
3248 (turn-on-smartparens-mode)
3249
3250 ;; prettify lambdas
3251 (font-lock-add-keywords
3252 nil `(("(\\(lambda\\>\\)"
3253 (0 (progn (compose-region (match-beginning 1) (match-end 1)
3254 ,(make-char 'greek-iso8859-7 107))
3255 nil))))))
3256 (add-hook 'prog-mode-hook 'prog-mode-defaults)
3257
3258 ;; enable flyspell in prog mode. text mode is handled
3259 (add-hook 'prog-mode-hook 'flyspell-prog-mode)
3260
3261
3262
3263 #+end_src
3264
3265 ** yank auto-indent
3266 #+begin_src emacs-lisp
3267 ;; automatically indenting yanked text if in programming-modes
3268 (defvar yank-indent-modes
3269 '(LaTeX-mode TeX-mode)
3270 "Modes in which to indent regions that are yanked (or yank-popped).
3271 Only modes that don't derive from `prog-mode' should be listed here.")
3272
3273 (defvar yank-indent-blacklisted-modes
3274 '(python-mode slim-mode haml-mode)
3275 "Modes for which auto-indenting is suppressed.")
3276
3277 (defvar yank-advised-indent-threshold 2000
3278 "Threshold (# chars) over which indentation does not automatically occur.")
3279
3280 (defun yank-advised-indent-function (beg end)
3281 "Do indentation, as long as the region isn't too large."
3282 (if (<= (- end beg) yank-advised-indent-threshold)
3283 (indent-region beg end nil)))
3284
3285 (defadvice yank (after yank-indent activate)
3286 "If current mode is one of 'yank-indent-modes,
3287 indent yanked text (with prefix arg don't indent)."
3288 (if (and (not (ad-get-arg 0))
3289 (not (member major-mode yank-indent-blacklisted-modes))
3290 (or (derived-mode-p 'prog-mode)
3291 (member major-mode yank-indent-modes)))
3292 (let ((transient-mark-mode nil))
3293 (yank-advised-indent-function (region-beginning) (region-end)))))
3294
3295 (defadvice yank-pop (after yank-pop-indent activate)
3296 "If current mode is one of 'yank-indent-modes,
3297 indent yanked text (with prefix arg don't indent)."
3298 (if (and (not (ad-get-arg 0))
3299 (not (member major-mode yank-indent-blacklisted-modes))
3300 (or (derived-mode-p 'prog-mode)
3301 (member major-mode yank-indent-modes)))
3302 (let ((transient-mark-mode nil))
3303 (yank-advised-indent-function (region-beginning) (region-end)))))
3304
3305 #+end_src
3306
3307
3308 * shell mode
3309 #+begin_src emacs-lisp
3310 ;; avoid stupid git crap like "warning, terminal not fully functional"
3311 (setenv "PAGER" "cat")
3312 ;; don't store successive duplicates in comint command history
3313 (setq comint-input-ignoredups t)
3314
3315 (defun add-mode-line-dirtrack ()
3316 (add-to-list 'mode-line-buffer-identification
3317 '(:propertize (" " default-directory " ") face dired-directory)))
3318 (add-hook 'shell-mode-hook 'add-mode-line-dirtrack)
3319
3320
3321 ;; don't fully understand it, but it works.
3322 ;; http://www.emacswiki.org/emacs/ShellDirtrackByProcfs
3323 (defun track-shell-directory/procfs ()
3324 (shell-dirtrack-mode 0)
3325 (add-hook 'comint-preoutput-filter-functions
3326 (lambda (str)
3327 (prog1 str
3328 (when (string-match comint-prompt-regexp str)
3329 (cd (file-symlink-p
3330 (format "/proc/%s/cwd" (process-id
3331 (get-buffer-process
3332 (current-buffer)))))))))
3333 nil t))
3334 (setq comint-buffer-maximum-size 100000)
3335 (add-to-list 'comint-output-filter-functions 'comint-truncate-buffer)
3336 (defun new-shell ()
3337 (interactive)
3338 (shell (generate-new-buffer-name "*shell*")))
3339 ;;
3340 (defun shell-wrap (prefix)
3341 "wrap the shell function, automatically generate a new name for a prefix arg"
3342 (interactive "P")
3343 (if prefix
3344 (new-shell)
3345 (shell)))
3346
3347 (add-hook 'shell-mode-hook 'track-shell-directory/procfs)
3348 #+end_src
3349 * smartparens
3350 the melpa git version had a catastrophic bug I reported.
3351 downgraded to marmalade version and everything is working fine.
3352 #+begin_src emacs-lisp
3353 (require 'smartparens-config)
3354 (show-smartparens-global-mode t)
3355
3356
3357 (defun gp/sp/pair-on-newline-and-indent (id action context)
3358 "Open a new brace or bracket expression, with relevant newlines and indent. "
3359 (save-excursion
3360 (newline)
3361 (indent-according-to-mode))
3362 (indent-according-to-mode))
3363
3364 ;; when opening a pair, and then inserting a newline, push the closing pair to another newline
3365 (sp-pair "{" nil :post-handlers
3366 '(:add ((lambda (id action context)
3367 (gp/sp/pair-on-newline-and-indent id action context)) (kbd "<return>"))))
3368 (sp-pair "[" nil :post-handlers
3369 '(:add ((lambda (id action context)
3370 (gp/sp/pair-on-newline-and-indent id action context)) (kbd "<return>"))))
3371
3372
3373 ;; in my version, this is not a pairing.
3374 ;; not sure if it is in a future version since I reverted to marmalade
3375 ;; Don't need c-comments in strings -- they frustrate filename globs
3376 ;; (sp-pair "/*" nil :unless '(sp-in-string-p))
3377
3378 ;; Don't need quotes to pair next to words
3379 (sp-pair "\"" nil :unless '(sp-point-before-word-p sp-point-after-word-p))
3380 (sp-pair "'" nil :unless '(sp-point-before-word-p sp-point-after-word-p))
3381
3382
3383 ;; todo, testout these mode specific settings from graphene.
3384 ;; Ruby-specific pairs and handlers
3385 (require 'smartparens-ruby)
3386
3387 ;; Markdown
3388 (sp-local-pair '(markdown-mode gfm-mode) "*" "*"
3389 :unless '(sp-in-string-p)
3390 :actions '(insert wrap))
3391
3392 ;; Except in HTML
3393 (sp-local-pair 'html-mode "\"" nil :unless '(:rem sp-point-after-word-p))
3394
3395
3396 #+end_src
3397 * smex
3398 todo; check out smex-show-unbound-commands shows frequently used commands that have no key bindings.
3399 #+begin_src emacs-lisp
3400 ; these must be before smex-initialize
3401 (setq
3402 smex-save-file "~/.emacs.d/.smex-items")
3403
3404 (smex-initialize)
3405 #+end_src
3406 * speedbar
3407 (sr-speedbar-close)
3408 (sr-speedbar-open)
3409
3410 ** todo, disabled cuz of broken package
3411 #+begin_src emacs-lisp :tangle no
3412 (require 'sr-speedbar)
3413 (setq speedbar-hide-button-brackets-flag t ;; didn't notice a diff
3414 speedbar-file-unshown-regexp "flycheck-.*"
3415 sr-speedbar-width 40
3416 sr-speedbar-width-x 40
3417 sr-speedbar-auto-refresh nil
3418 sr-speedbar-skip-other-window-p t
3419 sr-speedbar-right-side nil
3420 speedbar-hide-button-brackets-flag nil)
3421 #+end_src
3422 * spell correction
3423 #+begin_src emacs-lisp
3424 (setq
3425 ispell-program-name "hunspell"
3426 ispell-silently-savep t) ; don't prompt to save personal dictionary
3427
3428 (require 'rw-hunspell)
3429 #+end_src
3430 rw-hunspell sets up hunspell dictionary automagically.
3431
3432
3433 Rant: Hunspell SHOULD be standard. its used by firefox and openoffice and
3434 osx. In contrast, the first few words I added to aspell dictionary were
3435 "emacs" "customizable" and "timestamp". Hunspell already has those,
3436 thank god.
3437
3438 ispell-personal-dictionary does not document where the hunspell
3439 dictionary goes by default, but it is ~/.hunspell_en_US for me
3440
3441
3442 * tex
3443 #+begin_src emacs-lisp
3444 (setq-default TeX-PDF-mode t) ; use pdf
3445
3446 ; more sensible defaults based on info manual quickstart
3447 (setq TeX-auto-save t)
3448 (setq TeX-parse-self t)
3449
3450
3451 #+end_src
3452 * undo tree
3453 #+begin_src emacs-lisp
3454
3455 ;; undo-tree checks for minor modes which override
3456 ;; its minor mode keymap, and sets global keybinds if
3457 ;; that happens. this will prevent that, but I have no
3458 ;; reason to do that, so it is commented.
3459 ;; (defun undo-tree-overridden-undo-bindings-p () nil)
3460
3461 ;; todo, send patch undo-tree-visualize should scroll with the scroll key, instead of just pgup pgdn (aka next/prior)
3462 (global-undo-tree-mode)
3463 ;; disabled due to bug, something like unknown entry in undo tree canary
3464 ;; (setq undo-tree-auto-save-history t)
3465 (setq undo-outer-limit 100000000 ; per undo command
3466 undo-limit 500000000 ; undo history limit
3467 undo-strong-limit 600000000) ; undo history limit plus some extra
3468
3469
3470 #+end_src
3471
3472 * visible mark mode
3473
3474 these colors were better for dark theme
3475 #+begin_src emacs-lisp :tangle no
3476
3477
3478
3479 (defface visible-mark-face1
3480 '((((type tty) (class mono)))
3481 (t (:background "LimeGreen"))) "")
3482 (defface visible-mark-face2
3483 '((((type tty) (class mono)))
3484 (t (:background "red4"))) "")
3485 (defface visible-mark-forward-face1
3486 '((((type tty) (class mono)))
3487 (t (:background "dark magenta"))) "")
3488 (defface visible-mark-active
3489 '((((type tty) (class mono)))
3490 (t (:background "gold"))) "")
3491 (defface mouse-cursor-face
3492 '((((type tty) (class mono)))
3493 (t (:background "DeepPink1"))) "")
3494
3495 #+end_src
3496
3497
3498 #+begin_src emacs-lisp
3499
3500 (add-to-list 'load-path "~/.emacs.d/src/visible-mark")
3501
3502 ;; since it is not easy to change the mark overlay priority, I change this one.
3503 (setq show-paren-priority 999)
3504
3505
3506 (defface visible-mark-active
3507 '((((type tty) (class mono)))
3508 (t (:background "magenta"))) "")
3509
3510
3511
3512 (defface mouse-cursor-face
3513 '((((type tty) (class mono)))
3514 (t (:background "DeepPink1"))) "")
3515
3516
3517 (require 'visible-mark)
3518
3519 (setq visible-mark-faces '(visible-mark-face1 visible-mark-face2))
3520 (setq visible-mark-forward-faces '(visible-mark-forward-face1))
3521
3522
3523 ; highlight the last 2 marks
3524 (setq visible-mark-max 2)
3525 ; highlight 1 forward mark
3526 (setq visible-mark-forward-max 1)
3527 ; globally activate visible-mark-mode
3528 (global-visible-mark-mode +1)
3529
3530
3531 ;; todo, it doesn't seem to be exposed in elisp, but it would be nice
3532 ;; if I could define overlay faces to use inverse foreground color
3533
3534
3535 #+end_src
3536
3537 #+RESULTS:
3538 : t
3539
3540
3541 * key binds. keep at end of file
3542 this should come at the end because it depends on key maps being
3543 created in earlier sections.
3544
3545 ** emacs keys notes
3546 commands not needed in ido mode and their replacement in ido mode
3547 spell check fix -> use current pattern and start new one
3548 narrow -> create subdirectory
3549 org-cycle -> M-s search recently used directory
3550 vert split Window -> create file instead of select match
3551 delete-other-windows -> open dired buffer
3552 delete current window -> delete buffer/file
3553 find file -> search within all subdirectories
3554
3555 forward/back error
3556
3557 buffer select -> toggle find file / buffer
3558 up/down -> next/previous history
3559 forward/back -> ido-forward/back
3560
3561
3562 right keyboard attributes: movement, involve typing words
3563 left keyboard attributes: non-typing universal non-movement
3564
3565
3566
3567
3568 todo
3569 fix global unpop mark ring
3570 setup helm
3571 learn cedet and projectile and helm
3572 setup key for pop-global-mark
3573 try out C-M-\ indent region
3574 set quoted insert to some obscure keybind
3575 make currently overrided M-u uppercase word into something obscure
3576 remember mode
3577 bind shell-command to something better
3578 investigate tags
3579 investigate keys in isearch mode and find file mode
3580 try out occur. M-s o
3581 investigate programming modes. M-g n/b next/previous error. gdb?
3582 investigate org mode keys
3583 learn version control
3584 learn mail
3585 check out imenu
3586 bind capitalize-word to something obscure
3587 sentance/paragraph movement/marking should be swapped with sexp/paren movement based on mode
3588 bind fill-paragraph to something obscure
3589 setup linewise paste
3590 install magit (git control)
3591 magpie expansion provides a completion key for acronym expansion based on buffer text
3592 learn ediff
3593 universal google
3594 figure out auto-indent
3595 learn eshell and prelude settings for it
3596 combine register prefix and c-x prefix
3597 note: remember to think of mouse & foot pedals
3598 commands to change: select other window: C-x o.
3599 ** prefix keybind changes
3600 #+begin_src emacs-lisp
3601
3602
3603 ; prefix key binds.
3604 ; good info http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/
3605 ; rebinding the prefix keys are tricky. apparently, some modes ignore any redefinition of a prefix key and use it explicitly,
3606 ; so you have to dig into their key maps and redo things.
3607 ; There are 2 simpler alternatives which have their own downsides.
3608 ; One is cua mode, which I do not like because it smashes 2 keybinds onto 1 and limits what you can do.
3609 ; The other is keyboard-translate, which translates the key presses before anything else.
3610 ; The downside is that it translates them when you aren't using them as a prefix.
3611 ; Since the swaps I'm using are all very accessible, the only downside is some mental jugling when reading docs etc about these keybinds.
3612
3613 ; I've seen this as an another suggestion, it was a total fail. The prefix command took over both keys.
3614 ; (define-key key-translation-map [f12] "\C-c")
3615 ; (define-key key-translation-map "\C-c" [left])
3616
3617
3618 ;idea to remove the hook later since it is only needed at startup.
3619 ; did not work however, and there is not a real need to fix it, so I did not investigate
3620 ;(defun removeSwapHook ()
3621 ; (remove-hook 'buffer-list-update-hook 'myKeySwap)
3622 ; (remove-hook 'change-major-mode-hook 'removeSwapHook))
3623 ;(add-hook 'change-major-mode-hook 'removeSwapHook)
3624
3625
3626 ; went through almost all the relevant standard hooks,
3627 ; this overcomes a known bug that (keyboard-translate) does not get applied when running emacs daemon
3628 (add-hook 'buffer-list-update-hook (lambda () (interactive)
3629 (keyboard-translate ?\C-x ?\C-s)
3630 (keyboard-translate ?\C-s ?\C-x)
3631 (keyboard-translate ?\C-c ?\C-d)
3632 (keyboard-translate ?\C-d ?\C-c)))
3633
3634
3635
3636 ; these all don't work
3637 ; don't know why this doesn't error but reversing the keys does
3638 ;(keyboard-translate ?\t ?\M-\t)
3639 ;(keyboard-translate [M-tab] [tab])
3640 ; from what i can tell, it wants to use a keyboard-translate-table,
3641 ; which is a char table, which is a vector indexed by chars,
3642 ; and mod+tab is not a char (it has too many bits), it is an integer
3643 ; it actually says it can hold vectors or strings, but that it is obsolete to do so
3644 ;(characterp ?\M-a)
3645 ;(characterp ?\C-a)
3646
3647
3648
3649 #+end_src
3650
3651 ** named commands
3652 *** tramp sudo
3653 /ssh:host|sudo:host:
3654 when in the same session, you can then do:
3655 /sudo:root@host:
3656
3657 *** org insert table row
3658 [org-shiftmetadown/up]
3659 *** toggle line continuation / truncation / wrap
3660 toggle-truncate-lines
3661 *** auto-save on/off
3662 my-as-on/my-as-off
3663 *** toggle menu bar
3664 menu-bar-mode
3665 *** show abbreviations
3666 list-abbrevs
3667
3668 *** rename-file-and-buffer
3669 *** ediff-buffers
3670 *** refill-mode
3671 automatically balance a paragraph with newlines
3672 *** executable-make-buffer-file-executable-if-script-p
3673 make a script executable
3674 *** (setq lazy-highlight-cleanup nil)
3675 keep search highlight on after search is done
3676 *** auto-revert-tail-mode
3677 tail a file
3678 *** trash-file-and-buffer
3679 #+begin_src emacs-lisp
3680 (defun trash-file-and-buffer ()
3681 "Removes file connected to current buffer and kills buffer."
3682 (interactive)
3683 (let ((filename (buffer-file-name))
3684 (buffer (current-buffer))
3685 (name (buffer-name)))
3686 (if (not (and filename (file-exists-p filename)))
3687 (error "Buffer '%s' is not visiting a file!" name)
3688 (delete-file filename)
3689 (kill-buffer buffer)
3690 (message "File '%s' successfully removed" filename))))
3691
3692 #+end_src
3693 *** what-line
3694 *** linum-mode
3695 line numbers
3696
3697 *** sgml-pretty-print
3698 format xml in nxml-mode
3699 *** visual-line-mode
3700 toggle word wrap.
3701 ** compound commands
3702 *** C-xc
3703 exit0
3704 *** C-x s
3705 save file
3706 *** C-x e
3707 eval last sexp
3708 *** C-x u
3709 [undo-tree-visualize]
3710 *** C-j u/U
3711 [undo-tree save/restore state via register]
3712 *** C-c -
3713 [org insert table horizontal line or create list]
3714 *** C-x tab
3715 indent/dedent region
3716
3717 [shift-left and shift-right are default for indenting by tab stop,
3718 and they are only defined as lambdas so I copy them here
3719 to use with up and down.
3720 #+begin_src emacs-lisp
3721 ;; condition cuz emacs24 release doesn't have this yet
3722 (when (boundp 'indent-rigidly-map)
3723 (define-key indent-rigidly-map (kbd "<C-left>")
3724 (lambda (beg end) (interactive "r")
3725 (let* ((current (indent-rigidly--current-indentation beg end))
3726 (next (indent--next-tab-stop current)))
3727 (indent-rigidly beg end (- next current)))))
3728
3729 (define-key indent-rigidly-map (kbd "<C-right>")
3730 (lambda (beg end) (interactive "r")
3731 (let* ((current (indent-rigidly--current-indentation beg end))
3732 (next (indent--next-tab-stop current 'prev)))
3733 (indent-rigidly beg end (- next current))))))
3734 #+end_src
3735 *** C-x *
3736 [calc-dispatch]
3737 *** C-x =
3738 [point information]
3739 *** C-x d
3740 [dired]
3741 *** C-xb
3742 [ibuffer]
3743 #+begin_src emacs-lisp
3744 (global-set-key (kbd "C-x C-b") 'ibuffer)
3745 #+end_src
3746
3747 *** C-x r c
3748 rectangular clear, replace area with whitespace
3749 ** gnus
3750 searching overview.
3751 3 types:
3752 ingroup searching
3753 nnir searching with notmuch, specific group (not sure if it can do multiple)
3754 search all groups with mairix
3755 *** a]
3756 compose new message
3757 *** C-c C-c]
3758 send message
3759 *** s]
3760 save newsrc file, alterations to groups.
3761 *** g]
3762 gnus refresh / get new
3763 *** m]
3764 gnus new message
3765 *** F]
3766 gnus quoted reply all
3767 *** e]
3768 gnus draft edit message
3769 *** delete]
3770 gnus delete draft
3771 #+begin_src emacs-lisp
3772 (add-hook 'gnus-startup-hook
3773 (lambda ()
3774 (define-key gnus-summary-mode-map (kbd "<delete>") 'gnus-summary-delete-article)))
3775 #+end_src
3776
3777 *** b]
3778 mairix search
3779 #+begin_src emacs-lisp
3780 (add-hook 'gnus-startup-hook
3781 (lambda ()
3782 (define-key gnus-group-mode-map "b" 'nnmairix-search)
3783 (define-key gnus-summary-mode-map "b" 'nnmairix-search)))
3784 #+end_src
3785 *** B m]
3786 move message, or messages in region
3787 *** #]
3788 mark article, move with B m
3789 *** B delete]
3790 gnus delete draft
3791 *** / plus x a / b]
3792 search current group (or see info manual for more groups),
3793 using the gnus native search (its slow, do a notmuch or mairix search instead)
3794 x= extra (ie. to)
3795 todo; send in patch to make author search to in sent folder
3796 a = author
3797 / = subject
3798 b = body
3799 see C-h m for a full list
3800 *** G G ]
3801 do a nnir notmuch search, for the group on the current line
3802 *** A T ]
3803 jump to thread from nnir group
3804
3805 *** marks]
3806 ! = saved for later
3807 E = expired
3808 M-& apply process mark to a non-process mark command
3809 *** S D e]
3810 edit as new
3811 *** T k / C-M-k
3812 maybe rebind this to a shorter keybind, like del
3813 gnus-summary-kill-thread
3814 ** message mode
3815 *** C-ck]
3816 discard message
3817 ** notmuch
3818 *** space]
3819 notmuch advance to next message/thread
3820
3821 ** readline / bash / .inputrc
3822 *** M-0-9]
3823 bash digit-argument
3824
3825 removed drill from all these because I'm using emacs for shell now
3826 *** C-2]
3827 terminal X paste
3828 *** C-3]
3829 terminal open file manager
3830 *** C-q]
3831 bash exchange-point-and-mark
3832
3833 *** C-M-q]
3834 quoted insert
3835 *** C-w]
3836 bash kill-region
3837 *** C-e]
3838 bash yank-last-arg
3839 *** C-r
3840 bash history-search-backward
3841 *** C-t]
3842 shell-expand-line, expand like bash does u hit enter
3843 *** C-a]
3844 bash comment-line
3845 *** C-s]
3846 bash yank-nth-arg
3847 yank $1 of last argument, or nth if prefixed with a digit argument
3848 *** C-d]
3849 bash undo
3850 *** C-f]
3851 bash menu-complete
3852 *** C-g]
3853 bash edit-and-execute-command
3854 *** C-z
3855 *** C-x
3856 emacs hard to rebind
3857 looks like it actually wouldn't be that hard.
3858 possibly take the output from bind -p, make all those keys undefined.
3859 *** C-c
3860 quit/cancel
3861 *** C-v
3862 yank, aka paste
3863 *** C-M-v
3864 yank-pop
3865 *** C-b]
3866 bash menu-complete-backward
3867 *** tab
3868 completion
3869 *** C-tab]
3870 terminal find
3871 *** C-left/right]
3872 forward/backward-word
3873
3874 *** C-u]
3875 bash backward-kill-word
3876 *** C-i]
3877 terminal find up
3878 [ terminal crap, duplicate of tab ]
3879 *** C-o]
3880 bash operate-and-get-next, submit and bring up next item in history
3881 *** C-p]
3882 bash dabbrev-expand,
3883 complete historical command names
3884 *** C-h
3885 terminal incompatible junk
3886 *** C-k]
3887 bash kill-line, to end of line
3888 *** C-l]
3889 bash clear screen
3890 *** C-m]
3891 [--------]
3892 #+begin_src emacs-lisp
3893 (add-hook 'comint-mode-hook
3894 (lambda ()
3895 (define-key comint-mode-map "\C-m" nil)))
3896
3897 #+end_src
3898 *** C-space]
3899 bash set mark
3900 *** C-delete]
3901 bash delete word
3902 ** isearch
3903 *** C-w
3904 paste word/char under cursor into isearch
3905 *** M-n/p
3906 next/previous isearch history
3907 *** C-o
3908 isearch-occur
3909 Activate occur easily inside isearch
3910 from starter-kit
3911 #+begin_src emacs-lisp
3912 (define-key isearch-mode-map (kbd "C-o")
3913 (lambda () (interactive)
3914 (let ((case-fold-search isearch-case-fold-search))
3915 (occur (if isearch-regexp
3916 isearch-string
3917 (regexp-quote isearch-string))))))
3918 #+end_src
3919 *** m-r
3920 #+begin_src emacs-lisp
3921 (defun my-isearch-toggle-regexp ()
3922 (interactive)
3923 (isearch-toggle-regexp)
3924 (cond (isearch-regexp
3925 (global-set-key (kbd "C-r") 'isearch-backward-regexp)
3926 (define-key global-map (kbd "<kp-add>") 'isearch-forward-regexp))
3927 (t
3928 (global-set-key (kbd "C-r") 'isearch-backward)
3929 (define-key global-map (kbd "<kp-add>") 'isearch-forward))))
3930 (define-key isearch-mode-map (kbd "M-r") 'my-isearch-toggle-regexp)
3931 #+end_src
3932
3933 ** icomplete
3934 *** C-. C-,
3935 icomplete-forward/backward-completions
3936
3937 ** info
3938 *** [, ]
3939 forward / previous node, descend/ascend tree as needed
3940 *** x
3941 Info-follow-nearest-node
3942 #+begin_src emacs-lisp
3943 (define-key Info-mode-map "x" 'Info-follow-nearest-node)
3944 #+end_src
3945 m, f, n, p or ^ command, depending on where you click.
3946 ** auto-complete
3947 *** S-return
3948 select next completion candidate
3949 ac-expand
3950 ** agenda
3951 *** t]
3952 agenda cycle todo state
3953 ** org
3954 *** C-c / t]
3955 make just todo items visible
3956 *** S-<tab>
3957 org-shifttab global visibility cycle / move table cell
3958 *** C-cs]
3959 schedule todo item
3960 *** C-cx p]
3961 org set property
3962 *** C-c -]
3963 org insert horizontal line
3964 *** C-cq]
3965 org tag
3966 ** calc
3967 i'd like to drill these sometime when I have space in my head, or I
3968 plan to use calc.
3969 *** space
3970 [enter input to the stack, or duplicate top stack item]
3971 *** C-M-i
3972 [cycle 3 elements on stack]
3973 *** tab
3974 [cycle 2 elements on stack]
3975 *** n
3976 [negate]
3977 *** _
3978 [begin negative number]
3979 *** /
3980 [reciprocal]
3981 *** x
3982 [calc named command]
3983 *** M-delete
3984 [delete 2nd from top of stack]
3985 *** C-u [-]0-9
3986 [0=whole stack, 1-9=that many, -1-9=that element]
3987 *** delete
3988 [remove from the top of the stack]
3989 *** '
3990 [algebraic mode. infix expressions are calculated when input to the stack]
3991 *** m a
3992 [auto algebraic mode]
3993 *** $,$$,$$$
3994 [top x of stack reference]
3995 *** s s/t/r/u
3996 [store to variable: store, top, retrieve, unstore. the quick variables 0-9 don't need s prefix]
3997 *** U/D
3998 [undo/redo]
3999 *** t p/n/]/y
4000 [trail prev/next/end/yankh]
4001 *** `
4002 [calc edit mode, to edit the top of stack]
4003
4004 ** single/special keys
4005 *** tab key
4006 isearch
4007 #+begin_src emacs-lisp
4008 (define-key isearch-mode-map (kbd "<tab>") 'isearch-query-replace)
4009 #+end_src
4010 *** tab
4011 isearch-forward
4012 #+begin_src emacs-lisp
4013 ;; explained in http://stackoverflow.com/questions/7411920/how-to-bind-search-and-search-repeat-to-c-f-in-emacs
4014 (global-set-key (kbd "<kp-add>") 'isearch-forward)
4015 (define-key isearch-mode-map "\t" nil)
4016 (define-key isearch-mode-map (kbd "<kp-add>") 'isearch-repeat-forward)
4017 ;; get rid of the standard completion binding, always use auto-complete
4018 ;; this didn't work very well
4019 ;;(global-set-key (kbd "TAB") 'auto-complete)
4020 (define-key global-map [remap completion-at-point] 'auto-complete)
4021
4022 #+end_src
4023
4024 *** end
4025 move-end-of-line
4026 #+begin_src emacs-lisp
4027 ;; taken from emacs wiki, along with home function
4028 ;; http://www.emacswiki.org/emacs/BackToIndentationOrBeginning
4029 (defun point-in-comment ()
4030 "Determine if the point is inside a comment"
4031 (interactive)
4032 (let ((syn (syntax-ppss)))
4033 (and (nth 8 syn)
4034 (not (nth 3 syn)))))
4035 (defun end-of-code-or-line (arg)
4036 "Move to end of line, or before start of comments depending on situation.
4037 Toggle back and forth positions if we are already at one.
4038 Comments are recognized in any mode that sets syntax-ppss
4039 properly."
4040 (interactive "P")
4041 (when (catch 'bol
4042 (let ((start (point))
4043 (bol (save-excursion
4044 (beginning-of-line)
4045 (point)))
4046 (eol (progn (move-end-of-line arg) (point))))
4047 (while (point-in-comment)
4048 (backward-char)
4049 (when (= (point) bol)
4050 (throw 'bol t)))
4051 (throw 'bol (and (not (= eol start)) (>= start (point))))))
4052 (move-end-of-line arg)))
4053
4054 (global-set-key (kbd "<end>") 'end-of-code-or-line)(add-hook 'org-mode-hook (lambda () (define-key org-mode-map (kbd "<end>") 'org-end-of-line)))
4055 #+end_src
4056
4057 *** home
4058 back-to-indentation
4059 #+begin_src emacs-lisp
4060 (defun back-to-indentation-or-beginning ()
4061 (interactive)
4062 (if (= (point) (progn (back-to-indentation) (point)))
4063 (if (derived-mode-p 'org-mode)
4064 (org-beginning-of-line)
4065 (beginning-of-line))))
4066 (global-set-key (kbd "<home>") 'back-to-indentation-or-beginning)
4067
4068 #+end_src
4069
4070 *** s-tab
4071 indent-buffer
4072 #+begin_src emacs-lisp
4073 (global-set-key (kbd "<S-iso-lefttab>") 'indent-buffer)
4074 #+end_src
4075 *** s-delete
4076 send-shell
4077 #+begin_src emacs-lisp
4078
4079 (global-set-key (kbd "<S-delete>") 'send-shell)
4080
4081 ;; optional variables used by send-shell
4082 (setq shell-send-yank-key nil)
4083
4084 (defun repeat-shell ()
4085 (interactive)
4086 "Repeat the last command in shell-mode, displaying the window if needed."
4087 (let ((shell-buffer (get-buffer "*shell*")))
4088 (if shell-buffer
4089 (buffer-window-show shell-buffer)
4090 (let ((original-buffer (current-buffer)))
4091 (funcall 'shell)
4092 (setq shell-buffer (current-buffer))
4093 (switch-to-buffer original-buffer)))
4094 (with-current-buffer shell-buffer
4095 (goto-char (point-max))
4096 (call-interactively 'comint-previous-input)
4097 ;; the t flag makes the buffer advance
4098 (comint-send-input nil t))))
4099
4100 (setq compilation-filenames '("Makefile" "makefile"))
4101
4102 (defun get-nearest-compilation-file ()
4103 "Search for the compilation file traversing up the directory tree."
4104 (interactive)
4105 (let ((dir default-directory)
4106 (parent-dir (file-name-directory (directory-file-name default-directory)))
4107 (nearest-compilation-file 'nil))
4108 (while (and (not (string= dir parent-dir))
4109 (not nearest-compilation-file))
4110 (dolist (filename compilation-filenames)
4111 (setq file-path (concat dir filename))
4112 (when (file-readable-p file-path)
4113 (setq nearest-compilation-file file-path)))
4114 (setq dir parent-dir
4115 parent-dir (file-name-directory (directory-file-name parent-dir))))
4116 nearest-compilation-file))
4117 (defun run ()
4118 (interactive)
4119 "call run-fun if it is set, else run make if there is a makefile,
4120 else save and repeat last shell command.
4121 run-fun is meant to store file local variables, which show how to
4122 do the main thing we want on this file, generally compile and
4123 run.
4124
4125 example of setting it in a file:
4126 ;; Local Variables:
4127 ;; run-fun: merge-test
4128 ;; End: "
4129 (basic-save-buffer)
4130 (if (and (boundp 'run-fun) run-fun)
4131 (funcall run-fun)
4132 (let ((makefile (get-nearest-compilation-file)))
4133 (if (and makefile (stringp mode-name) (string= mode-name "C/l"))
4134 (compile (format
4135 "make -f %s" (get-nearest-compilation-file)))
4136 (repeat-shell)))))
4137
4138
4139 (defun send-shell ()
4140 (interactive)
4141 (send-shell-buffer "*shell*" 'shell (kbd "C-v")))
4142
4143 (defun send-python ()
4144 (interactive)
4145 (send-shell-buffer "*Python*" 'py-shell (kbd "C-v")))
4146
4147
4148 (defun send-shell-buffer (buffer-name &optional init shell-send-yank-key)
4149 "Send current line or region to shell-mode buffer.
4150 When in shell-mode, copy the current line to the
4151 most recently visited visible window.
4152
4153 SHELL-SEND-YANK-KEY: key to use instead
4154 of yank to paste into recent window. This allows compatibility with
4155 modes like org-mode which have their own yank function."
4156 (if (string= (buffer-name) buffer-name)
4157 ;; this section is copied out of comint-send-input
4158 (progn
4159 (let ((proc (get-buffer-process (current-buffer))))
4160 (if (not proc) (user-error "Current buffer has no process")
4161 (widen)
4162
4163 (let* ((pmark (process-mark proc))
4164 (intxt (if (>= (point) (marker-position pmark))
4165 (progn (if comint-eol-on-send (end-of-line))
4166 (buffer-substring pmark (point)))
4167 (let ((copy (funcall comint-get-old-input)))
4168 (goto-char pmark)
4169 (insert copy)
4170 copy))))
4171
4172 (if (= (length intxt) 0)
4173 (kill-new (comint-previous-matching-input-string "." 1))
4174 (kill-new intxt)))))
4175 (kill-append "\n" nil)
4176 (select-window (previous-window nil nil 'visible))
4177 (if (and (boundp 'shell-send-yank-key) shell-send-yank-key)
4178 (call-interactively (global-key-binding shell-send-yank-key))
4179 (yank))
4180 (select-window (next-window nil nil 'visible)))
4181 (let (start end)
4182 (if mark-active
4183 (setq start (mark)
4184 end (point))
4185 (setq start (save-excursion (beginning-of-line) (point))
4186 end (save-excursion (end-of-line) (point)))
4187 (let (line-move-visual)
4188 (call-interactively 'next-line)))
4189 (send-comint-input buffer-name start end init))))
4190
4191 ;; supporting functions
4192 (defun send-comint-input (buffer-name start end &optional init)
4193 "Input the region to BUFFER-NAME, assuming it is a comint-derived buffer.
4194 Show BUFFER-NAME if it is not show.
4195 Call INIT if BUFFER-NAME does not exist."
4196 (let ((input (filter-buffer-substring start end)))
4197 (send-comint-string buffer-name input init)))
4198
4199 (defun send-comint-string (buffer-name string &optional init)
4200 "Input the string to BUFFER-NAME, assuming it is a comint-derived buffer.
4201 Show BUFFER-NAME if it is not show.
4202 Call INIT if BUFFER-NAME does not exist."
4203 (let ((buffer (get-buffer buffer-name)))
4204 (unless buffer
4205 (message "nobuffer")
4206 ;; save-excursion etc. don't work for (shell), so I do this instead
4207 (if init (let ((original-buffer (current-buffer)))
4208 (funcall init (and (boundp 'send-shell-buffer-name) send-shell-buffer-name))
4209 (switch-to-buffer original-buffer)
4210 (setq buffer (get-buffer buffer-name)))
4211 (error "No existing buffer found and no init function argument. ")))
4212 (buffer-window-show buffer)
4213 (with-current-buffer buffer
4214 (let ((proc (get-buffer-process buffer)))
4215 (goto-char (process-mark proc))
4216 (insert string)
4217 (comint-send-input nil t)))))
4218
4219 (defun buffer-window-show (&optional buffer action)
4220 "Like temp-buffer-window-show, but removed stuff
4221 relevant to it being temp or help."
4222 (let (window frame)
4223 (with-current-buffer buffer
4224 (when (let ((window-combination-limit
4225 ;; When `window-combination-limit' equals
4226 ;; `temp-buffer' or `temp-buffer-resize' and
4227 ;; `temp-buffer-resize-mode' is enabled in this
4228 ;; buffer bind it to t so resizing steals space
4229 ;; preferably from the window that was split.
4230 (if (or (eq window-combination-limit 'temp-buffer)
4231 (and (eq window-combination-limit
4232 'temp-buffer-resize)
4233 temp-buffer-resize-mode))
4234 t
4235 window-combination-limit)))
4236 ;; debug
4237 ;;(message "window-combination-limit")
4238 ;;(print window-combination-limit)
4239 (setq window (display-buffer buffer action)))
4240 (setq frame (window-frame window))
4241 (unless (eq frame (selected-frame))
4242 (raise-frame frame))
4243 (setq minibuffer-scroll-window window)
4244 (set-window-hscroll window 0)
4245 ;; Return the window.
4246 window))))
4247
4248
4249 ;; when poping help, etc, allow reusing a window in a different frame if it is visible
4250 ;; figured this out after spending quite a while reading doc string for display-buffer
4251 ;; which is the main function which uses this.
4252 ;; it will use other vars or its arg to override this,
4253 ;; but those things are often nil.
4254 ;; aha moments in reading it: ACTION = (FUNCTION-or-FUNCTIONLIST ALIST)
4255 ;; FRAME adds an association to ACTION's alist, but it's not used if ACTION arg is nil.
4256 (setq display-buffer-fallback-action `(,(car display-buffer-fallback-action) . '(reusable-frames . visible)))
4257 ;; stop splitting windows verticallly when I open a buffer or shell
4258 (setq split-height-threshold nil)
4259 #+end_src
4260
4261 *** s-left arrow
4262 shell
4263 #+begin_src emacs-lisp
4264 (global-set-key (kbd "<S-kp-equal>") 'shell-wrap)
4265 #+end_src
4266 *** s-right arrow
4267 previous-buffer
4268 #+begin_src emacs-lisp
4269 (global-set-key (kbd "<S-kp-divide>") 'previous-buffer)
4270 #+end_src
4271 *** esc
4272 *** return
4273 new line
4274
4275 #+begin_src emacs-lisp
4276 ;; todo, this doesn't set the keybind for the help minibuffer
4277
4278
4279 (global-set-key (kbd "\r") 'indent-new-comment-line)
4280
4281 ;; don't use enter for autocomplete, we use tab or something
4282 (define-key ac-completing-map (kbd "<return>") nil)
4283 (define-key ac-completing-map "\r" nil)
4284
4285 (add-hook 'org-mode-hook
4286 (lambda ()
4287 ;; copied from org-mode, replace org-enter with org-enter-indent
4288 (org-defkey org-mode-map "\C-m" 'org-return-indent)))
4289
4290
4291 (add-hook 'comint-mode-hook
4292 (lambda ()
4293 (define-key comint-mode-map "\r" nil)
4294 (define-key comint-mode-map (kbd "<return>") 'comint-send-input)))
4295
4296 (add-hook 'comint-mode-hook
4297 (lambda ()
4298 (define-key comint-mode-map "\C-m" nil)
4299 (define-key comint-mode-map "\C-d" nil)))
4300
4301 #+end_src
4302
4303 *** s-return
4304 auto-correct-prev-word
4305 #+begin_src emacs-lisp
4306 (global-set-key (kbd "<S-return>") 'flyspell-auto-correct-previous-word)
4307 #+end_src
4308
4309 *** down arrow
4310 mark
4311 #+begin_src emacs-lisp
4312 (global-set-key (kbd "<kp-enter>") 'set-mark-command)
4313 #+end_src
4314 *** s-down arrow
4315 extended command
4316 #+begin_src emacs-lisp
4317 (global-set-key (kbd "<S-kp-enter>") 'smex)
4318 #+end_src
4319 *** s-up arrow
4320
4321 ** mouse
4322 *** mouse-2 mode line
4323 mouse-delete-other-windows
4324 *** C-mouse-2 mode line
4325 mouse-split-window-horizontally
4326 *** M-mouse-2 mode line
4327 *** S-mouse-2 mode line
4328 *** C-M-mouse-2 mode line
4329 *** C-S-mouse2 mode line
4330 *** mouse-3 mode line
4331 mouse-delete-window
4332 *** C-mouse-3 mode line
4333 *** M-mouse-3 mode line
4334 *** S-mouse-3 mode line
4335 *** C-M-mouse-3 mode line
4336 *** C-S-mouse-3 mode line
4337 *** mouse-1
4338 set cursor/mark
4339 *** C-mouse-1
4340 buffer list context menu
4341 *** M-mouse-1
4342 *** S-mouse-1
4343 *** C-M-mouse-1
4344 *** C-S-mouse-1
4345 *** mouse-2
4346 paste
4347 *** C-mouse-2
4348 *** M-mouse-2
4349 *** S-mouse-2
4350 *** C-M-mouse-2
4351 *** C-S-mouse-2
4352 *** mouse-3
4353 set-mark
4354 #+begin_src emacs-lisp
4355 (define-key global-map [down-mouse-3] 'mouse3-func)
4356 (global-set-key [mouse-3] 'mouse3-set-mark)
4357 (global-set-key [drag-mouse-3] 'mouse3-set-mark)
4358 #+end_src
4359 *** C-mouse-3
4360 global menu
4361 *** M-mouse-3
4362 *** S-mouse-3
4363 *** C-M-mouse-3
4364 *** C-S-mouse-3
4365 *** mouse-9
4366 move-mouse-to-point
4367 #+begin_src emacs-lisp
4368 (global-set-key (kbd "<mouse-6>") 'move-mouse-to-point)
4369 #+end_src
4370 *** C-mouse-9
4371 *** M-mouse-9
4372 *** S-mouse-9
4373 *** C-M-mouse-9
4374 *** C-S-mouse-9
4375 *** mouse-8
4376 *** C-mouse-8
4377 *** M-mouse-8
4378 *** S-mouse-8
4379 *** C-M-mouse-8
4380 *** C-S-mouse-8
4381 *** 1/kp-end
4382 *** C-1/kp-end
4383 *** M-1/kp-end
4384 *** S-1/kp-end
4385 *** C-M-1/kp-end
4386 *** C-S-1/kp-end
4387 *** 2/kp-down
4388 *** C-2/kp-down
4389 *** M-2/kp-down
4390 smex
4391 #+begin_src emacs-lisp
4392 ;; for when we have a standard keyboard which is not remapped
4393 (global-set-key (kbd "M-2") 'smex)
4394
4395 #+end_src
4396
4397 *** S-2/kp-down
4398 *** C-M-2/kp-down
4399 *** C-S-2/kp-down
4400 *** 3/kp-next
4401 *** C-3/kp-next
4402 *** M-3/kp-next
4403 *** S-3/kp-next
4404 *** C-M-3/kp-next
4405 *** C-S-3/kp-next
4406 *** 4/kp-left
4407 indent-region
4408 #+begin_src emacs-lisp
4409 (global-set-key (kbd "<kp-left>") 'indent-region)
4410 #+end_src
4411 *** C-4/kp-left
4412 *** M-4/kp-left
4413 *** S-4/kp-left
4414 *** C-M-4/kp-left
4415 *** C-S-4/kp-left
4416 *** 5/kp-begin
4417 mark-defun
4418 #+begin_src emacs-lisp
4419 (global-set-key (kbd "<kp-begin>") 'mark-defun)
4420 #+end_src
4421 *** C-5/kp-begin
4422 *** M-5/kp-begin
4423 *** S-5/kp-begin
4424 *** C-M-5/kp-begin
4425 *** C-S-5/kp-begin
4426 *** 6/kp-right
4427 ibuffer
4428 #+begin_src emacs-lisp
4429 (global-set-key (kbd "<kp-right>") 'ibuffer)
4430 #+end_src
4431 *** C-6/kp-right
4432 *** M-6/kp-right
4433 *** S-6/kp-right
4434 *** C-M-6/kp-right
4435 *** C-S-6/kp-right
4436 *** 7/kp-home
4437 *** C-7/kp-home
4438 *** M-7/kp-home
4439 *** S-7/kp-home
4440 *** C-M-7/kp-home
4441 *** C-S-7/kp-home
4442 *** 8/kp-up
4443 *** C-8/kp-up
4444 *** M-8/kp-up
4445 *** S-8/kp-up
4446 *** C-M-8/kp-up
4447 *** C-S-8/kp-up
4448 *** 9/kp-prior
4449 delete-horizontal-space
4450 #+begin_src emacs-lisp
4451 (global-set-key (kbd "<kp-prior>") 'delete-horizontal-space)
4452 #+end_src
4453 *** C-9/kp-prior
4454 *** M-9/kp-prior
4455 *** S-9/kp-prior
4456 *** C-M-9/kp-prior
4457 *** C-S-9/kp-prior
4458 *** 10/kp-insert
4459 *** C-10/kp-insert
4460 *** M-10/kp-insert
4461 *** S-10/kp-insert
4462 *** C-M-10/kp-insert
4463 *** C-S-10/kp-insert
4464 *** 11/kp-subtract
4465 *** C-11/kp-subtract
4466 *** M-11/kp-subtract
4467 *** S-11/kp-subtract
4468 *** C-M-11/kp-subtract
4469 *** C-S-11/kp-subtract
4470 *** 12/kp-add
4471 *** C-12/kp-add
4472 *** M-12/kp-add
4473 *** S-12/kp-add
4474 *** C-M-12/kp-add
4475 *** C-S-12/kp-add
4476 *** scroll
4477 up/dn / scroll
4478 on standard mouse, this scrolls,
4479 because we have the accuracy to pick things up and
4480 down easier, and because it is familiar.
4481 *** C-scroll
4482 cursor up/down fast
4483 #+begin_src emacs-lisp
4484 ;; compiling warns that next-line should be called interactively,
4485 ;; but we would have to do something dumb, like give it a
4486 ;; vector of keys in order to supply the 8 argument
4487 (defun down-fast ()
4488 (interactive)
4489 (next-line 8))
4490 (defun up-fast ()
4491 (interactive)
4492 (next-line -8))
4493
4494 (global-set-key (kbd "<C-up>") 'up-fast)
4495 (global-set-key (kbd "<C-down>") 'down-fast)
4496
4497 (add-hook 'comint-mode-hook
4498 (lambda ()
4499 (define-key comint-mode-map (kbd "<C-mouse-4>") 'comint-previous-prompt)
4500 (define-key comint-mode-map (kbd "<C-mouse-5>") 'comint-next-prompt)))
4501 #+end_src
4502
4503 *** M-scroll
4504 forward/back s-exp
4505 #+begin_src emacs-lisp
4506 (global-set-key (kbd "<M-mouse-4>") 'backward-sexp)
4507 (global-set-key (kbd "<M-mouse-5>") 'forward-sexp)
4508 #+end_src
4509 *** S-scroll
4510 expand/contract region
4511 #+begin_src emacs-lisp
4512 (global-set-key (kbd "<S-mouse-13>") 'my-contract-region)
4513 (global-set-key (kbd "<S-mouse-14>") 'er/expand-region)
4514 (global-set-key (kbd "<S-mouse-4>") 'my-contract-region)
4515 (global-set-key (kbd "<S-mouse-5>") 'er/expand-region)
4516 (global-set-key (kbd "<S-up>") 'my-contract-region)
4517 (global-set-key (kbd "<S-down>") 'er/expand-region)
4518
4519 (defun my-contract-region (arg)
4520 (interactive "p")
4521 (let ((current-prefix-arg '-))
4522 (call-interactively 'er/expand-region)))
4523 #+end_src
4524 *** C-M-scroll
4525 scroll
4526 background: I originally tried to make c-scroll be scroll
4527 , but this made
4528 for better compatibility with the standard mouse
4529 #+begin_src emacs-lisp
4530 (global-set-key (kbd "<C-M-mouse-4>") 'mwheel-scroll)
4531 (global-set-key (kbd "<C-M-mouse-5>") 'mwheel-scroll)
4532 ; (require 'smooth-scroll)
4533 ; (smooth-scroll-mode nil)
4534 ; (global-set-key (kbd "<C-M-mouse-4>") 'scroll-up-1)
4535 ;(global-set-key (kbd "<C-M-mouse-5>") 'scroll-down-1)
4536 #+end_src
4537 *** C-S-scroll
4538 increase / decrease text size
4539 #+begin_src emacs-lisp
4540 (global-set-key (kbd "<C-S-mouse-4>") 'text-scale-increase)
4541 (global-set-key (kbd "<C-S-mouse-5>") 'text-scale-decrease)
4542 (global-set-key (kbd "<C-S-mouse-13>") 'text-scale-increase)
4543 (global-set-key (kbd "<C-S-mouse-14>") 'text-scale-decrease)
4544 (global-set-key (kbd "<C-S-down>") 'text-scale-increase)
4545 (global-set-key (kbd "<C-S-up>") 'text-scale-decrease)
4546 #+end_src
4547 *** left-scroll
4548 left/right
4549 *** C-left-scroll
4550 back / forward word
4551 #+begin_src emacs-lisp
4552 (global-set-key (kbd "<C-left>") 'backward-symbol)
4553 (global-set-key (kbd "<C-right>") 'forward-symbol)
4554 #+end_src
4555 *** M-left-scroll
4556 ---
4557 unreachable
4558 *** S-left-scroll
4559 ---
4560 unreachable
4561 *** C-M-left-scroll
4562 ---
4563 unreachable
4564 *** C-S-left-scroll
4565 ---
4566 unreachable
4567 ** left primary
4568
4569 *** C-2
4570 copy-symbol
4571 #+begin_src emacs-lisp
4572 (global-unset-key (kbd "C-2"))
4573 (defun copy-symbol (&optional arg)
4574 "Copy symbol at point into kill-ring"
4575 (interactive "P")
4576 (kill-new (thing-at-point 'symbol)))
4577
4578 (global-set-key (kbd "C-2") 'copy-symbol)
4579 #+end_src
4580 *** M-2
4581 shell-cd-to-file
4582 #+begin_src emacs-lisp
4583
4584 (defun shell-cd-to-file ()
4585 (interactive)
4586 (let ((file (buffer-file-name)))
4587 (if file
4588 (send-comint-string "*shell*"
4589 (concat "c " (file-name-directory file))
4590 'shell)
4591 (message "%s" "shell-cd-to-file: buffer has no file name"))))
4592 (global-set-key (kbd "M-2") 'shell-cd-to-file)
4593 #+end_src
4594 *** C-M-2
4595 ---
4596 #+begin_src emacs-lisp
4597 (global-unset-key (kbd "C-M-2"))
4598 #+end_src
4599 *** C-S-2
4600 *** C-3
4601 dot-mode-execute
4602 #+begin_src emacs-lisp
4603 (global-set-key (kbd "C-3") 'dot-mode-execute)
4604 #+end_src
4605 *** M-3
4606 *** C-M-3
4607 recenter-top-bottom
4608 #+begin_src emacs-lisp
4609 (global-set-key (kbd "C-M-3") 'recenter-top-bottom)
4610 #+end_src
4611 *** C-S-3
4612 *** C-q
4613 org-cycle, comint previous arg
4614 #+begin_src emacs-lisp
4615 (add-hook 'org-mode-hook
4616 (lambda () (define-key org-mode-map (kbd "C-q") 'org-cycle)))
4617 (define-key widget-keymap (kbd "C-q") 'widget-forward)
4618 (add-hook 'comint-mode-hook
4619 (lambda () (define-key comint-mode-map (kbd "C-q") 'comint-insert-previous-argument)))
4620 #+end_src
4621 *** M-q
4622 org-archive-to-archive-sibling
4623 #+begin_src emacs-lisp
4624 (global-set-key (kbd "M-q") 'org-archive-to-archive-sibling)
4625 #+end_src
4626 *** C-M-q
4627 quoted-insert
4628 #+begin_src emacs-lisp
4629 (global-set-key (kbd "C-M-q") 'quoted-insert)
4630 #+end_src
4631 *** C-S-q
4632 *** C-w
4633 goto-t.org
4634 #+begin_src emacs-lisp
4635 (global-set-key (kbd "C-w") (lambda () (interactive) (goto-buffer-or-find-file "/a/t.org")))
4636 #+end_src
4637 *** M-w
4638 org-clock-in
4639 #+begin_src emacs-lisp
4640 (global-set-key (kbd "M-w") 'org-clock-in)
4641 #+end_src
4642 *** C-M-w
4643 *** C-S-w
4644 *** C-e
4645 copy-line
4646 #+begin_src emacs-lisp
4647 ;; todo, make repeated calls to this append the kills
4648 (defun copy-line (&optional arg)
4649 "Copy lines (as many as prefix argument) in the kill ring.
4650 Ease of use features:
4651 - Move to start of next line.
4652 - Appends the copy on sequential calls.
4653 - Use newline as last char even on the last line of the buffer.
4654 - If region is active, copy its lines."
4655 (interactive "p")
4656 (let ((beg (line-beginning-position))
4657 (end (line-end-position (or arg 1))))
4658 (when mark-active
4659 (if (> (point) (mark))
4660 (setq beg (save-excursion (goto-char (mark)) (line-beginning-position)))
4661 (setq end (save-excursion (goto-char (mark)) (line-end-position)))))
4662 (if (eq last-command 'copy-line)
4663 (kill-append (buffer-substring beg end) (< end beg))
4664 (kill-ring-save beg end)))
4665 (kill-append "\n" nil)
4666 ;; dun need cuz I have yank-better
4667 ;;(beginning-of-line (or (and arg (1+ arg)) 2))
4668 (if (and arg (not (= 1 arg))) (message "%d lines copied" arg)))
4669
4670 (global-set-key (kbd "C-e") 'copy-line)
4671 #+end_src
4672 *** M-e
4673 org-clock-in-last
4674 #+begin_src emacs-lisp
4675 (global-set-key (kbd "M-e") 'org-clock-in-last)
4676 #+end_src
4677 *** C-M-e
4678 *** C-S-e
4679 *** C-r
4680 isearch-backward
4681 #+begin_src emacs-lisp
4682 (global-set-key (kbd "C-r") 'isearch-backward)
4683 (add-hook 'comint-mode-hook
4684 (lambda ()
4685 (define-key comint-mode-map (kbd "C-r") 'comint-history-isearch-backward-regexp)))
4686 #+end_src
4687 *** M-r
4688 org-clock-out
4689 #+begin_src emacs-lisp
4690 (global-set-key (kbd "M-r") 'org-clock-out)
4691 #+end_src
4692 *** C-M-r
4693 *** C-S-r
4694 *** C-a
4695 copy buffer
4696 #+begin_src emacs-lisp
4697 (defun copy-all ()
4698 "Copy entire buffer to clipboard"
4699 (interactive)
4700 (clipboard-kill-ring-save (point-min) (point-max)))
4701 (global-set-key (kbd "C-a") 'copy-all)
4702 #+end_src
4703 *** M-a
4704 macro record
4705 #+begin_src emacs-lisp
4706 (global-set-key (kbd "M-a") 'kmacro-start-macro-or-insert-counter)
4707 #+end_src
4708 *** C-M-a
4709 macro end / call
4710 #+begin_src emacs-lisp
4711 (global-set-key (kbd "C-M-a") 'kmacro-end-or-call-macro)
4712 (add-hook 'perl-mode-hook (lambda () (define-key perl-mode-map (kbd "C-M-a") nil)))
4713 (add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-M-a") nil)))
4714 (add-hook 'c-mode-hook
4715 (lambda () (define-key c-mode-map (kbd "C-M-a") nil)))
4716
4717 #+end_src
4718 *** C-S-a
4719 *** C-s
4720 c-x prefix
4721
4722 *** M-s
4723 *** C-M-s
4724 split-window-vertically
4725 #+begin_src emacs-lisp
4726 (global-set-key (kbd "C-M-s") 'split-window-vertically)
4727 #+end_src
4728 *** C-S-s
4729 *** C-d
4730 C-c prefix
4731 *** M-d
4732 *** C-M-d
4733 swap buffer across windows
4734 from http://www.emacswiki.org/emacs/TransposeWindows
4735 #+begin_src emacs-lisp
4736 (setq swapping-buffer nil)
4737 (setq swapping-window nil)
4738 (defun swap-buffers-in-windows ()
4739 "Swap buffers between two windows"
4740 (interactive)
4741 (if (and swapping-window
4742 swapping-buffer)
4743 (let ((this-buffer (current-buffer))
4744 (this-window (selected-window)))
4745 (if (and (window-live-p swapping-window)
4746 (buffer-live-p swapping-buffer))
4747 (progn (switch-to-buffer swapping-buffer)
4748 (select-window swapping-window)
4749 (switch-to-buffer this-buffer)
4750 (select-window this-window)
4751 (message "Swapped buffers."))
4752 (message "Old buffer/window killed. Aborting."))
4753 (setq swapping-buffer nil)
4754 (setq swapping-window nil))
4755 (progn
4756 (setq swapping-buffer (current-buffer))
4757 (setq swapping-window (selected-window))
4758 (message "Buffer and window marked for swapping."))))
4759
4760 (global-set-key (kbd "C-M-d") 'swap-buffers-in-windows)
4761 #+end_src
4762 *** C-S-d
4763 *** C-f]
4764 kill-whole-line
4765 #+begin_src emacs-lisp
4766 (global-set-key (kbd "C-f") 'kill-whole-line-wrapper)
4767 (defun kill-whole-line-wrapper (&optional arg)
4768 "If we are at the end of the file, kill backwards instead of doing nothing."
4769 (interactive "P")
4770 (if (= (point) (point-max))
4771 (kill-whole-line -1)
4772 (kill-whole-line arg)))
4773 #+end_src
4774 *** M-f]
4775 print-var-at-point
4776 #+begin_src emacs-lisp
4777 (defun print-var-at-point ()
4778 (interactive)
4779 (let ((v (variable-at-point)))
4780 (if (symbolp v)
4781 (message "%s: %s" v (symbol-value v))
4782 (message "no symbol found at point"))))
4783 (global-set-key (kbd "M-f") 'print-var-at-point)
4784 #+end_src
4785
4786 *** C-M-f]
4787 kill rest of line
4788 #+begin_src emacs-lisp
4789
4790 (add-hook 'org-mode-hook
4791 (lambda ()
4792 (define-key org-mode-map (kbd "C-M-f") 'org-kill-line)))
4793
4794 (global-set-key (kbd "C-M-f") 'kill-line)
4795 #+end_src
4796 *** C-S-f
4797 *** C-g]
4798 cancel / other window
4799 #+begin_src emacs-lisp
4800 (global-set-key (kbd "C-g") 'other-window)
4801 #+end_src
4802 *** M-g]
4803 abort-recursive-edit
4804 #+begin_src emacs-lisp
4805 (global-set-key (kbd "M-g") 'abort-recursive-edit)
4806 #+end_src
4807 *** C-M-g]
4808 gnus
4809 #+begin_src emacs-lisp
4810 (global-set-key (kbd "C-M-g") 'gnus)
4811 #+end_src
4812 *** C-S-g
4813 *** C-z
4814 #+begin_src emacs-lisp
4815 (global-set-key (kbd "C-z") 'undo-tree-undo)
4816 #+end_src
4817 *** M-z
4818 *** C-M-z]
4819 *** C-S-z
4820 *** C-x
4821 kill-region
4822 #+begin_src emacs-lisp
4823 (global-set-key (kbd "C-s") 'kill-region)
4824 #+end_src
4825 *** M-x]
4826 append-next-kill
4827 #+begin_src emacs-lisp
4828 (global-set-key (kbd "M-x") 'append-next-kill)
4829 #+end_src
4830 *** C-M-x]
4831 cut-to-register
4832 #+begin_src emacs-lisp
4833 ;; same args as copy-to-register
4834 (defun cut-to-register (register start end &optional delete-flag region)
4835 (interactive (list (register-read-with-preview "Cut to register: ")
4836 (region-beginning)
4837 (region-end)
4838 current-prefix-arg
4839 t))
4840 (copy-to-register register start end t region))
4841
4842 (global-set-key (kbd "C-M-x") 'cut-to-register)
4843 #+end_src
4844 *** C-S-x
4845 *** C-c
4846 copy
4847 #+begin_src emacs-lisp
4848 (global-set-key (kbd "C-d") 'kill-ring-save)
4849 (add-hook 'c-mode-hook
4850 (lambda () (define-key c-mode-map (kbd "C-d") nil)))
4851 (add-hook 'comint-mode-hook
4852 (lambda ()
4853 (define-key comint-mode-map (kbd "C-d") nil)))
4854 ;; the base map is shared by many c-modes, like java
4855 (add-hook 'c-mode-hook
4856 (lambda ()
4857 (define-key c-mode-base-map "\C-d" nil)
4858 (define-key c-mode-base-map (kbd "<deletechar>") 'c-electric-delete-forward)))
4859
4860 #+end_src
4861 *** M-c]
4862 org-capture
4863 #+begin_src emacs-lisp
4864 (define-key global-map "\M-c" 'org-capture)
4865 #+end_src
4866 *** C-M-c]
4867 copy-to-register
4868 #+begin_src emacs-lisp
4869 (global-set-key (kbd "C-M-c") 'copy-to-register)
4870 #+end_src
4871 *** C-S-c
4872 *** C-v
4873 yank
4874 #+begin_src emacs-lisp
4875 (global-set-key (kbd "C-v") 'yank-better)
4876
4877
4878
4879 (defun yank-better (arg)
4880 "Paste, linewise if our kill ends with a newline.
4881 I change the behavior of plain prefix. It makes it not do linewise paste,
4882 because sometimes you want to yank pop and a linewise paste screws that up.
4883 c-u with no number normally makes the point go before the yank.
4884 That is pointless for me, as it would be just as easier and less
4885 thought to pop the mark after yanking cuz it is set to before the mark."
4886 (interactive "*P")
4887 (if (and (not (equal arg '(4))) (string-suffix-p "\n" (current-kill 0 t)))
4888 (beginning-of-line))
4889 (if (and (stringp mode-name) (string= mode-name "Org"))
4890 (call-interactively 'org-yank)
4891 (setq this-command 'yank)
4892 (call-interactively 'yank (and (not (equal arg '(4)))))))
4893
4894 (put 'yank-better 'delete-selection 'yank)
4895 #+end_src
4896 *** M-v]
4897 insert-register
4898 #+begin_src emacs-lisp
4899 (global-set-key (kbd "M-v") 'insert-register)
4900 #+end_src
4901 *** C-M-v]
4902 yank-pop
4903 #+begin_src emacs-lisp
4904 (global-set-key (kbd "C-M-v") 'yank-pop)
4905 #+end_src
4906 *** C-S-v
4907 *** C-b]
4908 delete-other-windows
4909 #+begin_src emacs-lisp
4910 (global-set-key (kbd "C-b") 'delete-other-windows)
4911 #+end_src
4912 *** M-b]
4913 isearch-backward-current-symbol
4914 #+begin_src emacs-lisp
4915 (global-set-key (kbd "M-b") 'isearch-backward-current-symbol)
4916 #+end_src
4917 *** C-M-b]
4918 isearch-current-symbol
4919 #+begin_src emacs-lisp
4920 (global-set-key (kbd "C-M-b") 'isearch-current-symbol)
4921 #+end_src
4922 *** C-S-b
4923 *** C-tab]
4924 ---
4925 in terminal, it's just TAB, duplicate keybind.
4926 *** M-tab]
4927 ---
4928 in terminal it's duplicated of C-M-i
4929 *** C-M-tab
4930 *** C-S-tab
4931 *** C-delete]
4932 kill-symbol
4933 #+begin_src emacs-lisp
4934 (global-set-key (kbd "<C-delete>") 'kill-symbol)
4935 (defun kill-symbol (arg)
4936 (interactive "p")
4937 (kill-region (point) (save-excursion (forward-symbol arg) (point))))
4938
4939 #+end_src
4940 *** M-delete
4941 *** C-M-delete]
4942 kill-sexp
4943 #+begin_src emacs-lisp
4944 (global-set-key (kbd "<C-M-delete>") 'kill-sexp)
4945 #+end_src
4946 *** C-S-delete
4947
4948 *** C-left-arrow]
4949 compile / comint search
4950 #+begin_src emacs-lisp
4951 (defun set-p (var)
4952 (and (bound-and-true-p var)
4953 (not (eq var 'unset))))
4954 (global-set-key (kbd "C-(") 'run)
4955
4956 ;; make compile work from the gtags root dir
4957 (defadvice compile (before pre-compile-advice activate)
4958 (basic-save-buffer)
4959 (when (set-p ggtags-project-root)
4960 (setq-local compile-saved-dir default-directory)
4961 (setq default-directory ggtags-project-root)))
4962 (defadvice compile (after post-compile-advice activate)
4963 (when (bound-and-true-p compile-saved-dir)
4964 (setq default-directory compile-saved-dir)))
4965
4966
4967 (add-hook 'c-mode-hook (lambda () (define-key c-mode-map (kbd "C-(") 'compile)))
4968 (add-hook 'comint-mode-hook
4969 (lambda ()
4970 (define-key isearch-mode-map (kbd "C-(") 'isearch-repeat-backward)
4971 (define-key comint-mode-map (kbd "C-(") 'isearch-backward)))
4972
4973 #+end_src
4974 *** M-left-arrow
4975 *** C-M-left-arrow]
4976 org-shiftup
4977 #+begin_src emacs-lisp
4978 (add-hook 'org-mode-hook
4979 (lambda () (define-key org-mode-map (kbd "C-M-(") 'org-shiftup)))
4980 #+end_src
4981 *** C-S-left-arrow
4982 *** C-right-arrow]
4983 keyboard-yank-primary
4984 #+begin_src emacs-lisp
4985 (defun keyboard-yank-primary ()
4986 (interactive)
4987 (let ((mouse-yank-at-point t))
4988 (mouse-yank-primary nil)))
4989 ;; paste selection
4990 (global-set-key (kbd "C-)") 'keyboard-yank-primary)
4991 #+end_src
4992 *** M-right-arrow
4993 *** C-M-right-arrow
4994 #+begin_src emacs-lisp
4995 (add-hook 'org-mode-hook
4996 (lambda () (define-key org-mode-map (kbd "C-M-)") 'org-shiftdown)))
4997 #+end_src
4998 *** C-S-right-arrow
4999 *** C-backspace]
5000 backward-kill-symbol
5001 #+begin_src emacs-lisp
5002 (global-set-key (kbd "<C-backspace>") 'backward-kill-symbol)
5003 (add-hook 'comint-mode-hook
5004 (lambda ()
5005 (define-key comint-mode-map (kbd "<C-backspace>") 'backward-kill-word)))
5006 (defun backward-kill-symbol (arg)
5007 (interactive "p")
5008 (kill-region (point) (save-excursion (backward-symbol arg) (point))))
5009 #+end_src
5010 *** M-backspace
5011 *** C-M-backspace]
5012 backward-kill-sexp
5013 #+begin_src emacs-lisp
5014 (global-set-key (kbd "<C-M-backspace>") 'backward-kill-sexp)
5015 #+end_src
5016 *** C-S-backspace
5017 *** C-f7
5018 *** M-f7
5019 *** C-M-f7
5020 *** C-S-f7
5021
5022 ** right primary
5023 *** C-*]
5024 split-window-horizontally
5025 #+begin_src emacs-lisp
5026 (global-set-key (kbd "C-*") 'split-window-horizontally)
5027 #+end_src
5028 *** M-*
5029 *** C-M-*]
5030 calc-dispatch
5031 #+begin_src emacs-lisp
5032 (global-set-key (kbd "C-M-*") 'calc-dispatch)
5033 #+end_src
5034 *** C-S-*
5035 *** C-9]
5036 delete-window-or-exit
5037 #+begin_src emacs-lisp
5038 (global-set-key (kbd "C-9") 'delete-window-or-exit)
5039
5040 (defun delete-window-or-exit ()
5041 "Delete window or exit emacs."
5042 (interactive)
5043 (if (condition-case nil (delete-window) (error t))
5044 (if (or (boundp 'server-process) (> (length (frame-list)) 1))
5045 (progn (basic-save-buffer) (delete-frame))
5046 (save-buffers-kill-terminal t))))
5047 #+end_src
5048 *** M-9]
5049 kill-buffer
5050 #+begin_src emacs-lisp
5051 (defun kill-buffer-no-ido ()
5052 "kill-buffer, avoid the ido remapping"
5053 (interactive)
5054 (kill-buffer))
5055 (global-set-key (kbd "M-9") 'kill-buffer-no-ido)
5056 #+end_src
5057 strangely, in simple mode, this is overridden.
5058 I found this map to override, but it didn't work, so it seems its being bound some other way.
5059 I did a grep of the emacs sources, but couldn't find anything.
5060 (define-key universal-argument-map [?9] nil)
5061
5062 *** C-M-9]
5063 end server edit
5064 ,save & kill buffer if it was opened externally via emacsclient
5065
5066 #+begin_src emacs-lisp
5067 (defun server-edit-save ()
5068 (interactive)
5069 (save-buffer)
5070 (server-edit))
5071 (global-set-key (kbd "C-M-9") 'server-edit-save)
5072 #+end_src
5073 *** C-S-9
5074 *** C-u]
5075 universal-argument
5076 *** M-u
5077 *** C-M-u]
5078 search-keybind
5079 #+begin_src emacs-lisp
5080 (global-set-key (kbd "C-M-u") 'search-keybind)
5081
5082 (defun search-keybind (regexp &optional nlines)
5083 (interactive (occur-read-primary-args))
5084 (save-excursion
5085 (describe-bindings)
5086 (set-buffer "*Help*")
5087 (occur regexp)
5088 (delete-windows-on "*Help*")
5089 ))
5090 #+end_src
5091 *** C-S-u
5092 *** C-i
5093 -----
5094 *** M-i
5095 *** C-M-i]
5096 query-replace-regexp
5097 #+begin_src emacs-lisp
5098 (global-set-key (kbd "C-M-i") 'query-replace-regexp)
5099 (add-hook 'flyspell-mode-hook
5100 (lambda () (define-key flyspell-mode-map (kbd "C-M-i") nil)))
5101 (add-hook 'text-mode-hook
5102 (lambda () (define-key text-mode-map (kbd "C-M-i") nil)))
5103
5104 #+end_src
5105 *** C-S-i
5106 *** C-o]
5107 occur
5108 #+begin_src emacs-lisp
5109 (global-set-key (kbd "C-o") 'occur)
5110 #+end_src
5111 *** M-o
5112 *** C-M-o]
5113 counsel-imenu
5114 #+begin_src emacs-lisp
5115 (global-set-key (kbd "C-M-o") 'counsel-imenu)
5116 #+end_src
5117 *** C-S-o
5118 *** C-p]
5119 move-mouse-to-point
5120 #+begin_src emacs-lisp
5121 (global-set-key (kbd "C-p") 'move-mouse-to-point)
5122 #+end_src
5123 *** M-p
5124 *** C-M-p]
5125 delete-horizontal-space
5126 #+begin_src emacs-lisp
5127 (global-set-key (kbd "C-M-p") 'delete-horizontal-space)
5128 #+end_src
5129 *** C-S-p
5130 *** C-j]
5131 pop-to-mark
5132 #+begin_src emacs-lisp
5133 (defun my-pop-to-mark-command ()
5134 "Jump to mark, and pop a new position for mark off the ring.
5135 \(Does not affect global mark ring\)."
5136 (interactive)
5137 (pop-to-mark-command)
5138 (if (and (derived-mode-p 'org-mode) (outline-invisible-p))
5139 (org-show-context 'mark-goto)))
5140
5141 (global-set-key (kbd "C-j") 'my-pop-to-mark-command)
5142 (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text)
5143 (add-hook 'ido-setup-hook
5144 (lambda () (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text)))
5145 (add-hook 'lisp-interaction-mode-hook
5146 (lambda ()
5147 (define-key lisp-interaction-mode-map (kbd "C-j") nil)))
5148
5149 #+end_src
5150 *** M-j]
5151 previous-error
5152 #+begin_src emacs-lisp
5153 (global-set-key (kbd "M-j") 'previous-error)
5154 #+end_src
5155 *** C-M-j]
5156
5157 register prefix
5158 #+begin_src emacs-lisp
5159 (define-key global-map (kbd "C-M-j") ctl-x-r-map)
5160 (define-key ctl-x-r-map "m" 'kmacro-to-register)
5161 #+end_src
5162
5163 *** C-S-j
5164 *** C-k]
5165 jump-to-register
5166 #+begin_src emacs-lisp
5167
5168 (global-set-key (kbd "C-k") 'jump-to-register)
5169 #+end_src
5170 *** M-k]
5171 next-error
5172 #+begin_src emacs-lisp
5173 (global-set-key (kbd "M-k") 'next-error)
5174 #+end_src
5175 *** C-M-k]
5176 man
5177 #+begin_src emacs-lisp
5178 (global-set-key (kbd "C-M-k") 'man)
5179 #+end_src
5180 *** C-S-k
5181 *** C-l]
5182 ivy-switch-buffer
5183 #+begin_src emacs-lisp
5184 (global-set-key (kbd "C-l") 'ivy-switch-buffer)
5185 #+end_src
5186 *** M-l
5187
5188 *** C-M-l]
5189 move cursor top bottom mid, comint clear screen
5190 #+begin_src emacs-lisp
5191 (global-set-key (kbd "C-M-l") 'move-to-window-line-top-bottom)
5192 #+end_src
5193 *** C-S-l
5194 *** C-;]
5195 used in flyspell, not sure what for, otherwise unbound
5196 *** M-;
5197 comment-dwim
5198 *** C-M-;]
5199 comment-current-line-dwim
5200 #+begin_src emacs-lisp
5201 (defun comment-current-line-dwim ()
5202 "Comment or uncomment the current line."
5203 (interactive)
5204 (save-excursion
5205 (push-mark (beginning-of-line) t t)
5206 (end-of-line)
5207 (comment-dwim nil))
5208 (move-beginning-of-line 2))
5209 (global-set-key (kbd "C-M-;") 'comment-current-line-dwim)
5210 #+end_src
5211 *** C-S-;
5212 *** C-m]
5213 *** M-m
5214 *** C-M-m]
5215 recursive grep
5216 #+begin_src emacs-lisp
5217 (define-key global-map (kbd "C-M-m") 'rgrep)
5218 #+end_src
5219 *** C-S-m
5220 *** C-,]
5221 counsel-find-file
5222 #+begin_src emacs-lisp
5223 (global-set-key (kbd "C-,") 'counsel-find-file)
5224 (add-hook 'flyspell-mode-hook
5225 (lambda () (define-key flyspell-mode-map (kbd "C-,") nil)))
5226 #+end_src
5227 *** M-,
5228 *** C-M-,]
5229 find-file-in-project
5230 #+begin_src emacs-lisp
5231 (global-set-key (kbd "C-M-,") 'find-file-in-project)
5232 #+end_src
5233 *** C-S-,
5234 *** C-.]
5235 find recent file
5236 Taken from starter kit.
5237 #+begin_src emacs-lisp
5238 (defun recentf-ido-find-file ()
5239 "Find a recent file using Ido."
5240 (interactive)
5241 (let* ((file-assoc-list
5242 (mapcar (lambda (x)
5243 (cons (file-name-nondirectory x)
5244 x))
5245 recentf-list))
5246 (filename-list
5247 (remove-duplicates (mapcar #'car file-assoc-list)
5248 :test #'string=))
5249 (filename (ido-completing-read "Choose recent file: "
5250 filename-list
5251 nil
5252 t)))
5253 (when filename
5254 (find-file (cdr (assoc filename
5255 file-assoc-list))))))
5256
5257 (add-hook 'flyspell-mode-hook
5258 (lambda () (define-key flyspell-mode-map (kbd "C-.") nil)))
5259 (define-key dot-mode-map (kbd "C-.") nil)
5260 (global-set-key (kbd "C-.") 'recentf-ido-find-file)
5261 (add-hook 'php-mode-hook
5262 (lambda () (define-key php-mode-map (kbd "C-.") nil)))
5263 #+end_src
5264 *** M-.
5265 *** C-M-.
5266 -
5267 #+begin_src emacs-lisp
5268 (define-key dot-mode-map (kbd "C-M-.") nil)
5269 ;; (global-set-key (kbd "C-M-.") 'execute-extended-command)
5270 #+end_src
5271 *** C-S-.
5272 *** C-/]
5273 join lines
5274 #+begin_src emacs-lisp
5275 (defun vim-style-join-line ()
5276 (interactive)
5277 (join-line '(4)))
5278 (global-set-key (kbd "C-/") 'vim-style-join-line)
5279 (define-key undo-tree-map (kbd "C-/") nil)
5280 #+end_src
5281 *** M-/
5282 *** C-M-/]
5283 copy-variable
5284 #+begin_src emacs-lisp
5285 (defun copy-variable (variable)
5286 (interactive
5287 (let ((v (variable-at-point))
5288 (enable-recursive-minibuffers t)
5289 val)
5290 (setq val (completing-read (if (symbolp v)
5291 (format
5292 "Describe variable (default %s): " v)
5293 "Describe variable: ")
5294 obarray
5295 (lambda (vv)
5296 (or (get vv 'variable-documentation)
5297 (and (boundp vv) (not (keywordp vv)))))
5298 t nil nil
5299 (if (symbolp v) (symbol-name v))))
5300 (list (if (equal val "")
5301 v (intern val)))))
5302 (kill-new (symbol-value variable)))
5303 (global-set-key (kbd "C-M-/") 'copy-variable)
5304
5305 #+end_src
5306 *** C-S-/
5307 *** C-8]
5308 calc-embedded-word
5309 #+begin_src emacs-lisp
5310 (global-set-key (kbd "C-8") 'calc-embedded-word)
5311 #+end_src
5312 *** M-8
5313 *** C-M-8
5314 *** C-S-8
5315 *** C-up-arrow]
5316 org prev headline
5317 #+begin_src emacs-lisp
5318 (define-key undo-tree-map "\C-_" nil)
5319 ;; disabled just because i don't want to accidentally hit it
5320 (define-key global-map "\C-_" nil)
5321 (global-set-key (kbd "<C-_>") 'beginning-of-defun)
5322
5323 (add-hook 'org-mode-hook
5324 (lambda ()
5325 (define-key org-mode-map (kbd "\C-_") 'outline-previous-visible-heading)))
5326
5327 #+end_src
5328
5329
5330 *** M-up-arrow
5331 *** C-M-up-arrow
5332 *** C-S-up-arrow
5333 winner undo
5334 #+begin_src emacs-lisp
5335 (global-set-key (kbd "<C-S-_>") 'winner-undo)
5336 #+end_src
5337 *** C-down-arrow]
5338 org next headline
5339 #+begin_src emacs-lisp
5340 (global-set-key (kbd "<C-kp-enter>") 'end-of-defun)
5341
5342 (add-hook 'org-mode-hook
5343 (lambda ()
5344 (define-key org-mode-map (kbd "<C-kp-enter>") 'outline-next-visible-heading)))
5345
5346 #+end_src
5347
5348
5349 *** M-down-arrow
5350 *** C-M-down-arrow]
5351 toggle-mark-activation
5352 #+begin_src emacs-lisp
5353 (defun toggle-mark-activation ()
5354 (interactive)
5355 (if mark-active
5356 (deactivate-mark t)
5357 (activate-mark)))
5358
5359 (global-set-key (kbd "<C-M-kp-enter>") 'toggle-mark-activation)
5360 #+end_src
5361 winner redo
5362 #+begin_src emacs-lisp
5363 (global-set-key (kbd "<C-S-kp-enter>") 'winner-redo)
5364 #+end_src
5365
5366 *** C-S-down-arrow]
5367 m-x for major mode
5368 #+begin_src emacs-lisp
5369 (global-set-key (kbd "<C-S-kp-enter>") 'smex-major-mode-commands)
5370 #+end_src
5371 *** C-lbracket
5372 ----
5373 *** M-lbracket
5374 *** C-M-lbracket]
5375 scroll-right
5376 #+begin_src emacs-lisp
5377 (global-set-key (kbd "C-M-[") 'scroll-right)
5378 #+end_src
5379 *** C-S-lbracket
5380 *** C-rbracket]
5381 fill-paragraph
5382 #+begin_src emacs-lisp
5383 (global-set-key (kbd "C-]") 'fill-paragraph)
5384 #+end_src
5385 *** M-rbracket
5386 *** C-M-rbracket]
5387 scroll-left
5388 #+begin_src emacs-lisp
5389 (global-set-key (kbd "C-M-]") 'scroll-left)
5390 #+end_src
5391 *** C-S-rbracket
5392 *** C-return]
5393 newline-anywhere
5394 #+begin_src emacs-lisp
5395 (defun newline-anywhere ()
5396 "Add a newline from anywhere in the line."
5397 (interactive)
5398 (end-of-line)
5399 (newline-and-indent))
5400 (global-set-key (kbd "<C-return>") 'newline-anywhere)
5401
5402 #+end_src
5403 *** M-return]
5404 plain newline
5405 #+begin_src emacs-lisp
5406 (defun plain-newline ()
5407 (interactive)
5408 (insert "\n"))
5409 (global-set-key (kbd "<M-return>") 'plain-newline)
5410 #+end_src
5411
5412 *** C-M-return
5413 #+begin_src emacs-lisp
5414 (defun newline-anywhere-previous ()
5415 "Add a newline from anywhere in the line."
5416 (interactive)
5417 (forward-line -1)
5418 (end-of-line)
5419 (newline-and-indent))
5420 (global-set-key (kbd "<C-M-return>") 'newline-anywhere-previous)
5421 #+end_src
5422 *** C-S-return
5423 *** C-space]
5424 org-edit-special
5425 #+begin_src emacs-lisp
5426 ;; (kbd "<C-space>") does not work, (kbd "C-SPC") should work
5427 (add-hook 'org-mode-hook
5428 (lambda ()
5429 (define-key org-mode-map (kbd "C-SPC") 'org-edit-special)
5430 ;; org-src-mode-map is broken in git version of emacs.
5431 ;; temporarily use this for exiting edit-special mode.
5432 (global-set-key (kbd "C-M--") 'org-edit-src-exit)
5433 (define-key org-src-mode-map (kbd "C-SPC") 'org-edit-src-exit)))
5434 #+end_src
5435 *** M-space
5436 *** C-M-space
5437 before or under cursor
5438 #+begin_src emacs-lisp
5439 (global-set-key (kbd "C-M-SPC") 'ispell-word)
5440 #+end_src
5441 *** C-S-space
5442 ** left secondary
5443 *** C-=
5444 *** M-=
5445 *** C-M-=
5446 *** C-S-=
5447 *** C-1
5448 *** M-1
5449 *** C-M-1
5450 *** C-S-1
5451 *** C-4
5452 *** M-4
5453 *** C-M-4
5454 widen
5455 #+begin_src emacs-lisp
5456 (global-set-key (kbd "C-M-4") 'widen)
5457 #+end_src
5458 *** C-S-4
5459 *** C-5
5460 *** M-5
5461 *** C-M-5
5462 *** C-S-5
5463 *** C-tab-key]
5464 query-replace
5465 #+begin_src emacs-lisp
5466
5467 (global-set-key (kbd "<C-kp-add>") 'query-replace)
5468 #+end_src
5469 *** M-tab-key
5470 *** C-M-tab-key
5471 *** C-S-tab-key
5472 *** C-t]
5473 org cycle todo / toggle comint motion
5474 #+begin_src emacs-lisp
5475 (add-hook 'org-mode-hook
5476 (lambda ()
5477 (define-key org-mode-map (kbd "C-t") 'org-todo)))
5478
5479 (defun my-comint-previous-input (arg)
5480 (interactive "*p")
5481 (if (comint-after-pmark-p)
5482 (comint-previous-input arg)
5483 (forward-line -1)))
5484
5485 (defun my-comint-next-input (arg)
5486 (interactive "*p")
5487 (if (comint-after-pmark-p)
5488 (comint-next-input arg)
5489 (forward-line)))
5490
5491 (add-hook 'comint-mode-hook
5492 (lambda ()
5493 (define-key comint-mode-map (kbd "C-t") 'comint-toggle-arrow-keys)
5494 (define-key comint-mode-map (kbd "<up>") 'my-comint-previous-input)
5495 (define-key comint-mode-map (kbd "<down>") 'my-comint-next-input)))
5496
5497
5498 (defun comint-toggle-arrow-keys ()
5499 (interactive)
5500 (toggle-arrow-keys comint-mode-map))
5501
5502 (setq-default comint-arrow-movement nil)
5503 (defun toggle-arrow-keys (map)
5504 (cond ((lookup-key map (kbd "<up>"))
5505 (setq-local comint-arrow-movement t)
5506 (define-key map (kbd "<up>") nil)
5507 (define-key map (kbd "<down>") nil))
5508 (t
5509 (setq-local comint-arrow-movement nil)
5510 (define-key map (kbd "<up>") 'my-comint-previous-input)
5511 (define-key map (kbd "<down>") 'my-comint-next-input)
5512 (goto-char (point-max)))))
5513
5514 (defun ian-sign-email ()
5515 (interactive)
5516 (insert "Ian Kelling
5517 https://iankelling.org"))
5518
5519 (eval-after-load "message"
5520 '(define-key message-mode-map (kbd "C-t") 'ian-sign-email))
5521 #+end_src
5522 Thanks for the update. I will be enjoying it.
5523
5524 #+RESULTS:
5525 : comint-toggle-arrow-keys
5526 *** M-t
5527 *** C-M-t]
5528 org timestamp
5529 #+begin_src emacs-lisp
5530 (global-set-key (kbd "C-M-t") 'org-time-stamp-with-time)
5531 #+end_src
5532 *** C-S-t
5533 *** C-home
5534 start of buffer
5535 *** M-home
5536 *** C-M-home
5537 *** C-S-home
5538 *** C-end
5539 end of buffer
5540 *** M-end
5541 *** C-M-end
5542 *** C-S-end
5543 *** C-f9
5544 *** M-f9
5545 *** C-M-f9
5546 *** C-S-f9
5547 ** right secondary
5548 *** C-6
5549 save-buffers-kill-emacs
5550 #+begin_src emacs-lisp
5551 (global-set-key (kbd "C-6") 'save-buffers-kill-emacs)
5552 #+end_src
5553 *** M-6
5554 *** C-M-6]
5555 insert-small-copyright
5556 #+begin_src emacs-lisp
5557 (defun insert-small-copyright ()
5558 (interactive)
5559 (beginning-of-line)
5560 (let ((beg (point)))
5561 (insert "Copyright (C) 2017 Ian Kelling\nThis program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>")
5562 (comment-region beg (point))))
5563
5564 (global-set-key (kbd "C-M-6") 'insert-small-copyright)
5565 #+end_src
5566 *** C-S-6
5567 *** C-7
5568 *** M-7
5569 *** C-M-7]
5570 insert-full-copyright
5571 #+begin_src emacs-lisp
5572 (defun insert-full-copyright ()
5573 (interactive)
5574 (beginning-of-line)
5575 (let ((beg (point)))
5576 (insert "Copyright (C) 2017 Ian Kelling\n")
5577 (insert "\n")
5578 (insert "This program is free software: you can redistribute it and/or modify\n")
5579 (insert "it under the terms of the GNU General Public License as published by\n")
5580 (insert "the Free Software Foundation, either version 3 of the License, or\n")
5581 (insert "(at your option) any later version.\n")
5582 (insert "\n")
5583 (insert "This program is distributed in the hope that it will be useful,\n")
5584 (insert "but WITHOUT ANY WARRANTY; without even the implied warranty of\n")
5585 (insert "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n")
5586 (insert "GNU General Public License for more details.\n")
5587 (insert "\n")
5588 (insert "You should have received a copy of the GNU General Public License\n")
5589 (insert "along with this program. If not, see <http://www.gnu.org/licenses/>.\n")
5590 (comment-region beg (point))))
5591
5592 (global-set-key (kbd "C-M-7") 'insert-full-copyright)
5593
5594 #+end_src
5595 *** C-S-7
5596 *** C-0
5597 text-scale-reset
5598 #+begin_src emacs-lisp
5599 (defun text-scale-reset ()
5600 (interactive)
5601 (text-scale-set 0))
5602 (global-set-key (kbd "C-0") 'text-scale-reset)
5603 #+end_src
5604 *** M-0
5605 *** C-M-0
5606 insert-apache
5607 #+begin_src emacs-lisp
5608 (defun insert-apache ()
5609 (interactive)
5610 (beginning-of-line)
5611 (let ((beg (point)))
5612 (insert "Copyright (C) 2017 Ian Kelling\n")
5613 (insert "\n")
5614 (insert "Licensed under the Apache License, Version 2.0 (the \"License\");\n")
5615 (insert "you may not use this file except in compliance with the License.\n")
5616 (insert "You may obtain a copy of the License at\n")
5617 (insert "\n")
5618 (insert " http://www.apache.org/licenses/LICENSE-2.0\n")
5619 (insert "\n")
5620 (insert "Unless required by applicable law or agreed to in writing, software\n")
5621 (insert "distributed under the License is distributed on an \"AS IS\" BASIS,\n")
5622 (insert "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n")
5623 (insert "See the License for the specific language governing permissions and\n")
5624 (insert "limitations under the License.\n")
5625 (comment-region beg (point))))
5626 (global-set-key (kbd "C-M-0") 'insert-apache)
5627 #+end_src
5628
5629 *** C-S-0
5630 *** C--
5631 *** M--
5632 *** C-M--
5633 org-edit-src-exit
5634 *** C-S--
5635 *** C-y]
5636 undo-tree-redo
5637 #+begin_src emacs-lisp
5638 (global-set-key (kbd "C-y") 'undo-tree-redo)
5639 #+end_src
5640
5641 *** M-y
5642 *** C-M-y
5643 *** C-S-y
5644 *** C-\
5645 #+begin_src emacs-lisp
5646 (global-set-key (kbd "C-\\") 'sr-speedbar-toggle)
5647 #+end_src
5648 *** M-\
5649 *** C-M-\]
5650 mark-defun
5651 #+begin_src emacs-lisp
5652 (global-set-key (kbd "C-M-\\") 'mark-defun)
5653 #+end_src
5654 *** C-S-\
5655 *** C-h
5656 help-prefix
5657
5658 *** M-h
5659 *** C-M-h
5660 *** C-S-h
5661 *** C-'
5662 eval-expression
5663 #+begin_src emacs-lisp
5664 (global-set-key (kbd "C-'") 'eval-expression)
5665 #+end_src
5666 *** M-'
5667 *** C-M-'
5668 *** C-S-'
5669 *** C-n]
5670 unpop to mark
5671 #+begin_src emacs-lisp
5672 (defun unpop-to-mark-command ()
5673 "Unpop off mark ring. Does nothing if mark ring is empty."
5674 (interactive)
5675 (when mark-ring
5676 (let ((pos (marker-position (car (last mark-ring)))))
5677 (if (not (= (point) pos))
5678 (goto-char pos)
5679 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
5680 (set-marker (mark-marker) pos)
5681 (setq mark-ring (nbutlast mark-ring))
5682 (goto-char (marker-position (car (last mark-ring))))))))
5683
5684 (global-set-key (kbd "C-n") 'unpop-to-mark-command)
5685 #+end_src
5686 *** M-n
5687 *** C-M-n]
5688 narrow-to-region
5689 #+begin_src emacs-lisp
5690 (global-set-key (kbd "C-M-n") 'narrow-to-region)
5691 #+end_src
5692 *** C-S-n
5693 *** C-rshift
5694 *** M-rshift
5695 *** C-M-rshift
5696 *** C-S-rshift
5697 *** C-escape]
5698 find-tag
5699 :ID: a6dd7e4c-1831-4493-bbfd-557dc2f9c856
5700 :CUSTOM_ID: 6901fa1b-c827-4525-b24b-bdb8fe5f638b
5701
5702
5703
5704
5705
5706
5707
5708
5709 :END:
5710 find-tag
5711 #+begin_src emacs-lisp
5712 (global-set-key (kbd "<C-escape>") 'find-tag)
5713 #+end_src
5714 *** M-escape
5715 *** C-M-escape
5716 *** C-S-escape
5717 * keybind table src
5718 not necessary to have at the end, but its convenient to have it next
5719 to its output.
5720 #+NAME: keybind-table-generator
5721 #+BEGIN_SRC emacs-lisp :results silent
5722 (defun org-custom-id-get (&optional pom create prefix)
5723 "Get the CUSTOM_ID property of the entry at point-or-marker POM.
5724 If POM is nil, refer to the entry at point.
5725 If the entry does not have a CUSTOM_ID, the function returns nil.
5726 However, when CREATE is non nil, create an ID if none is present already.
5727 PREFIX will be passed through to `org-id-new'.
5728 In any case, the CUSTOM_ID of the entry is returned."
5729 (org-with-point-at pom
5730 (let ((id (org-entry-get nil "CUSTOM_ID")))
5731 (cond
5732 ((and id (stringp id) (string-match "\\S-" id))
5733 id)
5734 (create
5735 (setq id (org-id-new prefix))
5736 (org-entry-put pom "CUSTOM_ID" id)
5737 (org-id-add-location id (buffer-file-name (buffer-base-buffer)))
5738 id)))))
5739
5740 (defun get-title()
5741 (interactive)
5742 (let ((title (plist-get (cadr (org-element-at-point)) ':title)))
5743 ;; remove brackets from [title]
5744 ;; I was at one point using org-drill for spaces repitition,
5745 ;; and enclosed question and answer by 2 sets of brackets.
5746 (string-match "[^[ ][^]]*" title)
5747 (setq title (match-string 0 title))
5748 (print title)
5749 title))
5750
5751
5752 (defun org-dblock-write:keybind-dblock (arg)
5753 (let (output)
5754 (save-excursion
5755 (goto-char (org-find-entry-with-id "beginning-of-keybind-table-data"))
5756 (let* ((table-level (org-current-level))
5757 (keybind-level (1+ table-level))
5758 (prefixes (list "C-M-S-" "C-M-" "C-S-" "M-S-" "M-" "C-" "S-"))
5759 table-title
5760 previous-prefixes
5761 )
5762 (while (>= (org-current-level) table-level)
5763 (setq table-title (get-title))
5764 (outline-next-heading)
5765 (let (found-prefixes
5766 found-all-prefixes)
5767 ;; go through the first few elements of the table to find out what column headings aka prefixes it should have
5768 (save-excursion
5769 (while (not found-all-prefixes)
5770 (let ((prefixes-copy prefixes)
5771 current-prefix
5772 found-prefix)
5773 (while (and prefixes-copy (not found-prefix))
5774 (setq current-prefix (car prefixes-copy))
5775 (when (and (> (length (get-title)) (length current-prefix))
5776 (string= (substring (get-title) 0 (length current-prefix)) current-prefix))
5777 (setq found-prefix t))
5778 (setq prefixes-copy (cdr prefixes-copy)))
5779 (unless found-prefix
5780 (setq current-prefix ""))
5781 (if (and found-prefixes (string= (car (last found-prefixes)) current-prefix))
5782 (setq found-all-prefixes t)
5783 (push current-prefix found-prefixes)))
5784 (outline-next-heading)))
5785 (setq found-prefixes (reverse found-prefixes))
5786
5787 ;; start a new table or repeat the prefixes in the current table
5788
5789 (if (or (not previous-prefixes) (equal previous-prefixes found-prefixes))
5790 (setq output (concat output "|-|\n| "))
5791 (setq output (concat output "|-|\n\n|-|\n| ")))
5792 (setq output (concat output table-title " | "))
5793 (setq previous-prefixes found-prefixes)
5794
5795 ;; add the prefixes
5796 (dolist (prefix found-prefixes)
5797 (setq output (concat output prefix "|")))
5798 (setq output (concat output "\n|-|\n"))
5799
5800
5801 (let (subtree-end)
5802 (while (>= (org-current-level) keybind-level)
5803 (dotimes (i (length found-prefixes))
5804 ;; add keybind name
5805 (when (= i 0)
5806 (setq output (concat output "| " (substring (get-title) (length (car found-prefixes))) " | ")))
5807 ;; add keybinds by searching for regex [keybind] to the start of the next heading
5808 (save-excursion
5809 (outline-next-heading)
5810 (setq subtree-end (point)))
5811 ;; skip over scheduled line
5812
5813 ;; see comment after source block to understand this regex
5814 (re-search-forward "^\\s-*\\([^*: ].*?$\\)" subtree-end t)
5815 (let ((m (match-string 1)))
5816 (when m
5817 (setq output (concat output "[[#" (org-custom-id-get (point) 'create) "][" m "]]")))
5818 (setq output (concat output " | ")))
5819 ;; advance to next keybind
5820 (outline-next-heading))
5821 (setq output (concat output "\n"))
5822 ))))))
5823 (setq output (concat output "|-|"))
5824 (insert output))
5825 (org-table-map-tables 'org-table-align 'quietly))
5826
5827
5828 #+END_SRC
5829 after source block due to bad parsing of comments in non emacs lisp mode
5830 some easily forgotten regex elements. whitespace: \\s-
5831 non-greedy star: *?
5832 subexpression for close bracket char or nothing: \\(\\]\\|\\)
5833
5834 * keybind tables
5835 :LOGBOOK:
5836 CLOCK: [2016-11-28 Mon 10:59]--[2016-11-28 Mon 10:59] => 0:00
5837 :END:
5838 dunno why but it takes doing ctrl-c twice to update this
5839 #+BEGIN: keybind-dblock
5840 |---------------------+------------------------|
5841 | single/special keys | |
5842 |---------------------+------------------------|
5843 | tab key | [[#6c10a716-1d8e-4ce4-8e26-64468f19c17a][isearch]] |
5844 | tab | [[#51ece189-1840-41a1-8ca0-19f9a0481895][isearch-forward]] |
5845 | end | [[#00d589b7-2b8e-494c-b761-3afefebe6ec6][move-end-of-line]] |
5846 | home | [[#7800e455-c3f6-4a8f-8907-b2292449ab67][back-to-indentation]] |
5847 | s-tab | [[#3072901e-5cf3-4d6e-9ac8-3ef64a5f6ad2][indent-buffer]] |
5848 | s-delete | [[#e53728b6-054d-4443-a03e-6cf02d13724d][send-shell]] |
5849 | s-left arrow | [[#d8c473ac-5507-4a6b-9e5a-46558c17b09f][shell]] |
5850 | s-right arrow | [[#cbae2b27-ff95-4b12-88e0-e1a0f7705db6][previous-buffer]] |
5851 | esc | |
5852 | return | [[#fab6adea-ed20-45ab-a0a3-776c68d5c3a5][new line]] |
5853 | s-return | [[#c433c837-24fa-45e1-8991-a4d380550ea0][auto-correct-prev-word]] |
5854 | down arrow | [[#7a868484-9c63-4a73-abda-7751cb2c02be][mark]] |
5855 | s-down arrow | [[#097b97e0-8ad8-40f7-8388-c4ace1706b38][extended command]] |
5856 | s-up arrow | |
5857 |---------------------+------------------------|
5858
5859 |-------------------+----------------------------+---------------------------------+--------------------+---------------+-------------+-------------|
5860 | mouse | | C- | M- | S- | C-M- | C-S- |
5861 |-------------------+----------------------------+---------------------------------+--------------------+---------------+-------------+-------------|
5862 | mouse-2 mode line | [[#69aaa631-6fb5-4beb-b2d8-c0f3d92c0a98][mouse-delete-other-windows]] | [[#501479ab-e1e2-497e-bd86-071f8afa3378][mouse-split-window-horizontally]] | | | | |
5863 | mouse-3 mode line | [[#917a1844-8c38-4f31-8616-50fc81334f2c][mouse-delete-window]] | | | | | |
5864 | mouse-1 | [[#4e60e2e4-8c2f-4450-8060-2d793ede530c][set cursor/mark]] | [[#b661f84f-57df-4095-9dc1-d1a876a53ee5][buffer list context menu]] | | | | |
5865 | mouse-2 | [[#086b0b50-054f-462d-92fa-b27852f887b0][paste]] | | | | | |
5866 | mouse-3 | [[#0481632e-9c50-4328-9365-c4b5bf967b66][set-mark]] | [[#9623c78f-7705-4cbe-a990-c24eb1067377][global menu]] | | | | |
5867 | mouse-9 | [[#efaec161-b279-4129-86fd-b410430926e4][move-mouse-to-point]] | | | | | |
5868 | mouse-8 | | | | | | |
5869 | 1/kp-end | | | | | | |
5870 | 2/kp-down | | | [[#50db5a06-452e-491f-875b-3de936a4d04a][smex]] | | | |
5871 | 3/kp-next | | | | | | |
5872 | 4/kp-left | [[#c44d0f65-9502-4cc6-9642-96d907f6b093][indent-region]] | | | | | |
5873 | 5/kp-begin | [[#2458c6bc-7113-4d4b-bbdf-206e1cb842a7][mark-defun]] | | | | | |
5874 | 6/kp-right | [[#3b79bc58-6067-43bd-9471-9d592744a25a][ibuffer]] | | | | | |
5875 | 7/kp-home | | | | | | |
5876 | 8/kp-up | | | | | | |
5877 | 9/kp-prior | [[#a3b51adb-4405-4d9f-9b88-a8faa479fbe7][delete-horizontal-space]] | | | | | |
5878 | 10/kp-insert | | | | | | |
5879 | 11/kp-subtract | | | | | | |
5880 | 12/kp-add | | | | | | |
5881 | 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]] |
5882 | 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]] |
5883 |-------------------+----------------------------+---------------------------------+--------------------+---------------+-------------+-------------|
5884
5885 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5886 | left primary | C- | M- | C-M- | C-S- |
5887 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5888 | 2 | [[#b7db9f5c-f31d-45fb-ac70-eb3ef9369d3d][copy-symbol]] | [[#53ecfda2-d9f6-4882-b7a2-9b3c859e3bcb][shell-cd-to-file]] | [[#33c4996d-92bc-4df0-b005-11553677be13][---]] | |
5889 | 3 | [[#401f56ff-6aba-4156-b128-f449b18c27af][dot-mode-execute]] | | [[#eb0cc3a8-b62e-4a24-9f84-cc8e854f91dd][recenter-top-bottom]] | |
5890 | 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]] | |
5891 | w | [[#20005b6d-9a9d-4b58-882c-7ce860c7a395][goto-t.org]] | [[#9531a0da-269f-4359-9124-e83fbf61a92f][org-clock-in]] | | |
5892 | e | [[#11e8f541-f0a0-4058-883a-98bd1e7b8c4d][copy-line]] | [[#74d0ed51-ddb5-488e-bf55-0f033916e319][org-clock-in-last]] | | |
5893 | r | [[#5088a8b2-a772-4660-a3b6-b8cca7099da6][isearch-backward]] | [[#8fe64424-1f11-4086-84b3-07c2af210c1c][org-clock-out]] | | |
5894 | 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]] | |
5895 | s | [[#f26dd0f5-0655-485f-8c76-e6dfc6abd947][C-x prefix]] | | [[#290ea04a-be99-416a-a95f-458045a91c93][split-window-vertically]] | |
5896 | d | [[#b699614a-9994-4fe7-b2c6-f0fe81b7ad2b][C-c prefix]] | | [[#d9f48fbe-0a32-4133-93fb-f43ff6ab0037][swap buffer]] | |
5897 | 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]] | |
5898 | g | [[#a58a1eda-43ed-437e-b483-5c312e0754a7][other-window / cancel]] | [[#a287d720-4419-4546-8262-1f377bb158d2][abort-recursive-edit]] | [[#327e18af-30b7-47e5-aa53-5f678788b4c1][gnus]] | |
5899 | z | [[#5c30ce7e-8bc6-45bf-b9b1-5c75334a3e27][undo-tree-undo]] | | | |
5900 | x | [[#ec1403d3-528e-41b1-a195-5563bc93e124][kill-region]] | [[#bb7c95d5-dd97-439d-bf1f-cdac98d11543][append-next-kill]] | [[#47cc90e3-335f-4c44-9f39-b732e5440664][append-next-kill]] | |
5901 | c | [[#400f06e1-8e45-443c-8d7b-3d1bb1176aab][copy]] | [[#7a265014-1e9c-4639-ad1d-26b3416379a8][org-capture]] | [[#503e0beb-6fda-4e94-9678-d58bd3cbbc8e][copy-to-register]] | |
5902 | v | [[#16411f68-7fe0-49e8-9a73-212471594f9e][yank]] | [[#fe04fffa-6f85-483a-b329-938531109c35][insert-register]] | [[#c559e9ea-1218-4ccb-9c3a-74cbac4be220][yank pop]] | |
5903 | 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]] | |
5904 | tab | [[#928505cb-707c-47ba-af54-5ae1df2ee07d][yas-insert-snippet]] | [[#64f91d86-afa9-4500-8d7d-ce8b2668726b][indent line]] | | |
5905 | delete | [[#e3d8653e-2282-4e3a-a4f5-29211ba2e647][kill-symbol]] | | [[#d9664937-d61c-4cc8-89c6-7f2182655c20][kill-sexp]] | |
5906 | left-arrow | [[#601c8172-f9b7-4e36-88ab-c66c2911b4d7][compile]] | | [[#91ddc121-db27-4f1c-a9ec-a4d29b96a7d2][org-shiftup]] | |
5907 | right-arrow | [[#5f66f60b-adcd-45dc-86b2-5d1225e2455c][paste selection]] | | [[#fc2147b4-a19a-4fde-bb53-e7ac28f0bfa1][org-shiftdown]] | |
5908 | backspace | [[#96f90a00-2260-4340-ae03-f4a86bd65502][backward-kill-symbol]] | | [[#606b0991-7431-4a8a-a909-b872e104cc88][backward-kill-sexp]] | |
5909 | f7 | | | | |
5910 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5911 | right primary | C- | M- | C-M- | C-S- |
5912 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5913 | * | [[#045c374c-b03e-42cb-b274-0f30c81fe3f3][split-window-horizontally]] | | [[#05cf6230-9263-4fd4-9812-4f32009eed46][calc-dispatch]] | |
5914 | 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]] | |
5915 | u | [[#327992c0-6eba-4935-aec1-49871c2a8619][universal-argument]] | | [[#7af825b1-92d8-4d5d-aaa1-8b4b466ea2e0][search-keybind]] | |
5916 | i | [[#3124e200-1d6e-4ad2-9a36-0d03e1e7dc38][-----]] | | [[#b2cc7cdd-c177-4ef2-af43-28ca7a338fda][query-replace-regexp]] | |
5917 | o | [[#b87a2c8a-7eb3-4661-9b28-589d14206c41][occur]] | | [[#d30ac3cd-1963-4bd0-8052-98e12b6524b0][counsel-imenu]] | |
5918 | p | [[#d84de055-e92e-478d-bb39-bc39acfa1586][move-mouse-to-point]] | | [[#08e65732-2fb1-4a78-9d18-cee87eb867a7][delete-horizontal-space]] | |
5919 | j | [[#ca1ce86b-dcea-45c1-9a8e-dd4f306776e8][pop-to-mark]] | [[#b92414e2-0d5b-4576-8fa5-5e7f1e32819a][previous-error]] | [[#8fe7cac2-ab1a-4b39-aced-10c5e0157e68][register prefix]] | |
5920 | k | [[#eb1c2360-bfd4-4d5c-b789-11b5ca5ba475][jump to register]] | [[#9061b192-735a-4273-ae36-993e6fad9205][next-error]] | [[#e1d768be-6b9b-4322-931f-3e570376ae15][man]] | |
5921 | l | [[#137995db-ee30-4738-90e2-54dcd5cadcf2][ivy-switch-buffer]] | | [[#56fcff3b-ffd9-4280-a226-4b58558906b8][move cursor top bottom mid]] | |
5922 | ; | [[#150bef9a-3faa-4c72-a176-88c3be56f612][comment-dwim]] | [[#211e76d9-d89a-4cc6-abce-69397d456fda][comment-dwim]] | [[#17035e1e-bbe6-44a6-ad54-6a39b04feac3][comment-current-line-dwim]] | |
5923 | m | | | [[#9a6a1998-4ed6-485e-9b2d-c36a42d7ec1a][recursive grep]] | |
5924 | , | [[#e4f617b2-d3f1-47e4-ae7f-2d64c4fd47b9][counsel-find-file]] | | [[#e0691924-11e1-48d2-abee-27945a409676][find-file-in-project]] | |
5925 | . | [[#6e97b7f1-c5cf-48bb-9c09-db1950dc1eae][recentf-ido-find-file]] | | [[#824d422c-67b6-4d68-af11-6a2135e528f5][-]] | |
5926 | / | [[#941a7fa8-84b9-434d-89a0-1487385ec479][join lines]] | | [[#37f67593-4f60-4d3b-9aad-6c9bc4882443][copy-variable]] | |
5927 | 8 | [[#45644cfa-d408-4a69-a97a-545ef46ba656][calc-embedded-word]] | | | |
5928 | up-arrow | [[#2dade04a-8ac7-483c-8675-5268af6eca2b][back defun/headline]] | | | [[#572d6618-471a-43c7-8a50-3f5e56f45cd7][winner undo]] |
5929 | 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]] |
5930 | lbracket | [[#9d9916dd-3280-47dd-aab1-cd28d5ebfe15][----]] | | [[#c10b53e9-657c-48f4-8afb-cad0e709bcd6][scroll-right]] | |
5931 | rbracket | [[#21b38c6b-3a46-4a08-8eca-d44abb148287][fill-paragraph]] | | [[#095c3d97-bc49-419a-a8c0-c7a21d46d980][scroll-left]] | |
5932 | 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]] | |
5933 | space | [[#b7d5a893-3045-4968-a150-cb813fddfe9e][org-edit-special]] | | [[#47b5912e-edc7-42ec-841b-f0e202b7f593][spell check word]] | |
5934 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5935 | left secondary | C- | M- | C-M- | C-S- |
5936 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5937 | = | | | | |
5938 | 1 | | | | |
5939 | 4 | | | [[#2d4de3c9-9e0c-4ab4-89e3-e41bfed3c9a7][widen]] | |
5940 | 5 | | | | |
5941 | tab-key | [[#2f527321-7f78-421b-b0c4-6fc810da0246][query-replace]] | | | |
5942 | t | [[#3bcdf4a3-f33c-4dad-ba94-e4fd3775eca6][org change todo state]] | | [[#47c64b9c-346d-45ad-8c38-865fe22d31a6][org insert timestamp]] | |
5943 | home | [[#1919659a-b466-4519-9276-8bf06a916066][start of buffer]] | | | |
5944 | end | [[#0a7bd629-cbcc-4761-8fe2-cc9370b985a4][end of buffer]] | | | |
5945 | f9 | | | | |
5946 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5947 | right secondary | C- | M- | C-M- | C-S- |
5948 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5949 | 6 | [[#e44e584b-d925-4036-9ad5-a90d02e74bef][save-buffers-kill-emacs]] | | [[#da73de75-0914-4f48-81d5-9b408433b14b][insert-small-copyright]] | |
5950 | 7 | | | [[#a68c6b8e-9911-475e-ab35-e239771fe881][insert-full-copyright]] | |
5951 | 0 | [[#96ae2fcc-3a0c-40c4-aef8-06aff3fd42be][text-scale-reset]] | | [[#0e7f83a5-600e-4016-af98-95904300c016][insert-apache]] | |
5952 | - | | | [[#6febc7ea-9cc7-488c-af34-538b8e69633b][org-edit-src-exit]] | |
5953 | y | [[#97aee7f1-3647-4602-a65a-45e8a3aa3a7c][undo-tree-redo]] | | | |
5954 | \ | [[#69005926-08ab-4adc-a163-44fed609cc95][sr-speedbar-toggle]] | | [[#27045e96-59a3-45b4-b0ff-6247aa5ed47e][mark-defun]] | |
5955 | h | [[#3c5f241f-fc62-459d-ab85-6b7c1fb04801][help-prefix]] | | | |
5956 | ' | [[#9f252721-a2d5-46c6-b268-8ed597256229][eval-expression]] | | | |
5957 | n | [[#65ac9206-1a67-48dc-8b72-26d763d7bf2b][unpop-to-mark-command]] | | [[#34fb8fbd-42dc-46b0-8c3c-c7e51edc9687][narrow-to-region]] | |
5958 | rshift | | | | |
5959 | escape | [[#da8bae21-a7be-45de-8027-1b26e6285e40][find-tag]] | | | |
5960 |-----------------+--------------------------------+---------------------------------+-------------------------------+--------------------------|
5961 #+END:
5962
5963 * persistent registers
5964 This needs to be at the end, because I visit a file, thus setting a
5965 mode, and the mode hook needs to be setup before that.
5966
5967 I'm using persistent registers instead of bookmarks. I dun use them
5968 much, so the added hassle of having to set it within this file is
5969 worth the benefit of only having one concept in my mind.
5970 #+begin_src emacs-lisp
5971 (dolist
5972 (r `(
5973 (?i (file . ,"~/.emacs.d/my-init.org"))
5974 (?t (file . ,"/a/x.txt"))
5975 ))
5976 (set-register (car r) (cadr r)))
5977 #+end_src
5978
5979 * keybind notes
5980 common keys, which would be better off doing swaps than rebinds:
5981 c-x prefix -> c-s
5982 c-c prefix -> c-d
5983 yank c-y -> c-c
5984 search c-s -> kp-add
5985 kill line c-k -> c-f
5986 undo c-_ -> c-z
5987 set-mark-command c-@ -> kp-enter
5988 quoted-insert c-q -> c-m-q
5989 recenter-top-bottom c-l -> c-m-3
5990 kill-region c-w -> c-x
5991
5992 commands to make less accessible
5993 narrow-to-defun/subtree -> M-2 maybe
5994 occur
5995
5996 command to make more accessible, ...
5997
5998
5999 * misc useful functions I'd rather have in a list than burried
6000 #+begin_src emacs-lisp :tangle no
6001 ;; these are usefull with (goto-char)
6002 ;; find named entity, other than headline
6003 (org-find-entry-with-id "string-number-or-symbol")
6004
6005 (org-find-exact-headline-in-buffer "heading" nil t)
6006
6007 (byte-recompile-file (expand-file-name "~/.emacs.d/my-init.el") t 0)
6008 (byte-recompile-directory (expand-file-name "~/.emacs.d") 0)
6009 (byte-recompile-directory (expand-file-name "~/.emacs.d/src/haskell-mode") 0)
6010
6011 ;; remove any indent level which is throughout the buffer
6012 (org-do-remove-indentation)
6013
6014 #+end_src
6015
6016 * TESTING / DEVELOPMENT AREA
6017
6018 ** new
6019 #+begin_src emacs-lisp
6020
6021
6022 #+end_src
6023
6024 ** key logging
6025 this article convinced me that trying to experiment with modal editing is a waste.
6026 http://chrisdone.com/posts/speculations-on-exclusive-editing
6027 I want to record my emacs commands simply to find optimiaztions, like if I often do some M-x command and should bind it
6028 to a key.
6029
6030
6031 #+begin_src emacs-lisp :tangle no
6032
6033 (setq keylog-list nil)
6034 (setq keylog-mode nil)
6035
6036 (defun keylog-save ()
6037
6038 ;; Check that the lock file does not exist
6039 (when (keyfreq-file-is-unlocked)
6040 ;; Lock the file
6041 (keyfreq-file-claim-lock)
6042
6043 ;; Check that we have the lock
6044 (if (eq (keyfreq-file-owner) (emacs-pid))
6045 (unwind-protect
6046 (progn
6047 ;; Load values and merge them with the current keyfreq-table
6048 (keyfreq-table-load table)
6049
6050 ;; Write the new frequencies
6051 (with-temp-file keyfreq-file
6052 (prin1 (cdr (keyfreq-list table 'no-sort)) (current-buffer))))
6053
6054 ;; Release the lock and reset the hash table.
6055 (keyfreq-file-release-lock)
6056 (clrhash table))
6057 )))
6058
6059 (defun my-keylogger-function ()
6060 (setq keylog-list (cons (list (current-time) current-prefix-arg this-command) keylog-list)))
6061 (add-hook 'pre-command-hook 'my-keylogger-function)
6062
6063 #+end_src
6064
6065 in a lisp expression, ; \\[ throws off forward-sexp
6066 when not in emacs lisp mode,
6067 even with (with-syntax-table emacs-lisp-mode-syntax-table
6068 forward-sexp)
6069 which is found in preceding-sexp
6070 potentially a bug, either in with-syntax-table, or
6071 in scan-lists, which is implemented in C
6072
6073
6074
6075
6076 why did it go to the init file?
6077 change EDITOR to emacsclient
6078 xserver-xorg-core=2:1.14.3-3ubuntu2
6079 (setq-default header-line-format nil) ; Copy mode-line
6080 (setq-default mode-line-format nil) ;
6081
6082
6083 #+RESULTS:
6084 : set-food-completions
6085
6086
6087
6088 useless gnus group keys:
6089 a
6090 c
6091
6092
6093 (add-to-list 'load-path "~/.emacs.d/emacs/site-lisp/org")
6094
6095 #+begin_src emacs-lisp
6096 (add-hook 'org-mode-hook
6097 (lambda () (define-key org-mode-map (kbd "C-y") nil)))
6098
6099 #+end_src
6100
6101
6102
6103
6104 (defun comint-send-string (process string)
6105 "Like `process-send-string', but also does extra bookkeeping for Comint mode."
6106 (if process
6107 (with-current-buffer (if (processp process)
6108 (process-buffer process)
6109 (get-buffer process))
6110 (comint-snapshot-last-prompt))
6111 (comint-snapshot-last-prompt))
6112 (process-send-string process string))
6113
6114
6115 * python
6116 todo: get smart-operator to work
6117 todo, checkout https://github.com/python-rope/ropemacs refactoring python,
6118 todo, try py-autopep8, autoformatter
6119 todo, check out some python linting stuff. pychecker is one, others are in *packages*
6120 todo, finish reading through python-mode.el functions
6121 ;; todo, figure out multi-line input in shell mode
6122
6123
6124 usefull m-x commands:
6125 m-x py-describe-mode: doc for mode which is extensive
6126 m-x py-sort-imports
6127 m-x py-guess-indent-offset: setup indent for code i didn't write
6128
6129 possibly usefull commands:
6130 found via looking through python-mode.el, quit like 1/4 through, cuz its tedious, last spot was at:
6131 (defun py-comment-region (beg end &optional arg)
6132 after finding py-describe-mode, it seemed to do a good job of documenting all the most important stuff
6133
6134 py-switch-to-python
6135 python-shell-completion-complete-or-indent may be usefull to get completion working in the shell
6136 py-insert-default-shebang
6137 py-electric-*
6138 py-indent-line-outmost
6139 py-newline-and-close-block
6140 py-indent-and-forward (indent line, move to next)
6141 py-fill-*
6142 py-which-function (for showing in the modeline)
6143 py-help-at-point
6144 py-execute-import-or-reload
6145 py-execute-def-or-class
6146 various pdb functions
6147
6148
6149 installing jedi
6150 #+begin_src sh :tangle no
6151 pi python-pip
6152 s pip install jedi virtualenv
6153 #+end_src
6154 then do m-x jedi:install-server
6155
6156
6157
6158 disabled because it takes 152 ms to load,
6159 and I don't know how to do it conditioally
6160 #+begin_src emacs-lisp :tangle no
6161
6162 ;; change from default python3 to be compatibile with Pywikibot
6163 (setq py-shell-name "/usr/bin/python")
6164 (require 'python-mode)
6165
6166 (setq py-autopep8-options '("--max-line-length=110"))
6167
6168 (defun py-execute-block-or-clause-create-shell ()
6169 (interactive)
6170 (cond ((get-buffer "*Python*")
6171 (py--execute-prepare "block-or-clause")
6172 (py-execute-block-or-clause)
6173 (call-interactively 'next-line))
6174 (t
6175 (py-shell)
6176 ;; py-shell starts the shell but not display the buffer on the first run
6177 ;; subsequent runs, it does. I grabbed this command from inside to
6178 ;; do just the relevant part from the second run, as a hack.
6179 ;; todo: report a bug on this
6180 (py--shell-manage-windows py-buffer-name))))
6181 (setq py-tab-shifts-region-p t)
6182 (setq py-tab-indents-region-p t)
6183
6184 (defun py-run ()
6185 "default action to run the current buffer"
6186 (basic-save-buffer)
6187 (py-execute-buffer))
6188
6189
6190 (add-hook 'python-mode-hook
6191 (lambda ()
6192 (setq run-fun 'py-run)
6193 (define-key python-mode-map (kbd "C-M-a") nil)
6194 (define-key python-mode-map (kbd "C-M-d") nil)
6195 (define-key python-mode-map (kbd "C-M-e") nil)
6196 (define-key python-mode-map (kbd "C-M-h") nil)
6197 (define-key python-mode-map (kbd "C-M-i") nil)
6198 (define-key python-mode-map (kbd "C-M-u") nil)
6199 (define-key python-mode-map (kbd "C-M-x") nil)
6200 (define-key python-mode-map (kbd "<tab>") 'indent-for-tab-command)
6201 (define-key python-mode-map (kbd "C-j") nil)
6202 (define-key python-mode-map (kbd "<C-backspace>") nil)
6203 ;;(define-key python-mode-map (kbd "C-(") (lambda () (interactive) (basic-save-buffer) (py-execute-buffer)))
6204 ;; fix default return bindings
6205 (define-key python-mode-map (kbd "C-j") nil)
6206 (define-key python-mode-map (kbd "RET") nil)
6207 (define-key python-mode-map (kbd "<return>") 'py-newline-and-indent)
6208 (define-key python-mode-map (kbd "<M-tab>") 'py-indent-line)
6209 (define-key python-mode-map (kbd "C-M-(") 'py-shift-left)
6210 (define-key python-mode-map (kbd "C-M-)") 'py-shift-right)
6211 (define-key python-mode-map (kbd "<home>") 'py-beginning-of-line)
6212 (define-key python-mode-map (kbd "<end>") 'py-end-of-line)
6213 (define-key python-mode-map (kbd "C-t") 'py-execute-block-or-clause-create-shell)
6214 (define-key python-mode-map (kbd "<S-delete>") 'py-ian-execute-line-or-region)
6215 ;; python mode adds these to this list, which is normally empty.
6216 ;; it makes my send-python function not reuse an existing python shell window
6217 ;; there are other ways to override this, but I don't know of any other value of
6218 ;; having this set.
6219 (setq same-window-buffer-names (delete "*Python*" same-window-buffer-names))
6220 (setq same-window-buffer-names (delete "*IPython*" same-window-buffer-names))))
6221
6222 ;; i dunno, why, but this didn't work:
6223 ;; and we can't eval-after-load cuz it is part of the greater python mode file
6224 (add-hook 'py-shell-hook
6225 (lambda ()
6226 (define-key py-shell-map "\r" nil)
6227 (define-key py-shell-map (kbd "<return>") 'comint-send-input)
6228 (define-key py-shell-map (kbd "C-t") 'py-shell-toggle-arrow-keys)
6229 (define-key py-shell-map "\C-d" nil)
6230 (define-key py-shell-map (kbd "<up>") 'my-comint-previous-input)
6231 (define-key py-shell-map (kbd "<down>") 'my-comint-next-input)))
6232
6233
6234 (defun py-ian-execute-line-or-region ()
6235 (interactive)
6236 (cond ((get-buffer "*Python*")
6237 (if mark-active
6238 (py-execute-region)
6239 (py-execute-statement))
6240 (call-interactively 'next-line))
6241 (t (py-shell))))
6242
6243 ;; http://tkf.github.io/emacs-jedi/latest/
6244 (add-hook 'python-mode-hook 'jedi:setup)
6245 (setq jedi:complete-on-dot t)
6246
6247 (defun py-shell-toggle-arrow-keys ()
6248 (interactive)
6249 (toggle-arrow-keys py-shell-map))
6250
6251 #+end_src
6252
6253
6254 ;; py-shell window stuff
6255 ;; it splits the window if the shell is in a different frame
6256 ;; which seems to be a bug, but it can be fixed with this option
6257 ;; (setq py-keep-windows-configuration 'force)
6258 ;; however, with py-execute-block-or-clause, if the shell is in a different frame,
6259 ;; you get errors "buffer is read only", when the point is near the beginning of a command
6260 ;; todo: test with emacs -Q and file a bug
6261 ;; if you execute py-execute-... without a python shell open,
6262 ;; it starts one, doesn't display it, and subsequent py-execute commands
6263 ;; give error "buffer is read only"
6264 ;; these functions fix / improve these problems
6265
6266
6267 ** initial python-mode setup
6268
6269 python-mode seems to be the most canonical package, based on
6270 https://docs.python.org/devguide/emacs.html
6271 much more feature rich than the emacs built in one.
6272
6273 getting it, it wants you to setup an account on launchpad by default,
6274 there is some way to get anonymous bzr access, but google didn't answer it right away,
6275 so fuck it, ill go the happy path.
6276
6277 based on error messages,
6278 add public ssh key to https://launchpad.net/people/+me
6279 bzr launchpad-login iank
6280 cd ~/.emacs.d/src/
6281 bzr branch lp:python-mode
6282
6283 add lines from INSTALL to init
6284
6285
6286 ** background on packages
6287 jedi appears most popular based on github stats
6288 pysmell appears dead
6289 ac-python appears dead
6290 https://github.com/proofit404/anaconda-mode seems to be kicking along
6291
6292
6293 ** misc notes:
6294
6295 python-mode has a TON of functions that are just aliases or verbatim wrappers of other functions.
6296 also has undocumented/unused vars all around. it is quite annoying.
6297
6298 the dedicated argument to py-shell does nothing,
6299 and py-dedicated-shell just sets that, so it is a waste
6300
6301
6302 ** background on sending to python shell
6303
6304 using the builtin python execute shell functions, sending one line doesn't really work well.
6305 The bulit in functions don't wait for further input if a block is not closed.
6306 And doing a copy/paste thing gets messed up because of indents.
6307 With some hacking, I could probably do copy/paste and remove indents, only to a
6308 certain level if we have entered a block and are waiting to finish it.
6309 But just doing the builtin execute block is a decent work around.
6310
6311
6312 Here is the scrapped function for single line built in sending to shell.
6313
6314
6315 (setq w32-enable-num-lock nil)
6316 (global-set-key (kbd "<num_lock>") 'left-char)
6317
6318
6319 (defun sqlup-find-correct-keywords ()
6320 "If emacs is handling the logic for syntax highlighting of SQL keywords, then we piggyback on top of that logic. If not, we use an sql-mode function to create a list of regular expressions and use that."
6321 (mapcar 'car (sql-add-product-keywords sql-product '())))
6322
6323
6324 largest subarray sum, array of pos and neg ints.