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