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