minor config update
[dot-emacs] / init.el
diff --git a/init.el b/init.el
index f6f68de64601216e94fa34119284dbfd3a19e5a6..e91121ded3628786f3166f302634219a3e0688e7 100644 (file)
--- a/init.el
+++ b/init.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2019 Ian Kelling
+;; Copyright (C) 2020 Ian Kelling
 
 ;; This program is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-
 ;; do m-x benchmark-init to see some benchmark stats
-;;(add-to-list 'load-path "~/.emacs.d/src/benchmark-init-el/")
+;;(add-to-list 'load-path (concat user-emacs-directory "src/benchmark-init-el/")
 ;;(require 'benchmark-init-loaddefs)
 ;;(benchmark-init/activate)
 
-
 ;;; init.el --- the start of customization
 
-;; (toggle-debug-on-error) ;uncomment to help debug
-
+;;(toggle-debug-on-error) ;uncomment to help debug
 
-;; Package.el added this a long time ago. emacs 26 gives a warning that
-;; this is obsolete, but it doesn't happen automatically in batch mode,
-;; and then emacs dies on error, so it doesn't seem obsolete to me.
 
 
 ;; stop from minimizing & freezing the gui
 (global-unset-key (kbd "C-z"))
 
 ;; speed up init https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/
-(setq gc-cons-threshold 100000000)
+;; https://github.com/jwiegley/dot-emacs/blob/master/init.el
+(defvar file-name-handler-alist-old file-name-handler-alist)
+(setq package-enable-at-startup nil
+      file-name-handler-alist nil
+      message-log-max 16384
+      gc-cons-threshold 402653184
+      gc-cons-percentage 0.6
+      auto-window-vscroll nil)
+
+(add-hook 'after-init-hook
+          `(lambda ()
+             (setq file-name-handler-alist file-name-handler-alist-old
+                   ;; 100 mb
+                   gc-cons-threshold 100000000))
+          ;; taken from wiegley, dunno why the t is there.
+          t)
+
+;; stuff to allow an alternate location for ~/.emacs.d
+(setq user-emacs-directory (file-name-directory user-init-file))
+(when (getenv "EHOME")
+  (setenv "HOME" (getenv "EHOME")))
+
+;; 2019-6-26, 1.26s
+;; ; to profile init:
+;; ; uncomment the following block
+;;(require 'benchmark-init)
+;;(add-hook 'after-init-hook 'benchmark-init/deactivate)
+;; ; Then run:
+;; ; emacs -f benchmark-init/show-durations-tabulated
+;; ; emacs -f benchmark-init/show-durations-tree
+;; ; to catch things post-init
+;; ; emacs -f benchmark-init/deactivate
 
 
 ;; these need to be done before the hook in order to satisfy the byte compiler or batch mode
 
-;; this is the builtin org mode
-;;(add-to-list 'load-path "~/.emacs.d/emacs/site-lisp/org")
-
-(add-to-list 'load-path "~/.emacs.d/src/readline-complete")
+(add-to-list 'load-path (concat user-emacs-directory "src/readline-complete"))
 
 ;; disabled since not used.
-;;(add-to-list 'load-path "~/.emacs.d/src/bbdb-csv-import")
-
-(add-to-list 'load-path "~/.emacs.d/src/ghci-completion")
-(add-to-list 'load-path "~/.emacs.d/src/mediawiki-el")
-(add-to-list 'load-path "~/.emacs.d/src/spray")
-(add-to-list 'load-path "~/.emacs.d/src/visible-mark")
-
+;;(add-to-list 'load-path (concat user-emacs-directory "src/bbdb-csv-import"))
+;;(add-to-list 'load-path (concat user-emacs-directory "src/spray"))
 
-;; git version of gnus
-;; (add-to-list 'load-path "~/.emacs.d/src/gnus/lisp")
-(require 'info)
-(add-to-list 'Info-default-directory-list "~/.emacs.d/src/gnus/texi")
+(add-to-list 'load-path (concat user-emacs-directory "src/visible-mark"))
 
-;; needed for git version
-;;(add-to-list 'load-path "~/.emacs.d/src/haskell-mode")
-;;(require 'haskell-mode-autoloads)
-;;(add-to-list 'Info-default-directory-list "~/.emacs.d/src/haskell-mode")
 
-;; for using custom/upstream bbdb
-;;(require 'bbdb-loaddefs "~/.emacs.d/src/bbdb/lisp/bbdb-loaddefs.el")
-;;(setq bbdb-print-tex-path "~/.emacs.d/src/bbdb/tex")
-
-
-;; iank: dunno what this was about
-;;(add-hook 'server-visit-hook 'raise-frame)
 
 (setq init-dir (file-name-directory load-file-name))
 ;; previously, i was doing byte-recompile-directory, but
 ;; now i just have one init file
 (unless (equal (user-uid) 0) ; don't make root owned files
-  (byte-recompile-file (expand-file-name "init.el" init-dir)))
-
-;; load init in `after-init-hook' so all packages are loaded. However, disabled because
-;; there seems to be no need.
-;; todo, learn about the weird evaluation order of this hook that requires the quoting.
-;; adapted from starter-kit
-;; (add-hook 'after-init-hook
-;;           `(lambda ()
-;;              (load-file (expand-file-name "myinit.el" init-dir))
-;;              ))
-
-
-;;; Weird package bug workaround
-
-
-;; without this, when installing a package, this message happens
-;;
-;; custom-handle-keyword: Unknown keyword :group
-;;
-;; but when i lookup the function, i get the following, and if
-;; I evaluate it, the error goes away. so I think the real
-;; definition is happening somewhere else
-
-(defun custom-handle-keyword (symbol keyword value type)
-  "For customization option SYMBOL, handle KEYWORD with VALUE.
-Fourth argument TYPE is the custom option type."
-  (if purify-flag
-      (setq value (purecopy value)))
-  (cond ((eq keyword :group)
-        (custom-add-to-group value symbol type))
-       ((eq keyword :version)
-        (custom-add-version symbol value))
-       ((eq keyword :package-version)
-        (custom-add-package-version symbol value))
-       ((eq keyword :link)
-        (custom-add-link symbol value))
-       ((eq keyword :load)
-        (custom-add-load symbol value))
-       ((eq keyword :tag)
-        (put symbol 'custom-tag value))
-       ((eq keyword :set-after)
-        (custom-add-dependencies symbol value))
-       (t
-        (error "Unknown keyword %s" keyword))))
-
+  (byte-recompile-file (expand-file-name "init.el" init-dir) nil 0)
+  (when (file-exists-p "/p/c/mymu4e.el")
+    (byte-recompile-file "/p/c/mymu4e.el" nil 0))
+  )
 
 ;;; misc emacs documentation
 
@@ -211,7 +173,7 @@ Fourth argument TYPE is the custom option type."
 ;; nnfolder-generate-active-file
 
 ;; to reset things, when changing mail group. I duno all the proper way, but it works to delete
-;; ~/Mail ~/.newsrc.eld ~/.dribble (or something)
+;; ~/Mail ~/.newsrc.eld ~/.newsrc-dribble
 
 
 ;;;;; mail sources vs select methods background
@@ -242,76 +204,38 @@ Fourth argument TYPE is the custom option type."
 
 
 ;;; things that should be at the beginning
-;; todo, evaluating this manually disables debug on error instead of toggling it
-(toggle-debug-on-error) ;uncomment to help debug and catch errors
-
-;; packages installed from package manager: i pretty much prioritize repos this way: gnu, then melpa, then marmalade.
-
-;; package-activated-list:
-;; ac-dabbrev ac-haskell-process ack-and-a-half alect-themes auctex bash-completion bbdb csv-mode cyberpunk-theme dot-mode expand-region f find-file-in-project flycheck foreign-regexp ggtags ghc gnuplot-mode goto-chg haskell-mode heroku-theme highlight-indentation highlight-symbol htmlize inf-ruby info+ inkpot-theme jedi auto-complete jedi-core epc ctable concurrent key-chord leuven-theme logstash-conf magit git-commit magit-popup misc-fns mouse+ naquadah-theme nginx-mode occidental-theme org paredit pcsv php-mode pkg-info epl popup py-autopep8 python-environment deferred python-info python-mode rainbow-mode rust-mode rw-hunspell s smartparens smex smooth-scroll sr-speedbar strings swiper ivy tabulated-list tangotango-theme thingatpt+ undo-tree vimrc-mode volatile-highlights web-mode with-editor dash async ws-butler yasnippet
-
-;;;; alternate keyboards
-;; todo, figure out an easy way to disable this when using external keyboard
-(if (display-graphic-p)
-    (setq
-     enter-key (kbd "<return>")
-     s-enter-key (kbd "<S-return>")
-     c-m-enter-key (kbd "<C-M-return>")
-     m-enter (kbd "<M-return>")
-     c-enter (kbd "<C-return>"))
-  (setq
-   enter-key (kbd "C-m")
-   s-enter-key (kbd "C-8")
-   c-m-enter-key (kbd "C-M-8")
-   m-enter (kbd "M-m")
-   c-enter (kbd "C-8")))
-
-(setq tp (string= (system-name) "tp"))
-(setq x200 (string= (system-name) "x2"))
-(setq laptop-keyboard (or tp x200))
-
-;; Ubiquitous Packages which should be loaded on startup rather than
-;;   autoloaded on demand since they are likely to be used in every
-;;   session.
-(require 'saveplace)
-(require 'ffap)
-(require 'uniquify)
-(require 'ansi-color)
-(require 'recentf)
 
-;; Better to have a list of packages in here vs installed manually.
-;;   However, I install manually because sometimes there are two
-;;   versions and it is not necessarily easy to reconcile that.
-;; based on marmalage website front page.
-(require 'package)
+;; from its README.md
+(eval-when-compile
+  (require 'use-package))
+(use-package use-package-ensure-system-package
+  :ensure t)
 
-;; little kit to help remove a down server
-;; (setq package-archives nil)
+;; Ubiquitous Packages. these could go anywhere actually
 
-;;(add-to-list 'package-archives
-;;             '("marmalade" .
-;;               "http://marmalade-repo.org/packages/"))
+;; find file at point
+(use-package ffap)
 
-(add-to-list 'package-archives
-             '("melpa" . "http://melpa.milkbox.net/packages/") t)
-(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
 
 
-;; keep our init.el clean, by moving customization elisp to it's own file
-(setq custom-file "~/.emacs.d/custom.el")
-(load custom-file 'noerror)
-
 
+(setq package-archives
+      (quote
+       (("gnu" . "https://elpa.gnu.org/packages/")
+        ("MELPA" . "https://melpa.org/packages/"))))
 
-;;; abreviations
-;; turn on abbrev mode globally
-(setq-default abbrev-mode t)
+;;(add-to-list 'package-archives
+;;             '("marmalade" .
+;;               "http://marmalade-repo.org/packages/"))
 
-;; default abbreviation mode file is .emacs.d/abbrev_defs.
-;; add-global-abbrev, add-mode-abbrev for expansion at point
-;; if all else fails, edit the abbrev file
+;; down atm 2020-08-30
+;;(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
 
 
+;; keep our init.el clean, by moving customization elisp to it's own file
+(setq custom-file (concat user-emacs-directory "custom.el"))
+;; empty atm
+;;(load custom-file 'noerror)
 
 
 ;;; auto-complete
@@ -320,18 +244,18 @@ Fourth argument TYPE is the custom option type."
 ;; disabled while I look for another alternative
 ;;(icomplete-mode)
 
+(unless (string= (daemonp) "server")
+  (setq ac-use-comphist nil))
 (require 'auto-complete-config)
 (ac-config-default)
 
 
 ;; complete after 1 char instead of default 2
-(setq ac-auto-start 1)
-(setq ac-delay 0.001)
+(setq ac-auto-start 1
+      ac-delay 0.001)
 
 (add-to-list 'ac-modes 'org-mode 'sql-mode)
 
-(defun ac-common-setup ()
-  (add-to-list 'ac-sources 'ac-source-yasnippet))
 
 ;; for org mode completion source taken from wiki.
 ;; it did not work. no idea why. todo, investigate
@@ -350,7 +274,8 @@ Fourth argument TYPE is the custom option type."
 (define-key ac-completing-map (kbd "<down>") nil)
 (define-key ac-completing-map (kbd "<S-return>") 'ac-expand)
 (define-key ac-completing-map "\t" 'ac-complete)
-(define-key ac-completing-map (kbd "<tab>") 'ac-complete)
+;;(define-key ac-completing-map (kbd "<tab>") 'ac-complete)
+(define-key ac-completing-map (kbd "TAB") 'ac-complete)
 
 
 
@@ -395,12 +320,14 @@ Fourth argument TYPE is the custom option type."
 
 (add-hook 'shell-mode-hook
           (lambda ()
-            (define-key shell-mode-map (kbd "<tab>") 'auto-complete)))
+            ;;(define-key shell-mode-map (kbd "<tab>") 'auto-complete)
+            (define-key shell-mode-map (kbd "TAB") 'auto-complete)
+            ))
 
 
 ;;; readline complete fix
 
-;; I need this function here, where INSIDE_EMACS is replaced with RLC_INSIDE_EMACS.
+;; I need this function here, where INSIDE_EMACS is replaced with LC_INSIDE_EMACS.
 ;; ian: last update 2017-1-7. update this periodically from upstream
 ;; like when we do a major emacs update
 (defun comint-exec-1 (name buffer command switches)
@@ -419,12 +346,12 @@ Fourth argument TYPE is the custom option type."
                    (format "COLUMNS=%d" (window-width)))
            (list "TERM=emacs"
                  (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))
-         (list (format "RLC_INSIDE_EMACS=%s,comint" emacs-version))
+         (list (format "LC_INSIDE_EMACS=%s,comint" emacs-version))
          process-environment))
        (default-directory
-         (if (file-accessible-directory-p default-directory)
-             default-directory
-           "/"))
+        (if (file-accessible-directory-p default-directory)
+            default-directory
+          "/"))
        proc decoding encoding changed)
     (let ((exec-path (if (and command (file-name-directory command))
                         ;; If the command has slashes, make sure we
@@ -447,7 +374,34 @@ Fourth argument TYPE is the custom option type."
        (set-process-coding-system proc decoding encoding))
     proc))
 
-;;; auto save & backup
+;;; auto save
+
+;; todo: patch this so i can turn it off like my-as-off-local.
+;; then try it out and see if it can replace my autosave.
+;; Or maybe with the new auto-save-visited-mode.
+;; (use-package super-save
+;;   :ensure t
+;;   :config
+;;   (setq super-save-exclude '("")
+;;         super-save-triggers
+;;         '(balance-windows
+;;           next-buffer
+;;           org-babel-execute-src-block
+;;           other-window
+;;           previous-buffer
+;;           split-window-below
+;;           split-window-horizontally
+;;           start-process-shell-command
+;;           switch-to-buffer
+;;           windmove-down
+;;           windmove-left
+;;           windmove-right
+;;           windmove-up)
+;;         )
+;;   (super-save-mode +1))
+
+
+
 (setq auto-save-timeout 1) ; idle time before auto-save.
 
 ;; main hook for my auto save
@@ -461,7 +415,9 @@ Fourth argument TYPE is the custom option type."
 
 ;; avoid window config hook saving too much, it can
 ;; get into loops in some random situations
-(setq my-auto-save-last nil)
+(defvar my-auto-save-last nil)
+(defvar my-as nil)
+(defvar my-auto-save-last nil)
 (defun my-auto-save-win ()
   (unless (eq (current-buffer) my-auto-save-last)
     (my-auto-save (current-buffer))))
@@ -473,7 +429,7 @@ Fourth argument TYPE is the custom option type."
          ;; mu4e has a bug right now, undo breaks when saving drafts
          (not (string= (buffer-file-name) "*draft*"))
          (buffer-modified-p)
-         (not (org-src-edit-buffer-p)))
+         (not (and (boundp 'org-src-edit-buffer-p) (org-src-edit-buffer-p))))
     ;; serial is incremented on each save, so let's do a bit less of them
     (not (derived-mode-p 'dns-mode))
     (setq my-auto-save-last last)
@@ -498,7 +454,7 @@ Fourth argument TYPE is the custom option type."
 
 (defun my-as-on-local (&rest ignore)
   (interactive)
-  (setq-local my-as on))
+  (setq-local my-as t))
 
 ;; based on suggestion in the emacs docs, redefine these 2 functions
 ;; to avoid prompt spamming the user when we do auto-save
@@ -554,13 +510,15 @@ A non-nil CURRENT-ONLY argument means save only current buffer."
       ;; assume hard linked files are done on purpose, don't screw them up
       backup-by-copying-when-linked t)
 
+(defvar last-backup-time 0)
 ;; todo, the time needs to be an integer, not a vector type thing
 (defun constant-backup ()
   "Backup conditioned on some time passing since last one.
   Hooked into 'before-save-hook."
   (cl-flet ((b-time (minutes)
-                    (< last-backup-time
-                       (- (current-time) (* 60 minutes)))))
+              (< last-backup-time
+                 ;; current-time is seconds, so convert minutes to seconds.
+                 (- (current-time) (* 60 minutes)))))
     (when (or (not (boundp 'last-backup-time)) (and (< (buffer-size) 10000000) (b-time 5)) (b-time 30))
       (setq buffer-backed-up nil)
       (setq-local last-backup-time (current-time)))))
@@ -592,56 +550,11 @@ A non-nil CURRENT-ONLY argument means save only current buffer."
 ;;         but new emacs version fixed all that, yay!.
 
 
-                                        ; not using, but here for documentation,
-                                        ; alternate way to enable and specify how long between autosaves.
-                                        ; number of input events between autosave.
-                                        ; lowest bound of functionality is actually about 15 input events
-                                        ;(setq auto-save-interval
-
-;;; bbdb
-;; based on bbdb manual
-;; also has instructions to integrate with gnus,
-
-(bbdb-initialize 'message)
-
-;; recommended by gnus,
-;; but seems like it could be good to have set for other stuff
-(setq user-full-name "Ian Kelling")
-;; general email setting? recommended by mu4e
-(setq message-kill-buffer-on-exit t)
-
-
-
-;; use d instead
-(add-hook 'bbdb-mode-hook
-          (lambda () (define-key bbdb-mode-map (kbd "C-k") nil))
-          ;; based on emacs24-starter-kit
-          (setq bbdb-offer-save 'auto
-                bbdb-notice-auto-save-file t
-                bbdb-expand-mail-aliases t
-                bbdb-canonicalize-redundant-nets-p t
-                bbdb-complete-name-allow-cycling t)
-          )
-
-;;(require 'bbdb-csv-import)
-
-;;; bookmark settings
-                                        ; save bookmarks whenever they are changed instead of just when emacs quits
-(setq bookmark-save-flag 1)
-                                        ; increase bookmark context size for better functionality
-(setq bookmark-search-size 2000)
-
-;;; c-like settings
-;; change last thing from gnu.
-;; notably this avoids brace indent after if, and 4 space indent
-(setq c-default-style '((java-mode . "java")
-                        (awk-mode . "awk")
-                        (other . "stroustrup")))
-;; for emacs itself, use
-;; (setq c-default-style '((java-mode . "java")
-;;                         (awk-mode . "awk")
-;;                         (other . "gnu")))
-;; (setq-default c-basic-offset 2)
+;; not using, but here for documentation,
+;; alternate way to enable and specify how long between autosaves.
+;; number of input events between autosave.
+;; lowest bound of functionality is actually about 15 input events
+;; (setq auto-save-interval ...)
 
 ;;; color theme
 
@@ -650,30 +563,50 @@ A non-nil CURRENT-ONLY argument means save only current buffer."
 ;; themes are available through ELPA.
 
 
-;; interesting light themes
-
-
 (defun override-theme (arg)
   (interactive)
   (while custom-enabled-themes
     (disable-theme (car custom-enabled-themes)))
   (load-theme arg t))
-(setq color-theme-is-global t)
+
+;; not a real var? remove when I see this again
+;;(setq color-theme-is-global t)
+
+;; temporary, make night be default
 
 (defun toggle-night ()
   (interactive)
   (cond  ((equal (car custom-enabled-themes) 'naquadah)
-          (override-theme 'leuven))
+          (override-theme 'ef-light))
          (t
           (override-theme 'naquadah))))
 
+(setq ef-themes-mixed-fonts t
+      ef-themes-variable-pitch-ui t)
+
 
 ;; in the leuven theme file, i made this change. will need to remake it
 ;; on package updates. I could fork, but its a pretty simple change
 ;; < `(default ((,class (:foreground "#333333" :background "#FFFFFF"))))
 ;; > `(default ((,class (:foreground "#333333" :background "#F6F6F0"))))
-(override-theme 'leuven)
+;;
+;; <   `(font-lock-comment-face ((,class (:slant italic :foreground "#8D8D84")))) ; #696969
+;; >   `(font-lock-comment-face ((,class (:slant italic :foreground "#484848")))) ; #696969
+
+;;(override-theme 'leuven)
 
+;; based on ef-themes README.org
+(mapc #'disable-theme custom-enabled-themes)
+;; the default blue is too dark and messes with erc colors
+(setq ef-light-palette-overrides
+      '((bg-mode-line "#efefef")))
+(ef-themes-select 'ef-light)
+;;(load-theme 'ef-light)
+
+
+;; for learning about faces, see
+;; useful snippet
+;; (byte-recompile-file "/home/iank/.emacs.d/elpa/leuven-theme-20220203.947/leuven-theme.el" nil 0)
 
 ;; disable color thing with this:
 ;;(disable-theme (car custom-enabled-themes))
@@ -696,8 +629,6 @@ A non-nil CURRENT-ONLY argument means save only current buffer."
 ;;(override-theme 'wombat) ; cursor not visible enough. from a wombat package, not sure which
 ;;(override-theme 'misterioso) ; cursor not visible enough
 
-
-
 ;;decent light themes
 ;;(override-theme 'alect-light) ; theres a -alt version, don't see a dif. could use this without dimming. from alect-something package
 ;;(override-theme 'occidental) ; from occidental-theme package
@@ -712,477 +643,83 @@ A non-nil CURRENT-ONLY argument means save only current buffer."
 
 
 
-
-;;; yasnippet
-
-;; cd ~/.emacs.d/src
-;; git clone --recursive https://github.com/capitaomorte/yasnippet
-;; touch snippets/.yas-make-groups
-
-;;   This all makes it so I can look through the default snippets
-;;   in the menu bar, but they don't show up elsewhere, because they are
-;;   mostly things I don't want.
-
-
-(require 'yasnippet)
-;; this needs to be before yas-global-mode
-(setq yas-snippet-dirs (list "~/.emacs.d/snippets"))
-(yas-global-mode 1)
-
-(setq
- yas-also-auto-indent-first-line t
- yas-choose-tables-first t
- yas-use-menu (quote full)
- ;; this sets ido-prompt as first function
- yas-prompt-functions
- '(yas-ido-prompt yas-dropdown-prompt yas-x-prompt yas-completing-prompt yas-no-prompt))
-
-;; todo, explore this option for wrapping region
-;; '(yas/wrap-around-region t))
-
 ;;; cross session settings
 
-;; Save a list of recent files visited.
-(recentf-mode 1)
-(setq recentf-max-saved-items 200
-      recentf-max-menu-items 15)
-
-
-(setq save-place t
-      save-place-version-control 'nospecial
-      save-place-limit 40000
-      save-place-file "~/.emacs.d/places")
-
-
-
-;; savehist keeps track of some history
-;; search entries
-(setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring)
-      ;; save every minute
-      savehist-autosave-interval 60
-      ;; keep the home clean
-      savehist-file "~/.emacs.d/.savehist")
-(savehist-mode 1)
-
-
-;;; ediff
-;; ediff-buffers is the main command to use
 
-;; ediff - don't start another frame for the control panel
-;; unfortunately, this doesn't allow me to use 2 frames for the diff buffers
-;; so disable this temporarily with the next line if you want that
-;; sometime I should setup 2 functions to explicitly do each type
-(setq ediff-window-setup-function 'ediff-setup-windows-plain)
-;;(setq ediff-window-setup-function 'ediff-setup-windows-default)
 
-;; do side by side diffs
-(setq ediff-split-window-function 'split-window-horizontally)
-
-
-
-;; Things I tried which didn't work, which intuitively I think should
-;; work better: I can open the second diff buffer in a new frame, and
-;; close it's window in the first frame after starting ediff, but when I
-;; hit n to go to the next diff, it restores the window in the first
-;; frame. Another thing I tried is to open 2 new frames and set them up
-;; as I want. However, if I try to open the *Ediff Control Panel* buffer
-;; in a different window from its original one, my mouse jumps to one of
-;; the diff frames, or if that isn't visible, the buffer just hangs
-;; until I select the original ediff control panel window. This seems
-;; like a bug to me. I am using a very recent development version of
-;; emacs.
+(use-package recentf
+  ;; defer & commands from jwiegley
+  :defer 10
+  :if (string= (daemonp) "server")
+  :commands (recentf-mode
+             recentf-add-file
+             recentf-apply-filename-handlers)
+  :config
+  (recentf-mode 1)
+  (setq recentf-max-saved-items 400
+        recentf-max-menu-items 15)
+  )
+
+(when (string= (daemonp) "server")
+  ;; save it every 5 minutes. https://www.emacswiki.org/emacs/RecentFiles
+  (run-at-time nil (* 5 60) 'recentf-save-list))
+
+;; less strong conditional: :unless noninteractive
+(use-package saveplace
+  :if (string= (daemonp) "server")
+  :config
+  (setq
+   save-place-version-control 'nospecial
+   save-place-limit 4000
+   save-place-file (concat user-emacs-directory "places"))
+  (save-place-mode 1))
+
+
+;; savehist keeps track of some history search entries
+(use-package savehist
+  :if (string= (daemonp) "server")
+  :config
+  (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring)
+        ;; save every minute
+        savehist-autosave-interval 60
+        ;; keep the home clean
+        savehist-file (concat user-emacs-directory ".savehist"))
+  (savehist-mode 1))
 
 ;;; dired
 
 ;; dired - reuse current buffer by pressing 'a'
 (put 'dired-find-alternate-file 'disabled nil)
 
-;;; mu4e
-
-;; alsot tried notmuch, it had some glitches, and it's config has a list
-;; of folders which i'd rather not publish, so it's config is archived.
-
-;;(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e")
-;;(add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e")
-(require 'mu4e)
-
-;; (setq mu4e-headers-results-limit 2000)
-
-(setq
- ;; common to gnus. default sendmail-query-once asks us, then sets this via customize.
- send-mail-function (quote sendmail-send-it)
- ;; use the standard imap folders
- mu4e-sent-folder   "/Sent"
- mu4e-drafts-folder "/Drafts"
- mu4e-trash-folder  "/Trash"
- ;; reindex new mail this often in seconds
- ;; show addresses instead of just names
- mu4e-view-show-addresses t
- mu4e-use-fancy-chars t
- mu4e-confirm-quit nil
- mu4e-headers-leave-behavior 'apply ;; dont ask, do whatever was marked
- mu4e-headers-fields (delq (assoc :mailing-list mu4e-headers-fields) mu4e-headers-fields)
- ;; default 500.
- mu4e-headers-results-limit 1000
- ;; tell exim to use from: as envelope from.
- ;; exim's default is use outgoing_msg_localpart@hostname.
- mail-specify-envelope-from t
-
- ;; looking up the list of maildirs when doing jo from summary
- ;; can take a few seconds if we have a ton of messages.
- ;; Only take that time for the first lookup.
- ;; if we add a new maildir, just restart mu4e for it to be in that list.
- mu4e-cache-maildir-list t
- ;; default is 8, way too small for my big monitors
- mu4e-headers-visible-lines 50
- )
-
-;; fucks up reading unread bookmark. when that is fixed, enable it
-;; (setq mu4e-update-interval 60)
 
+;; copied from dired-x info manual
+(with-eval-after-load 'dired
+  (require 'dired-x)
+  ;; use e instead for find file. i would like
+  ;; dired-do-async-shell-command, except it pops open some async
+  ;; shell buffer. i should figure out how to get rid of that.
+  (define-key dired-mode-map "f" 'dired-do-shell-command)
+  ;; Set dired-x global variables here.  For example:
+  ;; (setq dired-guess-shell-gnutar "gtar")
+  ;; (setq dired-x-hands-off-my-keys nil)
+  )
+(add-hook 'dired-mode-hook
+          (lambda ()
+            ;; Set dired-x buffer-local variables here.  For example:
+            ;; (dired-omit-mode 1)
+            ))
 
-;; this file includes setting up my email addresses, which are not public,
-;; including
-;; mu4e-user-mail-address-list
-;; and a function
-;; inspired by mu4e info manual, search for mu4e-compose-pre-hook.
-(load "/p/c/mu4e.el")
-
-(defun my-decrypt ()
-  ;; use for decrypting in mu4e
-  (interactive)
-  (beginning-of-buffer)
-  (when (search-forward "-----BEGIN PGP MESSAGE-----" nil t)
-    (read-only-mode 0)
-    (let ((start (match-beginning 0))
-          (end (search-forward "-----END PGP MESSAGE-----" nil t)))
-      (shell-command-on-region start end "gpg2 -dq" nil t shell-command-default-error-buffer t)
-      )))
-(add-hook 'mu4e-view-mode-hook 'my-decrypt)
-
-(defun mu-set-from-name (regexes)
-  "If we find an address matching regex, then set that address as the to,
-and whatever was used"
-  (when mu4e-compose-parent-message
-    (let ((found nil))
-      (while (and regexes (not found))
-        (setq re (car regexes)
-              regexes (cdr regexes)
-              found (mu4e-message-contact-field-matches
-                     mu4e-compose-parent-message :to re)))
-      (when found (setq user-mail-address (cdr found)
-                        user-full-name (car found)))
-      found)))
-(defun mu-set-from (regexes)
-  "If we find an address matching regex, then set that address as the to,
-and Ian Kelling as the name"
-  (when mu4e-compose-parent-message
-    (let ((found nil))
-      (while (and regexes (not found))
-        (setq re (car regexes)
-              regexes (cdr regexes)
-              found (cdr (mu4e-message-contact-field-matches
-                          mu4e-compose-parent-message :to re))))
-      (when found (setq user-mail-address found
-                        user-full-name "Ian Kelling"))
-      found)))
-
-
-(defun my-mu4e-to-fsf ()
-  "inspired by mu4e info manual, search for mu4e-compose-pre-hook."
-  (cond
-   ((mu-set-from '("iank@fsf.org"
-                   "iank@gnu.org")))
-   ((setq user-mail-address "iank@fsf.org"
-          user-full-name "Ian Kelling"))))
-
-
-;; on first run   mkdir -p /nocow/user/.mufsf; mu index --maildir=/nocow/user/fsfmd
-(defun mu-exit-wait ()
-  (interactive)
-  ;; taken from the mu source
-  (let* ((buf (get-buffer mu4e~proc-name))
-        (proc (and (buffer-live-p buf) (get-buffer-process buf))))
-    (mu4e-quit)
-    ;; without sleep, we get database locked by another process error when hitting u
-    ;; if another mu was running.
-    (if proc (sleep-for 0 1000))))
-
-(defun fsf-mu4e ()
-  (interactive)
-  (unless (equal mu4e-maildir "/nocow/user/fsfmd") (mu-exit-wait))
-  (setq
-   ;; fsf monitor is smaller
-   mu4e-headers-visible-lines 15
-   mu4e-maildir "/nocow/user/fsfmd"
-   mu4e-refile-folder "/Spam"
-   mu4e-index-lazy-check nil
-   mu4e-get-mail-command "true"
-   user-mail-address "iank@fsf.org"
-   ;; WARNING: be careful editing this, there needs to be a space after --, and my editor
-   ;; and git will automatically remove it unless i manually disable it.
-   mail-signature "
-
---
-Ian Kelling | Senior Systems Administrator, Free Software Foundation
-GPG Key: B125 F60B 7B28 7FF6 A2B7  DF8F 170A F0E2 9542 95DF
-https://fsf.org | https://gnu.org
-"
-
-   mu4e-user-mail-address-list '("iank@fsf.org"
-                                 "iank@gnu.org")
-   mu4e-maildir-shortcuts
-   '( ("/INBOX"     . ?i)
-      ("/sysadmin" . ?a)
-      ("/sec"  . ?x)
-      ("/rtcc"  . ?c)
-      ("/Drafts"     . ?d)
-      ("/Sent"     . ?s)
-      )
-   ) ;; end setq
-  (call-process "/a/exe/lnf" nil nil nil "-T" "/nocow/user/.mufsf" (concat (getenv "HOME") "/.mu"))
-  (add-hook 'mu4e-compose-pre-hook 'my-mu4e-to-fsf)
-  (remove-hook 'mu4e-compose-pre-hook 'my-mu4e-to)
-  (mu4e)) ;; end defun fsf-mu4e
-
-
-;; it's implemented in mu4e, but not in the actions list for
-;; some reason.
-(add-to-list 'mu4e-view-actions
-             '("browser view" . mu4e-action-view-in-browser) t)
-
-;; normally, you would add to this, but we want to
-;; modify unread messages. the first 4 are defined by default.
-(setq mu4e-bookmarks
-      `( ,(make-mu4e-bookmark
-           :name  "Unread messages"
-           ;; old less restrictive unread, for adapting in the future:
-           ;; flag:unread AND NOT flag:trashed AND NOT maildir:/Junk AND NOT maildir:/fwfw AND NOT maildir:/log
-           :query "flag:unread maildir:/INBOX"
-           :key ?u)
-         ,(make-mu4e-bookmark
-           :name "Today's messages"
-           :query "date:today..now"
-           :key ?t)
-         ,(make-mu4e-bookmark
-           :name "Last 7 days"
-           :query "date:7d..now"
-           :key ?w)
-         ,(make-mu4e-bookmark
-           :name "Messages with images"
-           :query "mime:image/*"
-           :key ?p))
-      )
-
-
-(defun mu4e-action-msgs-by-this-sender (msg)
-  "In header view, view messages by the sender of the message under point."
-  (let ((from (mu4e-message-field msg :from)))
-    (unless from
-      (mu4e-error "No from header for this message"))
-    ;; from is structured like: (("Anacron" . "root@x2.lan"))
-    (mu4e-headers-search (concat "f:" (cdar from)))))
-
-(add-to-list 'mu4e-headers-actions
-             '("from this sender" . mu4e-action-msgs-by-this-sender) t)
-(add-to-list 'mu4e-view-actions
-             '("from this sender" . mu4e-action-msgs-by-this-sender) t)
+;; the defaults are just some weird predefined list, like xpdf for pdf.
+(setq dired-guess-shell-alist-user
+      (list
+       (list ".*" "xdg-open")
+       ))
 
 
 ;;; elisp settings
-                                        ; when manually evaluating lisp, go into debugger on error
+;; when manually evaluating lisp, go into debugger on error
 (setq eval-expression-debug-on-error t)
-                                        ;reminder of useful var: debug-on-error
-
-
-;;; haskell
-
-;; useful comint-shell mode commands. If not prefaced with *, it means it is not in the haskell custom repl
-;; *todo: setup haskell c-t toggle arrow keys
-;; tab completion
-;; C-q insert prev arg
-;; C-( history search
-;; c-m-left/right move to next/prev prompts
-;; *c-enter, multi-line input
-;; *s-delete, send input across windows. (i can implement this)
-;; *c-m-l clear screen
-;; *haskell-process-interrupt, c-cc terminate job (i can implement this maybe)
-
-;; nice bash/readline functions missing in comint:
-;; yank-nth-arg
-;; operate-get-next
-;; menu-complete
-
-;; usefull comint commands:
-;; c-cl : list historic command in temp buffer
-;; C-c C-o comint-delete-output
-;; comint-restore-input, todo: put this on a randomish c-c key
-
-
-
-;; todo:
-;; checkout haskell repl functions:
-;; c-cv haskell-check, hlint
-;; C-M-q           prog-indent-sexp
-;; c-c.  haskell-mode-format-imports
-;; C-c M-/         haskell-doc-check-active
-;; haskell-process-generate-tags
-;; haskell-process-cabal-build
-;; haskell-cabal-command.. or something
-;; haskell-process-restart
-;; C-h v haskell-process-log
-;; C-h v haskell-process-show-debug-tips
-
-;; various not immediately useful functions:
-;; haskell-process-add-dependency
-;; haskell-process-touch-buffer
-;; haskell-process-cd
-;; haskell-process-unignore
-;; haskell-process-reload-devel-main
-
-
-;; rebind
-;; home: C-a             haskell-interactive-mode-beginning
-;; c-return: C-j             haskell-interactive-mode-newline-indent
-;; up/down: <C-down>        haskell-interactive-mode-history-next
 
-;; todo haskell mode better binds for:
-;; 'haskell-process-load-file
-;; 'haskell-process-do-type
-;; 'haskell-process-do-info
-;; 'inferior-haskell-send-decl
-
-
-;; commands which don't work in haskell-interactive-mode(hi) vs inferior-haskell-mode(ih, default)
-;; functions not in hi:
-;; inferior-haskell-find-definition, use tags instead
-;; inferior-haskell-find-haddock, todo, test if this works
-
-;; redefined ih to hi
-;; switch-to-haskell -> 'haskell-interactive-switch
-;; haskell-process-load-file -> inferior-haskell-load-file
-;; haskell-process-do-type -> inferior-haskell-type
-;; switch-to-haskell -> haskell-interactive-switch
-;; inferior-haskell-load-file -> 'haskell-process-load-file
-
-
-;; haskell-mode installation from source, based on its readme
-;; in the git directory,
-;; make all
-
-
-
-
-;; remove default option to not link the file
-(setq haskell-compile-command "ghc -Wall -ferror-spans -fforce-recomp %s")
-(add-hook 'haskell-indentation-mode-hook
-          (lambda ()
-            (define-key haskell-indentation-mode-map [?\C-d] nil)
-            (define-key haskell-indentation-mode-map
-              (kbd "<deletechar>")
-              'haskell-indentation-delete-char)))
-
-;;copied from haskell-mode docs in order to use the new, better, nondefault
-;;interactive mode.
-(eval-after-load "haskell-mode"
-  '(progn
-     (define-key haskell-mode-map (kbd "C-x C-d") nil)
-     (define-key haskell-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)
-     (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-file)
-     (define-key haskell-mode-map (kbd "C-c C-b") 'haskell-interactive-switch)
-     (define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
-     (define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
-     (define-key haskell-mode-map (kbd "C-c M-.") nil)
-     (define-key haskell-mode-map (kbd "C-c C-d") nil)))
-
-;; ghc-mod install http://www.mew.org/~kazu/proj/ghc-mod/en/emacs.html
-;; todo, try this out
-;; (autoload 'ghc-init "ghc" nil t)
-;;(add-hook 'haskell-mode-hook (lambda () (ghc-init) (flymake-mode)))
-
-
-
-;; from the package readme for ghci-completion
-(require 'ghci-completion)
-(add-hook 'inferior-haskell-mode-hook 'turn-on-ghci-completion)
-
-
-;; disable some rebinds. they are set to appropriate keys in the keybinds section
-(eval-after-load "haskell-mode"
-  '(progn
-     (define-key haskell-mode-map (kbd "C-a") 'nil)
-     (define-key haskell-mode-map (kbd "C-j") 'nil)))
-
-(eval-after-load "python-mode"
-  '(progn
-     (define-key python-mode-map (kbd "C-j") nil)))
-
-(defun pretty-lambdas-haskell ()
-  (font-lock-add-keywords
-   nil `((,(concat "(?\\(" (regexp-quote "\\") "\\)")
-          (0 (progn (compose-region (match-beginning 1) (match-end 1)
-                                    ,(make-char 'greek-iso8859-7 107))
-                    nil))))))
-;; from haskell-mode manual
-(add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan)
-(when (window-system)
-  (add-hook 'haskell-mode-hook 'pretty-lambdas-haskell))
-
-;; added from haskell-mode website install instructions
-                                        ;(load "/usr/share/emacs/site-lisp/haskell-mode/haskell-site-file")
-(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
-;;the three indentation modules are mutually exclusive - add at most one. Trying out the "most advanced"
-(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
-;;(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
-;;(add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent)
-
-
-;; todo, set this to some other key
-;;    (local-set-key (kbd "C-e") 'my-haskell-load-and-run)
-
-(defun my-haskell-load-and-run ()
-  "Loads and runs the current Haskell file."
-  (interactive)
-  (let ((start-buffer (current-buffer)))
-    (inferior-haskell-load-and-run inferior-haskell-run-command)
-    (sleep-for 0 100)
-    (end-of-buffer)
-    (pop-to-buffer start-buffer)))
-
-;; show haskell function in mode line
-;; todo, this broke after updating emacs
-;;(eval-after-load "which-func"
-;;  '(add-to-list 'which-func-modes 'haskell-mode))
-
-
-
-(add-hook 'interactive-haskell-mode-hook 'ac-haskell-process-setup)
-(add-hook 'haskell-interactive-mode-hook 'ac-haskell-process-setup)
-(eval-after-load "auto-complete"
-  '(add-to-list 'ac-modes 'haskell-interactive-mode))
-
-(add-hook 'haskell-mode-hook
-          (lambda () (define-key haskell-mode-map (kbd "C-(")
-                       (lambda () (interactive)
-                         (basic-save-buffer)
-                         (haskell-compile)
-                         (run-with-timer .3 nil 'repeat-shell)))))
-(add-hook 'haskell-cabal-mode-hook
-          (lambda () (define-key haskell-cabal-mode-map (kbd "C-(") 'haskell-compile)))
-
-
-
-(add-hook 'haskell-interactive-mode-hook
-          (lambda ()
-            (define-key haskell-interactive-mode-map "\r" nil)
-            (define-key haskell-interactive-mode-map (kbd "<return>") 'haskell-interactive-mode-return)))
-(add-hook 'haskell-indentation-mode-hook (lambda () (define-key haskell-indentation-mode-map "\r" nil)))
-
-
-
-(add-hook 'haskell-interactive-mode-hook
-          (lambda ()
-            (define-key haskell-interactive-mode-map (kbd "<C-M-return>") 'haskell-interactive-mode-newline-indent)))
 
 ;;; isearch
 (setq
@@ -1261,11 +798,7 @@ https://fsf.org | https://gnu.org
     (isearch-yank-symbol partialp)))
 
 
-
-                                        ; lets look through emacs starter kit before we throw this out.
-
-
-                                        ;   automatically wrap to the top of the buffer when isearch fails
+;;   automatically wrap to the top of the buffer when isearch fails
 (defadvice isearch-search (after isearch-no-fail activate)
   (unless isearch-success
     (ad-disable-advice 'isearch-search 'after 'isearch-no-fail)
@@ -1276,11 +809,11 @@ https://fsf.org | https://gnu.org
 
 ;; Activate occur easily inside isearch
 (define-key isearch-mode-map (kbd "C-o")
-  (lambda () (interactive)
-    (let ((case-fold-search isearch-case-fold-search))
-      (occur (if isearch-regexp
-                 isearch-string
-               (regexp-quote isearch-string))))))
+            (lambda () (interactive)
+              (let ((case-fold-search isearch-case-fold-search))
+                (occur (if isearch-regexp
+                           isearch-string
+                         (regexp-quote isearch-string))))))
 ;;; lisp / elisp mode setings
 
 (add-hook 'emacs-lisp-mode-hook 'starter-kit-remove-elc-on-save)
@@ -1312,52 +845,69 @@ https://fsf.org | https://gnu.org
 ;; interactive modes don't need whitespace checks
 (defun interactive-lisp-coding-defaults ()
   (whitespace-mode -1))
-(setq prelude-interactive-lisp-coding-hook 'prelude-interactive-lisp-coding-defaults)
 
+;;; modes with little configuration needed
 
-;; ielm is an interactive Emacs Lisp shell
-(defun ielm-mode-defaults ()
-  (run-hooks 'prelude-interactive-lisp-coding-hook)
-  (turn-on-eldoc-mode))
-(add-hook 'ielm-mode-hook 'ielm-mode-defaults)
 
-;;; mediawiki
 
-(eval-after-load "mediawiki"
-  '(progn
-     (remove-hook 'outline-minor-mode-hook 'mediawiki-outline-magic-keys)
-     (add-hook 'mediawiki-mode-hook
-               (lambda () (define-key mediawiki-mode-map (kbd "C-(") 'mediawiki-save-reload)))
+(custom-set-variables
+ '(css-indent-offset 2)
+ '(sh-here-document-word "'EOF'")
+ '(outline-minor-mode-prefix "\ 3\ 1")
+ '(tramp-default-method "ssh")
+ ;; change last thing from gnu.
+ ;; notably this avoids brace indent after if, and 4 space indent
+ ;; for emacs itself, use
+ ;; (setq c-default-style '((java-mode . "java")
+ ;;                         (awk-mode . "awk")
+ ;;                         (other . "gnu")))
+ ;; (setq-default c-basic-offset 2)
+ '(c-default-style '((java-mode . "java")
+                     (awk-mode . "awk")
+                     (other . "stroustrup")))
+ )
 
-     ;; mediawiki mode has a bug that it will claim an edit conflict unless you reload after saving.
-     ;; I also like to save with no edit summary for previewing on my local mw instance
-     (defun mediawiki-save-reload ()
-       (interactive)
-       (and (mediawiki-save "") (mediawiki-reload)))))
-;;; modes with little configuration needed
-;; busted:
-;;(require 'csv-mode)
-;;(add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode))
 
-(require 'outshine)
-(add-hook 'outline-minor-mode-hook 'outshine-mode)
-(add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
-(add-hook 'sh-mode-hook 'outline-minor-mode)
+(setq
+ ;; ediff-buffers is the main command to use
+ ;; don't start another frame for the control panel
+ ;; unfortunately, this doesn't allow me to use 2 frames for the diff buffers
+ ;; so disable this temporarily with the next line if you want that
+ ;; sometime I should setup 2 functions to explicitly do each type
+ ediff-window-setup-function 'ediff-setup-windows-plain
+ ;;(setq ediff-window-setup-function 'ediff-setup-windows-default)
+ ;; do side by side diffs
+ ediff-split-window-function 'split-window-horizontally
+ ;; ediff things I tried which didn't work, which intuitively I think should
+ ;; work better: I can open the second diff buffer in a new frame, and
+ ;; close it's window in the first frame after starting ediff, but when I
+ ;; hit n to go to the next diff, it restores the window in the first
+ ;; frame. Another thing I tried is to open 2 new frames and set them up
+ ;; as I want. However, if I try to open the *Ediff Control Panel* buffer
+ ;; in a different window from its original one, my mouse jumps to one of
+ ;; the diff frames, or if that isn't visible, the buffer just hangs
+ ;; until I select the original ediff control panel window. This seems
+ ;; like a bug to me. I am using a very recent development version of
+ ;; emacs.
 
+ )
 
+;; disabled temporarily. todo, look into it
+;;(add-hook 'outline-minor-mode-hook 'outshine-mode)
 
-(setq org-caldav-url "https://cal.iankelling.org"
-      org-caldav-calendar-id "ian"
-      org-caldav-inbox "/p/cal.org")
-;;(org-caldav-sync)
 
 
-;;(require 'dtrt-indent)
-;;(setq dtrt-indent-mode t)
+;; this file includes setting up my email addresses, which are not public,
+;; including
+;; mu4e-user-mail-address-list
+;; and a function
+;; inspired by mu4e info manual, search for mu4e-compose-pre-hook.
+(when (file-exists-p "/p/c/mymu4e.el")
+  (load "/p/c/mymu4e"))
 
-(setq css-indent-offset 2)
 
-(load-file "/a/h/iank-mod.el")
+(when (file-exists-p "/a/h/iank-mod.el")
+  (load-file "/a/h/iank-mod.el"))
 
 ;; from when i was running my own patches
 ;;(add-to-list 'load-path "/a/opt/ws-butler")
@@ -1371,83 +921,40 @@ https://fsf.org | https://gnu.org
 ;; be pasting whitespace significant things in here, so
 ;; just don't do anything.
 ;; todo: propose this upstream
+;; fundamental mode for files like .asc
 (add-to-list 'ws-butler-global-exempt-modes 'message-mode)
+(add-to-list 'ws-butler-global-exempt-modes 'dns-mode)
+(add-to-list 'ws-butler-global-exempt-modes 'fundamental-mode)
 
 (ws-butler-global-mode)
 
-
-
-(require 'nginx-mode)
+;; disabled because i dont edit nginx files enough
+;; to have this loaded at startup
+;;(use-package nginx-mode)
 ;;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:
 ;;(add-to-list 'auto-mode-alist '("/etc/nginx/sites-available/.*" . nginx-mode))
 
 ;; todo, put this on a hook with prog mode
 ;;(highlight-indentation-mode 1)
 
-(add-hook 'auto-revert-tail-mode-hook
-          (lambda ()
-            (when (string=
-                   buffer-file-name
-                   "/var/log/cloudman/development/cm-service.log")
-              (setq-local prev-auto-revert-max 0)
-              ;; set buffer-local hook
-              (add-hook 'after-revert-hook 'tail-colorize nil t))))
-(defun tail-colorize ()
-  (ansi-color-apply-on-region prev-auto-revert-max (point-max))
-  (setq-local prev-auto-revert-max (point-max)))
-
-
-;; gnu global
-(require 'ggtags)
-(add-hook 'c-mode-common-hook
-          (lambda () (ggtags-mode 1)
-            (setq c-label-minimum-indentation 0)))
-
-;; specific to my unusual keybind setup, you may want to
-;; pick different keys
-(define-key ggtags-mode-map (kbd "C-M-o") 'ggtags-find-tag-dwim)
-(define-key ggtags-mode-map (kbd "C-M-m") 'ggtags-grep)
-
-(defun gtags-update-single(filename)
-  "Update Gtags database for changes in a single file"
-  (interactive)
-  (start-process "update-gtags" "update-gtags" "bash" "-c" (concat "cd " ggtags-project-root " ; gtags --single-update " filename )))
-
-(defun gtags-update-current-file()
-  (interactive)
-  (let ((rel-filename (replace-regexp-in-string
-                       ggtags-project-root "."
-                       (buffer-file-name (current-buffer)))))
-    (gtags-update-single rel-filename)))
-
-(defun gtags-update-hook()
-  "Update GTAGS file incrementally upon saving a file"
-  (when (and ggtags-mode ggtags-project-root)
-    (gtags-update-current-file)))
 
-(add-hook 'after-save-hook 'gtags-update-hook)
-
-;; i'd like to make some elisp which modifies a keymap to remove
-;; all binds which don't match a predicate.
-;; I tried setting a keymap to a new keymap,
-;; but that didn't register as functional.
-;; so I'd need to modify the list in place.
-
-(require 'magit)
-
-
-;; colorize hex colors: use rainbow mode
-
-
-;; message mode prompted me on first message.
-;; a function which describes options then sets this
-;; the other options were to use smtp directly or pass to another mail client
-;; here we use the standard sendmail interface, which I use postfix for
-(setq send-mail-function (quote sendmail-send-it))
-
-(require 'spray)
-(global-set-key (kbd "C-M-w") 'spray-mode)
-;; remember, h/l = move. f/s = faster/slower, space = pause, all others quit
+;; example of a syntax highlighted tail
+(use-package autorevert
+  :defer t
+  :config
+  (defvar prev-auto-revert-max)
+  (defun tail-colorize ()
+    (ansi-color-apply-on-region prev-auto-revert-max (point-max))
+    (setq-local prev-auto-revert-max (point-max)))
+  (add-hook 'auto-revert-tail-mode-hook
+            (lambda ()
+              (when (string=
+                     buffer-file-name
+                     "/var/log/cloudman/development/cm-service.log")
+                (setq-local prev-auto-revert-max 0)
+                ;; set buffer-local hook
+                (add-hook 'after-revert-hook 'tail-colorize nil t))))
+  )
 
 ;; delete active selection with self-insert commands
 (delete-selection-mode t)
@@ -1455,55 +962,21 @@ https://fsf.org | https://gnu.org
 ;; Transparently open compressed files
 (auto-compression-mode t)
 
-;; Highlight matching parenthesesq when the pointq is on them.
-;; not needed since smart paren mode?
-;;  (show-paren-mode 1)
-
-
-;; not documented, but looking at the source, I find this
-;; stops me from being asked what command on every C-c-c
-;; when doing a latex document.
-(setq TeX-command-force "LaTeX")
-
 ;; dot mode, repeats last action
 (require 'dot-mode)
-(add-hook 'find-file-hooks 'dot-mode-on)
-
+(add-hook 'find-file-hook 'dot-mode-on)
 
 ;; clean up obsolete buffers automatically at midnight
 (require 'midnight)
 
-
-;; disabled because it takes 400ms on startup
-;; ;; emacs regexes are too limited.
-;; (require 'foreign-regexp)
-;; ;; perl is most powerful, but javascript is pretty close and
-;; ;; I'd rather know javascript stuff than perl
-;; (custom-set-variables
-;;  '(foreign-regexp/regexp-type 'javascript) ;; Choose by your preference.
-;;  '(reb-re-syntax 'foreign-regexp)) ;; Tell re-builder to use foreign regexp.
-;; ;; it would be nice to add documentation to do this for more commands to that package
-;; ;; disabled because it's too slow. but I'd still m-x it for advanced replacements
-;; ;;(define-key global-map [remap isearch-forward-regexp] 'foreign-regexp/isearch-forward)
-
-
 ;; saner regex syntax
 (require 're-builder)
 (setq reb-re-syntax 'string)
 
 
-;; use shift + arrow keys to switch between visible buffers
-;; todo, set these keys to something else
-(require 'windmove)
-(windmove-default-keybindings)
-
-
 ;; show the name of the current function definition in the modeline
-(require 'which-func)
-(setq which-func-modes t)
 (which-function-mode 1)
 
-
 ;; enable winner-mode to manage window configurations
 (winner-mode +1)
 
@@ -1531,11 +1004,6 @@ https://fsf.org | https://gnu.org
 
 ;; todo, turn on auto-fill just for txt files
 ;;(add-hook 'text-mode-hook 'turn-on-auto-fill)
-(add-hook 'text-mode-hook 'turn-on-flyspell)
-
-
-;; auto indent shell script comments
-(setq sh-indent-comment t)
 
 ;; random extra highlights
 (require 'volatile-highlights)
@@ -1546,51 +1014,77 @@ https://fsf.org | https://gnu.org
 (temp-buffer-resize-mode 1)
 
 
-(require 'info+)
-;; based on suggestions in info+.el, I also installed  misc-fns, strings, and thingatpt+
-;; remove some bad keybinds from info+
-(define-key Info-mode-map [mouse-4]         nil)
-(define-key Info-mode-map [mouse-5]         nil)
+(defun my-info-init()
+  (require 'info+)
+  ;; based on suggestions in info+.el, I also installed  misc-fns, strings, and thingatpt+
+  ;; remove some bad keybinds from info+
+  (define-key Info-mode-map [mouse-4]         nil)
+  (define-key Info-mode-map [mouse-5]         nil))
 
+(add-hook 'info-mode-hook 'my-info-init)
 
-(require 'smooth-scroll)
-;; long gnus summary buffers lags too much with this,
-;; but I like it enough to leave it enabled by default
-;; and crank up the step size to be faster
-;; and it doesn't have a way to enable it only for certain modes etc.
-;; todo sometime, make it work for certain modes only
-(smooth-scroll-mode t)
-;; its too slow with the default of 2
-(setq smooth-scroll/vscroll-step-size 7)
-;; sublimity doesn't work as good going fast by default
-;; smooth-scrolling.el, does not do smooth scrolling. its about cursor location
 
+;;; misc general settings
 
-(setq sh-here-document-word "'EOF'")
 
-(setq tramp-default-method "ssh")
-;;; misc general settings
+;; I tried to look for a function that would set this that is
+;; not part of the emacs interactive customize stuff, but didn't see one
+;; in the faces documentation.
 
-(ivy-mode 1)
-(add-hook 'text-mode-hook (lambda () (auto-fill-mode t)))
-(setq counsel-find-file-at-point t)
+(custom-set-faces
+ ;; custom-set-faces was added by Custom.
+ ;; If you edit it by hand, you could mess it up, so be careful.
+ ;; Your init file should contain only one such instance.
+ ;; If there is more than one, they won't work right.
+ '(header-line ((t (:background "default" :foreground "default" :overline nil :underline nil))))
+ '(region ((t nil))))
 
-;; easier to read with just spaces as separator
-(setf (nth 2 ido-decorations) "   ")
 
+;; from tramp manual, use the same ssh controlmaster. I was having problems with
+;; tramp prompting me for a username and pass.
+(customize-set-variable 'tramp-use-ssh-controlmaster-options nil)
 
-;; https://www.emacswiki.org/emacs/FillParagraph
-;; make list items start paragraphs.
-(setq paragraph-start "\f\\|[ \t]*$\\|[ \t]*[-+*] ")
+(setq
+ ;; avoid this stupid prompt when doing sudo-edit
+ ;; Save auth info to file ~/.authinfo? [y/n/N/e/?]
+ ;; which doesn't actually use the default N by pressing enter,
+ ;; and doesn't actually save the 'never' setting like it claims.
+ ;; todo: file a bug.
+ auth-source-save-behavior nil
+ auto-revert-interval 2
+ ;; fix eof end of file newline
+ mode-require-final-newline t
+ require-final-newline t
+ auto-revert-verbose nil
+ auto-revert-remote-files t
+ ;; save bookmarks whenever they are changed instead of just when emacs quits
+ bookmark-save-flag 1
+ ;; increase bookmark context size for better functionality
+ bookmark-search-size 2000
+ ;; https://www.emacswiki.org/emacs/FillParagraph
+ ;; make list items start paragraphs.
+ paragraph-start "\f\\|[ \t]*$\\|[ \t]*[-+*] "
+ sh-basic-offset 2
+ vc-follow-symlinks t
+ dired-confirm-shell-command nil
+ dired-deletion-confirmer '(lambda (x) t)
+ dired-listing-switches "-alh"
+ dired-recursive-deletes 'always
+ dired-clean-confirm-killing-deleted-buffers nil
+ undo-outer-limit 100000000 ; per undo command
+ undo-limit 500000000 ; undo history limit
+ undo-strong-limit 600000000 ; undo history limit plus some extra
+ )
 
-(setq sh-basic-offset 2)
-(setq vc-follow-symlinks t)
 
-;; give us a shell to start instead of scratch
-;;(setq initial-buffer-choice (lambda () (new-shell)))
 
-;; disable this nasty function, as I always use a gui
-(defun suspend-frame() (interactive))
+(ivy-mode 1)
+(add-hook 'text-mode-hook (lambda () (auto-fill-mode t)))
+(setq counsel-find-file-at-point t)
+
+(eval-after-load "ido"
+  ;; easier to read with just spaces as separator
+  (quote (setf (nth 2 ido-decorations) "   ")))
 
 ;; Seed the random-number generator
 (random t)
@@ -1598,6 +1092,14 @@ https://fsf.org | https://gnu.org
 ;; easier to remember than keybinds
 (defalias 'scrypt 'mml-secure-message-encrypt-pgpmime)
 (defalias 'sign 'mml-secure-message-sign-pgpmime)
+;; otherwise we get error on sending:
+;; mml-secure-epg-sign: Couldn’t find any signer names; try setting `mml-secure-smime-sign-with-sender'.
+;; i dunno why sign+encrypt doesnt cause this, seems kinda dumb,
+;;
+(setq mml-secure-openpgp-sign-with-sender t)
+;; i dun use smime, the smime signing fails complaining it doesnt have
+;; my key. todo: learn about smime
+(setq mml-secure-smime-sign-with-sender t)
 (defun encrypt ()
   (interactive)
   (mml-secure-message-encrypt-pgpmime 'dontsign))
@@ -1625,11 +1127,10 @@ https://fsf.org | https://gnu.org
 (setq font-lock-maximum-decoration t
       inhibit-startup-message t
       transient-mark-mode t
-      delete-by-moving-to-trash t
       shift-select-mode nil
       truncate-partial-width-windows nil
       uniquify-buffer-name-style 'forward
-      oddmuse-directory "~/.emacs.d/oddmuse"
+      oddmuse-directory (concat user-emacs-directory "oddmuse")
       echo-keystrokes 0.1
       mark-ring-max 160
       sort-fold-case t  ; case insensitive line sorting
@@ -1641,9 +1142,6 @@ https://fsf.org | https://gnu.org
       ring-bell-function 'ignore
       case-replace nil
       revert-without-query '(".*")
-      ;; don't pause display code on input.
-      ;; smoother display performance at slight cost of input performance
-      redisplay-dont-pause t
       font-lock-maximum-decoration t) ; probably default and not necesary
 
 
@@ -1657,7 +1155,7 @@ https://fsf.org | https://gnu.org
               indicate-empty-lines t) ; mark end of buffer
 
 
-(blink-cursor-mode '(-4))
+(blink-cursor-mode 0)
 (menu-bar-mode -1)
 (tool-bar-mode -1)
 
@@ -1683,7 +1181,6 @@ https://fsf.org | https://gnu.org
       inhibit-startup-message t
       inhibit-startup-echo-area-message t
       inhibit-startup-screen t
-      compilation-read-command nil ;; just don't compile with unsafe file local vars
       kill-buffer-query-functions (remq 'process-kill-buffer-query-function
                                         kill-buffer-query-functions))
 
@@ -1726,7 +1223,7 @@ https://fsf.org | https://gnu.org
 (defun fill-buffer ()
   (interactive)
   (save-mark-and-excursion
-    (beginning-of-buffer)
+    (goto-char (point-min))
     (while (= (forward-line) 0)
       (fill-paragraph))))
 
@@ -1819,71 +1316,6 @@ Go to the next directory based on where the cursor is."
 ;; make window title be the buffer name
 (setq frame-title-format "%b")
 
-                                        ; -----------------------------
-                                        ; fixing up the mode line
-                                        ; modified from mastering emacs blog
-                                        ; ----------------------------
-
-(defvar mode-line-cleaner-alist
-  `((auto-complete-mode . "")
-    (yas/minor-mode . "")
-    (paredit-mode . "")
-    (auto-fill-function . "")
-    (eldoc-mode . "")
-    (abbrev-mode . "")
-    (flyspell-mode . "")
-    (glasses-mode . "")
-    (dot-mode . "")
-    (yas-global-mode . "")
-    (yas-minor-mode . "")
-    (volatile-highlights-mode . "")
-    (highlight-symbol-mode . "")
-    ;; Major modes
-    (lisp-interaction-mode . "λ")
-    (hi-lock-mode . "")
-    (python-mode . "Py")
-    (emacs-lisp-mode . "EL")
-    (nxhtml-mode . "nx"))
-  "Alist for `clean-mode-line'.
-
-  When you add a new element to the alist, keep in mind that you
-  must pass the correct minor/major mode symbol and a string you
-  want to use in the modeline *in lieu of* the original.")
-
-
-(defun clean-mode-line ()
-  (interactive)
-  (loop for cleaner in mode-line-cleaner-alist
-        do (let* ((mode (car cleaner))
-                  (mode-str (cdr cleaner))
-                  (old-mode-str (cdr (assq mode minor-mode-alist))))
-             (when old-mode-str
-               (setcar old-mode-str mode-str))
-             ;; major mode
-             (when (eq mode major-mode)
-               (setq mode-name mode-str)))))
-
-                                        ; disabled
-                                        ;  (add-hook 'after-change-major-mode-hook 'clean-mode-line)
-
-
-  ;;; alias the new `flymake-report-status-slim' to
-  ;;; `flymake-report-status'
-(defalias 'flymake-report-status 'flymake-report-status-slim)
-(defun flymake-report-status-slim (e-w &optional status)
-  "Show \"slim\" flymake status in mode line."
-  (when e-w
-    (setq flymake-mode-line-e-w e-w))
-  (when status
-    (setq flymake-mode-line-status status))
-  (let* ((mode-line " Î¦"))
-    (when (> (length flymake-mode-line-e-w) 0)
-      (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
-    (setq mode-line (concat mode-line flymake-mode-line-status))
-    (setq flymake-mode-line mode-line)
-    (force-mode-line-update)))
-
-
 (defun my-after-change-major-mode-hook ()
   (setq mode-line-mule-info nil
         minor-mode-alist nil
@@ -1905,17 +1337,9 @@ Go to the next directory based on where the cursor is."
          (y (cdr pos)))
     (set-mouse-position (selected-frame) x y)))
 
-;;;; keybinds for wow mouse
-
-(global-set-key (kbd "<mouse-6>") 'move-mouse-to-point)
-(global-set-key (kbd "<kp-left>") 'indent-region)
-(global-set-key (kbd "<kp-begin>") 'mark-defun)
-(global-set-key (kbd "<kp-right>") 'ibuffer)
-(global-set-key (kbd "<kp-prior>") 'delete-horizontal-space)
-
 ;;; org mode
 
-;; todo work on org-cycle-emulate-tab
+
 
 ;; todo, this doesn't work for a non-standard keybind
 ;;(setq org-special-ctrl-k t)
@@ -1958,19 +1382,19 @@ Go to the next directory based on where the cursor is."
       org-extend-today-until 0
       org-startup-truncated nil
       org-clock-persist t
+      org-use-sub-superscripts "{}"
+      org-export-with-sub-superscripts nil
       org-clock-mode-line-total 'today
       ;; global STYLE property values for completion
       org-global-properties (quote (("STYLE_ALL" . "habit")))
       org-special-ctrl-a/e t  ;; home and end work special in headlines
       org-completion-use-ido t
+      ;; i had some problem with this in the past, but don't know what, so whatever.
+      org-cycle-emulate-tab nil
       org-catch-invisible-edits 'smart)
 
-;; non universally recommended settings
 (setq
- org-default-notes-file (concat org-directory "/a/t.org")
- org-agenda-files (quote ("/a/t.org"))
- org-mobile-directory "/p/org-mobile"
- org-mobile-inbox-for-pull "/p/from-mobile.org"
+ org-default-notes-file "/a/t.org"
  org-directory "/p")
 
 ;; modeilne populated from (org-clock-get-clocked-time)
@@ -1978,17 +1402,15 @@ Go to the next directory based on where the cursor is."
 ;; which is populated by a function which starts from (org-clock-get-sum-start)
 ;;
 
-(org-clock-persistence-insinuate)
-
+(eval-after-load "org"
+  '(org-clock-persistence-insinuate))
 
 (defun time-to-org-day (time)
   (round (time-to-number-of-days
           (time-subtract time (list 0 (* 3600 org-extend-today-until) 0)))))
 
-
 (defun my-org-confirm-babel-evaluate (lang body)
   (not (or (string= (buffer-file-name) "/a/t.org")
-           (string= (buffer-file-name) "/home/iank/.emacs.d/my-init.org")
            )))
 (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
 
@@ -1998,22 +1420,6 @@ Go to the next directory based on where the cursor is."
   ;; '(4) is the argument passed by universal prefix
   (org-time-stamp (if arg arg '(4)) t))
 
-(defun ian-org-work-time ()
-  (interactive)
-  (save-excursion
-    (set-buffer "t.org")
-    (goto-char (org-find-entry-with-id "ian-identifier-1"))
-    (org-clock-in)))
-
-(defun ian-org-idle-time ()
-  (interactive)
-  (save-excursion
-    (goto-char (org-find-entry-with-id "ian-identifier-2"))
-    (set-buffer "t.org")
-    (org-clock-in)))
-
-
-
 ;; based on http://stackoverflow.com/questions/3758139/variable-pitch-for-org-mode-fixed-pitch-for-tables
 ;; keywords: proportional font, monospace
 
@@ -2025,15 +1431,19 @@ Go to the next directory based on where the cursor is."
 (defun variable-pitch-off ()
   (variable-pitch-mode 0))
 (add-hook 'yaml-mode-hook 'variable-pitch-off)
+(add-hook 'dns-mode-hook 'variable-pitch-off)
 
 
-(set-face-attribute 'org-table nil :family (face-attribute 'fixed-pitch :family))
-(set-face-attribute 'org-code nil :family (face-attribute 'fixed-pitch :family))
-(set-face-attribute 'org-formula nil :family (face-attribute 'fixed-pitch :family))
-(set-face-attribute 'org-link nil :family (face-attribute 'fixed-pitch :family))
-(set-face-attribute 'org-block nil :family (face-attribute 'fixed-pitch :family))
-(set-face-attribute 'org-date nil :family (face-attribute 'fixed-pitch :family))
+(defun my-org-face-init()
+  (set-face-attribute 'org-table nil :family (face-attribute 'fixed-pitch :family))
+  (set-face-attribute 'org-code nil :family (face-attribute 'fixed-pitch :family))
+  (set-face-attribute 'org-formula nil :family (face-attribute 'fixed-pitch :family))
+  (set-face-attribute 'org-link nil :family (face-attribute 'fixed-pitch :family))
+  (set-face-attribute 'org-block nil :family (face-attribute 'fixed-pitch :family))
+  (set-face-attribute 'org-date nil :family (face-attribute 'fixed-pitch :family))
+  )
 
+(eval-after-load "org" '(my-org-face-init))
 
 (defun remove-org-binds ()
   (define-key org-mode-map (kbd "<M-return>") nil)
@@ -2069,7 +1479,10 @@ Go to the next directory based on where the cursor is."
 (defun prog-mode-defaults ()
   "Default coding hook, useful with any programming language."
   ;; so that I can do completion before the dialog pops up
-  (local-set-key (kbd "<tab>") 'auto-complete)
+  ;;(local-set-key (kbd "<tab>") 'auto-complete)
+  (local-set-key (kbd "TAB") 'auto-complete)
+  (define-key emacs-lisp-mode-map (kbd "M-q") nil)
+
   ;; todo, this is causing error message on loading file, prolly not working
   ;;(flycheck-mode +1)
   (setq ac-sources (delq 'ac-source-dictionary ac-sources))
@@ -2078,7 +1491,8 @@ Go to the next directory based on where the cursor is."
   ;; this says do autofilling using newcomment.el. The "only" is a misnomer.
   (set (make-local-variable 'comment-auto-fill-only-comments) t)
   (column-number-mode t)
-  (turn-on-smartparens-mode)
+  ;; trying without
+  ;; (turn-on-smartparens-mode)
 
   ;; prettify lambdas
   (font-lock-add-keywords
@@ -2088,9 +1502,6 @@ Go to the next directory based on where the cursor is."
                     nil))))))
 (add-hook 'prog-mode-hook 'prog-mode-defaults)
 
-;; enable flyspell in prog mode. text mode is handled
-(add-hook 'prog-mode-hook 'flyspell-prog-mode)
-
 
 
 ;;; yank auto-indent
@@ -2134,6 +1545,29 @@ indent yanked text (with prefix arg don't indent)."
 
 
 ;;; shell mode
+
+
+;;  # eval: (outline-minor-mode)
+;; # outline-regexp: "\\( *\\)# [*]\\{1,8\\} "
+
+(defun outline-level ()
+  "Return the depth to which a statement is nested in the outline.
+Point must be at the beginning of a header line.
+This is actually either the level specified in `outline-heading-alist'
+or else the number of characters matched by `outline-regexp'."
+  (or (cdr (assoc (match-string 0) outline-heading-alist))
+      (let ((whitespace-end (match-end 1))
+            (match-begin (match-beginning 0)))
+        (if (= whitespace-end match-begin)
+            (- (match-end 0) match-begin)
+          (- (match-end 0) whitespace-end)
+          ))))
+;; originally:
+;;(or (cdr (assoc (match-string 0) outline-heading-alist))
+;;    (- (match-end 0) (match-beginning 0))))
+
+
+
 ;; avoid stupid git crap like "warning, terminal not fully functional"
 (setenv "PAGER" "cat")
 ;; don't store successive duplicates in comint command history
@@ -2172,67 +1606,19 @@ indent yanked text (with prefix arg don't indent)."
     (shell)))
 
 (add-hook 'shell-mode-hook 'track-shell-directory/procfs)
-;;; smartparens
-;; the melpa git version had a catastrophic bug I reported.
-;; downgraded to marmalade version and everything is working fine.
-(require 'smartparens-config)
-(show-smartparens-global-mode t)
-
-
-(defun gp/sp/pair-on-newline-and-indent (id action context)
-  "Open a new brace or bracket expression, with relevant newlines and indent. "
-  (save-excursion
-    (newline)
-    (indent-according-to-mode))
-  (indent-according-to-mode))
-
-;; when opening a pair, and then inserting a newline, push the closing pair to another newline
-(sp-pair "{" nil :post-handlers
-         '(:add ((lambda (id action context)
-                   (gp/sp/pair-on-newline-and-indent id action context)) (kbd "<return>"))))
-(sp-pair "[" nil :post-handlers
-         '(:add ((lambda (id action context)
-                   (gp/sp/pair-on-newline-and-indent id action context)) (kbd "<return>"))))
-
-
-;; in my version, this is not a pairing.
-;; not sure if it is in a future version since I reverted to marmalade
-;; Don't need c-comments in strings -- they frustrate filename globs
-;; (sp-pair "/*" nil :unless '(sp-in-string-p))
-
-;; Don't need quotes to pair next to words
-(sp-pair "\"" nil :unless '(sp-point-before-word-p sp-point-after-word-p))
-(sp-pair "'" nil :unless '(sp-point-before-word-p sp-point-after-word-p))
-
-
-;; todo, testout these mode specific settings from graphene.
-;; Ruby-specific pairs and handlers
-(require 'smartparens-ruby)
-
-;; Markdown
-(sp-local-pair '(markdown-mode gfm-mode) "*" "*"
-               :unless '(sp-in-string-p)
-               :actions '(insert wrap))
-
-;; Except in HTML
-(sp-local-pair 'html-mode "\"" nil :unless '(:rem sp-point-after-word-p))
-
-
-;;; smex
-;;  todo; check out smex-show-unbound-commands shows frequently used commands that have no key bindings.
-                                        ; these must be before smex-initialize
-(setq
- smex-save-file "~/.emacs.d/.smex-items")
-
-(smex-initialize)
 ;;; spell correction
 (setq
  ispell-program-name "hunspell"
  ispell-silently-savep t) ; don't prompt to save personal dictionary
 
-(require 'rw-hunspell)
+(use-package rw-hunspell
+  :defer t)
 ;; rw-hunspell sets up hunspell dictionary automagically.
 
+(use-package flyspell
+  :ensure-system-package hunspell
+  :hook ((prog-mode . flyspell-prog-mode)
+         (text-mode . turn-on-flyspell)))
 
 ;; Rant: Hunspell SHOULD be standard. its used by firefox and openoffice and
 ;; osx. In contrast, the first few words I added to aspell dictionary were
@@ -2244,26 +1630,29 @@ indent yanked text (with prefix arg don't indent)."
 
 
 ;;; tex
-(setq-default TeX-PDF-mode t) ; use pdf
-
-                                        ; more sensible defaults based on info manual quickstart
-(setq TeX-auto-save t)
-(setq TeX-parse-self t)
-
 
+(use-package latex-mode
+  :no-require t
+  :config
+  (setq-default TeX-PDF-mode t) ; use pdf
+  ;; more sensible defaults based on info manual quickstart
+  (setq TeX-auto-save t
+        TeX-parse-self t
+        ;; not documented, but looking at the source, I find this
+        ;; stops me from being asked what command on every C-c-c
+        ;; when doing a latex document.
+        TeX-command-force "LaTeX"
+        ))
 
 ;;; visible mark mode
 
 ;; since it is not easy to change the mark overlay priority, I change this one.
 (setq show-paren-priority 999)
 
-
 (defface visible-mark-active
   '((((type tty) (class mono)))
     (t (:background "magenta"))) "")
 
-
-
 (defface mouse-cursor-face
   '((((type tty) (class mono)))
     (t (:background "DeepPink1"))) "")
@@ -2271,15 +1660,14 @@ indent yanked text (with prefix arg don't indent)."
 
 (require 'visible-mark)
 
-(setq visible-mark-faces '(visible-mark-face1 visible-mark-face2))
-(setq visible-mark-forward-faces '(visible-mark-forward-face1))
-
-
-                                        ; highlight the last 2 marks
-(setq visible-mark-max 2)
-                                        ; highlight 1 forward mark
-(setq visible-mark-forward-max 1)
-                                        ; globally activate visible-mark-mode
+(setq
+ visible-mark-faces '(visible-mark-face1 visible-mark-face2)
+ visible-mark-forward-faces '(visible-mark-forward-face1)
+ ;; highlight the last 2 marks
+ visible-mark-max 2
+ ;; highlight 1 forward mark
+ visible-mark-forward-max 1)
+;; globally activate visible-mark-mode
 (global-visible-mark-mode +1)
 
 
@@ -2287,15 +1675,48 @@ indent yanked text (with prefix arg don't indent)."
 ;; if I could define overlay faces to use inverse foreground color
 
 
-;;; zrc
-(require 'znc)
-(setq erc-fill-prefix "")
+;; (setq comment-start "<br align=\"left\"")
+;;
+
+;; (setq comment-start "#" comment-padding " ")
+
+
+;; graphviz fill, for html left aligned labels
+(defun grfil()
+  (interactive)
+  (setq comment-start "<br align=\"left\"/>&nbsp;")
+  (setq comment-padding " ")
+  (setq fill-column 50)
+  ;; (setq fill-column 30)
+  (mark-paragraph)
+  ;; (call-interactively 'uncomment-region)
+  (fill-paragraph)
+  (call-interactively 'comment-region)
+  (deactivate-mark)
+  (save-excursion
+    (goto-char (region-beginning))
+    (next-line)
+    (comment-line 1)
+    )
+  )
+
+;; (chirp)
+(defun chirp()
+  (message "chirp nothing"))
+;;; znc/erc
 (defun chirp()
   (interactive)
-  (setq vol 50)
-  (when (string= (system-name) "tp") (setq vol 40))
-  (start-process-shell-command "ignoreme" nil (format "mpv --no-terminal --vo=null --volume=%d /a/bin/data/bird.mp3" vol)))
+  (setq vol 80)
+  (when (string= (system-name) "kd") (setq vol 60))
+  ;; speed is there so i can adjust and make it go slow so it plays long enough to adjust in pavucontrol
+  (start-process-shell-command "ignoreme" nil (format "mpv --speed=1 --no-terminal --vo=null --volume=%d /a/bin/data/d20.wav" vol)))
 ;; from https://www.emacswiki.org/emacs/ErcSound
+(defun chirp-slow()
+  (interactive)
+  (setq vol 50)
+  (when (string= (system-name) "tp") (setq vol 80))
+  ;; speed is there so i can adjust and make it go slow so it plays long enough to adjust in pavucontrol
+  (start-process-shell-command "ignoreme" nil (format "mpv --speed=.2 --no-terminal --vo=null --volume=%d /a/bin/data/d20.wav" vol)))
 
 (defun erc-my-privmsg-sound (proc parsed)
   (let* ((tgt (car (erc-response.command-args parsed)))
@@ -2305,22 +1726,101 @@ indent yanked text (with prefix arg don't indent)."
      ;; We must return nil. See help for `erc-server-PRIVMSG-functions'
      nil)))
 
-(add-hook 'erc-server-PRIVMSG-functions
-          'erc-my-privmsg-sound)
-
 (defun erc-sound-if-not-server (match-type nickuserhost msg)
   (unless (string-match "Server:[0-9]+" nickuserhost)
     (chirp)))
-(add-hook 'erc-text-matched-hook 'erc-sound-if-not-server)
-
-(erc-track-mode 1)
-(setq
- ;; consider invisible frames to be unseen. seems like an obvious default
- erc-track-visibility 'visible
- ;; switch to buffer where i've been mentioned, etc instead of oldest
- erc-track-switch-direction 'importance)
 
+(defun erc-sound-if-not-server (match-type nickuserhost msg)
+  ;; (message "d1 %s" nickuserhost)
+  (unless (or (string-match-p "Server:[0-9]+" nickuserhost) (string-match-p "leah" nickuserhost))
+    (chirp)))
 
+(use-package erc
+  :defer t
+  :custom-face
+  (erc-current-nick-face ((t :weight bold :foreground "red")))
+  :init
+  (which-function-mode 0)
+  ;; fuck that default turquoise
+  (setq erc-fill-prefix ""
+        ;; consider invisible frames to be unseen. seems like an obvious default
+        erc-track-visibility 'visible
+        ;; switch to buffer where i've been mentioned, etc instead of oldest
+        erc-track-switch-direction 'importance
+        ;; defaults minus fill. todo: modify the list instead of specifying it explicitly in case the defaults change
+        erc-modules
+        '(autojoin button completion imenu irccontrols list match menu move-to-prompt netsplit networks noncommands readonly ring stamp track)
+        ;; expanded from https://www.emacswiki.org/emacs/ErcChannelTracking,
+        ;; ignore various messages
+        erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"
+                                  "324" "329" "332" "333" "353")
+        ;; seems good, i don't care about the server buffer generally
+        erc-track-exclude-server-buffer t
+        ;; dont highlight channels just cuz of new messages, except for pms or some new channel I haven't listed in my config.
+
+        erc-track-shorten-cutoff 40
+        ;; sed -rn 's/.*(#[^>]*).*/"\1"/p' /p/c/machine_specific/li/filesystem/var/lib/znc/configs/znc.conf
+        erc-track-priority-faces-only (list
+                                        "#conservancy"
+                                        "#fosdem"
+                                        "#fsf"
+                                        "#fsf-licensing"
+                                        "#fsfe"
+                                        "#fsfsys"
+                                        "#gnu"
+                                        "#librecmc"
+                                        "#libreplanet"
+                                        "#mnt-reform"
+                                        "#nouveau"
+                                        "#pump.io"
+                                        "#savannah"
+                                        "#seagl"
+                                        "#social"
+                                        "#spamassassin"
+                                        "#talos-workstation"
+                                        "#trisquel"
+                                        "#trisquel-dev"
+                                        "#overseers"
+                                        "#gdb"
+                                        "#gcc"
+                                        "#glibc"
+                                        "#binutils"
+                                        "#gnu-linux-libre"
+                                        "#parabola"
+                                        "#guix"
+                                        "#gnu-ops"
+                                        "#gcc"
+                                        )
+  ;; so that we don't show channels where i havent been mmentioned
+  erc-track-faces-priority-list '(erc-current-nick-face
+                                  erc-keyword-face
+                                  erc-pal-face
+                                  erc-nick-msg-face
+                                  erc-direct-msg-face
+                                  erc-fool-face)
+
+
+  ) ; end setq
+
+:config
+(add-hook 'erc-server-PRIVMSG-functions
+          'erc-my-privmsg-sound)
+(add-hook 'erc-text-matched-hook 'erc-sound-if-not-server)
+(erc-track-mode 1)
+(defun erc-track--switch-buffer (fun arg)
+  (if (not erc-track-mode)
+      (message (concat "Enable the ERC track module if you want to use the"
+                      " tracking minor mode"))
+    (cond (erc-modified-channels-alist
+          ;; if we're not in erc-mode, set this buffer to return to
+           (if-let ((buf (erc-track-get-active-buffer arg))
+                    ((buffer-live-p buf)))
+               (funcall fun buf)
+             (erc-modified-channels-update)
+             (erc-track--switch-buffer fun arg)))
+         ;; if no active channels, switch back to what we were doing before
+         (t (switch-to-buffer "#fsfsys")))))
+)
 ;;; named commands
 (defun rm-file-and-buffer ()
   "Removes file connected to current buffer and kills buffer."
@@ -2343,8 +1843,12 @@ indent yanked text (with prefix arg don't indent)."
 ;; worth the benefit of only having one concept in my mind.
 (dolist
     (r `(
-         (?i (file . ,"~/.emacs.d/my-init.org"))
+         (?i (file . ,(concat user-emacs-directory "init.el")))
+         (?o (file . ,"/b/w/work.org"))
          (?t (file . ,"/a/t.org"))
+         (?s (file . ,"/usr/share/doc/exim4-base/spec.txt.gz"))
+         (?w (file . ,"/p/w.org"))
+         (?k (file . ,"/a/bin/ds/Arduino/Model01-Firmware/Model01-Firmware.ino"))
          (?x (file . ,"/a/x.txt"))
          ))
   (set-register (car r) (cadr r)))
@@ -2353,9 +1857,38 @@ indent yanked text (with prefix arg don't indent)."
       undo-limit 500000000 ; undo history limit
       undo-strong-limit 600000000) ; undo history limit plus some extra
 
+
+;;; undo-fu mode
+
+;; thank god i'm done with undo-tree and the bug where my auto-saveing
+;; would cause it to lose all undo history, strangely especially in
+;; email buffers. it would claim the undo was outside the visible
+;; buffer.
+
+(use-package undo-fu
+  :config
+  (global-unset-key (kbd "C-z")))
+
+(use-package undo-fu-session
+  :if (string= (daemonp) "server")
+  :config
+  (setq undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'")))
+
+(when (string= (daemonp) "server")
+  (unless (equal (user-uid) 0) ; don't make root owned files
+    (global-undo-fu-session-mode)
+    (when (file-exists-p "/p/c/undo-fu-session")
+      (setq undo-fu-session-directory "/p/c/undo-fu-session"))
+    ))
+
+
 ;;; keybinds
 
 ;;;; misc
+
+(define-prefix-command 'terminal-key-map)
+(global-set-key (kbd "\e[") 'terminal-key-map)
+
 (global-set-key (kbd "C-x C-b") 'ibuffer)
 
 
@@ -2364,11 +1897,11 @@ indent yanked text (with prefix arg don't indent)."
 ;; from starter-kit
 
 (define-key isearch-mode-map (kbd "C-o")
-  (lambda () (interactive)
-    (let ((case-fold-search isearch-case-fold-search))
-      (occur (if isearch-regexp
-                 isearch-string
-               (regexp-quote isearch-string))))))
+            (lambda () (interactive)
+              (let ((case-fold-search isearch-case-fold-search))
+                (occur (if isearch-regexp
+                           isearch-string
+                         (regexp-quote isearch-string))))))
 
 
 (defun my-isearch-toggle-regexp ()
@@ -2388,13 +1921,13 @@ indent yanked text (with prefix arg don't indent)."
 
 ;;;; single/special keys
 ;;;;; tab - isearch
-(define-key isearch-mode-map (kbd "<tab>") 'isearch-query-replace)
+;; todo: this doesnt work. needs <tab>, which doesnt work in terminal. fix that.
+(define-key isearch-mode-map (kbd "TAB") 'isearch-query-replace)
 
 ;;;;; f12 - isearch-forward
 ;; explained in http://stackoverflow.com/questions/7411920/how-to-bind-search-and-search-repeat-to-c-f-in-emacs
 (global-set-key (kbd "<kp-add>") 'isearch-forward)
 (global-set-key (kbd "<f12>") 'isearch-forward)
-(define-key isearch-mode-map "\t" nil)
 (define-key isearch-mode-map (kbd "<kp-add>") 'isearch-repeat-forward)
 (define-key isearch-mode-map (kbd "<f12>") 'isearch-repeat-forward)
 ;; get rid of the standard completion binding, always use auto-complete
@@ -2442,7 +1975,16 @@ indent yanked text (with prefix arg don't indent)."
 (global-set-key (kbd "<home>") 'back-to-indentation-or-beginning)
 
 ;;;;; s-tab - indent-buffer
-(global-set-key (kbd "<S-iso-lefttab>") 'indent-buffer)
+;; This is translated from S-<iso-lefttab> in graphicsal mode. previously, I had
+;; also set (kbd "<S-iso-lefttab>"),
+;; But I stopped because it overrides minor mode mappings, and i don't want to do that, at least not only in graphical mode.
+;;
+(global-set-key (kbd "<backtab>") 'indent-buffer)
+
+(add-hook 'org-mode-hook
+          (lambda ()
+            (define-key org-mode-map (kbd "<backtab>") nil)))
+
 ;;;;; s-delete - send-shell
 
 (global-set-key (kbd "<S-delete>") 'send-shell)
@@ -2626,11 +2168,12 @@ modes like org-mode which have their own yank function."
 ;; stop splitting windows verticallly when I open a buffer or shell
 (setq split-height-threshold nil)
 
-;;;;; s-left arrow - shell
-(global-set-key (kbd "<S-left>") 'shell-wrap)
-(add-hook 'org-mode-hook
-          (lambda ()
-            (define-key org-mode-map (kbd "<S-left>") nil)))
+;;;;; s-left arrow - ---
+;; cant be used in terminal
+;; When I had a binding, i did this so org-mode wouldnt clobber it
+;; (add-hook 'org-mode-hook
+;;           (lambda ()
+;;             (define-key org-mode-map (kbd "<S-left>") nil)))
 
 ;;;;; s-right arrow - keyboard-yank-primary
 (defun keyboard-yank-primary ()
@@ -2642,8 +2185,8 @@ modes like org-mode which have their own yank function."
 (add-hook 'org-mode-hook
           (lambda ()
             (define-key org-mode-map (kbd "<S-right>") nil)))
-;;;;; esc
-                                        ; todo, test out if this can be used
+;;;;; esc --- terminal dup
+;; todo, test out if this can be used
 ;;;;; return - new line
 
 ;; todo, this doesn't set the keybind for the help minibuffer
@@ -2664,7 +2207,7 @@ modes like org-mode which have their own yank function."
 (add-hook 'comint-mode-hook
           (lambda ()
             (define-key comint-mode-map "\r" nil)
-            (define-key comint-mode-map (kbd "<return>") 'comint-send-input)))
+            (define-key comint-mode-map (kbd "RET") 'comint-send-input)))
 
 (add-hook 'comint-mode-hook
           (lambda ()
@@ -2676,7 +2219,7 @@ modes like org-mode which have their own yank function."
 ;; kp-enter is shift return in terminal
 (global-set-key (kbd "<kp-enter>") 'flyspell-auto-correct-previous-word)
 
-;;;;; s-down arrow - my-contract-region
+;;;;; s-up arrow - my-contract-region
 (global-set-key (kbd "<S-up>") 'my-contract-region)
 ;;;;; c-up/down move 8 lines
 
@@ -2735,16 +2278,6 @@ modes like org-mode which have their own yank function."
 
 ;;;; left primary
 
-;;;;; C-2 copy-symbol
-
-(global-unset-key (kbd "C-2"))
-(defun copy-symbol (&optional arg)
-  "Copy symbol at point into kill-ring"
-  (interactive "P")
-  (kill-new (thing-at-point 'symbol)))
-
-(global-set-key (kbd "C-2") 'copy-symbol)
-
 ;;;;; M-2 shell-cd-to-file
 
 
@@ -2758,19 +2291,24 @@ modes like org-mode which have their own yank function."
       (message "%s" "shell-cd-to-file: buffer has no file name"))))
 (global-set-key (kbd "M-2") 'shell-cd-to-file)
 
-;;;;; C-M-2 ---
-                                        ; todo. whats going on here?
+;;;;; C-M-2 copy-symbol
 (global-unset-key (kbd "C-M-2"))
+(defun copy-symbol (&optional arg)
+  "Copy symbol at point into kill-ring"
+  (interactive "P")
+  (kill-new (thing-at-point 'symbol)))
+
+(global-set-key (kbd "C-M-2") 'copy-symbol)
 
-;;;;; C-3 dot-mode-execute
+;;;;; M-3 dot-mode-execute
 
-(global-set-key (kbd "C-3") 'dot-mode-execute)
+(global-set-key (kbd "M-3") 'dot-mode-execute)
 
 ;;;;; C-M-3 recenter-top-bottom
 
 (global-set-key (kbd "C-M-3") 'recenter-top-bottom)
 
-;;;;; C-q org-cycle, comint previous arg
+;;;;; C-q org/bicycle-cycle, comint previous arg
 
 (global-set-key (kbd "C-q") 'bicycle-cycle)
 (add-hook 'org-mode-hook
@@ -2779,19 +2317,24 @@ modes like org-mode which have their own yank function."
 (add-hook 'comint-mode-hook
           (lambda () (define-key comint-mode-map (kbd "C-q") 'comint-insert-previous-argument)))
 
-;;;;; M-q org-archive-to-archive-sibling
+;;;;; M-q org/bicycle-cycle global
 
-(global-set-key (kbd "M-q") 'org-archive-to-archive-sibling)
+(add-hook 'org-mode-hook
+          (lambda ()
+            (define-key org-mode-map (kbd "M-q") 'org-shifttab)))
+(global-set-key (kbd "M-q") 'bicycle-cycle-global)
 
 ;;;;; C-M-q quoted-insert
 
 (global-set-key (kbd "C-M-q") 'quoted-insert)
 
-;;;;; C-w ---
-;; in terminal, it's ctrl-backspace, duplicate keybind.
-;;;;; M-w org-clock-in
+;;;;; C-w counsel-find-file
+
+(global-set-key (kbd "C-w") 'counsel-find-file)
+
+;;;;; M-w shell
 
-(global-set-key (kbd "M-w") 'org-clock-in)
+(global-set-key (kbd "M-w") 'shell-wrap)
 
 ;;;;; C-e copy-line
 
@@ -2820,9 +2363,7 @@ modes like org-mode which have their own yank function."
 
 (global-set-key (kbd "C-e") 'copy-line)
 
-;;;;; M-e org-clock-in-last
-
-(global-set-key (kbd "M-e") 'org-clock-in-last)
+;;;;; M-e ?? unused
 
 ;;;;; C-r isearch-backward
 
@@ -2831,9 +2372,8 @@ modes like org-mode which have their own yank function."
           (lambda ()
             (define-key comint-mode-map (kbd "C-r") 'comint-history-isearch-backward-regexp)))
 
-;;;;; M-r org-clock-out
+;;;;; M-r ?? unused
 
-(global-set-key (kbd "M-r") 'org-clock-out)
 
 ;;;;; C-a copy buffer
 
@@ -2844,85 +2384,66 @@ modes like org-mode which have their own yank function."
 (global-set-key (kbd "C-a") 'copy-all)
 
 ;;;;; C-s - c-x prefix
-  ; prefix key binds.
-  ; good info http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/
-  ; rebinding the prefix keys are tricky. apparently, some modes ignore any redefinition of a prefix key and use it explicitly,
-  ; so you have to dig into their key maps and redo things.
-  ; There are 2 simpler alternatives which have their own downsides.
-  ; One is cua mode, which I do not like because it smashes 2 keybinds onto 1 and limits what you can do.
-  ; The other is keyboard-translate, which translates the key presses before anything else.
-  ; The downside is that it translates them when you aren't using them as a prefix.
-  ; Since the swaps I'm using are all very accessible, the only downside is some mental jugling when reading docs etc about these keybinds.
-
-  ; I've seen this as an another suggestion, it was a total fail. The prefix command took over both keys.
-  ; (define-key key-translation-map [f12] "\C-c")
-  ; (define-key key-translation-map "\C-c" [left])
-
-
-  ;idea to remove the hook later since it is only needed at startup.
-  ; did not work however, and there is not a real need to fix it, so I did not investigate
-  ;(defun removeSwapHook ()
-  ;  (remove-hook 'buffer-list-update-hook 'myKeySwap)
-  ;  (remove-hook 'change-major-mode-hook 'removeSwapHook))
-  ;(add-hook 'change-major-mode-hook 'removeSwapHook)
-
-
-  ; went through almost all the relevant standard hooks,
-  ; this overcomes a known bug that (keyboard-translate) does not get applied when running emacs daemon
-  (add-hook 'buffer-list-update-hook (lambda () (interactive)
-                                       (keyboard-translate ?\C-x ?\C-s)
-                                       (keyboard-translate ?\C-s ?\C-x)
-                                       (keyboard-translate ?\C-c ?\C-d)
-                                       (keyboard-translate ?\C-d ?\C-c)))
-
-
-
-  ; these all don't work
-  ; don't know why this doesn't error but reversing the keys does
-  ;(keyboard-translate ?\t ?\M-\t)
-  ;(keyboard-translate [M-tab] [tab])
-  ; from what i can tell, it wants to use a keyboard-translate-table,
-  ; which is a char table, which is a vector indexed by chars,
-  ; and mod+tab is not a char (it has too many bits), it is an integer
-  ; it actually says it can hold vectors or strings, but that it is obsolete to do so
-  ;(characterp ?\M-a)
-  ;(characterp ?\C-a)
+;; prefix key binds.
+;; good info http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/
+;; rebinding the prefix keys are tricky. apparently, some modes ignore any redefinition of a prefix key and use it explicitly,
+;; so you have to dig into their key maps and redo things.
+;; There are 2 simpler alternatives which have their own downsides.
+;; One is cua mode, which I do not like because it smashes 2 keybinds onto 1 and limits what you can do.
+;; The other is keyboard-translate, which translates the key presses before anything else.
+;; The downside is that it translates them when you aren't using them as a prefix.
+;; Since the swaps I'm using are all very accessible, the only downside is some mental jugling when reading docs etc about these keybinds.
+
+;; I've seen this as an another suggestion, it was a total fail. The prefix command took over both keys.
+;; (define-key key-translation-map [f12] "\C-c")
+;; (define-key key-translation-map "\C-c" [left])
+
+
+;;idea to remove the hook later since it is only needed at startup.
+;; did not work however, and there is not a real need to fix it, so I did not investigate
+;;(defun removeSwapHook ()
+;;  (remove-hook 'buffer-list-update-hook 'myKeySwap)
+;;  (remove-hook 'change-major-mode-hook 'removeSwapHook))
+;;(add-hook 'change-major-mode-hook 'removeSwapHook)
+
+
+;; went through almost all the relevant standard hooks,
+;; this overcomes a known bug that (keyboard-translate) does not get applied when running emacs daemon
+(add-hook 'buffer-list-update-hook (lambda () (interactive)
+                                     (keyboard-translate ?\C-x ?\C-s)
+                                     (keyboard-translate ?\C-s ?\C-x)
+                                     (keyboard-translate ?\C-c ?\C-d)
+                                     (keyboard-translate ?\C-d ?\C-c)))
+
+
+
+;; these all don't work
+;; don't know why this doesn't error but reversing the keys does
+;;(keyboard-translate ?\t ?\M-\t)
+;;(keyboard-translate [M-tab] [tab])
+;; from what i can tell, it wants to use a keyboard-translate-table,
+;; which is a char table, which is a vector indexed by chars,
+;; and mod+tab is not a char (it has too many bits), it is an integer
+;; it actually says it can hold vectors or strings, but that it is obsolete to do so
+;;(characterp ?\M-a)
+;;(characterp ?\C-a)
 
 ;;;;; C-M-s - split-window-vertically
 
 (global-set-key (kbd "C-M-s") 'split-window-vertically)
 
 ;;;;; C-d - C-c prefix
-;;;;; C-M-d - swap buffer across windows
-;; from http://www.emacswiki.org/emacs/TransposeWindows
 
-(setq swapping-buffer nil)
-(setq swapping-window nil)
-(defun swap-buffers-in-windows ()
-  "Swap buffers between two windows"
-  (interactive)
-  (if (and swapping-window
-           swapping-buffer)
-      (let ((this-buffer (current-buffer))
-            (this-window (selected-window)))
-        (if (and (window-live-p swapping-window)
-                 (buffer-live-p swapping-buffer))
-            (progn (switch-to-buffer swapping-buffer)
-                   (select-window swapping-window)
-                   (switch-to-buffer this-buffer)
-                   (select-window this-window)
-                   (message "Swapped buffers."))
-          (message "Old buffer/window killed.  Aborting."))
-        (setq swapping-buffer nil)
-        (setq swapping-window nil))
-    (progn
-      (setq swapping-buffer (current-buffer))
-      (setq swapping-window (selected-window))
-      (message "Buffer and window marked for swapping."))))
-
-(global-set-key (kbd "C-M-d") 'swap-buffers-in-windows)
-
-;;;;; C-f] - kill-whole-line
+;;;;; M-d - run
+
+(global-set-key (kbd "M-d") 'run)
+
+;;;;; C-M-d - split-window-horizontally
+
+(global-set-key (kbd "C-M-d") 'split-window-horizontally)
+
+
+;;;;; C-f - kill-whole-line
 
 (global-set-key (kbd "C-f") 'kill-whole-line-wrapper)
 (defun kill-whole-line-wrapper (&optional arg)
@@ -2951,29 +2472,38 @@ modes like org-mode which have their own yank function."
             (define-key org-mode-map (kbd "C-M-f") 'org-kill-line)))
 
 (global-set-key (kbd "C-M-f") 'kill-line)
-;;;;; C-g - cancel / other window
-
-(global-set-key (kbd "C-g") 'other-window)
-
+;;;;; C-g - keyboard-quit
 ;;;;; M-g - abort-recursive-edit
 
 (global-set-key (kbd "M-g") 'abort-recursive-edit)
 
-;;;;; C-M-g - gnus
+;;;;; C-M-g - mu4e
 
 (global-set-key (kbd "C-M-g") 'mu4e)
 
 ;;;;; C-z - undo-only
-
-(global-set-key (kbd "C-z") 'undo-only)
+;;(global-set-key (kbd "C-z") 'undo-tree-undo)
+(global-set-key (kbd "C-z") 'undo-fu-only-undo)
+;;;;; C-M-z - suspend-frame
+(global-set-key (kbd "C-M-z") 'suspend-frame)
+;; this is never good in a gui
+(when (window-system)
+  (defun suspend-frame() (interactive)))
 
 ;;;;; C-x - kill-region
 
 (global-set-key (kbd "C-s") 'kill-region)
 
-;;;;; M-x - smex
+;;;;; M-x - counsel-m-x
 
-(global-set-key (kbd "M-x") 'smex)
+
+;;  todo; check out smex-show-unbound-commands shows frequently used commands that have no key bindings.
+;; this must be before smex-initialize
+(setq
+ smex-save-file (concat user-emacs-directory ".smex-items"))
+
+;; this uses smex
+(global-set-key (kbd "M-x") 'counsel-M-x)
 
 ;;;;; C-M-x - cut-to-register
 
@@ -2991,8 +2521,10 @@ modes like org-mode which have their own yank function."
 ;;;;; C-c - copy
 
 (global-set-key (kbd "C-d") 'kill-ring-save)
-(add-hook 'c-mode-hook
-          (lambda () (define-key c-mode-map (kbd "C-d") nil)))
+(add-hook 'c-mode-common-hook
+          (lambda ()
+            (define-key c-mode-map (kbd "C-d") nil)
+            (define-key c++-mode-map (kbd "C-d") nil)))
 (add-hook 'comint-mode-hook
           (lambda ()
             (define-key comint-mode-map (kbd "C-d") nil)))
@@ -3003,9 +2535,9 @@ modes like org-mode which have their own yank function."
             (define-key c-mode-base-map (kbd "<deletechar>") 'c-electric-delete-forward)))
 
 
-;;;;; M-c - org-capture
+;;;;; M-c - delete-other-windows
 
-(define-key global-map "\M-c" 'org-capture)
+(define-key global-map "\M-c" 'delete-other-windows)
 
 ;;;;; C-M-c - copy-to-register
 
@@ -3015,6 +2547,10 @@ modes like org-mode which have their own yank function."
 
 (global-set-key (kbd "C-v") 'yank-better)
 
+(add-hook 'ivy-mode-hook
+          (lambda ()
+            (define-key ivy-minibuffer-map (kbd "C-v") nil)))
+
 
 
 (defun yank-better (arg)
@@ -3042,9 +2578,9 @@ modes like org-mode which have their own yank function."
 
 (global-set-key (kbd "C-M-v") 'yank-pop)
 
-;;;;; C-b - delete-other-windows
+;;;;; C-b - other-window
 
-(global-set-key (kbd "C-b") 'delete-other-windows)
+(global-set-key (kbd "C-b") 'other-window)
 
 ;;;;; M-b - isearch-backward-current-symbol
 
@@ -3103,10 +2639,13 @@ modes like org-mode which have their own yank function."
 ;;;;; C-right-arrow - forward-symbol
 ;;;;; C-M-right-arrow - org-shiftdown
 (add-hook 'org-mode-hook
-(lambda () (define-key org-mode-map (kbd "C-M-)") 'org-shiftdown)))
+          (lambda () (define-key org-mode-map (kbd "C-M-)") 'org-shiftdown)))
 
 ;;;;; C-backspace - backward-kill-symbol
 
+(define-key terminal-key-map (kbd "4b") 'backward-kill-symbol) ;c-backspace in my konsole
+
+;; c-w is duplicate in terminal
 (global-set-key (kbd "<C-backspace>") 'backward-kill-symbol)
 (add-hook 'comint-mode-hook
           (lambda ()
@@ -3120,17 +2659,9 @@ modes like org-mode which have their own yank function."
 (global-set-key (kbd "<C-M-backspace>") 'backward-kill-sexp)
 
 ;;;; right primary
-;;;;; C-* - split-window-horizontally
-
-(global-set-key (kbd "C-*") 'split-window-horizontally)
+;;;;; M-8 - delete-window-or-exit
 
-;;;;; C-M-* - calc-dispatch
-
-(global-set-key (kbd "C-M-*") 'calc-dispatch)
-
-;;;;; C-9 - delete-window-or-exit
-
-(global-set-key (kbd "C-9") 'delete-window-or-exit)
+(global-set-key (kbd "M-8") 'delete-window-or-exit)
 
 (defun delete-window-or-exit ()
   "Delete window or exit emacs."
@@ -3140,6 +2671,11 @@ modes like org-mode which have their own yank function."
           (progn (basic-save-buffer) (delete-frame))
         (save-buffers-kill-terminal t))))
 
+;;;;; C-* - --- terminal
+;;;;; C-M-* - calc-dispatch
+
+(global-set-key (kbd "C-M-*") 'calc-dispatch)
+
 ;;;;; M-9 - kill-buffer
 
 (defun kill-buffer-no-ido ()
@@ -3157,297 +2693,285 @@ modes like org-mode which have their own yank function."
 ;;  save & kill buffer if it was opened externally via emacsclient
 
 
-  (defun server-edit-save ()
-    (interactive)
-    (save-buffer)
-    (server-edit))
-  (global-set-key (kbd "C-M-9") 'server-edit-save)
+(defun server-edit-save ()
+  (interactive)
+  (save-buffer)
+  (server-edit))
+(global-set-key (kbd "C-M-9") 'server-edit-save)
 
 ;;;;; C-u - universal-argument
 ;;;;; C-M-u - search-keybind
 
-  (global-set-key (kbd "C-M-u") 'search-keybind)
+(global-set-key (kbd "C-M-u") 'search-keybind)
 
-  (defun search-keybind (regexp &optional nlines)
-    (interactive (occur-read-primary-args))
-    (save-excursion
-      (describe-bindings)
-      (set-buffer "*Help*")
-      (occur regexp)
-      (delete-windows-on "*Help*")
-      ))
+(defun search-keybind (regexp &optional nlines)
+  (interactive (occur-read-primary-args))
+  (save-excursion
+    (describe-bindings)
+    (set-buffer "*Help*")
+    (occur regexp)
+    (delete-windows-on "*Help*")
+    ))
+
+;;;;; C-i -
+;; todo: try making use
+;; this is the key in terminal
+;;M-[ 4 d is undefined
+
+;; previously had this for enhancing graphical keybinds,
+;; but afaik its no help since i want terminal to work
+;; the same.
+;;  (define-key input-decode-map [?\C-i] [C-i])
 
-;;;;; C-i - -----
 ;;;;; C-M-i - query-replace-regexp
 
-  (global-set-key (kbd "C-M-i") 'query-replace-regexp)
-  (add-hook 'flyspell-mode-hook
-            (lambda () (define-key flyspell-mode-map (kbd "C-M-i") nil)))
-  (add-hook 'text-mode-hook
-            (lambda () (define-key text-mode-map (kbd "C-M-i") nil)))
+(global-set-key (kbd "C-M-i") 'query-replace-regexp)
+(add-hook 'flyspell-mode-hook
+          (lambda () (define-key flyspell-mode-map (kbd "C-M-i") nil)))
+(add-hook 'text-mode-hook
+          (lambda () (define-key text-mode-map (kbd "C-M-i") nil)))
 
 
 ;;;;; C-o - occur
 
-  (global-set-key (kbd "C-o") 'occur)
+(global-set-key (kbd "C-o") 'occur)
 
 ;;;;; C-M-o - counsel-imenu
 
-  (global-set-key (kbd "C-M-o") 'counsel-imenu)
+(global-set-key (kbd "C-M-o") 'counsel-imenu)
 
 ;;;;; C-p - move-mouse-to-point
 
-  (global-set-key (kbd "C-p") 'move-mouse-to-point)
+(global-set-key (kbd "C-p") 'move-mouse-to-point)
 
 ;;;;; C-M-p - delete-horizontal-space
 
-  (global-set-key (kbd "C-M-p") 'delete-horizontal-space)
+(global-set-key (kbd "C-M-p") 'delete-horizontal-space)
 
 ;;;;; C-j - pop-to-mark
 
-  (defun my-pop-to-mark-command ()
-    "Jump to mark, and pop a new position for mark off the ring.
+(defun my-pop-to-mark-command ()
+  "Jump to mark, and pop a new position for mark off the ring.
                      \(Does not affect global mark ring\)."
-    (interactive)
-    (pop-to-mark-command)
-    (if (and (derived-mode-p 'org-mode) (outline-invisible-p))
-        (org-show-context 'mark-goto)))
-
-  (global-set-key (kbd "C-j") 'my-pop-to-mark-command)
-  (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text)
-  (add-hook 'ido-setup-hook
-            (lambda () (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text)))
-  (add-hook 'lisp-interaction-mode-hook
-            (lambda ()
-              (define-key lisp-interaction-mode-map (kbd "C-j") nil)))
+  (interactive)
+  (pop-to-mark-command)
+  (if (and (derived-mode-p 'org-mode) (outline-invisible-p))
+      (org-show-context 'mark-goto)))
+
+(global-set-key (kbd "C-j") 'my-pop-to-mark-command)
+(add-hook 'ido-setup-hook
+          (lambda ()
+            (define-key ido-common-completion-map (kbd "C-j") 'ido-select-text)
+            ))
+(add-hook 'lisp-interaction-mode-hook
+          (lambda ()
+            (define-key lisp-interaction-mode-map (kbd "C-j") nil)))
 
 
 ;;;;; M-j - previous-error
 
-  (global-set-key (kbd "M-j") 'previous-error)
+(global-set-key (kbd "M-j") 'previous-error)
 
 ;;;;; C-M-j - register prefix
 
-  (define-key global-map (kbd "C-M-j") ctl-x-r-map)
-  (define-key ctl-x-r-map "m" 'kmacro-to-register)
+(define-key global-map (kbd "C-M-j") ctl-x-r-map)
+(define-key ctl-x-r-map "m" 'kmacro-to-register)
 
 
 ;;;;; C-k - jump-to-register
 
 
-  (global-set-key (kbd "C-k") 'jump-to-register)
+(global-set-key (kbd "C-k") 'jump-to-register)
 
 ;;;;; M-k - next-error
 
-  (global-set-key (kbd "M-k") 'next-error)
+(global-set-key (kbd "M-k") 'next-error)
 
 ;;;;; C-M-k - man
 
-  (global-set-key (kbd "C-M-k") 'man)
+(global-set-key (kbd "C-M-k") 'man)
 
 ;;;;; C-l - ivy-switch-buffer
 
-  (global-set-key (kbd "C-l") 'ivy-switch-buffer)
+(global-set-key (kbd "C-l") 'ivy-switch-buffer)
 
 ;;;;; C-M-l - move cursor top bottom mid, comint clear screen
 
-  (global-set-key (kbd "C-M-l") 'move-to-window-line-top-bottom)
+(global-set-key (kbd "C-M-l") 'move-to-window-line-top-bottom)
 
 ;;;;; C-; - used in flyspell, not sure what for, otherwise unbound
 ;;;;; M-; - comment-dwim
 ;;;;; C-M-; - comment-current-line-dwim
 
-  (defun comment-current-line-dwim ()
-    "Comment or uncomment the current line."
-    (interactive)
-    (save-excursion
-      (push-mark (beginning-of-line) t t)
-      (end-of-line)
-      (comment-dwim nil))
-    (move-beginning-of-line 2))
-  (global-set-key (kbd "C-M-;") 'comment-current-line-dwim)
-
+(defun comment-current-line-dwim ()
+  "Comment or uncomment the current line."
+  (interactive)
+  (save-excursion
+    (push-mark (beginning-of-line) t t)
+    (end-of-line)
+    (comment-dwim nil))
+  (move-beginning-of-line 2))
+(global-set-key (kbd "C-M-;") 'comment-current-line-dwim)
+
+;;;;; C-m - ---
+;; terminal/console needs this. otherwise, we could do this
+;; to make C-m be a valid key in graphical mode.
+;;  (define-key input-decode-map [?\C-m] [C-m])
 ;;;;; C-M-m - recursive grep
 
-  (define-key global-map (kbd "C-M-m") 'rgrep)
+(define-key global-map (kbd "C-M-m") 'rgrep)
 
-;;;;; C-, - ounsel-find-file
+;;;;; C-, - ---
+;; not recognized by terminal, can't get konsole keydef file to recognize comma,
+;; todo: dig into konsole sources, or try newer version than t8
 
-  (global-set-key (kbd "C-,") 'counsel-find-file)
-  (add-hook 'flyspell-mode-hook
-            (lambda () (define-key flyspell-mode-map (kbd "C-,") nil)))
+(add-hook 'flyspell-mode-hook
+          (lambda () (define-key flyspell-mode-map (kbd "C-,") nil)))
 
 ;;;;; C-M-, - ind-file-in-project
 
-  (global-set-key (kbd "C-M-,") 'find-file-in-project)
+(global-set-key (kbd "C-M-,") 'find-file-in-project)
 
 ;;;;; C-. - find recent file
-;;  Taken from starter kit.
-
-  (defun recentf-ido-find-file ()
-    "Find a recent file using Ido."
-    (interactive)
-    (let* ((file-assoc-list
-            (mapcar (lambda (x)
-                      (cons (file-name-nondirectory x)
-                            x))
-                    recentf-list))
-           (filename-list
-            (remove-duplicates (mapcar #'car file-assoc-list)
-                               :test #'string=))
-           (filename (ido-completing-read "Choose recent file: "
-                                          filename-list
-                                          nil
-                                          t)))
-      (when filename
-        (find-file (cdr (assoc filename
-                               file-assoc-list))))))
-
-  (add-hook 'flyspell-mode-hook
-            (lambda () (define-key flyspell-mode-map (kbd "C-.") nil)))
-  (define-key dot-mode-map (kbd "C-.") nil)
-  (global-set-key (kbd "C-.") 'recentf-ido-find-file)
-  (add-hook 'php-mode-hook
-            (lambda () (define-key php-mode-map (kbd "C-.") nil)))
+
+(add-hook 'flyspell-mode-hook
+          (lambda () (define-key flyspell-mode-map (kbd "C-.") nil)))
+(define-key dot-mode-map (kbd "C-.") nil)
+(define-key terminal-key-map (kbd "4c") 'counsel-recentf)
+(global-set-key (kbd "C-.") 'counsel-recentf)
+(add-hook 'php-mode-hook
+          (lambda () (define-key php-mode-map (kbd "C-.") nil)))
 
 ;;;;; C-M-. - -
 
-  (define-key dot-mode-map (kbd "C-M-.") nil)
-  ;;  (global-set-key (kbd "C-M-.") 'execute-extended-command)
+(define-key dot-mode-map (kbd "C-M-.") nil)
+;;  (global-set-key (kbd "C-M-.") 'execute-extended-command)
 
 ;;;;; C-/ - join lines
 
-  (defun vim-style-join-line ()
-    (interactive)
-    (join-line '(4)))
-  (global-set-key (kbd "C-/") 'vim-style-join-line)
+(defun vim-style-join-line ()
+  (interactive)
+  (join-line '(4)))
+;; terminal
+(global-set-key (kbd "C-_") 'vim-style-join-line)
+;; gui
+(global-set-key (kbd "C-/") 'vim-style-join-line)
 
 ;;;;; C-M-/ - copy-buffer-file-name
 
-  ;; haven't bound this atm, todo, maybe someday?
-  (defun copy-variable (variable)
-    (interactive
-     (let ((v (variable-at-point))
-          (enable-recursive-minibuffers t)
-          val)
-       (setq val (completing-read (if (symbolp v)
-                                     (format
-                                      "Describe variable (default %s): " v)
-                                   "Describe variable: ")
-                                 obarray
-                                 (lambda (vv)
-                                    (or (get vv 'variable-documentation)
-                                        (and (boundp vv) (not (keywordp vv)))))
-                                 t nil nil
-                                 (if (symbolp v) (symbol-name v))))
-       (list (if (equal val "")
-                v (intern val)))))
-    (kill-new (symbol-value variable)))
-
-  (defun copy-buffer-file-name ()
-    (interactive)
-    (let ((name (cond
-                 ((derived-mode-p 'mu4e-view-mode) (mu4e-message-field-at-point :path))
-                 (t buffer-file-name))
-                ))
-      (kill-new name)
-      (message name)))
-
-
-  (global-set-key (kbd "C-M-/") 'copy-buffer-file-name)
+;; haven't bound this atm, todo, maybe someday?
+(defun copy-variable (variable)
+  (interactive
+   (let ((v (variable-at-point))
+        (enable-recursive-minibuffers t)
+        val)
+     (setq val (completing-read (if (symbolp v)
+                                   (format
+                                    "Describe variable (default %s): " v)
+                                 "Describe variable: ")
+                               obarray
+                               (lambda (vv)
+                                  (or (get vv 'variable-documentation)
+                                      (and (boundp vv) (not (keywordp vv)))))
+                               t nil nil
+                               (if (symbolp v) (symbol-name v))))
+     (list (if (equal val "")
+              v (intern val)))))
+  (kill-new (symbol-value variable)))
+
+(defun copy-buffer-file-name ()
+  (interactive)
+  (let ((name (cond
+               ((derived-mode-p 'mu4e-view-mode) (mu4e-message-field-at-point :path))
+               (t buffer-file-name))
+              ))
+    (kill-new name)
+    (message name)))
 
 
+(global-set-key (kbd "C-M-/") 'copy-buffer-file-name)
 
-;;;;; C-8 - calc-embedded-word
 
-  (global-set-key (kbd "C-8") 'calc-embedded-word)
 
 ;;;;; C-up-arrow - org prev headline
 
-  ;; disabled just because i don't want to accidentally hit it
-  (define-key global-map "\C-_" nil)
-  (global-set-key (kbd "<C-_>") 'beginning-of-defun)
+;; disabled just because i don't want to accidentally hit it
+(define-key global-map "\C-_" nil)
+(global-set-key (kbd "<C-_>") 'beginning-of-defun)
 
-  (add-hook 'org-mode-hook
-            (lambda ()
-              (define-key org-mode-map (kbd "\C-_") 'outline-previous-visible-heading)))
+(add-hook 'org-mode-hook
+          (lambda ()
+            (define-key org-mode-map (kbd "\C-_") 'outline-previous-visible-heading)))
 
 
 
 
 ;;;;; C-S-up-arrow - winner undo
 
-  (global-set-key (kbd "<C-S-_>") 'winner-undo)
+(global-set-key (kbd "<C-S-_>") 'winner-undo)
 
 ;;;;; C-down-arrow - org next headline
 
-  (global-set-key (kbd "<C-kp-enter>") 'end-of-defun)
+(global-set-key (kbd "<C-kp-enter>") 'end-of-defun)
 
-  (add-hook 'org-mode-hook
-            (lambda ()
-              (define-key org-mode-map (kbd "<C-kp-enter>") 'outline-next-visible-heading)))
+(add-hook 'org-mode-hook
+          (lambda ()
+            (define-key org-mode-map (kbd "<C-kp-enter>") 'outline-next-visible-heading)))
 
 
 
 
 ;;;;; C-M-down-arrow - toggle-mark-activation
 
-  (defun toggle-mark-activation ()
-    (interactive)
-    (if mark-active
-        (deactivate-mark t)
-      (activate-mark)))
+(defun toggle-mark-activation ()
+  (interactive)
+  (if mark-active
+      (deactivate-mark t)
+    (activate-mark)))
 
-  (global-set-key (kbd "<C-M-kp-enter>") 'toggle-mark-activation)
+(global-set-key (kbd "<C-M-kp-enter>") 'toggle-mark-activation)
 
 ;;;;; C-S-down-arrow  winner redo
 
-  (global-set-key (kbd "<C-S-kp-enter>") 'winner-redo)
+(global-set-key (kbd "<C-S-kp-enter>") 'winner-redo)
 
 
 ;;;;; C-S-down-arrow - m-x for major mode
 
-  (global-set-key (kbd "<C-S-kp-enter>") 'smex-major-mode-commands)
+;; todo, update this for ivy
+(global-set-key (kbd "<C-S-kp-enter>") 'smex-major-mode-commands)
 
 ;;;;; C-lbracket - ----
 ;;;;; C-M-lbracket - scroll-right
 
-  (global-set-key (kbd "C-M-[") 'scroll-right)
+(global-set-key (kbd "C-M-[") 'scroll-right)
 
 ;;;;; C-rbracket - fill-paragraph
 
-  (global-set-key (kbd "C-]") 'fill-paragraph)
+(global-set-key (kbd "C-]") 'fill-paragraph)
 
 ;;;;; C-M-rbracket - scroll-left
 
-  (global-set-key (kbd "C-M-]") 'scroll-left)
+(global-set-key (kbd "C-M-]") 'scroll-left)
 
 ;;;;; C-return - newline-anywhere
 
-  (defun newline-anywhere ()
-    "Add a newline from anywhere in the line."
-    (interactive)
-    (end-of-line)
-    (newline-and-indent))
-  (global-set-key (kbd "<C-return>") 'newline-anywhere)
+(defun newline-anywhere ()
+  "Add a newline from anywhere in the line."
+  (interactive)
+  (end-of-line)
+  (newline-and-indent))
+;; todo use alternate keybind make this work for terminal
+(global-set-key (kbd "<C-return>") 'newline-anywhere)
 
 
 ;;;;; M-return - plain newline
 
-  (defun plain-newline ()
-    (interactive)
-    (insert "\n"))
-  (global-set-key (kbd "<M-return>") 'plain-newline)
-
-
-;;;;; C-M-return - newline-anywhere-previous
-(defun newline-anywhere-previous ()
-  "Add a newline from anywhere in the line."
+(defun plain-newline ()
   (interactive)
-  (forward-line -1)
-  (end-of-line)
-  (newline-and-indent))
-(global-set-key (kbd "<C-M-return>") 'newline-anywhere-previous)
+  (insert "\n"))
+(global-set-key (kbd "M-RET") 'plain-newline)
+
 
 ;;;;; C-space - org-edit-special
 
@@ -3480,6 +3004,8 @@ modes like org-mode which have their own yank function."
           (lambda ()
             (define-key org-mode-map (kbd "C-t") 'org-todo)))
 
+
+
 (defun my-comint-previous-input (arg)
   (interactive "*p")
   (if (comint-after-pmark-p)
@@ -3526,9 +3052,9 @@ modes like org-mode which have their own yank function."
 ;;;;; C-home - start of buffer
 ;;;;; C-end - end of buffer
 ;;;; right secondary
-;;;;; C-6 - save-buffers-kill-emacs
+;;;;; C-^ - save-buffers-kill-emacs exit quit
 
-(global-set-key (kbd "C-6") 'save-buffers-kill-emacs)
+(global-set-key (kbd "C-^") 'save-buffers-kill-emacs)
 
 ;;;;; C-M-6 - insert-small-copyright
 
@@ -3536,18 +3062,22 @@ modes like org-mode which have their own yank function."
   (interactive)
   (beginning-of-line)
   (let ((beg (point)))
-    (insert "Copyright (C) 2017 Ian Kelling\nThis program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>")
+    (insert "Copyright (C) 2019 Ian Kelling\nThis program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>")
     (comment-region beg (point))))
 
 (global-set-key (kbd "C-M-6") 'insert-small-copyright)
 
+;;;;; M-7 - calc-embedded-word
+
+(global-set-key (kbd "M-7") 'calc-embedded-word)
+
 ;;;;; C-M-7 - insert-full-copyright
 
 (defun insert-full-copyright ()
   (interactive)
   (beginning-of-line)
   (let ((beg (point)))
-    (insert "Copyright (C) 2017 Ian Kelling\n")
+    (insert "Copyright (C) 2019 Ian Kelling\n")
     (insert "\n")
     (insert "This program is free software: you can redistribute it and/or modify\n")
     (insert "it under the terms of the GNU General Public License as published by\n")
@@ -3599,7 +3129,8 @@ modes like org-mode which have their own yank function."
 ;;;;; C-M-- - org-edit-src-exit
 ;;;;; C-y - undo
 
-(global-set-key (kbd "C-y") 'undo)
+;;(global-set-key (kbd "C-y") 'undo-tree-redo)
+(global-set-key (kbd "C-y") 'undo-fu-only-redo)
 (add-hook 'org-mode-hook
           (lambda () (define-key org-mode-map (kbd "C-y") nil)))
 
@@ -3640,3 +3171,9 @@ modes like org-mode which have their own yank function."
 ;;;;; C-escape - find-tag
 
 (global-set-key (kbd "<C-escape>") 'find-tag)
+
+
+;; Local Variables:
+;; eval: (outline-minor-mode)
+;; outline-regexp: "\\( *\\);;;\\{1,8\\} "
+;; End: