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