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