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