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