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