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