1 ;; Copyright (C) 2020 Ian Kelling
3 ;; This program is free software: you can redistribute it and/or modify
4 ;; it under the terms of the GNU General Public License as published by
5 ;; the Free Software Foundation, either version 3 of the License, or
6 ;; (at your option) any later version.
8 ;; This program is distributed in the hope that it will be useful,
9 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;; GNU General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ;; do m-x benchmark-init to see some benchmark stats
17 ;;(add-to-list 'load-path (concat user-emacs-directory "src/benchmark-init-el/")
18 ;;(require 'benchmark-init-loaddefs)
19 ;;(benchmark-init/activate)
21 ;;; init.el --- the start of customization
23 ;;(toggle-debug-on-error) ;uncomment to help debug
26 ;; stop from minimizing & freezing the gui
27 ;; used to freeze emacs and was really annoying,
28 ;; seems its changed now. no harm in keeping this though.
29 (global-unset-key (kbd "C-z"))
31 ;; speed up init https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/
32 ;; https://github.com/jwiegley/dot-emacs/blob/master/init.el
33 (defvar file-name-handler-alist-old file-name-handler-alist)
34 (setq package-enable-at-startup nil
35 file-name-handler-alist nil
37 gc-cons-threshold 402653184
38 gc-cons-percentage 0.6
39 auto-window-vscroll nil)
41 (add-hook 'after-init-hook
43 (setq file-name-handler-alist file-name-handler-alist-old
45 gc-cons-threshold 100000000))
46 ;; taken from wiegley, dunno why the t is there.
49 ;; stuff to allow an alternate location for ~/.emacs.d
50 (setq user-emacs-directory (file-name-directory user-init-file))
51 (when (getenv "EHOME")
52 (setenv "HOME" (getenv "EHOME")))
56 ;; ; uncomment the following block
57 ;;(require 'benchmark-init)
58 ;;(add-hook 'after-init-hook 'benchmark-init/deactivate)
60 ;; ; emacs -f benchmark-init/show-durations-tabulated
61 ;; ; emacs -f benchmark-init/show-durations-tree
62 ;; ; to catch things post-init
63 ;; ; emacs -f benchmark-init/deactivate
66 ;; these need to be done before the hook in order to satisfy the byte compiler or batch mode
68 (add-to-list 'load-path (concat user-emacs-directory "src/readline-complete"))
70 ;; disabled since not used.
71 ;;(add-to-list 'load-path (concat user-emacs-directory "src/bbdb-csv-import"))
72 ;;(add-to-list 'load-path (concat user-emacs-directory "src/spray"))
74 (add-to-list 'load-path (concat user-emacs-directory "src/visible-mark"))
78 (setq init-dir (file-name-directory load-file-name))
79 ;; previously, i was doing byte-recompile-directory, but
80 ;; now i just have one init file
81 (unless (equal (user-uid) 0) ; don't make root owned files
82 (byte-recompile-file (expand-file-name "init.el" init-dir) nil 0)
83 (when (file-exists-p "/p/c/mymu4e.el")
84 (byte-recompile-file "/p/c/mymu4e.el" nil 0))
87 ;;; misc emacs documentation
89 ;;;; how to find auto-saved files that need recovering
90 ;; find a recently dated file in ~/.emacs.d/auto-save-list/, and see the files listed in it.
91 ;; #file# is an auto-save file. It may or may not be different than the file is corresponds to.
92 ;; If it is different, emacs will give a message about recovering it when you open it.
94 ;;;; misc org functions
96 ;; ;; these are usefull with (goto-char)
97 ;; ;; find named entity, other than headline
98 ;; (org-find-entry-with-id "string-number-or-symbol")
100 ;; (org-find-exact-headline-in-buffer "heading" nil t)
102 ;; ;; remove any indent level which is throughout the buffer
103 ;; (org-do-remove-indentation)
108 ;; good info http://www.emacswiki.org/emacs/GnusTutorial
109 ;; good info http://www.emacs.uniyar.ac.ru/doc/em24h/emacs183.htm
112 ;; After downloading mailing list archives, once you have an mbox file,
113 ;; there are rather straightforward ways to get it into any mail program,
114 ;; but I will cover gnus, which I use and is a bit tricky.
116 ;; gnus has a native search (limited, too slow for body text searches), and external search engine integration.
117 ;; gnus manual recommends converting to maildir for searching local mail, but importing lots of maildir messages to gnus
118 ;; takes 10+ minutes, so scratch that option. it suggests 2 alternate options
119 ;; mairix. for mbox, it doesn't integrate 100% with gnus, it copies the search results to a mbox
120 ;; and tells gnus to make a group of that mbox and display it. This means the read state won't be persistent, but otherwise
123 ;; local imap server which will use the mbox and provide search.
124 ;; dovecot is modular, theres a dovecot-common which uses recommends to install i guess it's most used modules. Its
125 ;; description is completely not useful. Anyways, I'm not sure if there is any benefit to installing this over just the
129 ;; dovecot by default also makes a an inbox folder based on the normal local mail location /var/mail/<username>
130 ;; those locations are adjustable and well documented via the var mail_location in
131 ;; /etc/dovecot/conf.d/10-mail.conf
132 ;; 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
133 ;; is. you could make the var be empty, which apparently has the same effect.
135 ;; Originally just linked the default location ~/.mail, but I changed to altering the config since ~/.mail since it seems
136 ;; other things like postfix use that location
138 ;; based on http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html
139 ;; other links that poped up contained outdated, innacurate information
140 ;; http://sachachua.com/blog/2008/05/geek-how-to-use-offlineimap-and-the-dovecot-mail-server-to-read-your-gmail-in-emacs-efficiently/
141 ;; http://www.emacswiki.org/emacs/JamesFerguson
142 ;; http://www.sanityinc.com/articles/read-mailing-lists-in-emacs-over-imap/
144 ;; Within emacs you can move messages between mbox and maildir etc, which is a nice flexibility.
148 ;; doc group for mbox:
149 ;; in gnus, do gnus-group-make-doc-group (G f in groups buffer) and point to the file
151 ;; info about groups created within gnus is stored in ~/.newsrc.eld
152 ;; also stored is a duplication of what email messages are read/unread,
153 ;; what newsgroups are subsribed to and read/unread,
154 ;; probably more stuff, everything that gnus saves.
157 ;; searching the body of the messages, i cut off after a few minutes.
158 ;; i can grep the file in just a couple seconds
162 ;; we can also get mbox from gmane
163 ;; http://notmuchmail.org/howto/#index7h2
166 ;; gnus can't search mboxes except with its builtin search which is extremely slow. mairix can do mbox files from the command
167 ;; line, but not from within gnus, but from mairix.el, which can then open the results in gnus
169 ;; mbox can be converted to maildir easily, but gnus loads lots of maildir messages extremely slow. it parses all the
170 ;; headers and generates a nov file for each.
172 ;; nnfolder-generate-active-file
174 ;; to reset things, when changing mail group. I duno all the proper way, but it works to delete
175 ;; ~/Mail ~/.newsrc.eld ~/.newsrc-dribble
178 ;;;;; mail sources vs select methods background
179 ;; I found this very confusing when first reading through the manual. "mail sources" is a term that does not simply mean
180 ;; sources of mail, it is much narrower for gnus. sources of mail can be either "mail sources" or select methods. Mail
181 ;; sources will move mail to ~/Mail (not sure what format), and split it into groups according to variables. You can use
182 ;; "mail sources" for maildir / imap, but those can also be read via select methods, which do not move the mail from their
183 ;; location, but use them in their native format. This is what I want to do, and I can simply ignore mail
184 ;; sources. Confusing terminology is that "fetching mail" "scanning mail", lots of things mail doesn't mean all mail, it
185 ;; means specifically from "mail sources". The words "articles" and "news" is used in connection with select methods, aka my actual mail.
189 ;;;;; caching background
192 ;; there is also ~/News/cache, filled with a bunch of articles, like 300 megs. can't figure out why.
193 ;; Grepped for caching in the manual, found 2 main things.
194 ;; cache is for 2 purposes. to cache locally, and to keep articles from expiring, called persistence
195 ;; gnus-use-cache, which puts things if they are
196 ;; gnus-cache-enter-articles
197 ;; things go in cache when they are marked certain ways by default, ticked and dormant
198 ;; and read articles are moved out of the cache
199 ;; still no idea why i have a bunch in the cache, but I set a var so that my mail won't get cached
200 ;; I'm gonna delete the cache, and check on it later see what exactly is going in there
201 ;; And of course, I moved ~/News to my encrypted drive and symlinked it
205 ;;; things that should be at the beginning
207 ;; from its README.md
209 (require 'use-package))
212 ;; Ubiquitous Packages. these could go anywhere actually
214 ;; find file at point
220 (setq package-archives
222 (("gnu" . "https://elpa.gnu.org/packages/")
223 ("MELPA" . "https://melpa.org/packages/"))))
225 ;;(add-to-list 'package-archives
227 ;; "http://marmalade-repo.org/packages/"))
229 ;; down atm 2020-08-30
230 ;;(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
233 ;; keep our init.el clean, by moving customization elisp to it's own file
234 (setq custom-file (concat user-emacs-directory "custom.el"))
236 ;;(load custom-file 'noerror)
241 ;; auto-completion in minibuffer
242 ;; disabled while I look for another alternative
245 (require 'auto-complete-config)
249 ;; complete after 1 char instead of default 2
250 (setq ac-auto-start 1)
251 (setq ac-delay 0.001)
253 (add-to-list 'ac-modes 'org-mode 'sql-mode)
256 ;; for org mode completion source taken from wiki.
257 ;; it did not work. no idea why. todo, investigate
258 ;; the ac-sources code is at http://www.emacswiki.org/emacs/AutoCompleteSources
259 ;; i've deleted it here so as to save space and not spam this file
260 ;;(defun my-ac-org-mode ()
261 ;; (setq ac-sources (append ac-sources '(ac-source-org))))
264 ;; this makes the org-self-insert command not do a flyspell spell check.
265 ;; low priority thing to look into sometime
266 (ac-flyspell-workaround)
269 (define-key ac-completing-map (kbd "<up>") nil)
270 (define-key ac-completing-map (kbd "<down>") nil)
271 (define-key ac-completing-map (kbd "<S-return>") 'ac-expand)
272 (define-key ac-completing-map "\t" 'ac-complete)
273 ;;(define-key ac-completing-map (kbd "<tab>") 'ac-complete)
274 (define-key ac-completing-map (kbd "TAB") 'ac-complete)
278 ;;; auto-complete readline-complete
280 (require 'readline-complete)
281 ;; not sure how I made these, but I deleted, and
282 ;; it would be nice to make them again sometime
283 ;;(require 'src-loaddefs)
285 ;; disabled cuz broken
286 ;; redefining function in readline-complete so ac-complete only uses readline as a source
287 (defun ac-rlc-setup-sources ()
288 "Add me to shell-mode-hook!"
289 (setq ac-sources '(ac-source-shell)))
290 (add-hook 'shell-mode-hook 'ac-rlc-setup-sources)
292 ;; generally unnecessary, but why not
293 (setq explicit-shell-file-name "bash")
295 ;; readline-complete says to add this line.
296 ;; however, it up my procfs directory tracking hook
297 ;; because get-process doesn't notice the child shell.
298 ;; instead, I've removed export EMACS=t from
299 ;; comint-exec-1 (the function which initially sets it)
300 ;; by finding it in emacs sources and redefinind it here
301 ;; and done stty echo in my bashrc
302 ;;(setq explicit-bash-args '("-c" "export EMACS=; stty echo; bash"))
305 (setq explicit-bash-args nil)
306 (setq comint-process-echoes t)
307 ;; default of 30 is way too slow. todo, consider pushing this upstream
308 (setq rlc-attempts 5)
310 (add-to-list 'ac-modes 'shell-mode)
312 ;; readline-complete recommends this (i assume this format),
313 ;; but greping finds no reference in emacs or my .emacs.d
314 ;; so I'm assuming it is for an older emacs
315 ;;(setq explicit-ssh-args '("-t"))
317 (add-hook 'shell-mode-hook
319 ;;(define-key shell-mode-map (kbd "<tab>") 'auto-complete)
320 (define-key shell-mode-map (kbd "TAB") 'auto-complete)
324 ;;; readline complete fix
326 ;; I need this function here, where INSIDE_EMACS is replaced with LC_INSIDE_EMACS.
327 ;; ian: last update 2017-1-7. update this periodically from upstream
328 ;; like when we do a major emacs update
329 (defun comint-exec-1 (name buffer command switches)
330 (let ((process-environment
332 ;; If using termcap, we specify `emacs' as the terminal type
333 ;; because that lets us specify a width.
334 ;; If using terminfo, we specify `dumb' because that is
335 ;; a defined terminal type. `emacs' is not a defined terminal type
336 ;; and there is no way for us to define it here.
337 ;; Some programs that use terminfo get very confused
338 ;; if TERM is not a valid terminal type.
339 ;; ;; There is similar code in compile.el.
340 (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
341 (list "TERM=dumb" "TERMCAP="
342 (format "COLUMNS=%d" (window-width)))
344 (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))
345 (list (format "LC_INSIDE_EMACS=%s,comint" emacs-version))
346 process-environment))
348 (if (file-accessible-directory-p default-directory)
351 proc decoding encoding changed)
352 (let ((exec-path (if (and command (file-name-directory command))
353 ;; If the command has slashes, make sure we
354 ;; first look relative to the current directory.
355 (cons default-directory exec-path) exec-path)))
356 (setq proc (apply 'start-file-process name buffer command switches)))
357 ;; Some file name handler cannot start a process, fe ange-ftp.
358 (unless (processp proc) (error "No process started"))
359 (let ((coding-systems (process-coding-system proc)))
360 (setq decoding (car coding-systems)
361 encoding (cdr coding-systems)))
362 ;; Even if start-file-process left the coding system for encoding data
363 ;; sent from the process undecided, we had better use the same one
364 ;; as what we use for decoding. But, we should suppress EOL
366 (if (and decoding (not encoding))
367 (setq encoding (coding-system-change-eol-conversion decoding 'unix)
370 (set-process-coding-system proc decoding encoding))
375 ;; todo: patch this so i can turn it off like my-as-off-local.
376 ;; then try it out and see if it can replace my autosave.
377 ;; Or maybe with the new auto-save-visited-mode.
378 ;; (use-package super-save
381 ;; (setq super-save-exclude '("")
382 ;; super-save-triggers
385 ;; org-babel-execute-src-block
388 ;; split-window-below
389 ;; split-window-horizontally
390 ;; start-process-shell-command
397 ;; (super-save-mode +1))
401 (setq auto-save-timeout 1) ; idle time before auto-save.
403 ;; main hook for my auto save
404 (add-hook 'auto-save-hook 'my-auto-save)
405 ;; additional hook to try to deal with emacs not auto-saving when a buffer isn't active
406 (add-hook 'window-configuration-change-hook 'my-auto-save-win)
408 ;; this function from mu4e really does not like buffer saving
409 (advice-add 'message-send-and-exit :before 'my-as-off)
410 (advice-add 'message-send-and-exit :after 'my-as-on)
412 ;; avoid window config hook saving too much, it can
413 ;; get into loops in some random situations
414 (defvar my-auto-save-last nil)
416 (defvar my-auto-save-last nil)
417 (defun my-auto-save-win ()
418 (unless (eq (current-buffer) my-auto-save-last)
419 (my-auto-save (current-buffer))))
421 (defun my-auto-save (&optional last)
425 ;; mu4e has a bug right now, undo breaks when saving drafts
426 (not (string= (buffer-file-name) "*draft*"))
428 (not (and (boundp 'org-src-edit-buffer-p) (org-src-edit-buffer-p))))
429 ;; serial is incremented on each save, so let's do a bit less of them
430 (not (derived-mode-p 'dns-mode))
431 (setq my-auto-save-last last)
432 (let (message-log-max)
433 ;; a bit of a hack to partially suppress the constant saving in the echo area
434 (with-temp-message ""
435 (basic-save-buffer)))))
437 ;; in the message-send-and-exit advice, got an error because it passed an arg.
438 ;; didn't look into why, just add ignored args.
439 (defun my-as-off (&rest ignore)
443 (defun my-as-off-local (&rest ignore)
445 (setq-local my-as nil))
447 (defun my-as-on (&rest ignore)
451 (defun my-as-on-local (&rest ignore)
453 (setq-local my-as t))
455 ;; based on suggestion in the emacs docs, redefine these 2 functions
456 ;; to avoid prompt spamming the user when we do auto-save
457 (defun ask-user-about-supersession-threat (fn)
460 "File for %s has changed on disk outside of emacs. Auto-save is overwriting it, however
461 a backup is being created in case that is not what you intended." buffer-file-name)
462 (setq buffer-backed-up nil))
464 (defadvice ask-user-about-lock (before lock-deactivate-as activate)
465 (make-local-variable 'my-as)
467 (message "proper autosave has been turned off for this buffer because of lock file problem.
468 In this buffer, do M-x my-as-on to reenable"))
470 ;; todo, this doesn't work consistently to override the auto-save message
471 (defalias 'do-auto-save-original (symbol-function 'do-auto-save))
472 (defun do-auto-save (&optional no-message current-only)
473 "This function has been modified to wrap the original so that NO-MESSAGE
474 is always set to t, since we auto-save a lot, it spams otherwise.
475 The original doc string is as follows:
477 Auto-save all buffers that need it.
478 This is all buffers that have auto-saving enabled
479 and are changed since last auto-saved.
480 Auto-saving writes the buffer into a file
481 so that your editing is not lost if the system crashes.
482 This file is not the file you visited; that changes only when you save.
483 Normally we run the normal hook `auto-save-hook' before saving.
486 A non-nil NO-MESSAGE argument means do not print any message if successful.
487 A non-nil CURRENT-ONLY argument means save only current buffer."
489 (do-auto-save-original t current-only))
491 ;; enable MY auto-save
494 ;;; backups, separate from auto-save
497 ;; set backup file location
498 (setq backup-directory-alist '(("." . "~/.editor-backups")))
499 (setq auto-save-file-name-transforms
500 '((".*" "~/.editor-backups/" t)))
502 (setq version-control t ;; Use version numbers for backups
503 kept-new-versions 100
505 delete-old-versions t ;; delete old versions silently
506 ;; assume hard linked files are done on purpose, don't screw them up
507 backup-by-copying-when-linked t)
509 (defvar last-backup-time 0)
510 ;; todo, the time needs to be an integer, not a vector type thing
511 (defun constant-backup ()
512 "Backup conditioned on some time passing since last one.
513 Hooked into 'before-save-hook."
514 (cl-flet ((b-time (minutes)
516 (- (current-time) (* 60 minutes)))))
517 (when (or (not (boundp 'last-backup-time)) (and (< (buffer-size) 10000000) (b-time 5)) (b-time 30))
518 (setq buffer-backed-up nil)
519 (setq-local last-backup-time (current-time)))))
521 ;; make a backup on auto-save, because the backup feature is not
522 ;; utilized with my-auto-save, only normal interactive save.
523 ;; todo, enable when fixed
524 ;;(add-hook 'before-save-hook 'constant-backup)
526 (add-hook 'auto-save-hook 'auto-save-size-limit)
528 (defun auto-save-size-limit ()
529 (when (and (not backup-inhibited) (> (buffer-size) 2000000))
530 (message "Backups disabled for this buffer due to size > 2 megs")
531 (make-local-variable 'backup-inhibited)
532 (setq backup-inhibited t)))
536 ;; ;; the faq suggests to auto-save using
537 ;; (setq auto-save-visited-file-name t)
538 ;; and to toggle auto-saving in the current buffer, type `M-x auto-save-mode'
540 ;; however, this is buggy.
541 ;; it leaves around lock files, which can be disabled with
542 ;; (setq create-lockfiles nil)
543 ;; but it is also buggy on other things that appear to hook onto file saving
544 ;; so i created my own function, which originally had bugs,
545 ;; but new emacs version fixed all that, yay!.
548 ;; not using, but here for documentation,
549 ;; alternate way to enable and specify how long between autosaves.
550 ;; number of input events between autosave.
551 ;; lowest bound of functionality is actually about 15 input events
552 ;; (setq auto-save-interval ...)
556 ;; A Theme builder is available at http://elpa.gnu.org/themes/ along with
557 ;; a list of pre-built themes at http://elpa.gnu.org/themes/view.html and
558 ;; themes are available through ELPA.
561 (defun override-theme (arg)
563 (while custom-enabled-themes
564 (disable-theme (car custom-enabled-themes)))
567 ;; not a real var? remove when I see this again
568 ;;(setq color-theme-is-global t)
570 ;; temporary, make night be default
572 (defun toggle-night ()
574 (cond ((equal (car custom-enabled-themes) 'naquadah)
575 (override-theme 'leuven))
577 (override-theme 'naquadah))))
580 ;; in the leuven theme file, i made this change. will need to remake it
581 ;; on package updates. I could fork, but its a pretty simple change
582 ;; < `(default ((,class (:foreground "#333333" :background "#FFFFFF"))))
583 ;; > `(default ((,class (:foreground "#333333" :background "#F6F6F0"))))
584 (override-theme 'leuven)
587 ;; disable color thing with this:
588 ;;(disable-theme (car custom-enabled-themes))
590 ;; decent dark themes
592 ;;(override-theme 'tangotango)
593 ;;(override-theme 'deeper-blue)
594 ;;(override-theme 'tango-dark)
595 ;;(override-theme 'tsdh-dark)
597 ;;(override-theme 'heroku)
598 ;;(override-theme 'inkpot) ;; part of inkpot-theme package
599 ;;(override-theme 'naquadah) ; org mode features, part of naquadah-theme package
600 ;;(override-theme 'spolsky) ;; part of sublime-themes package
601 ;;(override-theme 'twilight-anti-bright) ;; from twilight-anti-bright-theme package
603 ;; interesting but not usable colors
604 ;;(override-theme 'cyberpunk) ; cool org mode features, from cyberpunk-theme package
605 ;;(override-theme 'wombat) ; cursor not visible enough. from a wombat package, not sure which
606 ;;(override-theme 'misterioso) ; cursor not visible enough
608 ;;decent light themes
609 ;;(override-theme 'alect-light) ; theres a -alt version, don't see a dif. could use this without dimming. from alect-something package
610 ;;(override-theme 'occidental) ; from occidental-theme package
613 ;;color-theme is deprecated in emacs 24.
615 ;; theme packages i tried then removed:
616 ;; ignored ones that didn't use the new theme engine
618 ;;66 packages (zenburn-theme-2.1, zen-and-art-theme-1.0.1, waher-theme-20130917.7, ujelly-theme-1.0.35, twilight-theme-1.0.0, twilight-bright-theme-20130605.143, twilight-anti-bright-theme-20120713.316, tronesque-theme-1.3, tron-theme-12, toxi-theme-0.1.0, tommyh-theme-1.2, tango-2-theme-1.0.0, sunny-day-theme-20131203.1250, sublime-themes-20140117.323, subatomic-theme-20131011.1048, soothe-theme-0.3.16, soft-morning-theme-20131211.1342, soft-charcoal-theme-20130924.1206, sea-before-storm-theme-0.3, purple-haze-theme-20130929.1751, phoenix-dark-pink-theme-20130905.941, phoenix-dark-mono-theme-20130306.1215, pastels-on-dark-theme-0.3, obsidian-theme-20130920.937, nzenburn-theme-20130513, noctilux-theme-20131019.31, mustang-theme-20130920.939, monokai-theme-0.0.10, molokai-theme-20130828.0, late-night-theme-0.0, jujube-theme-0.1, ir-black-theme-20130302.2355, gruvbox-theme-20131229.1458, gruber-darker-theme-0.6, grandshell-theme-20140118.1003, github-theme-0.0.3, gandalf-theme-0.1, flatland-theme-20131204.858, django-theme-20131022.202, deep-thought-theme-0.1.1, dakrone-theme-20131212.1159, colorsarenice-theme-20131128.1106, color-theme-wombat+-0.0.2, color-theme-wombat-0.0.1, color-theme-twilight-0.1, color-theme-tango-0.0.2, color-theme-solarized-20120301, color-theme-sanityinc-solarized-2.25, color-theme-railscasts-0.0.2, color-theme-monokai-0.0.5, color-theme-molokai-0.1, color-theme-ir-black-1.0.1, color-theme-heroku-1.0.0, color-theme-github-0.0.3, color-theme-eclipse-0.0.2, color-theme-dpaste-0.0.1, color-theme-dawn-night-1.0, color-theme-colorful-obsolescence-0.0.1, color-theme-cobalt-0.0.2, color-theme-20080305.34, clues-theme-20130908.801, busybee-theme-20130920.942, bubbleberry-theme-0.1.2, mblage-theme-20130715.621, anti-zenburn-theme-20140104.1542, ample-zen-theme-0.2)
623 ;;; cross session settings
626 ;; defer & commands from jwiegley
628 :commands (recentf-mode
630 recentf-apply-filename-handlers)
633 (setq recentf-max-saved-items 400
634 recentf-max-menu-items 15)
637 (use-package saveplace
638 :unless noninteractive
641 save-place-version-control 'nospecial
642 save-place-limit 4000
643 save-place-file (concat user-emacs-directory "places"))
647 ;; savehist keeps track of some history search entries
648 (use-package savehist
649 :unless noninteractive
651 (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring)
653 savehist-autosave-interval 60
654 ;; keep the home clean
655 savehist-file (concat user-emacs-directory ".savehist"))
660 ;; dired - reuse current buffer by pressing 'a'
661 (put 'dired-find-alternate-file 'disabled nil)
664 ;; when manually evaluating lisp, go into debugger on error
665 (setq eval-expression-debug-on-error t)
670 isearch-allow-scroll t
671 search-ring-update t) ;; dont start an edit when going to previous search
673 (defun isearch-yank-regexp (regexp)
674 "Pull REGEXP into search regexp."
675 (let ((isearch-regexp nil)) ;; Dynamic binding of global.
676 (isearch-yank-string regexp))
677 (isearch-search-and-update))
679 (defun isearch-yank-symbol (&optional partialp backward)
680 "Put symbol at current point into search string.
682 If PARTIALP is non-nil, find all partial matches."
685 (let (from to bound sym)
687 ; this block taken directly from find-tag-default
688 ; we couldn't use the function because we need the internal from and to values
690 ;; Look at text around `point'.
692 (skip-syntax-backward "w_") (setq from (point)))
694 (skip-syntax-forward "w_") (setq to (point)))
696 ;; Look between `line-beginning-position' and `point'.
698 (and (setq bound (line-beginning-position))
699 (skip-syntax-backward "^w_" bound)
700 (> (setq to (point)) bound)
701 (skip-syntax-backward "w_")
702 (setq from (point))))
703 ;; Look between `point' and `line-end-position'.
705 (and (setq bound (line-end-position))
706 (skip-syntax-forward "^w_" bound)
707 (< (setq from (point)) bound)
708 (skip-syntax-forward "w_")
710 (buffer-substring-no-properties from to)))
712 (message "No symbol at point"))
714 (goto-char (1+ from)))
716 (goto-char (1- to))))
719 (isearch-yank-string sym)
721 (concat "\\_<" (regexp-quote sym) "\\_>")))))
723 (defun isearch-current-symbol (&optional partialp)
724 "Incremental search forward with symbol under point.
726 Prefixed with \\[universal-argument] will find all partial
729 (let ((start (point)))
730 (isearch-forward-regexp nil 1)
731 (isearch-yank-symbol partialp)))
734 (defun isearch-backward-current-symbol (&optional partialp)
735 "Incremental search backward with symbol under point.
737 Prefixed with \\[universal-argument] will find all partial
740 (let ((start (point)))
741 (isearch-backward-regexp nil 1)
742 (isearch-yank-symbol partialp)))
745 ;; automatically wrap to the top of the buffer when isearch fails
746 (defadvice isearch-search (after isearch-no-fail activate)
747 (unless isearch-success
748 (ad-disable-advice 'isearch-search 'after 'isearch-no-fail)
749 (ad-activate 'isearch-search)
750 (isearch-repeat (if isearch-forward 'forward))
751 (ad-enable-advice 'isearch-search 'after 'isearch-no-fail)
752 (ad-activate 'isearch-search)))
754 ;; Activate occur easily inside isearch
755 (define-key isearch-mode-map (kbd "C-o")
756 (lambda () (interactive)
757 (let ((case-fold-search isearch-case-fold-search))
758 (occur (if isearch-regexp
760 (regexp-quote isearch-string))))))
761 ;;; lisp / elisp mode setings
763 (add-hook 'emacs-lisp-mode-hook 'starter-kit-remove-elc-on-save)
764 (defun starter-kit-remove-elc-on-save ()
765 "If you're saving an elisp file, likely the .elc is no longer valid."
766 (make-local-variable 'after-save-hook)
767 (add-hook 'after-save-hook
769 (if (file-exists-p (concat buffer-file-name "c"))
770 (delete-file (concat buffer-file-name "c"))))))
773 (defun emacs-lisp-mode-defaults ()
774 ;; checkdoc has an annoying feature that wants a header and footer
775 ;; in every elisp buffer as if they all were packages
776 ;; todo, see if there is a way
777 ;; to make checkdoc usable instead of just disabling it as I do here
778 (if (boundp 'flycheck-checkers)
779 (setq flycheck-checkers (remove 'emacs-lisp-checkdoc flycheck-checkers)))
781 (add-hook 'emacs-lisp-mode-hook 'emacs-lisp-mode-defaults)
783 (define-key lisp-mode-map (kbd "<M-up>") 'backward-up-list)
784 (define-key lisp-mode-map (kbd "<M-down>") 'down-list)
785 (define-key emacs-lisp-mode-map (kbd "<M-up>") 'backward-up-list)
786 (define-key emacs-lisp-mode-map (kbd "<M-down>") 'down-list)
787 (define-key emacs-lisp-mode-map (kbd "<M-escape>") 'find-function-at-point)
789 ;; interactive modes don't need whitespace checks
790 (defun interactive-lisp-coding-defaults ()
791 (whitespace-mode -1))
793 ;;; modes with little configuration needed
795 (custom-set-variables
796 '(css-indent-offset 2)
797 '(sh-here-document-word "'EOF'")
798 '(outline-minor-mode-prefix "
\ 3\ 1")
799 '(tramp-default-method "ssh")
800 ;; change last thing from gnu.
801 ;; notably this avoids brace indent after if, and 4 space indent
802 ;; for emacs itself, use
803 ;; (setq c-default-style '((java-mode . "java")
804 ;; (awk-mode . "awk")
806 ;; (setq-default c-basic-offset 2)
807 '(c-default-style '((java-mode . "java")
809 (other . "stroustrup")))
814 ;; ediff-buffers is the main command to use
815 ;; don't start another frame for the control panel
816 ;; unfortunately, this doesn't allow me to use 2 frames for the diff buffers
817 ;; so disable this temporarily with the next line if you want that
818 ;; sometime I should setup 2 functions to explicitly do each type
819 ediff-window-setup-function 'ediff-setup-windows-plain
820 ;;(setq ediff-window-setup-function 'ediff-setup-windows-default)
821 ;; do side by side diffs
822 ediff-split-window-function 'split-window-horizontally
823 ;; ediff things I tried which didn't work, which intuitively I think should
824 ;; work better: I can open the second diff buffer in a new frame, and
825 ;; close it's window in the first frame after starting ediff, but when I
826 ;; hit n to go to the next diff, it restores the window in the first
827 ;; frame. Another thing I tried is to open 2 new frames and set them up
828 ;; as I want. However, if I try to open the *Ediff Control Panel* buffer
829 ;; in a different window from its original one, my mouse jumps to one of
830 ;; the diff frames, or if that isn't visible, the buffer just hangs
831 ;; until I select the original ediff control panel window. This seems
832 ;; like a bug to me. I am using a very recent development version of
837 ;; disabled temporarily. todo, look into it
838 ;;(add-hook 'outline-minor-mode-hook 'outshine-mode)
842 ;; this file includes setting up my email addresses, which are not public,
844 ;; mu4e-user-mail-address-list
846 ;; inspired by mu4e info manual, search for mu4e-compose-pre-hook.
847 (when (file-exists-p "/p/c/mymu4e.el")
848 (load "/p/c/mymu4e.el"))
851 (when (file-exists-p "/a/h/iank-mod.el")
852 (load-file "/a/h/iank-mod.el"))
854 ;; from when i was running my own patches
855 ;;(add-to-list 'load-path "/a/opt/ws-butler")
858 ;; todo: I think this is broken, it keeps collapsing the last line
859 ;; for empty messages.
861 ;; the main problem is when it deletes the blank line at the end
862 ;; of a message with an empty body. but I might also
863 ;; be pasting whitespace significant things in here, so
864 ;; just don't do anything.
865 ;; todo: propose this upstream
866 (add-to-list 'ws-butler-global-exempt-modes 'message-mode)
868 (ws-butler-global-mode)
870 ;; disabled because i dont edit nginx files enough
871 ;; to have this loaded at startup
872 ;;(use-package nginx-mode)
873 ;;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:
874 ;;(add-to-list 'auto-mode-alist '("/etc/nginx/sites-available/.*" . nginx-mode))
876 ;; todo, put this on a hook with prog mode
877 ;;(highlight-indentation-mode 1)
880 ;; example of a syntax highlighted tail
881 (use-package autorevert
884 (defvar prev-auto-revert-max)
885 (defun tail-colorize ()
886 (ansi-color-apply-on-region prev-auto-revert-max (point-max))
887 (setq-local prev-auto-revert-max (point-max)))
888 (add-hook 'auto-revert-tail-mode-hook
892 "/var/log/cloudman/development/cm-service.log")
893 (setq-local prev-auto-revert-max 0)
894 ;; set buffer-local hook
895 (add-hook 'after-revert-hook 'tail-colorize nil t))))
898 ;; delete active selection with self-insert commands
899 (delete-selection-mode t)
901 ;; Transparently open compressed files
902 (auto-compression-mode t)
904 ;; dot mode, repeats last action
906 (add-hook 'find-file-hook 'dot-mode-on)
908 ;; clean up obsolete buffers automatically at midnight
911 ;; saner regex syntax
912 (require 're-builder)
913 (setq reb-re-syntax 'string)
916 ;; show the name of the current function definition in the modeline
917 (setq which-func-modes t)
918 (which-function-mode 1)
920 ;; enable winner-mode to manage window configurations
923 ;; meaningful names for buffers with the same name
925 (setq uniquify-buffer-name-style 'forward
926 uniquify-separator "/"
927 ;; for sdx work. until I figure out a better way.
928 ;; maybe something like projectile can do it,
929 ;; or hacking around the status bar
930 uniquify-min-dir-content 2
931 uniquify-after-kill-buffer-p t ; rename after killing uniquified
932 uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
935 ;; makefiles require tabs
936 ;; todo: find a makefile indent function that works,
937 ;; best I could find is this one which means don't indent at all
939 (add-hook 'makefile-mode-hook
941 (setq indent-tabs-mode t)
942 (setq indent-line-function (lambda () 'no-indent))))
945 ;; todo, turn on auto-fill just for txt files
946 ;;(add-hook 'text-mode-hook 'turn-on-auto-fill)
948 ;; random extra highlights
949 (require 'volatile-highlights)
950 (volatile-highlights-mode t)
953 ;; make help buffers smaller when it makes sense
954 (temp-buffer-resize-mode 1)
957 (defun my-info-init()
959 ;; based on suggestions in info+.el, I also installed misc-fns, strings, and thingatpt+
960 ;; remove some bad keybinds from info+
961 (define-key Info-mode-map [mouse-4] nil)
962 (define-key Info-mode-map [mouse-5] nil))
964 (add-hook 'info-mode-hook 'my-info-init)
967 ;;; misc general settings
970 ;; I tried to look for a function that would set this that is
971 ;; not part of the emacs interactive customize stuff, but didn't see one
972 ;; in the faces documentation.
975 ;; custom-set-faces was added by Custom.
976 ;; If you edit it by hand, you could mess it up, so be careful.
977 ;; Your init file should contain only one such instance.
978 ;; If there is more than one, they won't work right.
979 '(header-line ((t (:background "default" :foreground "default" :overline nil :underline nil))))
983 ;; from tramp manual, use the same ssh controlmaster. I was having problems with
984 ;; tramp prompting me for a username and pass.
985 (customize-set-variable 'tramp-use-ssh-controlmaster-options nil)
988 auto-revert-interval 2
989 ;; fix eof end of file newline
990 mode-require-final-newline t
991 require-final-newline t
992 auto-revert-verbose nil
993 auto-revert-remote-files t
994 ;; save bookmarks whenever they are changed instead of just when emacs quits
996 ;; increase bookmark context size for better functionality
997 bookmark-search-size 2000
998 ;; https://www.emacswiki.org/emacs/FillParagraph
999 ;; make list items start paragraphs.
1000 paragraph-start "\f\\|[ \t]*$\\|[ \t]*[-+*] "
1002 vc-follow-symlinks t
1006 (add-hook 'text-mode-hook (lambda () (auto-fill-mode t)))
1007 (setq counsel-find-file-at-point t)
1009 (eval-after-load "ido"
1010 ;; easier to read with just spaces as separator
1011 (quote (setf (nth 2 ido-decorations) " ")))
1013 ;; Seed the random-number generator
1016 ;; easier to remember than keybinds
1017 (defalias 'scrypt 'mml-secure-message-encrypt-pgpmime)
1018 (defalias 'sign 'mml-secure-message-sign-pgpmime)
1019 ;; otherwise we get error on sending:
1020 ;; mml-secure-epg-sign: Couldn’t find any signer names; try setting `mml-secure-smime-sign-with-sender'.
1021 ;; i dunno why sign+encrypt doesnt cause this, seems kinda dumb,
1023 (setq mml-secure-openpgp-sign-with-sender t)
1024 ;; i dun use smime, the smime signing fails complaining it doesnt have
1025 ;; my key. todo: learn about smime
1026 (setq mml-secure-smime-sign-with-sender t)
1029 (mml-secure-message-encrypt-pgpmime 'dontsign))
1031 ;; don't highlight the region.
1032 (set-face-background 'region nil)
1034 ;; this fixes save error for python example code
1035 (define-coding-system-alias 'UTF-8 'utf-8)
1037 ;; i don't use frame titles, but if I ever do
1038 ;; this starter kit setting is probably good
1039 (if window-system (setq frame-title-format '(buffer-file-name "%f" ("%b"))))
1042 ;;(prefer-coding-system 'utf-8-unix)
1044 ;; remove ugly 3d box feature
1045 (set-face-attribute 'mode-line nil :box nil)
1047 (add-to-list 'default-frame-alist
1048 '(font . "DejaVu Sans Mono-11"))
1049 ; the default will jump 2 sizes.
1050 (setq text-scale-mode-step 1.1)
1051 (setq font-lock-maximum-decoration t
1052 inhibit-startup-message t
1053 transient-mark-mode t
1054 delete-by-moving-to-trash t
1055 shift-select-mode nil
1056 truncate-partial-width-windows nil
1057 uniquify-buffer-name-style 'forward
1058 oddmuse-directory (concat user-emacs-directory "oddmuse")
1061 sort-fold-case t ; case insensitive line sorting
1062 global-mark-ring-max 1000
1063 ;; the visible bell seems to lag the ui
1065 ;; turn off audible bell
1066 ;; https://www.emacswiki.org/emacs/AlarmBell
1067 ring-bell-function 'ignore
1069 revert-without-query '(".*")
1070 font-lock-maximum-decoration t) ; probably default and not necesary
1073 (setq-default indent-tabs-mode nil ;; don't use tabs to indent
1077 ;; wrap at word boundaries instead of mid-word
1080 indicate-empty-lines t) ; mark end of buffer
1083 (blink-cursor-mode '(-4))
1088 ;; enable various commands
1089 (put 'narrow-to-region 'disabled nil)
1090 (put 'narrow-to-page 'disabled nil)
1091 (put 'narrow-to-defun 'disabled nil)
1092 (put 'upcase-region 'disabled nil)
1093 (put 'downcase-region 'disabled nil)
1094 (put 'scroll-left 'disabled nil)
1095 ;; these from graphene, haven't read about them yet
1096 (put 'ido-complete 'disabled nil)
1097 (put 'ido-exit-minibuffer 'disabled nil)
1098 (put 'dired-find-alternate-file 'disabled nil)
1099 (put 'autopair-newline 'disabled nil)
1103 ;;disable and minimize various prompts/messages
1104 (fset 'yes-or-no-p 'y-or-n-p)
1105 (setq confirm-nonexistent-file-or-buffer nil
1106 inhibit-startup-message t
1107 inhibit-startup-echo-area-message t
1108 inhibit-startup-screen t
1109 kill-buffer-query-functions (remq 'process-kill-buffer-query-function
1110 kill-buffer-query-functions))
1113 ;; exit without bothering me
1114 ;; http://stackoverflow.com/questions/2706527/make-emacs-stop-asking-active-processes-exist-kill-them-and-exit-anyway/2708042#2708042
1115 (add-hook 'comint-exec-hook
1116 (lambda () (set-process-query-on-exit-flag (get-buffer-process (current-buffer)) nil)))
1117 ;; based on save-buffers-kill-emacs help string, don't ask about clients when exiting
1118 ;; apparently this would need to be in some later hook. dunno where is best, but this works
1119 (defadvice save-buffers-kill-emacs (before no-client-prompt-advice activate)
1120 (setq kill-emacs-query-functions (delq 'server-kill-emacs-query-function kill-emacs-query-functions)))
1124 ;; (custom-set-faces
1125 ;; ;; setting header-line-format to " " as a hack for a top margin the oly thning I could find to do a top margin
1126 ;; '(header-line ((t (:background "default" :foreground "default" :overline nil :underline nil))))
1127 ;; ;; don't highlight the region
1128 ;; '(region ((t nil))))
1129 (setq-default header-line-format " ")
1132 (setq initial-scratch-message nil)
1135 ;; vertical margin background.
1136 ;; google turned up: http://lists.gnu.org/archive/html/help-gnu-emacs/2014-03/msg00544.html
1137 ;; the xresource doesn't work for me, probably an xmonad thing.
1139 ;; figured out I needed to customize the header line face. To find the face, M-x list-faces-display or just google / search
1141 ;; then M-x customize-face
1143 ;; unchecked some stuff so that it inherits from default.
1145 ;;; misc function definitions
1148 (defun fill-buffer ()
1150 (save-mark-and-excursion
1151 (goto-char (point-min))
1152 (while (= (forward-line) 0)
1156 (defun next-backup-dir ()
1157 "In a directory listing from rsync -n,
1158 Go to the next directory based on where the cursor is."
1160 (let* ((start-col (current-column))
1161 (end-col (progn (skip-chars-forward "^/\n") (current-column)))
1163 (beginning-of-line 1)
1164 (buffer-substring-no-properties (point) (+ (point) end-col)))))
1167 (while (and (not (eobp))
1168 (string= dir (buffer-substring-no-properties (point) (+ (point) end-col))))
1170 (forward-char-same-line start-col)))
1171 ;; copy paste this for fast keybind
1172 ;;(local-set-key (kbd "<kp-enter>"))
1175 (defun goto-buffer-or-find-file (file-name)
1176 "If buffer is with FILE-NAME exists, go to it, else open the file using full path."
1178 (let ((b (get-buffer (file-name-nondirectory file-name))))
1180 (switch-to-buffer b)
1181 (find-file file-name))))
1186 ;; todo, i think this is broken. perhaps the last goto-char is not accounting for buffer or something
1187 (defun unpop-global-mark ()
1188 "Unpop off global mark ring. Does nothing if mark ring is empty."
1190 (when global-mark-ring
1191 (setq global-mark-ring (cons (copy-marker (mark-marker)) global-mark-ring))
1192 (let ((lm (car (last global-mark-ring))))
1193 (set-marker (mark-marker) (marker-position lm) (marker-buffer lm)))
1194 (when (null (mark t)) (ding))
1195 (setq global-mark-ring (nbutlast global-mark-ring))
1196 (goto-char (marker-position (mark-marker)))))
1198 (defun indent-buffer ()
1199 "Indents the entire buffer."
1201 (cond ((derived-mode-p 'org-mode)
1202 (org-indent-region (point-min) (point-max)))
1203 ((derived-mode-p 'python-mode)
1206 (indent-region (point-min) (point-max)))))
1209 ;; TODO doesn't work with uniquify
1210 (defun rename-file-and-buffer ()
1211 "Renames current buffer and file it is visiting."
1213 (let ((name (buffer-name))
1214 (filename (buffer-file-name)))
1215 (if (not (and filename (file-exists-p filename)))
1216 (message "Buffer '%s' is not visiting a file!" name)
1217 (let ((new-name (read-file-name "New name: " filename)))
1218 (cond ((get-buffer new-name)
1219 (message "A buffer named '%s' already exists!" new-name))
1221 (rename-file name new-name 1)
1222 (rename-buffer new-name)
1223 (set-visited-file-name new-name)
1224 (set-buffer-modified-p nil)))))))
1228 (defun sudo-edit (&optional arg)
1230 (if (or arg (not buffer-file-name))
1231 (find-file (concat "/sudo::" (ido-read-file-name "File: ")))
1232 (find-alternate-file (concat "/sudo::" buffer-file-name))))
1236 (defun backward-symbol (arg)
1238 (forward-symbol (- arg)))
1241 ;; make window title be the buffer name
1242 (setq frame-title-format "%b")
1244 (defun my-after-change-major-mode-hook ()
1245 (setq mode-line-mule-info nil
1246 minor-mode-alist nil
1247 mode-line-position nil)) ; todo, make only flymake status show up
1249 (add-hook 'after-change-major-mode-hook 'my-after-change-major-mode-hook)
1253 (setq focus-follows-mouse t
1254 mouse-autoselect-window t
1256 ;;;; move-mouse-to-point
1257 ;; todo, this is buggy with multiple windows open.
1258 (defun move-mouse-to-point ()
1260 (let* ((pos (posn-col-row (posn-at-point)))
1261 (x (+ (car pos) 2)) ; no idea why this is off by 1-2
1263 (set-mouse-position (selected-frame) x y)))
1267 ;; todo work on org-cycle-emulate-tab
1269 ;; todo, this doesn't work for a non-standard keybind
1270 ;;(setq org-special-ctrl-k t)
1272 ;; todo, generally fix org mode keys
1273 ;; todo, org-mark-element, unbdind from M-h, bind to mark defun key
1275 ;(org-babel-do-load-languages
1276 ; 'org-babel-load-languages
1277 ; '((emacs-lisp . t)
1282 ;; make shell work like interactive bash shell
1283 (setq org-babel-default-header-args:sh
1284 '((:results . "output") (:shebang . "#!/bin/bash -l")))
1286 ;; my patch to output stderr
1287 (setq org-babel-use-error-buffer nil)
1290 ;; org-mode manual suggests these, but I haven't used them.
1291 ;;(global-set-key "\C-cl" 'org-store-link)
1292 ;;(global-set-key "\C-ca" 'org-agenda)
1293 ;; this got in the way of a haskell mode command
1294 ;;(global-set-key "\C-cb" 'org-iswitchb)
1298 ;; org-src-tab-acts-natively t ; broken option. using next instead, todo fix
1300 (setq org-src-fontify-natively t ; make babel blocks nice
1301 org-adapt-indentation nil
1302 org-src-preserve-indentation t
1303 ;; The most basic logging is to keep track of when a TODO item was finished.
1305 ;; use a drawer to keep the logs tidy
1306 org-log-into-drawer t
1307 org-extend-today-until 0
1308 org-startup-truncated nil
1310 org-use-sub-superscripts "{}"
1311 org-export-with-sub-superscripts nil
1312 org-clock-mode-line-total 'today
1313 ;; global STYLE property values for completion
1314 org-global-properties (quote (("STYLE_ALL" . "habit")))
1315 org-special-ctrl-a/e t ;; home and end work special in headlines
1316 org-completion-use-ido t
1317 org-catch-invisible-edits 'smart)
1320 org-default-notes-file "/a/t.org"
1323 ;; modeilne populated from (org-clock-get-clocked-time)
1324 ;; which is populated from the var org-clock-total-time
1325 ;; which is populated by a function which starts from (org-clock-get-sum-start)
1328 (eval-after-load "org"
1329 '(org-clock-persistence-insinuate))
1331 (defun time-to-org-day (time)
1332 (round (time-to-number-of-days
1333 (time-subtract time (list 0 (* 3600 org-extend-today-until) 0)))))
1335 (defun my-org-confirm-babel-evaluate (lang body)
1336 (not (or (string= (buffer-file-name) "/a/t.org")
1338 (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
1341 (defun org-time-stamp-with-time (arg)
1343 ;; '(4) is the argument passed by universal prefix
1344 (org-time-stamp (if arg arg '(4)) t))
1346 ;; based on http://stackoverflow.com/questions/3758139/variable-pitch-for-org-mode-fixed-pitch-for-tables
1347 ;; keywords: proportional font, monospace
1349 (defun variable-pitch-on ()
1350 (variable-pitch-mode 1))
1351 (add-hook 'fundamental-mode-hook 'variable-pitch-on)
1352 (add-hook 'org-mode-hook 'variable-pitch-on)
1353 (add-hook 'text-mode-hook 'variable-pitch-on)
1354 (defun variable-pitch-off ()
1355 (variable-pitch-mode 0))
1356 (add-hook 'yaml-mode-hook 'variable-pitch-off)
1359 (defun my-org-face-init()
1360 (set-face-attribute 'org-table nil :family (face-attribute 'fixed-pitch :family))
1361 (set-face-attribute 'org-code nil :family (face-attribute 'fixed-pitch :family))
1362 (set-face-attribute 'org-formula nil :family (face-attribute 'fixed-pitch :family))
1363 (set-face-attribute 'org-link nil :family (face-attribute 'fixed-pitch :family))
1364 (set-face-attribute 'org-block nil :family (face-attribute 'fixed-pitch :family))
1365 (set-face-attribute 'org-date nil :family (face-attribute 'fixed-pitch :family))
1368 (eval-after-load "org" '(my-org-face-init))
1370 (defun remove-org-binds ()
1371 (define-key org-mode-map (kbd "<M-return>") nil)
1372 (define-key org-mode-map (kbd "C-'") nil)
1373 (define-key org-mode-map (kbd "C-y") nil)
1374 (define-key org-mode-map (kbd "<C-return>") nil)
1375 (define-key org-mode-map (kbd "<C-M-kp-enter>") nil)
1376 (define-key org-mode-map (kbd "C-,") nil)
1377 (define-key org-mode-map (kbd "C-M-m") nil)
1378 (define-key org-mode-map (kbd "C-k") nil)
1379 (define-key org-mode-map (kbd "C-j") nil)
1380 (define-key org-mode-map (kbd "C-M-i") nil)
1381 (define-key org-mode-map (kbd "C-M-t") nil)
1382 (define-key org-mode-map (kbd "M-a") 'nil)
1383 (define-key org-mode-map (kbd "C-a") nil)
1384 (define-key org-mode-map (kbd "M-e") nil)
1385 (define-key org-mode-map (kbd "C-e") nil)
1386 (define-key org-mode-map (kbd "C-3") nil)
1387 (define-key org-mode-map (kbd "<M-left>") nil)
1388 (define-key org-mode-map (kbd "<M-right>") nil)
1389 (define-key org-mode-map (kbd "<S-return>") nil)
1390 (define-key org-mode-map (kbd "<tab>") nil)
1391 (define-key org-mode-map (kbd "<C-S-down>") nil)
1392 (define-key org-mode-map (kbd "<C-S-up>") nil)
1393 (define-key org-mode-map (kbd "<S-down>") nil)
1394 (define-key org-mode-map (kbd "<S-up>") nil)
1395 (define-key org-mode-map "\t" nil))
1396 (add-hook 'org-mode-hook 'remove-org-binds)
1398 ;;; prog-mode-defaults
1401 (defun prog-mode-defaults ()
1402 "Default coding hook, useful with any programming language."
1403 ;; so that I can do completion before the dialog pops up
1404 ;;(local-set-key (kbd "<tab>") 'auto-complete)
1405 (local-set-key (kbd "TAB") 'auto-complete)
1406 ;; todo, this is causing error message on loading file, prolly not working
1407 ;;(flycheck-mode +1)
1408 (setq ac-sources (delq 'ac-source-dictionary ac-sources))
1409 (highlight-symbol-mode)
1410 (make-local-variable 'column-number-mode)
1411 ;; this says do autofilling using newcomment.el. The "only" is a misnomer.
1412 (set (make-local-variable 'comment-auto-fill-only-comments) t)
1413 (column-number-mode t)
1415 ;; (turn-on-smartparens-mode)
1418 (font-lock-add-keywords
1419 nil `(("(\\(lambda\\>\\)"
1420 (0 (progn (compose-region (match-beginning 1) (match-end 1)
1421 ,(make-char 'greek-iso8859-7 107))
1423 (add-hook 'prog-mode-hook 'prog-mode-defaults)
1427 ;;; yank auto-indent
1428 ;; automatically indenting yanked text if in programming-modes
1429 (defvar yank-indent-modes
1430 '(LaTeX-mode TeX-mode)
1431 "Modes in which to indent regions that are yanked (or yank-popped).
1432 Only modes that don't derive from `prog-mode' should be listed here.")
1434 (defvar yank-indent-blacklisted-modes
1435 '(python-mode slim-mode haml-mode)
1436 "Modes for which auto-indenting is suppressed.")
1438 (defvar yank-advised-indent-threshold 2000
1439 "Threshold (# chars) over which indentation does not automatically occur.")
1441 (defun yank-advised-indent-function (beg end)
1442 "Do indentation, as long as the region isn't too large."
1443 (if (<= (- end beg) yank-advised-indent-threshold)
1444 (indent-region beg end nil)))
1446 (defadvice yank (after yank-indent activate)
1447 "If current mode is one of 'yank-indent-modes,
1448 indent yanked text (with prefix arg don't indent)."
1449 (if (and (not (ad-get-arg 0))
1450 (not (member major-mode yank-indent-blacklisted-modes))
1451 (or (derived-mode-p 'prog-mode)
1452 (member major-mode yank-indent-modes)))
1453 (let ((transient-mark-mode nil))
1454 (yank-advised-indent-function (region-beginning) (region-end)))))
1456 (defadvice yank-pop (after yank-pop-indent activate)
1457 "If current mode is one of 'yank-indent-modes,
1458 indent yanked text (with prefix arg don't indent)."
1459 (if (and (not (ad-get-arg 0))
1460 (not (member major-mode yank-indent-blacklisted-modes))
1461 (or (derived-mode-p 'prog-mode)
1462 (member major-mode yank-indent-modes)))
1463 (let ((transient-mark-mode nil))
1464 (yank-advised-indent-function (region-beginning) (region-end)))))
1470 ;; # eval: (outline-minor-mode)
1471 ;; # outline-regexp: "\\( *\\)# [*]\\{1,8\\} "
1474 ;; avoid stupid git crap like "warning, terminal not fully functional"
1475 (setenv "PAGER" "cat")
1476 ;; don't store successive duplicates in comint command history
1477 (setq comint-input-ignoredups t)
1479 (defun add-mode-line-dirtrack ()
1480 (add-to-list 'mode-line-buffer-identification
1481 '(:propertize (" " default-directory " ") face dired-directory)))
1482 (add-hook 'shell-mode-hook 'add-mode-line-dirtrack)
1485 ;; don't fully understand it, but it works.
1486 ;; http://www.emacswiki.org/emacs/ShellDirtrackByProcfs
1487 (defun track-shell-directory/procfs ()
1488 (shell-dirtrack-mode 0)
1489 (add-hook 'comint-preoutput-filter-functions
1492 (when (string-match comint-prompt-regexp str)
1494 (format "/proc/%s/cwd" (process-id
1496 (current-buffer)))))))))
1498 (setq comint-buffer-maximum-size 100000)
1499 (add-to-list 'comint-output-filter-functions 'comint-truncate-buffer)
1502 (shell (generate-new-buffer-name "*shell*")))
1504 (defun shell-wrap (prefix)
1505 "wrap the shell function, automatically generate a new name for a prefix arg"
1511 (add-hook 'shell-mode-hook 'track-shell-directory/procfs)
1512 ;;; spell correction
1514 ispell-program-name "hunspell"
1515 ispell-silently-savep t) ; don't prompt to save personal dictionary
1517 (use-package rw-hunspell
1519 ;; rw-hunspell sets up hunspell dictionary automagically.
1521 (use-package flyspell
1522 :ensure-system-package hunspell
1523 :hook ((prog-mode . flyspell-prog-mode)
1524 (text-mode . turn-on-flyspell)))
1526 ;; Rant: Hunspell SHOULD be standard. its used by firefox and openoffice and
1527 ;; osx. In contrast, the first few words I added to aspell dictionary were
1528 ;; "emacs" "customizable" and "timestamp". Hunspell already has those,
1531 ;; ispell-personal-dictionary does not document where the hunspell
1532 ;; dictionary goes by default, but it is ~/.hunspell_en_US for me
1537 (use-package latex-mode
1540 (setq-default TeX-PDF-mode t) ; use pdf
1541 ;; more sensible defaults based on info manual quickstart
1542 (setq TeX-auto-save t
1544 ;; not documented, but looking at the source, I find this
1545 ;; stops me from being asked what command on every C-c-c
1546 ;; when doing a latex document.
1547 TeX-command-force "LaTeX"
1550 ;;; visible mark mode
1552 ;; since it is not easy to change the mark overlay priority, I change this one.
1553 (setq show-paren-priority 999)
1555 (defface visible-mark-active
1556 '((((type tty) (class mono)))
1557 (t (:background "magenta"))) "")
1559 (defface mouse-cursor-face
1560 '((((type tty) (class mono)))
1561 (t (:background "DeepPink1"))) "")
1564 (require 'visible-mark)
1567 visible-mark-faces '(visible-mark-face1 visible-mark-face2)
1568 visible-mark-forward-faces '(visible-mark-forward-face1)
1569 ;; highlight the last 2 marks
1571 ;; highlight 1 forward mark
1572 visible-mark-forward-max 1)
1573 ;; globally activate visible-mark-mode
1574 (global-visible-mark-mode +1)
1577 ;; todo, it doesn't seem to be exposed in elisp, but it would be nice
1578 ;; if I could define overlay faces to use inverse foreground color
1585 (when (string= (system-name) "kd") (setq vol 80))
1586 ;; speed is there so i can adjust and make it go slow so it plays long enough to adjust in pavucontrol
1587 (start-process-shell-command "ignoreme" nil (format "mpv --speed=1 --no-terminal --vo=null --volume=%d /a/bin/data/bird.mp3" vol)))
1588 ;; from https://www.emacswiki.org/emacs/ErcSound
1592 (when (string= (system-name) "tp") (setq vol 80))
1593 ;; speed is there so i can adjust and make it go slow so it plays long enough to adjust in pavucontrol
1594 (start-process-shell-command "ignoreme" nil (format "mpv --speed=.2 --no-terminal --vo=null --volume=%d /a/bin/data/bird.mp3" vol)))
1596 (defun erc-my-privmsg-sound (proc parsed)
1597 (let* ((tgt (car (erc-response.command-args parsed)))
1598 (privp (erc-current-nick-p tgt)))
1601 ;; We must return nil. See help for `erc-server-PRIVMSG-functions'
1604 (defun erc-sound-if-not-server (match-type nickuserhost msg)
1605 (unless (string-match "Server:[0-9]+" nickuserhost)
1611 (setq erc-fill-prefix ""
1612 ;; consider invisible frames to be unseen. seems like an obvious default
1613 erc-track-visibility 'visible
1614 ;; switch to buffer where i've been mentioned, etc instead of oldest
1615 erc-track-switch-direction 'importance
1616 ;; defaults minus fill. todo: modify the list instead of specifying it explicitly in case the defaults change
1618 '(autojoin button completion irccontrols list match menu move-to-prompt netsplit networks noncommands readonly ring stamp track)
1621 (add-hook 'erc-server-PRIVMSG-functions
1622 'erc-my-privmsg-sound)
1623 (add-hook 'erc-text-matched-hook 'erc-sound-if-not-server)
1626 (defun rm-file-and-buffer ()
1627 "Removes file connected to current buffer and kills buffer."
1629 (let ((filename (buffer-file-name))
1630 (buffer (current-buffer))
1631 (name (buffer-name)))
1632 (if (not (and filename (file-exists-p filename)))
1633 (error "Buffer '%s' is not visiting a file!" name)
1634 (delete-file filename)
1635 (kill-buffer buffer)
1636 (message "File '%s' successfully removed" filename))))
1638 ;;; persistent registers
1639 ;; This needs to be at the end, because I visit a file, thus setting a
1640 ;; mode, and the mode hook needs to be setup before that.
1642 ;; I'm using persistent registers instead of bookmarks. I dun use them
1643 ;; much, so the added hassle of having to set it within this file is
1644 ;; worth the benefit of only having one concept in my mind.
1647 (?i (file . ,(concat user-emacs-directory "init.el")))
1648 (?o (file . ,"/a/work.org"))
1649 (?t (file . ,"/a/t.org"))
1650 (?s (file . ,"/usr/share/doc/exim4-base/spec.txt.gz"))
1651 (?w (file . ,"/p/w.org"))
1652 (?k (file . ,"/a/bin/ds/Arduino/Model01-Firmware/Model01-Firmware.ino"))
1653 (?x (file . ,"/a/x.txt"))
1655 (set-register (car r) (cadr r)))
1657 (setq undo-outer-limit 100000000 ; per undo command
1658 undo-limit 500000000 ; undo history limit
1659 undo-strong-limit 600000000) ; undo history limit plus some extra
1664 ;; note, this has weird errors when it was before recentf-mode
1666 (use-package undo-tree
1668 ;; more resilient undo-tree-history if we have its location set up front.
1669 (setq undo-tree-history-directory-alist '(("." . (concat user-emacs-directory ".undo-tree-history")))
1670 undo-outer-limit 100000000 ; per undo command
1671 undo-limit 500000000 ; undo history limit
1672 undo-strong-limit 600000000 ; undo history limit plus some extra
1673 ;; Undo in region just happens accidentally, and throws me off
1674 undo-tree-enable-undo-in-region nil)
1675 ;; disabled due to bug, something like unknown entry in undo tree canary
1676 ;; (setq undo-tree-auto-save-history t)
1678 ;; todo, send patch undo-tree-visualize should scroll with the scroll key, instead of just pgup pgdn (aka next/prior)
1679 (global-undo-tree-mode)
1680 ;; simple way to fix that enable undo-tree starts out disabled in org-mode
1681 (defun undo-tree-overridden-undo-bindings-p() nil))
1687 (define-prefix-command 'terminal-key-map)
1688 (global-set-key (kbd "\e[") 'terminal-key-map)
1690 (global-set-key (kbd "C-x C-b") 'ibuffer)
1694 ;; Activate occur easily inside isearch
1697 (define-key isearch-mode-map (kbd "C-o")
1698 (lambda () (interactive)
1699 (let ((case-fold-search isearch-case-fold-search))
1700 (occur (if isearch-regexp
1702 (regexp-quote isearch-string))))))
1705 (defun my-isearch-toggle-regexp ()
1707 (isearch-toggle-regexp)
1708 (cond (isearch-regexp
1709 (global-set-key (kbd "C-r") 'isearch-backward-regexp)
1710 (define-key global-map (kbd "<f12>") 'isearch-forward-regexp))
1712 (global-set-key (kbd "C-r") 'isearch-backward)
1713 (define-key global-map (kbd "<f12>") 'isearch-forward))))
1714 (define-key isearch-mode-map (kbd "M-r") 'my-isearch-toggle-regexp)
1717 (define-key Info-mode-map "x" 'Info-follow-nearest-node)
1720 ;;;; single/special keys
1722 ;; todo: this doesnt work. needs <tab>, which doesnt work in terminal. fix that.
1723 (define-key isearch-mode-map (kbd "TAB") 'isearch-query-replace)
1725 ;;;;; f12 - isearch-forward
1726 ;; explained in http://stackoverflow.com/questions/7411920/how-to-bind-search-and-search-repeat-to-c-f-in-emacs
1727 (global-set-key (kbd "<kp-add>") 'isearch-forward)
1728 (global-set-key (kbd "<f12>") 'isearch-forward)
1729 (define-key isearch-mode-map (kbd "<kp-add>") 'isearch-repeat-forward)
1730 (define-key isearch-mode-map (kbd "<f12>") 'isearch-repeat-forward)
1731 ;; get rid of the standard completion binding, always use auto-complete
1732 ;; this didn't work very well
1733 ;;(global-set-key (kbd "TAB") 'auto-complete)
1734 (define-key global-map [remap completion-at-point] 'auto-complete)
1736 ;;;;; end - move-end-of-line
1737 ;; taken from emacs wiki, along with home function
1738 ;; http://www.emacswiki.org/emacs/BackToIndentationOrBeginning
1739 (defun point-in-comment ()
1740 "Determine if the point is inside a comment"
1742 (let ((syn (syntax-ppss)))
1744 (not (nth 3 syn)))))
1745 (defun end-of-code-or-line (arg)
1746 "Move to end of line, or before start of comments depending on situation.
1747 Toggle back and forth positions if we are already at one.
1748 Comments are recognized in any mode that sets syntax-ppss
1752 (let ((start (point))
1753 (bol (save-excursion
1756 (eol (progn (move-end-of-line arg) (point))))
1757 (while (point-in-comment)
1759 (when (= (point) bol)
1761 (throw 'bol (and (not (= eol start)) (>= start (point))))))
1762 (move-end-of-line arg)))
1764 (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)))
1766 ;;;;; home - back-to-indentation
1767 (defun back-to-indentation-or-beginning ()
1769 (if (= (point) (progn (back-to-indentation) (point)))
1770 (if (derived-mode-p 'org-mode)
1771 (org-beginning-of-line)
1772 (beginning-of-line))))
1773 (global-set-key (kbd "<home>") 'back-to-indentation-or-beginning)
1775 ;;;;; s-tab - indent-buffer
1777 (global-set-key (kbd "<S-iso-lefttab>") 'indent-buffer)
1779 (global-set-key (kbd "<backtab>") 'indent-buffer)
1780 ;;;;; s-delete - send-shell
1782 (global-set-key (kbd "<S-delete>") 'send-shell)
1784 ;; optional variables used by send-shell
1785 (setq shell-send-yank-key nil)
1787 (defun repeat-shell ()
1789 "Repeat the last command in shell-mode, displaying the window if needed."
1790 (let ((shell-buffer (get-buffer "*shell*")))
1792 (buffer-window-show shell-buffer)
1793 (let ((original-buffer (current-buffer)))
1795 (setq shell-buffer (current-buffer))
1796 (switch-to-buffer original-buffer)))
1797 (with-current-buffer shell-buffer
1798 (goto-char (point-max))
1799 (call-interactively 'comint-previous-input)
1800 ;; the t flag makes the buffer advance
1801 (comint-send-input nil t))))
1803 (setq compilation-filenames '("Makefile" "makefile"))
1805 (defun get-nearest-compilation-file ()
1806 "Search for the compilation file traversing up the directory tree."
1808 (let ((dir default-directory)
1809 (parent-dir (file-name-directory (directory-file-name default-directory)))
1810 (nearest-compilation-file 'nil))
1811 (while (and (not (string= dir parent-dir))
1812 (not nearest-compilation-file))
1813 (dolist (filename compilation-filenames)
1814 (setq file-path (concat dir filename))
1815 (when (file-readable-p file-path)
1816 (setq nearest-compilation-file file-path)))
1817 (setq dir parent-dir
1818 parent-dir (file-name-directory (directory-file-name parent-dir))))
1819 nearest-compilation-file))
1822 "call run-fun if it is set, else run make if there is a makefile,
1823 else save and repeat last shell command.
1824 run-fun is meant to store file local variables, which show how to
1825 do the main thing we want on this file, generally compile and
1828 example of setting it in a file:
1830 ;; run-fun: merge-test
1833 (if (and (boundp 'run-fun) run-fun)
1835 (let ((makefile (get-nearest-compilation-file)))
1836 (if (and makefile (stringp mode-name) (string= mode-name "C/l"))
1838 "make -f %s" (get-nearest-compilation-file)))
1842 (defun send-shell ()
1844 (send-shell-buffer "*shell*" 'shell (kbd "C-v")))
1846 (defun send-python ()
1848 (send-shell-buffer "*Python*" 'py-shell (kbd "C-v")))
1851 (defun send-shell-buffer (buffer-name &optional init shell-send-yank-key)
1852 "Send current line or region to shell-mode buffer.
1853 When in shell-mode, copy the current line to the
1854 most recently visited visible window.
1856 SHELL-SEND-YANK-KEY: key to use instead
1857 of yank to paste into recent window. This allows compatibility with
1858 modes like org-mode which have their own yank function."
1859 (if (string= (buffer-name) buffer-name)
1860 ;; this section is copied out of comint-send-input
1862 (let ((proc (get-buffer-process (current-buffer))))
1863 (if (not proc) (user-error "Current buffer has no process")
1866 (let* ((pmark (process-mark proc))
1867 (intxt (if (>= (point) (marker-position pmark))
1868 (progn (if comint-eol-on-send (end-of-line))
1869 (buffer-substring pmark (point)))
1870 (let ((copy (funcall comint-get-old-input)))
1875 (if (= (length intxt) 0)
1876 (kill-new (comint-previous-matching-input-string "." 1))
1877 (kill-new intxt)))))
1878 (kill-append "\n" nil)
1879 (select-window (previous-window nil nil 'visible))
1880 (if (and (boundp 'shell-send-yank-key) shell-send-yank-key)
1881 (call-interactively (global-key-binding shell-send-yank-key))
1883 (select-window (next-window nil nil 'visible)))
1888 (setq start (save-excursion (beginning-of-line) (point))
1889 end (save-excursion (end-of-line) (point)))
1890 (let (line-move-visual)
1891 (call-interactively 'next-line)))
1892 (send-comint-input buffer-name start end init))))
1894 ;; supporting functions
1895 (defun send-comint-input (buffer-name start end &optional init)
1896 "Input the region to BUFFER-NAME, assuming it is a comint-derived buffer.
1897 Show BUFFER-NAME if it is not show.
1898 Call INIT if BUFFER-NAME does not exist."
1899 (let ((input (filter-buffer-substring start end)))
1900 (send-comint-string buffer-name input init)))
1902 (defun send-comint-string (buffer-name string &optional init)
1903 "Input the string to BUFFER-NAME, assuming it is a comint-derived buffer.
1904 Show BUFFER-NAME if it is not show.
1905 Call INIT if BUFFER-NAME does not exist."
1906 (let ((buffer (get-buffer buffer-name)))
1908 (message "nobuffer")
1909 ;; save-excursion etc. don't work for (shell), so I do this instead
1910 (if init (let ((original-buffer (current-buffer)))
1911 (funcall init (and (boundp 'send-shell-buffer-name) send-shell-buffer-name))
1912 (switch-to-buffer original-buffer)
1913 (setq buffer (get-buffer buffer-name)))
1914 (error "No existing buffer found and no init function argument. ")))
1915 (buffer-window-show buffer)
1916 (with-current-buffer buffer
1917 (let ((proc (get-buffer-process buffer)))
1918 (goto-char (process-mark proc))
1920 (comint-send-input nil t)))))
1922 (defun buffer-window-show (&optional buffer action)
1923 "Like temp-buffer-window-show, but removed stuff
1924 relevant to it being temp or help."
1926 (with-current-buffer buffer
1927 (when (let ((window-combination-limit
1928 ;; When `window-combination-limit' equals
1929 ;; `temp-buffer' or `temp-buffer-resize' and
1930 ;; `temp-buffer-resize-mode' is enabled in this
1931 ;; buffer bind it to t so resizing steals space
1932 ;; preferably from the window that was split.
1933 (if (or (eq window-combination-limit 'temp-buffer)
1934 (and (eq window-combination-limit
1935 'temp-buffer-resize)
1936 temp-buffer-resize-mode))
1938 window-combination-limit)))
1940 ;;(message "window-combination-limit")
1941 ;;(print window-combination-limit)
1942 (setq window (display-buffer buffer action)))
1943 (setq frame (window-frame window))
1944 (unless (eq frame (selected-frame))
1945 (raise-frame frame))
1946 (setq minibuffer-scroll-window window)
1947 (set-window-hscroll window 0)
1948 ;; Return the window.
1952 ;; when poping help, etc, allow reusing a window in a different frame if it is visible
1953 ;; figured this out after spending quite a while reading doc string for display-buffer
1954 ;; which is the main function which uses this.
1955 ;; it will use other vars or its arg to override this,
1956 ;; but those things are often nil.
1957 ;; aha moments in reading it: ACTION = (FUNCTION-or-FUNCTIONLIST ALIST)
1958 ;; FRAME adds an association to ACTION's alist, but it's not used if ACTION arg is nil.
1959 (setq display-buffer-fallback-action `(,(car display-buffer-fallback-action) . '(reusable-frames . visible)))
1960 ;; stop splitting windows verticallly when I open a buffer or shell
1961 (setq split-height-threshold nil)
1963 ;;;;; s-left arrow - ---
1964 ;; cant be used in terminal
1965 ;; When I had a binding, i did this so org-mode wouldnt clobber it
1966 ;; (add-hook 'org-mode-hook
1968 ;; (define-key org-mode-map (kbd "<S-left>") nil)))
1970 ;;;;; s-right arrow - keyboard-yank-primary
1971 (defun keyboard-yank-primary ()
1973 (let ((mouse-yank-at-point t))
1974 (mouse-yank-primary nil)))
1976 (global-set-key (kbd "<S-right>") 'keyboard-yank-primary)
1977 (add-hook 'org-mode-hook
1979 (define-key org-mode-map (kbd "<S-right>") nil)))
1980 ;;;;; esc --- terminal dup
1981 ;; todo, test out if this can be used
1982 ;;;;; return - new line
1984 ;; todo, this doesn't set the keybind for the help minibuffer
1987 (global-set-key (kbd "\r") 'indent-new-comment-line)
1989 ;; don't use enter for autocomplete, we use tab or something
1990 (define-key ac-completing-map (kbd "<return>") nil)
1991 (define-key ac-completing-map "\r" nil)
1993 (add-hook 'org-mode-hook
1995 ;; copied from org-mode, replace org-enter with org-enter-indent
1996 (org-defkey org-mode-map "\C-m" 'org-return-indent)))
1999 (add-hook 'comint-mode-hook
2001 (define-key comint-mode-map "\r" nil)
2002 (define-key comint-mode-map (kbd "RET") 'comint-send-input)))
2004 (add-hook 'comint-mode-hook
2006 (define-key comint-mode-map "\C-m" nil)
2007 (define-key comint-mode-map "\C-d" nil)))
2009 ;;;;; s-return - auto-correct-prev-word
2010 (global-set-key (kbd "<S-return>") 'flyspell-auto-correct-previous-word)
2011 ;; kp-enter is shift return in terminal
2012 (global-set-key (kbd "<kp-enter>") 'flyspell-auto-correct-previous-word)
2014 ;;;;; s-up arrow - my-contract-region
2015 (global-set-key (kbd "<S-up>") 'my-contract-region)
2016 ;;;;; c-up/down move 8 lines
2018 ;; compiling warns that next-line should be called interactively,
2019 ;; but we would have to do something dumb, like give it a
2020 ;; vector of keys in order to supply the 8 argument
2028 (global-set-key (kbd "<C-up>") 'up-fast)
2029 (global-set-key (kbd "<C-down>") 'down-fast)
2031 ;;;;; c-scroll comint prev/next prompt
2033 (add-hook 'comint-mode-hook
2035 (define-key comint-mode-map (kbd "<C-mouse-4>") 'comint-previous-prompt)
2036 (define-key comint-mode-map (kbd "<C-mouse-5>") 'comint-next-prompt)))
2037 ;;;;; m-scroll prev/next sexp
2038 (global-set-key (kbd "<M-mouse-4>") 'backward-sexp)
2039 (global-set-key (kbd "<M-mouse-5>") 'forward-sexp)
2040 ;;;;; S-scroll expand/contract region
2041 (global-set-key (kbd "<S-mouse-13>") 'my-contract-region)
2042 (global-set-key (kbd "<S-mouse-14>") 'er/expand-region)
2043 (global-set-key (kbd "<S-mouse-4>") 'my-contract-region)
2044 (global-set-key (kbd "<S-mouse-5>") 'er/expand-region)
2046 (defun my-contract-region (arg)
2048 (let ((current-prefix-arg '-))
2049 (call-interactively 'er/expand-region)))
2051 ;; todo: define c-m scroll. i manually set to normal scrolling, i dunno why
2054 ;;;;; c-s-scroll scale text
2056 (global-set-key (kbd "<C-S-mouse-4>") 'text-scale-increase)
2057 (global-set-key (kbd "<C-S-mouse-5>") 'text-scale-decrease)
2058 (global-set-key (kbd "<C-S-mouse-13>") 'text-scale-increase)
2059 (global-set-key (kbd "<C-S-mouse-14>") 'text-scale-decrease)
2060 (global-set-key (kbd "<C-S-down>") 'text-scale-increase)
2061 (global-set-key (kbd "<C-S-up>") 'text-scale-decrease)
2064 ;;;;; s-up arrow er/expand-region
2065 (global-set-key (kbd "<S-down>") 'er/expand-region)
2066 ;;;;; c-left/right move symbol
2068 (global-set-key (kbd "<C-left>") 'backward-symbol)
2069 (global-set-key (kbd "<C-right>") 'forward-symbol)
2073 ;;;;; M-2 shell-cd-to-file
2076 (defun shell-cd-to-file ()
2078 (let ((file (buffer-file-name)))
2080 (send-comint-string "*shell*"
2081 (concat "c " (file-name-directory file))
2083 (message "%s" "shell-cd-to-file: buffer has no file name"))))
2084 (global-set-key (kbd "M-2") 'shell-cd-to-file)
2086 ;;;;; C-M-2 copy-symbol
2087 (global-unset-key (kbd "C-M-2"))
2088 (defun copy-symbol (&optional arg)
2089 "Copy symbol at point into kill-ring"
2091 (kill-new (thing-at-point 'symbol)))
2093 (global-set-key (kbd "C-M-2") 'copy-symbol)
2095 ;;;;; M-3 dot-mode-execute
2097 (global-set-key (kbd "M-3") 'dot-mode-execute)
2099 ;;;;; C-M-3 recenter-top-bottom
2101 (global-set-key (kbd "C-M-3") 'recenter-top-bottom)
2103 ;;;;; C-q org-cycle, comint previous arg
2105 (global-set-key (kbd "C-q") 'bicycle-cycle)
2106 (add-hook 'org-mode-hook
2107 (lambda () (define-key org-mode-map (kbd "C-q") 'org-cycle)))
2108 (define-key widget-keymap (kbd "C-q") 'widget-forward)
2109 (add-hook 'comint-mode-hook
2110 (lambda () (define-key comint-mode-map (kbd "C-q") 'comint-insert-previous-argument)))
2113 ;;;;; C-M-q quoted-insert
2115 (global-set-key (kbd "C-M-q") 'quoted-insert)
2117 ;;;;; C-w counsel-find-file
2119 (global-set-key (kbd "C-w") 'counsel-find-file)
2123 (global-set-key (kbd "M-w") 'shell-wrap)
2127 ;; todo, make repeated calls to this append the kills
2128 (defun copy-line (&optional arg)
2129 "Copy lines (as many as prefix argument) in the kill ring.
2130 Ease of use features:
2131 - Move to start of next line.
2132 - Appends the copy on sequential calls.
2133 - Use newline as last char even on the last line of the buffer.
2134 - If region is active, copy its lines."
2136 (let ((beg (line-beginning-position))
2137 (end (line-end-position (or arg 1))))
2139 (if (> (point) (mark))
2140 (setq beg (save-excursion (goto-char (mark)) (line-beginning-position)))
2141 (setq end (save-excursion (goto-char (mark)) (line-end-position)))))
2142 (if (eq last-command 'copy-line)
2143 (kill-append (buffer-substring beg end) (< end beg))
2144 (kill-ring-save beg end)))
2145 (kill-append "\n" nil)
2146 ;; dun need cuz I have yank-better
2147 ;;(beginning-of-line (or (and arg (1+ arg)) 2))
2148 (if (and arg (not (= 1 arg))) (message "%d lines copied" arg)))
2150 (global-set-key (kbd "C-e") 'copy-line)
2154 ;;;;; C-r isearch-backward
2156 (global-set-key (kbd "C-r") 'isearch-backward)
2157 (add-hook 'comint-mode-hook
2159 (define-key comint-mode-map (kbd "C-r") 'comint-history-isearch-backward-regexp)))
2164 ;;;;; C-a copy buffer
2167 "Copy entire buffer to clipboard"
2169 (clipboard-kill-ring-save (point-min) (point-max)))
2170 (global-set-key (kbd "C-a") 'copy-all)
2172 ;;;;; C-s - c-x prefix
2173 ;; prefix key binds.
2174 ;; good info http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/
2175 ;; rebinding the prefix keys are tricky. apparently, some modes ignore any redefinition of a prefix key and use it explicitly,
2176 ;; so you have to dig into their key maps and redo things.
2177 ;; There are 2 simpler alternatives which have their own downsides.
2178 ;; One is cua mode, which I do not like because it smashes 2 keybinds onto 1 and limits what you can do.
2179 ;; The other is keyboard-translate, which translates the key presses before anything else.
2180 ;; The downside is that it translates them when you aren't using them as a prefix.
2181 ;; Since the swaps I'm using are all very accessible, the only downside is some mental jugling when reading docs etc about these keybinds.
2183 ;; I've seen this as an another suggestion, it was a total fail. The prefix command took over both keys.
2184 ;; (define-key key-translation-map [f12] "\C-c")
2185 ;; (define-key key-translation-map "\C-c" [left])
2188 ;;idea to remove the hook later since it is only needed at startup.
2189 ;; did not work however, and there is not a real need to fix it, so I did not investigate
2190 ;;(defun removeSwapHook ()
2191 ;; (remove-hook 'buffer-list-update-hook 'myKeySwap)
2192 ;; (remove-hook 'change-major-mode-hook 'removeSwapHook))
2193 ;;(add-hook 'change-major-mode-hook 'removeSwapHook)
2196 ;; went through almost all the relevant standard hooks,
2197 ;; this overcomes a known bug that (keyboard-translate) does not get applied when running emacs daemon
2198 (add-hook 'buffer-list-update-hook (lambda () (interactive)
2199 (keyboard-translate ?\C-x ?\C-s)
2200 (keyboard-translate ?\C-s ?\C-x)
2201 (keyboard-translate ?\C-c ?\C-d)
2202 (keyboard-translate ?\C-d ?\C-c)))
2206 ;; these all don't work
2207 ;; don't know why this doesn't error but reversing the keys does
2208 ;;(keyboard-translate ?\t ?\M-\t)
2209 ;;(keyboard-translate [M-tab] [tab])
2210 ;; from what i can tell, it wants to use a keyboard-translate-table,
2211 ;; which is a char table, which is a vector indexed by chars,
2212 ;; and mod+tab is not a char (it has too many bits), it is an integer
2213 ;; it actually says it can hold vectors or strings, but that it is obsolete to do so
2214 ;;(characterp ?\M-a)
2215 ;;(characterp ?\C-a)
2217 ;;;;; C-M-s - split-window-vertically
2219 (global-set-key (kbd "C-M-s") 'split-window-vertically)
2221 ;;;;; C-d - C-c prefix
2225 (global-set-key (kbd "M-d") 'run)
2227 ;;;;; C-M-d - split-window-horizontally
2229 (global-set-key (kbd "C-M-d") 'split-window-horizontally)
2232 ;;;;; C-f - kill-whole-line
2234 (global-set-key (kbd "C-f") 'kill-whole-line-wrapper)
2235 (defun kill-whole-line-wrapper (&optional arg)
2236 "If we are at the end of the file, kill backwards instead of doing nothing."
2238 (if (= (point) (point-max))
2239 (kill-whole-line -1)
2240 (kill-whole-line arg)))
2242 ;;;;; M-f - print-var-at-point
2244 (defun print-var-at-point ()
2246 (let ((v (variable-at-point)))
2248 (message "%s: %s" v (symbol-value v))
2249 (message "no symbol found at point"))))
2250 (global-set-key (kbd "M-f") 'print-var-at-point)
2253 ;;;;; C-M-f - kill rest of line
2256 (add-hook 'org-mode-hook
2258 (define-key org-mode-map (kbd "C-M-f") 'org-kill-line)))
2260 (global-set-key (kbd "C-M-f") 'kill-line)
2261 ;;;;; C-g - keyboard-quit
2262 ;;;;; M-g - abort-recursive-edit
2264 (global-set-key (kbd "M-g") 'abort-recursive-edit)
2268 (global-set-key (kbd "C-M-g") 'mu4e)
2270 ;;;;; C-z - undo-only
2271 (global-set-key (kbd "C-z") 'undo-tree-undo)
2272 ;;;;; C-M-z - suspend-frame
2273 (global-set-key (kbd "C-M-z") 'suspend-frame)
2274 ;; this is never good in a gui
2275 (when (window-system)
2276 (defun suspend-frame() (interactive)))
2278 ;;;;; C-x - kill-region
2280 (global-set-key (kbd "C-s") 'kill-region)
2282 ;;;;; M-x - counsel-m-x
2285 ;; todo; check out smex-show-unbound-commands shows frequently used commands that have no key bindings.
2286 ;; this must be before smex-initialize
2288 smex-save-file (concat user-emacs-directory ".smex-items"))
2291 (global-set-key (kbd "M-x") 'counsel-M-x)
2293 ;;;;; C-M-x - cut-to-register
2295 ;; same args as copy-to-register
2296 (defun cut-to-register (register start end &optional delete-flag region)
2297 (interactive (list (register-read-with-preview "Cut to register: ")
2302 (copy-to-register register start end t region))
2304 (global-set-key (kbd "C-M-x") 'cut-to-register)
2308 (global-set-key (kbd "C-d") 'kill-ring-save)
2309 (add-hook 'c-mode-hook
2310 (lambda () (define-key c-mode-map (kbd "C-d") nil)))
2311 (add-hook 'comint-mode-hook
2313 (define-key comint-mode-map (kbd "C-d") nil)))
2314 ;; the base map is shared by many c-modes, like java
2315 (add-hook 'c-mode-hook
2317 (define-key c-mode-base-map "\C-d" nil)
2318 (define-key c-mode-base-map (kbd "<deletechar>") 'c-electric-delete-forward)))
2321 ;;;;; M-c - delete-other-windows
2323 (define-key global-map "\M-c" 'delete-other-windows)
2325 ;;;;; C-M-c - copy-to-register
2327 (global-set-key (kbd "C-M-c") 'copy-to-register)
2331 (global-set-key (kbd "C-v") 'yank-better)
2335 (defun yank-better (arg)
2336 "Paste, linewise if our kill ends with a newline.
2337 I change the behavior of plain prefix. It makes it not do linewise paste,
2338 because sometimes you want to yank pop and a linewise paste screws that up.
2339 c-u with no number normally makes the point go before the yank.
2340 That is pointless for me, as it would be just as easier and less
2341 thought to pop the mark after yanking cuz it is set to before the mark."
2343 (if (and (not (equal arg '(4))) (string-suffix-p "\n" (current-kill 0 t)))
2344 (beginning-of-line))
2345 (if (and (stringp mode-name) (string= mode-name "Org"))
2346 (call-interactively 'org-yank)
2347 (setq this-command 'yank)
2348 (call-interactively 'yank (and (not (equal arg '(4)))))))
2350 (put 'yank-better 'delete-selection 'yank)
2352 ;;;;; M-v - insert-register
2354 (global-set-key (kbd "M-v") 'insert-register)
2356 ;;;;; C-M-v - yank-pop
2358 (global-set-key (kbd "C-M-v") 'yank-pop)
2360 ;;;;; C-b - other-window
2362 (global-set-key (kbd "C-b") 'other-window)
2364 ;;;;; M-b - isearch-backward-current-symbol
2366 (global-set-key (kbd "M-b") 'isearch-backward-current-symbol)
2368 ;;;;; C-M-b - isearch-current-symbol
2370 (global-set-key (kbd "C-M-b") 'isearch-current-symbol)
2373 ;; in terminal, it's just TAB, duplicate keybind.
2375 ;; in terminal it's duplicated of C-M-i
2376 ;;;;; C-delete - kill-symbol
2378 (global-set-key (kbd "<C-delete>") 'kill-symbol)
2379 (defun kill-symbol (arg)
2381 (kill-region (point) (save-excursion (forward-symbol arg) (point))))
2384 ;;;;; C-M-delete - kill-sexp
2386 (global-set-key (kbd "<C-M-delete>") 'kill-sexp)
2388 ;;;;; C-left-arrow - compile / comint search
2391 (and (bound-and-true-p var)
2392 (not (eq var 'unset))))
2393 (global-set-key (kbd "C-(") 'run)
2395 ;; make compile work from the gtags root dir
2396 (defadvice compile (before pre-compile-advice activate)
2398 (when (set-p ggtags-project-root)
2399 (setq-local compile-saved-dir default-directory)
2400 (setq default-directory ggtags-project-root)))
2401 (defadvice compile (after post-compile-advice activate)
2402 (when (bound-and-true-p compile-saved-dir)
2403 (setq default-directory compile-saved-dir)))
2406 (add-hook 'c-mode-hook (lambda () (define-key c-mode-map (kbd "C-(") 'compile)))
2407 (add-hook 'comint-mode-hook
2409 (define-key isearch-mode-map (kbd "C-(") 'isearch-repeat-backward)
2410 (define-key comint-mode-map (kbd "C-(") 'isearch-backward)))
2413 ;;;;; C-M-left-arrow - org-shiftup
2415 (add-hook 'org-mode-hook
2416 (lambda () (define-key org-mode-map (kbd "C-M-(") 'org-shiftup)))
2418 ;;;;; C-right-arrow - forward-symbol
2419 ;;;;; C-M-right-arrow - org-shiftdown
2420 (add-hook 'org-mode-hook
2421 (lambda () (define-key org-mode-map (kbd "C-M-)") 'org-shiftdown)))
2423 ;;;;; C-backspace - backward-kill-symbol
2425 (define-key terminal-key-map (kbd "4b") 'backward-kill-symbol) ;c-backspace in my konsole
2427 ;; c-w is duplicate in terminal
2428 (global-set-key (kbd "<C-backspace>") 'backward-kill-symbol)
2429 (add-hook 'comint-mode-hook
2431 (define-key comint-mode-map (kbd "<C-backspace>") 'backward-kill-word)))
2432 (defun backward-kill-symbol (arg)
2434 (kill-region (point) (save-excursion (backward-symbol arg) (point))))
2436 ;;;;; C-M-backspace - backward-kill-sexp
2438 (global-set-key (kbd "<C-M-backspace>") 'backward-kill-sexp)
2441 ;;;;; M-8 - delete-window-or-exit
2443 (global-set-key (kbd "M-8") 'delete-window-or-exit)
2445 (defun delete-window-or-exit ()
2446 "Delete window or exit emacs."
2448 (if (condition-case nil (delete-window) (error t))
2449 (if (or (boundp 'server-process) (> (length (frame-list)) 1))
2450 (progn (basic-save-buffer) (delete-frame))
2451 (save-buffers-kill-terminal t))))
2453 ;;;;; C-* - --- terminal
2454 ;;;;; C-M-* - calc-dispatch
2456 (global-set-key (kbd "C-M-*") 'calc-dispatch)
2458 ;;;;; M-9 - kill-buffer
2460 (defun kill-buffer-no-ido ()
2461 "kill-buffer, avoid the ido remapping"
2464 (global-set-key (kbd "M-9") 'kill-buffer-no-ido)
2466 ;; strangely, in simple mode, this is overridden.
2467 ;; I found this map to override, but it didn't work, so it seems its being bound some other way.
2468 ;; I did a grep of the emacs sources, but couldn't find anything.
2469 ;; (define-key universal-argument-map [?9 nil)
2471 ;;;;; C-M-9 - end server edit
2472 ;; save & kill buffer if it was opened externally via emacsclient
2475 (defun server-edit-save ()
2479 (global-set-key (kbd "C-M-9") 'server-edit-save)
2481 ;;;;; C-u - universal-argument
2482 ;;;;; C-M-u - search-keybind
2484 (global-set-key (kbd "C-M-u") 'search-keybind)
2486 (defun search-keybind (regexp &optional nlines)
2487 (interactive (occur-read-primary-args))
2490 (set-buffer "*Help*")
2492 (delete-windows-on "*Help*")
2496 ;; todo: try making use
2497 ;; this is the key in terminal
2498 ;;M-[ 4 d is undefined
2500 ;; previously had this for enhancing graphical keybinds,
2501 ;; but afaik its no help since i want terminal to work
2503 ;; (define-key input-decode-map [?\C-i] [C-i])
2505 ;;;;; C-M-i - query-replace-regexp
2507 (global-set-key (kbd "C-M-i") 'query-replace-regexp)
2508 (add-hook 'flyspell-mode-hook
2509 (lambda () (define-key flyspell-mode-map (kbd "C-M-i") nil)))
2510 (add-hook 'text-mode-hook
2511 (lambda () (define-key text-mode-map (kbd "C-M-i") nil)))
2516 (global-set-key (kbd "C-o") 'occur)
2518 ;;;;; C-M-o - counsel-imenu
2520 (global-set-key (kbd "C-M-o") 'counsel-imenu)
2522 ;;;;; C-p - move-mouse-to-point
2524 (global-set-key (kbd "C-p") 'move-mouse-to-point)
2526 ;;;;; C-M-p - delete-horizontal-space
2528 (global-set-key (kbd "C-M-p") 'delete-horizontal-space)
2530 ;;;;; C-j - pop-to-mark
2532 (defun my-pop-to-mark-command ()
2533 "Jump to mark, and pop a new position for mark off the ring.
2534 \(Does not affect global mark ring\)."
2536 (pop-to-mark-command)
2537 (if (and (derived-mode-p 'org-mode) (outline-invisible-p))
2538 (org-show-context 'mark-goto)))
2540 (global-set-key (kbd "C-j") 'my-pop-to-mark-command)
2541 (add-hook 'ido-setup-hook
2543 (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text)
2545 (add-hook 'lisp-interaction-mode-hook
2547 (define-key lisp-interaction-mode-map (kbd "C-j") nil)))
2550 ;;;;; M-j - previous-error
2552 (global-set-key (kbd "M-j") 'previous-error)
2554 ;;;;; C-M-j - register prefix
2556 (define-key global-map (kbd "C-M-j") ctl-x-r-map)
2557 (define-key ctl-x-r-map "m" 'kmacro-to-register)
2560 ;;;;; C-k - jump-to-register
2563 (global-set-key (kbd "C-k") 'jump-to-register)
2565 ;;;;; M-k - next-error
2567 (global-set-key (kbd "M-k") 'next-error)
2571 (global-set-key (kbd "C-M-k") 'man)
2573 ;;;;; C-l - ivy-switch-buffer
2575 (global-set-key (kbd "C-l") 'ivy-switch-buffer)
2577 ;;;;; C-M-l - move cursor top bottom mid, comint clear screen
2579 (global-set-key (kbd "C-M-l") 'move-to-window-line-top-bottom)
2581 ;;;;; C-; - used in flyspell, not sure what for, otherwise unbound
2582 ;;;;; M-; - comment-dwim
2583 ;;;;; C-M-; - comment-current-line-dwim
2585 (defun comment-current-line-dwim ()
2586 "Comment or uncomment the current line."
2589 (push-mark (beginning-of-line) t t)
2592 (move-beginning-of-line 2))
2593 (global-set-key (kbd "C-M-;") 'comment-current-line-dwim)
2596 ;; terminal/console needs this. otherwise, we could do this
2597 ;; to make C-m be a valid key in graphical mode.
2598 ;; (define-key input-decode-map [?\C-m] [C-m])
2599 ;;;;; C-M-m - recursive grep
2601 (define-key global-map (kbd "C-M-m") 'rgrep)
2604 ;; not recognized by terminal, can't get konsole keydef file to recognize comma,
2605 ;; todo: dig into konsole sources, or try newer version than t8
2607 (add-hook 'flyspell-mode-hook
2608 (lambda () (define-key flyspell-mode-map (kbd "C-,") nil)))
2610 ;;;;; C-M-, - ind-file-in-project
2612 (global-set-key (kbd "C-M-,") 'find-file-in-project)
2614 ;;;;; C-. - find recent file
2616 (add-hook 'flyspell-mode-hook
2617 (lambda () (define-key flyspell-mode-map (kbd "C-.") nil)))
2618 (define-key dot-mode-map (kbd "C-.") nil)
2619 (define-key terminal-key-map (kbd "4c") 'counsel-recentf)
2620 (global-set-key (kbd "C-.") 'counsel-recentf)
2621 (add-hook 'php-mode-hook
2622 (lambda () (define-key php-mode-map (kbd "C-.") nil)))
2626 (define-key dot-mode-map (kbd "C-M-.") nil)
2627 ;; (global-set-key (kbd "C-M-.") 'execute-extended-command)
2629 ;;;;; C-/ - join lines
2631 (defun vim-style-join-line ()
2635 (global-set-key (kbd "C-_") 'vim-style-join-line)
2637 (global-set-key (kbd "C-/") 'vim-style-join-line)
2638 (define-key undo-tree-map (kbd "C-/") nil)
2639 (define-key undo-tree-map (kbd "C-_") nil)
2641 ;;;;; C-M-/ - copy-buffer-file-name
2643 ;; haven't bound this atm, todo, maybe someday?
2644 (defun copy-variable (variable)
2646 (let ((v (variable-at-point))
2647 (enable-recursive-minibuffers t)
2649 (setq val (completing-read (if (symbolp v)
2651 "Describe variable (default %s): " v)
2652 "Describe variable: ")
2655 (or (get vv 'variable-documentation)
2656 (and (boundp vv) (not (keywordp vv)))))
2658 (if (symbolp v) (symbol-name v))))
2659 (list (if (equal val "")
2661 (kill-new (symbol-value variable)))
2663 (defun copy-buffer-file-name ()
2666 ((derived-mode-p 'mu4e-view-mode) (mu4e-message-field-at-point :path))
2667 (t buffer-file-name))
2673 (global-set-key (kbd "C-M-/") 'copy-buffer-file-name)
2677 ;;;;; C-up-arrow - org prev headline
2679 ;; disabled just because i don't want to accidentally hit it
2680 (define-key global-map "\C-_" nil)
2681 (global-set-key (kbd "<C-_>") 'beginning-of-defun)
2683 (add-hook 'org-mode-hook
2685 (define-key org-mode-map (kbd "\C-_") 'outline-previous-visible-heading)))
2690 ;;;;; C-S-up-arrow - winner undo
2692 (global-set-key (kbd "<C-S-_>") 'winner-undo)
2694 ;;;;; C-down-arrow - org next headline
2696 (global-set-key (kbd "<C-kp-enter>") 'end-of-defun)
2698 (add-hook 'org-mode-hook
2700 (define-key org-mode-map (kbd "<C-kp-enter>") 'outline-next-visible-heading)))
2705 ;;;;; C-M-down-arrow - toggle-mark-activation
2707 (defun toggle-mark-activation ()
2713 (global-set-key (kbd "<C-M-kp-enter>") 'toggle-mark-activation)
2715 ;;;;; C-S-down-arrow winner redo
2717 (global-set-key (kbd "<C-S-kp-enter>") 'winner-redo)
2720 ;;;;; C-S-down-arrow - m-x for major mode
2722 ;; todo, update this for ivy
2723 (global-set-key (kbd "<C-S-kp-enter>") 'smex-major-mode-commands)
2725 ;;;;; C-lbracket - ----
2726 ;;;;; C-M-lbracket - scroll-right
2728 (global-set-key (kbd "C-M-[") 'scroll-right)
2730 ;;;;; C-rbracket - fill-paragraph
2732 (global-set-key (kbd "C-]") 'fill-paragraph)
2734 ;;;;; C-M-rbracket - scroll-left
2736 (global-set-key (kbd "C-M-]") 'scroll-left)
2738 ;;;;; C-return - newline-anywhere
2740 (defun newline-anywhere ()
2741 "Add a newline from anywhere in the line."
2744 (newline-and-indent))
2745 ;; todo use alternate keybind make this work for terminal
2746 (global-set-key (kbd "<C-return>") 'newline-anywhere)
2749 ;;;;; M-return - plain newline
2751 (defun plain-newline ()
2754 (global-set-key (kbd "M-RET") 'plain-newline)
2757 ;;;;; C-space - org-edit-special
2759 ;; commented due to new keyboard needing ctrl-space for mark
2760 ;; (kbd "<C-space>") does not work, (kbd "C-SPC") should work
2761 ;; (add-hook 'org-mode-hook
2763 ;; (define-key org-mode-map (kbd "C-SPC") 'org-edit-special)
2764 ;; ;; org-src-mode-map is broken in git version of emacs.
2765 ;; ;; temporarily use this for exiting edit-special mode.
2766 ;; (global-set-key (kbd "C-M--") 'org-edit-src-exit)
2767 ;; (define-key org-src-mode-map (kbd "C-SPC") 'org-edit-src-exit)))
2769 ;;;;; C-M-space - before or under cursor
2771 (global-set-key (kbd "C-M-SPC") 'ispell-word)
2775 (global-set-key (kbd "C-M-4") 'widen)
2777 ;;;;; C-tab-key - query-replace
2780 (global-set-key (kbd "<C-kp-add>") 'query-replace)
2782 ;;;;; C-t - org cycle todo / toggle comint motion
2784 (add-hook 'org-mode-hook
2786 (define-key org-mode-map (kbd "C-t") 'org-todo)))
2788 (defun my-comint-previous-input (arg)
2790 (if (comint-after-pmark-p)
2791 (comint-previous-input arg)
2794 (defun my-comint-next-input (arg)
2796 (if (comint-after-pmark-p)
2797 (comint-next-input arg)
2800 (add-hook 'comint-mode-hook
2802 (define-key comint-mode-map (kbd "C-t") 'comint-toggle-arrow-keys)
2803 (define-key comint-mode-map (kbd "<up>") 'my-comint-previous-input)
2804 (define-key comint-mode-map (kbd "<down>") 'my-comint-next-input)))
2807 (defun comint-toggle-arrow-keys ()
2809 (toggle-arrow-keys comint-mode-map))
2811 (setq-default comint-arrow-movement nil)
2812 (defun toggle-arrow-keys (map)
2813 (cond ((lookup-key map (kbd "<up>"))
2814 (setq-local comint-arrow-movement t)
2815 (define-key map (kbd "<up>") nil)
2816 (define-key map (kbd "<down>") nil))
2818 (setq-local comint-arrow-movement nil)
2819 (define-key map (kbd "<up>") 'my-comint-previous-input)
2820 (define-key map (kbd "<down>") 'my-comint-next-input)
2821 (goto-char (point-max)))))
2823 (eval-after-load "message"
2824 '(define-key message-mode-map (kbd "C-t") 'mail-signature))
2827 ;;;;; C-M-t - org timestamp
2829 (global-set-key (kbd "C-M-t") 'org-time-stamp-with-time)
2831 ;;;;; C-home - start of buffer
2832 ;;;;; C-end - end of buffer
2833 ;;;; right secondary
2834 ;;;;; C-^ - save-buffers-kill-emacs
2836 (global-set-key (kbd "C-^") 'save-buffers-kill-emacs)
2838 ;;;;; C-M-6 - insert-small-copyright
2840 (defun insert-small-copyright ()
2843 (let ((beg (point)))
2844 (insert "Copyright (C) 2019 Ian Kelling\nThis program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>")
2845 (comment-region beg (point))))
2847 (global-set-key (kbd "C-M-6") 'insert-small-copyright)
2849 ;;;;; M-7 - calc-embedded-word
2851 (global-set-key (kbd "M-7") 'calc-embedded-word)
2853 ;;;;; C-M-7 - insert-full-copyright
2855 (defun insert-full-copyright ()
2858 (let ((beg (point)))
2859 (insert "Copyright (C) 2019 Ian Kelling\n")
2861 (insert "This program is free software: you can redistribute it and/or modify\n")
2862 (insert "it under the terms of the GNU General Public License as published by\n")
2863 (insert "the Free Software Foundation, either version 3 of the License, or\n")
2864 (insert "(at your option) any later version.\n")
2866 (insert "This program is distributed in the hope that it will be useful,\n")
2867 (insert "but WITHOUT ANY WARRANTY; without even the implied warranty of\n")
2868 (insert "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n")
2869 (insert "GNU General Public License for more details.\n")
2871 (insert "You should have received a copy of the GNU General Public License\n")
2872 (insert "along with this program. If not, see <http://www.gnu.org/licenses/>.\n")
2873 (comment-region beg (point))))
2875 (global-set-key (kbd "C-M-7") 'insert-full-copyright)
2878 ;;;;; C-0 - text-scale-reset
2880 (defun text-scale-reset ()
2883 (global-set-key (kbd "C-0") 'text-scale-reset)
2885 ;;;;; C-M-0 - insert-apache
2887 (defun insert-apache ()
2890 (let ((beg (point)))
2891 (insert "Copyright (C) 2017 Ian Kelling\n")
2893 (insert "Licensed under the Apache License, Version 2.0 (the \"License\");\n")
2894 (insert "you may not use this file except in compliance with the License.\n")
2895 (insert "You may obtain a copy of the License at\n")
2897 (insert " http://www.apache.org/licenses/LICENSE-2.0\n")
2899 (insert "Unless required by applicable law or agreed to in writing, software\n")
2900 (insert "distributed under the License is distributed on an \"AS IS\" BASIS,\n")
2901 (insert "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n")
2902 (insert "See the License for the specific language governing permissions and\n")
2903 (insert "limitations under the License.\n")
2904 (comment-region beg (point))))
2905 (global-set-key (kbd "C-M-0") 'insert-apache)
2908 ;;;;; C-M-- - org-edit-src-exit
2911 (global-set-key (kbd "C-y") 'undo-tree-redo)
2912 (add-hook 'org-mode-hook
2913 (lambda () (define-key org-mode-map (kbd "C-y") nil)))
2916 ;;;;; C-\ - sr-speedbar-toggle
2917 (global-set-key (kbd "C-\\") 'sr-speedbar-toggle)
2919 ;;;;; C-M-\ - mark-defun
2921 (global-set-key (kbd "C-M-\\") 'mark-defun)
2923 ;;;;; C-h - help-prefix
2925 ;;;;; C-' - val-expression
2927 (global-set-key (kbd "C-'") 'eval-expression)
2929 ;;;;; C-n - unpop to mark
2931 (defun unpop-to-mark-command ()
2932 "Unpop off mark ring. Does nothing if mark ring is empty."
2935 (let ((pos (marker-position (car (last mark-ring)))))
2936 (if (not (= (point) pos))
2938 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
2939 (set-marker (mark-marker) pos)
2940 (setq mark-ring (nbutlast mark-ring))
2941 (goto-char (marker-position (car (last mark-ring))))))))
2943 (global-set-key (kbd "C-n") 'unpop-to-mark-command)
2945 ;;;;; C-M-n - narrow-to-region
2947 (global-set-key (kbd "C-M-n") 'narrow-to-region)
2949 ;;;;; C-escape - find-tag
2951 (global-set-key (kbd "<C-escape>") 'find-tag)
2955 ;; eval: (outline-minor-mode)
2956 ;; outline-regexp: "\\( *\\);;;\\{1,8\\} "