Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
10184 lines (9115 sloc) 322 KB
;;; init.el --- Thomas Frössman emacs init
;;; Commentary:
;;
;;; Code:
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
;; (package-initialize)
;;; init
;;;; set emacs start time
(defconst emacs-start-time (current-time))
(setq-default ;; alloc.c
gc-cons-threshold (* 20 1204 1204)
gc-cons-percentage 0.5)
;;;; Set some things early
(and (fboundp 'menu-bar-mode)
menu-bar-mode
(not (eq system-type 'darwin))
(menu-bar-mode -1))
(and (fboundp 'tool-bar-mode)
tool-bar-mode
(tool-bar-mode -1))
(and (fboundp 'scroll-bar-mode)
scroll-bar-mode
(scroll-bar-mode -1))
(setq default-frame-alist '((vertical-scroll-bars . nil)
(tool-bar-lines . 0)
(menu-bar-lines . 0)
(fullscreen . nil)))
(when load-file-name
(load (expand-file-name
"load-path" (file-name-directory load-file-name)) nil t))
(setq
abbrev-file-name (expand-file-name
"abbrev_defs.el" user-lisp-directory)
)
(eval-and-compile
(defvar my-log-verbose nil)
;; (setq my-log-verbose t)
(if my-log-verbose
(setq byte-compile-verbose t)
(setq ad-redefinition-action 'accept))
(setq use-package-verbose my-log-verbose
use-package-debug nil
use-package-enable-imenu-support t
use-package-minimum-reported-time 0.01))
;;; Emacs version check and feature inhibitions
(defvar degrade-p-minimalism nil
"If set to non nil a lighter emacs config is used. ")
(and
(not noninteractive)
(or (not (boundp 'emacs-version)) (string< emacs-version "24.3"))
(warn "Use a newer version of Emacs for a full featured environment!"))
;;;; package.el
(eval-and-compile
(setq
package-enable-at-startup nil
package-archives
'(("melpa-stable" . "https://stable.melpa.org/packages/")
("melpa" . "https://melpa.org/packages/")
("marmalade" . "https://marmalade-repo.org/packages/")
("org" . "http://orgmode.org/elpa/")
("gnu" . "https://elpa.gnu.org/packages/")
;; ("sc" . "http://joseito.republika.pl/sunrise-commander/")
))
(unless (boundp 'package-pinned-packages)
(setq package-pinned-packages ()))
(defun require-package (package &optional min-version no-refresh)
"Install given PACKAGE, optionally requiring MIN-VERSION.
If NO-REFRESH is non-nil, the available package lists will not be
re-downloaded in order to locate PACKAGE."
(if (package-installed-p package min-version)
t
(if (or (assoc package package-archive-contents) no-refresh)
(package-install package)
(progn
(package-refresh-contents)
(require-package package min-version t))))))
(defvar byte-compile-warnings nil)
(eval-when-compile
(require 'package)
(package-initialize t)
(require-package 'use-package)
(require 'use-package)
;; (require-package 'names)
;; (require 'names)
(defmacro executable-find* (command)
"Macro form of executable-find..."
(executable-find command)))
;;;; load packages
(require 'cl)
(use-package dash
:ensure t
:demand
:commands (dash-enable-fontlock)
:init
(progn
(add-hook 'emacs-lisp-mode-hook 'dash-enable-font-lock)))
(use-package dash-functional :ensure t :defer)
(use-package memoize :ensure t :defer)
(use-package s :ensure t)
(use-package f :ensure t)
(use-package bind-key :ensure t)
(use-package smartrep :ensure t)
(use-package diminish :ensure t)
(use-package deferred :ensure t :commands (deferred:$))
(use-package let-alist :ensure t :commands (let-alist))
(use-package request-deferred :ensure t :defer)
(use-package concurrent :ensure t :defer)
(use-package load-relative :ensure t :defer)
(use-package loc-changes :ensure t :defer)
(use-package epc :ensure t :defer)
(use-package ctable :ensure t :defer)
(use-package fringe-helper :ensure t :defer)
;; (use-package button-lock :ensure t :diminish "" :defer)
(use-package fakir :ensure t :defer)
(use-package fuzzy :ensure t :defer)
(use-package python-environment
:ensure t
:defer
:init
(progn
(setq python-environment-directory "~/.virtualenvs/"
python-environment-default-root-name "emacs-default")))
;; Try to load private el env
(require 'private-init nil (not my-log-verbose))
;;;; startup.el
(defun display-startup-echo-area-message ())
(setq
auto-save-list-file-prefix (expand-file-name
"auto-save-list/" user-data-directory)
inhibit-startup-message t
inhibit-splash-screen t
inhibit-startup-buffer-menu t
inhibit-startup-echo-area-message t
initial-major-mode 'initial-mode
initial-scratch-message ";;_
;; __ _,******
;; ,-----, _ _,**
;; | Mu! | _ ____,****
;; ;-----; _
;; \\ ^__^
;; \\ (^^)\\_______
;; ^-(..)\\ )\\/\\/^_^
;; ||----w |
;; __.-''*-,.,____||_____||___,_.-
;; '' ''
")
;;; some early compat functions
(eval-and-compile
;; for < emacs25
(when (not (fboundp 'save-mark-and-excursion))
(defmacro save-mark-and-excursion (&rest body)
`(save-excursion ,@body)))
;; Provide `defvar-local' and `setq-local' for Emacs 24.2 and below
(unless (fboundp 'defvar-local)
(defmacro defvar-local (var val &optional docstring)
"Define VAR as a buffer-local variable with default value VAL.
Like `defvar' but additionally marks the variable as being automatically
buffer-local wherever it is set."
(declare (debug defvar) (doc-string 3))
;; Can't use backquote here, it's too early in the bootstrap.
(list 'progn (list 'defvar var val docstring)
(list 'make-variable-buffer-local (list 'quote var)))))
(unless (fboundp 'setq-local)
(defmacro setq-local (var val)
"Set variable VAR to value VAL in current buffer."
;; Can't use backquote here, it's too early in the bootstrap.
(list 'set (list 'make-local-variable (list 'quote var)) val))))
;;; initial mode.
;;
(defvar initial-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c c") 'lisp-interaction-mode)
(define-key map (kbd "C-c C-c") 'lisp-interaction-mode)
map)
"Keymap for `initial-mode'.")
(define-derived-mode initial-mode nil "Initial"
"Major mode for start up buffer.
\\{initial-mode-map}"
(setq-local text-mode-variant t)
(setq-local indent-line-function 'indent-relative))
;;; base directories
;;
(defconst backup-dir
(expand-file-name (concat "backups/" (user-real-login-name) "/")
user-data-directory)
"Directory for Emacs backups.")
(defconst
autosave-dir
(expand-file-name (concat "autosaves/" (user-real-login-name) "/")
user-data-directory)
"Directory for Emacs auto saves.")
(make-directory autosave-dir t)
(setq
backup-directory-alist (list (cons "." backup-dir))
auto-save-file-name-transforms `((".*" ,autosave-dir t)))
(add-to-list 'load-suffixes ".el.gpg")
;; Try to load local customize file
(setq custom-file (expand-file-name
"custom-set-variables.el" user-data-directory))
(load custom-file 'noerror 'nomessage)
;; Do some key binding stuff early
(global-unset-key (kbd "M-o"))
(global-unset-key (kbd "C-z"))
(global-unset-key (kbd "C-x C-z"))
(defvar my-files-map)
(defvar my-dirs-map)
(defvar my-buffers-map)
(defvar my-other-map)
(define-prefix-command 'my-files-map)
(define-prefix-command 'my-dirs-map)
(define-prefix-command 'my-buffers-map)
(define-prefix-command 'my-other-map)
(global-set-key (kbd "C-x f") my-files-map)
(global-set-key (kbd "C-x d") my-dirs-map)
(global-set-key (kbd "C-x b") my-buffers-map)
(global-set-key (kbd "C-c o") my-other-map)
(global-set-key (kbd "C-h o") my-other-map)
(global-set-key (kbd "M-o") my-other-map)
(define-key my-other-map (kbd "s") search-map)
;; (bind-key )
(defvar region-bindings-mode-map
(let ((region-bindings-mode-map (make-sparse-keymap)))
region-bindings-mode-map)
"Keymaps for command `region-bindings-mode-map'.")
;;;; utils
;;;; Modes and mode groupings
(defmacro hook-into-modes (func modes)
"Add hook `FUNC' to multiple `MODES'."
`(dolist (mode-hook ,modes)
(add-hook mode-hook ,func)))
(defvar my-lisp-modes
'(emacs-lisp-mode
inferior-emacs-lisp-mode
ielm-mode
lisp-mode
inferior-lisp-mode
lisp-interaction-mode
slime-repl-mode
clojure-mode))
(defvar my-lisp-mode-hooks
(mapcar (function
(lambda (mode)
(intern
(concat (symbol-name mode) "-hook"))))
my-lisp-modes))
(defvar my-prog-mode-hooks
'(prog-mode-hook
emacs-lisp-mode-hook
pyhon-mode-hook
coffee-mode-hook
js-mode-hook
js2-mode-hook
actionscript-mode-hook
ruby-mode-hook
haskell-mode-hook
clojure-mode-hook
go-mode-hook
groovy-mode-hook
qml-mode-hook
kivy-mode-hook))
(defvar my-significant-whitespace-mode-hooks
'(coffee-mode-hook
python-mode-hook
haskell-mode-hook
stylus-mode-hook
haml-mode-hook
kivy-mode-hook))
(defvar my-markup-mode-hooks-1
'(markdown-mode-hook
rst-mode-hook))
;; org-mode is a bit special so i dont want it among the other ones.
(defvar my-markup-mode-hooks-2
'(org-mode-hook))
(defvar my-html-like-modes
'(html-mode
handlebars
nxml-mode
web-mode
haml-mode))
(defvar my-html-like-mode-hooks
'(html-mode-hook
handlebars-mode-hook
nxml-mode-hook
web-mode-hook))
;; haml-mode is a bit special since it is ws significant
(defvar my-html-like-mode-hooks-2
'(haml-mode-hook))
(defvar my-css-like-modes
'(css-mode
stylus-mode
sass-mode
scss-mode))
(defvar my-css-like-mode-hooks
'(css-mode-hook
stylus-mode-hook
scss-mode-hook
sass-mode-hook))
;;; Enable disabled commands
(--each '(narrow-to-defun narrow-to-page narrow-to-region
upcase-region downcase-region
scroll-left dired-find-alternate-file erase-buffer)
(put it 'disabled nil))
;;; Environment vars
(setenv "NODE_NO_READLINE" "1") ;; nodejs
;;; functions: Settings in defined in c source
(setq-default ;; keyboard.c
echo-keystrokes 0.1)
(setq-default ;; minibuf.c
;; NOTE enable-recursive-minibuffers this can be quite confusing
enable-recursive-minibuffers nil)
(setq-default ;; fns.c
use-dialog-box nil)
(setq-default ;; xfns.c
x-gtk-file-dialog-help-text nil)
(setq-default ;; coding.c
locale-coding-system 'utf-8)
(transient-mark-mode 1)
(make-variable-buffer-local 'transient-mark-mode)
(put 'transient-mark-mode 'permanent-local t)
(setq-default ;; buffer.c
tab-width 4
indicate-empty-lines nil
transient-mark-mode t
fill-column 79)
(setq-default ;; indent.c
indent-tabs-mode nil)
(setq-default ;; dispnew.c
visible-bell nil)
(setq-default ;; xdisp.c
frame-title-format "emacs - %b"
scroll-step 1
scroll-margin 0
scroll-conservatively 10000
scroll-up-aggressively 0.01
scroll-down-aggressively 0.01
auto-window-vscroll nil)
(setq-default
;; scroll-preserve-screen-position t
scroll-preserve-screen-position 1)
(setq-default ;; xdisp.c
truncate-partial-width-windows 50)
(setq-default ;; fileio.c
delete-by-moving-to-trash t)
(setq-default ;; filelock.c
create-lockfiles nil)
(setq-default ;; lread.c
load-prefer-newer t)
(setq-default ;; dired.c
completion-ignored-extensions
'("-min.css" "-min.js" ".a" ".annot" ".aux" ".bbl" ".bbl" ".bin" ".blg" ".blg"
".bzr/" ".class" ".cma" ".cmi" ".cmo" ".cmt" ".cmti" ".cmx" ".cmxa" ".cp"
".cp" ".cps" ".cps" ".d64fsl" ".dfsl" ".dx32fsl" ".dx64fsl" ".dxl" ".elc"
".fas" ".fasl" ".fmt" ".fn" ".fn" ".fns" ".fns" ".fsl" ".fx32fsl" ".fx64fsl"
".git/" ".glo" ".glo" ".gmo" ".hg/" ".hi" ".idx" ".idx" ".ky" ".ky" ".kys"
".kys" ".la" ".lbin" ".lib" ".ln" ".lo" ".lof" ".lof" ".lot" ".lot" ".lx32fsl"
".lx64fsl" ".map" ".mem" ".min.css" ".min.js" ".mo" ".o" ".p64fsl" ".pfsl"
".pg" ".pg" ".pgs" ".pgs" ".pyc" ".pyo" ".pyx" ".rbc" ".sass-cache" ".so"
".sparcf" ".svn/" ".sx32fsl" ".sx64fsl" ".test" ".tfm" ".toc" ".tp" ".tp"
".tps" ".tps" ".ufsl" ".vr" ".vr" ".vrs" ".vrs" ".wx32fsl" ".wx64fsl" ".x86f"
"CVS/" "_MTN/" "_darcs/" "~"))
(setq-default ;; xterm.c
x-underline-at-descent-line t)
;;; functions: early gui setup
(defvar theme-bright nil "A light theme.")
(defvar theme-dark nil "A dark theme.")
(use-package solarized-theme
:ensure t
:if window-system
:init
(progn
(setq solarized-use-less-bold t
solarized-use-more-italic t
solarized-emphasize-indicators nil
solarized-distinct-fringe-background nil
solarized-high-contrast-mode-line nil))
:config
(progn
(load "solarized-theme-autoloads" nil t)
(setq theme-dark 'my-solarized-dark
theme-bright 'my-solarized-light)))
(use-package zenburn-theme
:ensure t
:if (not window-system)
:config
(progn
(use-package anti-zenburn-theme
:ensure t
:config
(load "anti-zenburn-theme-autoloads" nil t))
(load "zenburn-theme-autoloads" nil t)
(setq theme-dark 'zenburn
theme-bright 'anti-zenburn)))
(defun post-change-theme ()
(set-face-inverse-video-p 'vertical-border nil)
(set-face-background 'vertical-border (face-background 'default)))
(eval
'(set-display-table-slot standard-display-table
'vertical-border
(make-glyph-code ?┃)))
(defun dark-theme ()
"Switch to dark mode (dark color theme)."
(interactive)
(when theme-dark
(load-theme theme-dark t)
(setq dark-theme-on t)
(post-change-theme)))
(defun bright-theme ()
"Switch to light mode (light color theme)."
(interactive)
(when theme-bright
(load-theme theme-bright t)
(setq dark-theme-on nil)
(post-change-theme)))
(defun toggle-dark-theme ()
"Toggle between light and dark modes."
(interactive)
(if (bound-and-true-p dark-theme-on)
(bright-theme)
(dark-theme))
(post-change-theme))
(and (not (boundp 'dark-theme-on))
(not noninteractive)
;; (not (not window-system))
(not degrade-p-minimalism)
(if (file-exists-p "~/.config/darkmode")
(dark-theme)
(bright-theme)))
(add-hook 'focus-in-hook
#'(lambda ()
(if (file-exists-p "~/.config/darkmode")
(when (not dark-theme-on) (dark-theme))
(when dark-theme-on (bright-theme)))))
(setq sml/theme nil)
(use-package smart-mode-line
:ensure t
:if (and
(not noninteractive)
(not (not window-system))
(not degrade-p-minimalism))
:commands (sml/setup)
:preface
(progn
(load "smart-mode-line-autoloads" t t))
:init
(progn
(setq
sml/modified-char "m"
sml/read-only-char "r"
sml/outside-modified-char "M"
sml/mule-info ""
sml/shorten-modes nil
sml/projectile-replacement-format ":p/%s:"
sml/replacer-regexp-list
'(("^~/\.virtualenvs/\\([^/]+\\)" ":e/\\1:")
("^/sudo:.*:" ":su:")
("^~/dropbox/" ":db:")))
(sml/setup)))
(use-package dynamic-fonts
:ensure t
:commands (dynamic-fonts-setup)
:init
(progn
(setq
dynamic-fonts-preferred-monospace-fonts
'("PragmataPro" "Consolas" "Monaco" "Menlo" "DejaVu Sans Mono"
"Droid Sans Mono Pro" "Droid Sans Mono" "Inconsolata" "Source Code Pro"
"Lucida Console" "Envy Code R" "Andale Mono" "Lucida Sans Typewriter"
"Lucida Typewriter" "Panic Sans" "Bitstream Vera Sans Mono"
"Excalibur Monospace" "Courier New" "Courier" "Cousine" "Lekton"
"Ubuntu Mono" "Liberation Mono" "BPmono" "Anonymous Pro"
"ProFontWindows")
dynamic-fonts-preferred-monospace-point-size 11
dynamic-fonts-preferred-proportional-fonts
'("PT Sans" "Lucida Grande" "Segoe UI" "DejaVu Sans" "Bitstream Vera"
"Tahoma" "Verdana" "Helvetica" "Arial Unicode MS" "Arial")
dynamic-fonts-preferred-proportional-point-size 11)
(defvar my-monospaced-font "Pragmata Pro-11")
(defvar my-variable-pitch-font "Pt Sans-13")
;; (defvar my-variable-pitch-font "Input Sans Compressed-11.8")
;; (defvar my-monospaced-font "Input Mono Compressed-11.8")
(when (s-starts-with? "fogskum" system-name)
(setq my-monospaced-font "Pragmata Pro-13"
my-variable-pitch-font "Pt Sans-13"))
(when (s-starts-with? "blopp" system-name)
(setq my-monospaced-font "Pragmata Pro-15"
my-variable-pitch-font "Pt Sans-15"))
(defun my-set-fonts ()
(interactive)
(when window-system
(condition-case nil
(progn
(set-face-attribute 'default nil :font my-monospaced-font)
;; (set-face-attribute 'default nil :font my-monospaced-font :width 'ultra-condensed :weight 'normal )
(set-face-attribute 'fixed-pitch nil :font my-monospaced-font)
(set-face-attribute 'variable-pitch nil :font my-variable-pitch-font))
(error
(progn
(message
"Setting default fonts failed, running dynamic-fonts-setup...")
(dynamic-fonts-setup))))))
(add-hook 'after-init-hook 'my-set-fonts t)))
(use-package nav-flash
:ensure t
:commands (nav-flash-show)
:init
(progn
(setq nav-flash-delay 0.6)
(add-hook 'imenu-after-jump-hook 'nav-flash-show nil t)
(defun flash-defun()
"Flash current defun"
(interactive)
(save-restriction
(narrow-to-defun)
(nav-flash-show (point-min) (point-max))))
(defvar nav-flash-show-soon-timer nil)
(defun nav-flash-show-soon-cancel-timer ()
(when nav-flash-show-soon-timer
(cancel-timer nav-flash-show-soon-timer)
(setq nav-flash-show-soon nil)))
(defun nav-flash-show-soon (&optional later)
(nav-flash-show-soon-cancel-timer)
(setq nav-flash-show-soon-timer
(run-with-timer (if later 0.4 0.25) nil
'(lambda ()
(nav-flash-show)))))
(defun nav-flash-show-later ()
(nav-flash-show-soon t))
(add-hook 'focus-in-hook 'nav-flash-show-later)
(add-hook 'focus-out-hook 'nav-flash-show-soon-cancel-timer)
(defun recenter-top-bottom-flash ()
(interactive)
(call-interactively 'recenter-top-bottom)
(nav-flash-show))
(bind-key "C-l" 'recenter-top-bottom-flash)
(defun move-to-window-line-top-bottom-flash ()
(interactive)
(call-interactively 'move-to-window-line-top-bottom)
(nav-flash-show))
(bind-key "M-r" 'move-to-window-line-top-bottom-flash)
(defun scroll-up-command-flash ()
(interactive)
(call-interactively 'scroll-up-command)
(nav-flash-show-soon))
(bind-key "M-v" 'scroll-down-command-flash)
(defun scroll-down-command-flash ()
(interactive)
(call-interactively 'scroll-down-command)
(nav-flash-show-soon))
(bind-key "C-v" 'scroll-up-command-flash)))
;;; functions: Main settings block
;;;; subr
;; misc Emacs settings not directly related to loading a package
(defalias 'yes-or-no-p 'y-or-n-p)
;; (and (eq system-type 'darwin)
;; window-system
;; (setq mac-option-modifier nil
;; mac-command-modifier 'meta))
(defvar my-normal-cursor-type 'bar)
(setq-default fringes-outside-margins t)
;;;; server
(defun workspace-prefix ()
(let ((res (if (and
(eq window-system 'x)
(executable-find* "wsname"))
(shell-command-to-string "wsname -p"))))
(if (and res (not (s-blank? res))) res)))
(use-package server
:commands server-start-maybe
:init
(progn
(add-hook 'after-init-hook
'server-start-maybe))
:config
(progn
(defun server-guess-name ()
(let ((workspace-prefix (workspace-prefix)))
(and
workspace-prefix
(equal server-name "server")
(setq server-name workspace-prefix))))
(server-guess-name)
(defun server-start-maybe ()
(and (not (server-running-p))
(server-start nil t)))))
;;;; auth
(use-package auth-source
:defer
:init
(progn
(setq ;; auth.el
auth-sources '("~/.authinfo.gpg"))))
(use-package sh-script
:defer
:init
(progn
(setq ;; sh-mode.el
sh-basic-offset 2
sh-indentation 2)))
;;;; apropos
(setq ;; apropos.el
apropos-do-all t)
;;;; files.el
(setq ;; files.el
confirm-kill-emacs 'yes-or-no-p)
;;;; font locking
;; (setq font-lock-global-modes '(not web-mode))
(unless noninteractive
(setq font-lock-maximum-decoration t)
;; (global-font-lock-mode t)
)
;;;; Be silent about successful auto saving
(defadvice do-auto-save (around do-auto-save-silent activate)
(ad-set-arg 0 t)
ad-do-it)
;;;; jit-lock
(setq
jit-lock-stealth-time nil
jit-lock-stealth-nice 0.03
jit-lock-stealth-load 200
jit-lock-stealth-verbose nil
jit-lock-chunk-size 500
;; jit-lock-defer-time 0.05
)
;;;; ansi-color
(setq
ansi-color-for-comint-mode t)
;;;; mule / conding.c
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(set-language-environment "UTF-8")
(define-coding-system-alias 'UTF-8 'utf-8)
(defconst my-use-semantic-instead-of-which-func
(and
(boundp 'emacs-version)
(string< "24.4" emacs-version)))
(use-package semantic
:commands (my-semantic-setup)
:init
(progn
(setq
semantic-default-submodes nil
semanticdb-default-save-directory (expand-file-name
"semanticdb" user-data-directory))
(when my-use-semantic-instead-of-which-func
(hook-into-modes 'my-semantic-setup '(python-mode-hook malabar-mode))))
:config
(progn
(defun my-semantic-setup ()
(semantic-mode)
(semantic-idle-scheduler-mode)
;; (semantic-decoration-mode)
(semantic-idle-breadcrumbs-mode)
)))
;;;; bookmark
(setq
bookmark-default-file (expand-file-name
"bookmarks" user-data-directory))
;;;; cedet
(setq
srecode-map-save-file (expand-file-name
"srecode-map.el" user-data-directory))
;;;; message (for gmail)
;; set up for gmail
(setq
message-send-mail-function 'smtpmail-send-it
smtpmail-stream-type 'starttls
smtpmail-default-smtp-server "smtp.gmail.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587)
;;;; minibuffer
(when (boundp 'completion-styles)
(add-to-list ;; add initials to complete list
'completion-styles 'initials t))
;;;; tooltip
(setq
tooltip-delay 0.8
;;tooltip-hide-delay 10
;;tooltip-recent-seconds 1
x-gtk-use-system-tooltips nil)
(use-package vc
:defer
:init
(progn
(setq vc-follow-symlinks t)
(if noninteractive
;;Disable all vcs back ends (Emacs starts faster)
(setq vc-handled-backends ())
(setq vc-handled-backends '(Git Hg)))
(use-package vc-annotate
:defer
:init
(progn
(defun my-vc-annotate-hook ()
(unless
(memq 'vc-annotate-annotation buffer-invisibility-spec)
(vc-annotate-toggle-annotation-visibility)))
(add-hook 'vc-annotate-mode-hook 'my-vc-annotate-hook))
:config
(progn
(defun vc-annotate-get-time-set-line-props ()
(let ((bol (point))
(date (vc-call-backend vc-annotate-backend 'annotate-time))
(inhibit-read-only t))
(assert (>= (point) bol))
(put-text-property bol (point) 'invisible 'vc-annotate-annotation)
(when (string-equal "Git" vc-annotate-backend)
(save-excursion
(goto-char bol)
(search-forward "(")
(let ((p1 (point)))
(re-search-forward " [0-9]")
(remove-text-properties p1 (1- (point)) '(invisible nil))
)))
date))))
))
(defun current-buffer-remote-p ()
(--any? (and it (file-remote-p it))
(list
(buffer-file-name)
list-buffers-directory
default-directory))
;; (and (fboundp 'tramp-tramp-file-p) (-any? 'tramp-tramp-file-p
;; (list
;; (buffer-file-name)
;; list-buffers-directory
;; default-directory)))
)
(use-package tramp
:defer
:init
(progn
(setq vc-ignore-dir-regexp
(format "\\(%s\\)\\|\\(%s\\)"
vc-ignore-dir-regexp
tramp-file-name-regexp))))
;;;; simple
(setq
column-number-mode t
kill-whole-line nil
shift-select-mode nil
eval-expression-print-level nil
idle-update-delay 1)
(and (fboundp 'x-cut-buffer-or-selection-value)
(eq system-type 'gnu/linux)
(setq interprogram-paste-function
'x-cut-buffer-or-selection-value))
;;;; browse-url
(when (eq 'gnu/linux system-type)
(setq
browse-url-browser-function 'browse-url-generic
browse-url-generic-program "sensible-browser"))
;;;; url
(setq
url-configuration-directory (expand-file-name
"url/" user-data-directory))
;;;; man
(setq
Man-notify-method 'pushy)
;;;; paragraphs
(setq
sentence-end-double-space nil)
(use-package subword
:defer t
:diminish ""
:init
(progn
(unless noninteractive
(global-subword-mode))))
(use-package compile
:defer
:config
(progn
(add-to-list 'compilation-error-regexp-alist-alist
'(my-go . ("^\t+\\([^()\t\n]+\\):\\([0-9]+\\):? .*$" 1 2)) t)
(setq compilation-ask-about-save nil
compilation-error-regexp-alist
'(
my-go
absoft
;; ada
aix
ant
bash
borland
python-tracebacks-and-caml
comma
cucumber
msft
edg-1
edg-2
epc
ftnchek
iar
ibm
irix
java
;; jikes-file
;; maven
;; jikes-line
gcc-include
ruby-Test::Unit
gnu
lcc
makepp
mips-1
mips-2
msft
omake
oracle
perl
php
rxp
;; sparc-pascal-file
;; sparc-pascal-line
;; sparc-pascal-example
sun
;; sun-ada
;; watcom
4bsd
gcov-file
gcov-header
gcov-nomark
gcov-called-line
gcov-never-called
;; perl--Pod::Checker
;; perl--Test
;; perl--Test2
;; perl--Test::Harness
weblint
)
)
(defun my-compilation-mode-hook ()
;; (jit-lock-defer-fontification)
(setq truncate-lines t)
(setq-local truncate-partial-width-windows nil))
(add-hook 'compilation-mode-hook 'my-compilation-mode-hook)
(add-hook 'compilation-minor-mode-hook 'my-compilation-mode-hook)
(defun my-colorize-compilation-buffer ()
(when (eq major-mode 'compilation-mode)
(use-package ansi-color)
(ansi-color-apply-on-region compilation-filter-start (point-max))))
(add-hook 'compilation-filter-hook 'my-colorize-compilation-buffer)))
;;;; eshell
(setq ;; eshell
eshell-directory-name (expand-file-name user-data-directory))
;;;; whitespace-mode
(setq-default
whitespace-line-column nil)
(bind-key "M-o m w" 'whitespace-mode)
;;;; window
(setq
switch-to-buffer-preserve-window-point t)
;;;; tracking
(setq ;; tracking
tracking-most-recent-first t)
;;; functions: Main Key bindings
;; This is very special because what I have done to my caps lock key.
(define-key special-event-map (kbd "<key-17>") 'ignore)
(define-key special-event-map (kbd "<M-key-17>") 'ignore)
;; (unbind-key "C-x C-l") ;; downcase region
;; (unbind-key "C-x C-u") ;; upcase region
;; (unbind-key "M-l") ;; downcase word
;; (unbind-key "M-u") ;; upcase word
;; (unbind-key "M-c") ;; capitalize word
(unbind-key "<mouse-3>")
;; make home/end behave the same as elsewhere on 'darwin
(bind-key "<home>" 'beginning-of-line)
(bind-key "<end>" 'end-of-line)
(bind-key "C-h B" 'describe-personal-keybindings)
(bind-key "C-h I" 'info)
(bind-key "C-h s" (lambda nil (interactive) (switch-to-buffer "*scratch*")))
(bind-key "C-?" 'undo)
(bind-key "C-_" 'redo)
(bind-key* "C-." 'undo) ;; NOTE this does not work in terminals
(bind-key* "C-," 'redo) ;; NOTE this does not work in terminals
(bind-key "<f5>" (lambda nil (interactive) (jump-to-register ?5)))
(bind-key "<f6>" (lambda nil (interactive) (jump-to-register ?6)))
(bind-key "<f7>" (lambda nil (interactive) (jump-to-register ?7)))
(bind-key "<f8>" (lambda nil (interactive) (jump-to-register ?8)))
(bind-key "C-<f5>" (lambda nil (interactive) (window-configuration-to-register ?5)))
(bind-key "C-<f6>" (lambda nil (interactive) (window-configuration-to-register ?6)))
(bind-key "C-<f7>" (lambda nil (interactive) (window-configuration-to-register ?7)))
(bind-key "C-<f8>" (lambda nil (interactive) (window-configuration-to-register ?8)))
(bind-key "S-<f5>" (lambda nil (interactive) (window-configuration-to-register ?5)))
(bind-key "S-<f6>" (lambda nil (interactive) (window-configuration-to-register ?6)))
(bind-key "S-<f7>" (lambda nil (interactive) (window-configuration-to-register ?7)))
(bind-key "S-<f8>" (lambda nil (interactive) (window-configuration-to-register ?8)))
;; (bind-key "<f9>" 'previous-buffer)
;; (bind-key "<f10>" 'next-buffer)
;; (bind-key "<f11>" 'switch-to-buffer)
(bind-key "<f12>" 'ibuffer)
;; (bind-key "<f5>" 'ibuffer)
(bind-key "C-H-n" 'forward-paragraph)
(bind-key "C-H-p" 'backward-paragraph)
(defun my-next-error (&optional arg reset)
""
(interactive)
(next-error arg reset)
(recenter)
)
(defun my-previous-error (&optional n)
""
(interactive)
(my-next-error (- (or n 1))))
(bind-key "M-H-n" 'my-next-error)
(bind-key "M-H-p" 'my-previous-error)
(bind-key "C-s-n" 'forward-paragraph)
(bind-key "C-s-p" 'backward-paragraph)
(bind-key "M-s-n" 'my-next-error)
(bind-key "M-s-p" 'my-previous-error)
;; (bind-key "S-C-<left>" 'shrink-window-horizontally)
;; (bind-key "S-C-<right>" 'enlarge-window-horizontally)
;; (bind-key "S-C-<down>" 'shrink-window)
;; (bind-key "S-C-<up>" 'enlarge-window)
(unbind-key "C-<prior>")
(unbind-key "C-<next>")
(bind-key "<M-prior>" 'previous-error)
(bind-key "<M-next>" 'next-error)
;; lisp-mode TODO: maybe move?
;;(define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
(bind-key "M-o l" 'toggle-truncate-lines)
;; (bind-key "C-c l" "lambda" lisp-mode-shared-map)
(bind-key "RET" 'reindent-then-newline-and-indent lisp-mode-shared-map)
(bind-key "C-\\" 'lisp-complete-symbol lisp-mode-shared-map)
(bind-key "C-c v" 'eval-buffer lisp-mode-shared-map)
(bind-key "M-o !" 'my-emacs-cleanup)
(bind-key* "M-j" 'my-join-line)
(bind-key "C-a" 'beginning-of-line-or-indentation)
(bind-key "H-n" 'my-scroll-other-window-up)
(bind-key "H-p" 'my-scroll-other-window-down)
(bind-key "C-x 4 n" 'clone-buffer-and-narrow-to-function)
(bind-key "C-x o" 'save-some-buffers-other-window)
(bind-key "C-x C-o" 'save-some-buffers-other-frame)
;; NOTE while being handy using smartrep with other-*
;; functions is a bit slow for some reason.
;;
;; (smartrep-define-key
;; global-map
;; "C-x"
;; '(("o" . save-some-buffers-other-window)
;; ("C-o" . save-some-buffers-other-frame)))
(global-set-key [remap goto-line] 'goto-line-with-feedback)
(bind-key "C-x f f" 'find-file)
(bind-key "C-x b b" 'switch-to-buffer)
(bind-key "C-x C-b" 'switch-to-buffer)
(bind-key "C-x b ." 'ibuffer)
(bind-key "C-x b C-<SPC>" 'previous-buffer)
(bind-key "C-x b C-n" 'next-buffer)
(bind-key "C-s" 'isearch-forward-regexp)
(bind-key "C-r" 'isearch-backward-regexp)
(bind-key "C-M-s" 'isearch-forward)
(bind-key "C-M-r" 'isearch-backward)
(global-set-key (kbd "C-x C-1") 'delete-other-windows)
(global-set-key (kbd "C-x C-2") 'split-window-below)
(global-set-key (kbd "C-x C-3") 'split-window-right)
(global-set-key (kbd "C-x C-0") 'delete-window)
(unbind-key "M-t")
(bind-keys
;; :map undo-tree-visualizer-mode-map
:prefix-map my-transpose-map
:prefix "M-t"
("c" . transpose-chars)
("w" . transpose-words)
("t" . transpose-words)
("M-t" . transpose-words)
("l" . transpose-lines)
("e" . transpose-sexps)
("s" . transpose-sentences)
("p" . transpose-paragraphs))
;;; functions: buffers
;;;; bufferswitch
(defvar my-bs-always-show-regexps
(list (regexp-opt (list "*scratch*" "*info*"))
"*magit:.+" "*Man" "*Org Agenda.+")
"*Buffer regexps to always show when buffer switching.")
(defvar my-bs-never-show-regexps '("^\\s-" "^\\*" "TAGS$" "type-break")
"*Buffer regexps to never show when buffer switching.")
(defvar my-ido-ignore-dired-buffers t
"*If non-nil, buffer switching should ignore dired buffers.")
(defun my-bs-str-in-regexp-list (str regexp-list)
"Return non-nil if str matches anything in regexp-list."
(let ((case-fold-search nil))
(catch 'done
(dolist (regexp regexp-list)
(when (string-match regexp str)
(throw 'done t))))))
(defun my-bs-ignore-buffer (name)
"Return non-nil if the named buffer should be ignored."
(or
(and (not (my-bs-str-in-regexp-list name my-bs-always-show-regexps))
(my-bs-str-in-regexp-list name my-bs-never-show-regexps))
(and my-ido-ignore-dired-buffers
(with-current-buffer name
(and (equal major-mode 'dired-mode)
(not (string= name "*Find*")))))
;;Test to see if the window is visible on an existing visible frame.
(memq name
(mapcar
(lambda (x)
(buffer-name
(window-buffer
(frame-selected-window x))))
(visible-frame-list)))))
;;;; get-buffers-matching-mode
(defun get-buffers-matching-mode (mode)
"Returns a list of buffers where their major-mode is equal to MODE."
(let ((buffer-mode-matches '()))
(dolist (buf (buffer-list))
(with-current-buffer buf
(if (eq mode major-mode)
(add-to-list 'buffer-mode-matches buf))))
buffer-mode-matches))
;;;; kill buffers based on mode
(defun kill-buffers (mode)
"Kill buffers."
(save-excursion
(let((count 0))
(dolist(buffer (buffer-list))
(set-buffer buffer)
(when (equal major-mode mode)
(setq count (1+ count))
(kill-buffer buffer)))
(message "Killed %i buffer(s)." count ))))
(defun kill-all-elisp-buffers ()
"Kill all elisp buffers."
(interactive)
(kill-buffers 'emacs-lisp-mode))
(defun kill-all-org-buffers ()
"Kill all org buffers."
(interactive)
(kill-buffers 'org-mode))
(defun my-emacs-cleanup ()
"Kill some buffers."
(interactive)
(kill-buffers 'emacs-lisp-mode)
(when (fboundp 'org-save-all-org-buffers)
(org-save-all-org-buffers))
(kill-buffers 'org-mode)
(kill-buffers 'dired-mode))
;;;; kill this buffer if not modified
(defun kill-this-buffer-if-not-modified ()
(interactive)
;; taken from menu-bar.el
(if (menu-bar-non-minibuffer-window-p)
(kill-buffer-if-not-modified (current-buffer))
(abort-recursive-edit)))
;;;; switch to minibuffer
(defun switch-to-minibuffer ()
"Switch to minibuffer window."
(interactive)
(if (active-minibuffer-window)
(select-window (active-minibuffer-window))
(error "Minibuffer is not active")))
;; (bind-key "C-c o" 'switch-to-minibuffer)
;;;; stop-using-minibuffer
(defun stop-using-minibuffer ()
"kill the minibuffer"
(when (and (>= (recursion-depth) 1) (active-minibuffer-window))
(abort-recursive-edit)))
;; NOTE this is slightly annoying
;; (add-hook 'mouse-leave-buffer-hook 'stop-using-minibuffer)
;;;; recursive-minibuffer-minor-mode
(define-minor-mode recursive-minibuffer-mode
"Minor mode to enable recursive minibuffer"
:init-value nil
:global t
:group 'minibuffer
(if recursive-minibuffer-mode
(progn
(setq enable-recursive-minibuffers t)
(minibuffer-depth-indicate-mode))
(setq enable-recursive-minibuffers nil)))
;; (recursive-minibuffer-mode)
;;; functions: files / directories
;;;; dired jump commands
(defun dired-project-root ()
"Open dired buffer at the project root."
(interactive)
(if (project-root-function)
(dired (project-root-function))
(message "No active project for this buffer.")))
(bind-key "C-x d e" 'dired-project-root)
(defun dired-23c ()
"dired-23c"
(interactive)
(dired "~/src/gitlab.23c.se/"))
(bind-key "C-x d 2" 'dired-23c)
(defun dired-src ()
"dired-src"
(interactive)
(dired "~/src/"))
(bind-key "C-x d r" 'dired-src)
(defun dired-repos ()
"dired-repos"
(interactive)
(dired-src))
(defun dired-downloads ()
"dired-downloads"
(interactive)
(dired "~/Downloads/"))
(defun dired-notes ()
"dired-notes"
(interactive)
(dired "~/notes/"))
(bind-key "C-x d n" 'dired-notes)
(defun dired-sitepackages ()
"Jump to sitepackages directory."
(interactive)
(let* ((program (concat
"python -c 'import distutils;"
"print(distutils.sysconfig.get_python_lib())';"))
(output (shell-command-to-string program))
(fun (first (split-string output)))
(directory (car (last (split-string output)))))
(when directory
(dired directory))))
(bind-key "C-x d s" 'dired-sitepackages)
(defun dired-virtualenv ()
"Open a dired buffer at to current virtualenv"
(interactive)
(let
((virtual-env (getenv "VIRTUAL_ENV")))
(when (not (equal virtual-env 'nil))
(dired virtual-env))))
;;;; file jump commands
(defun find-custom-set-variables ()
"Opens emacs init"
(interactive)
(find-file
(expand-file-name
"custom-set-variables.el" user-data-directory)))
(defun find-init ()
"Opens emacs init"
(interactive)
(find-file
(expand-file-name
"init.el" user-emacs-directory)))
(defun find-bash-history ()
"Open bash history file"
(interactive)
(find-file "~/.bash_history")
(read-only-mode 1)
(goto-char (point-max))
(auto-revert-tail-mode 1))
(defun find-syslog ()
"Open syslog"
(interactive)
(find-file "/var/log/syslog")
(read-only-mode 1)
(goto-char (point-max))
(auto-revert-tail-mode 1))
(defun find-notes ()
"find file in notes, FAST."
(interactive)
(let* ((default-directory user-notes-directory)
(files (->> (-concat (f-entries "agenda/" nil t)
(f-entries "org/" nil t)
(f-entries "library/" nil t)
(directory-files "sheet/" t))
(--map (s-chop-prefix (s-concat default-directory "/") it))
(projectile-sort-by-recentf-first)
(projectile-sort-by-recently-active-first)
(mapcar #'(lambda (x)
(--map (if (s-suffix? it x) x )
'(".md" ".markdown" ".s" ".org" ".txt" ".plu" ".org.gpg"))))
(-flatten)
(--filter (not (s-matches? "/reveal\.js/" it ))))))
(if files
(find-file (ido-completing-read "" files))
(message "Err0#wr"))))
(bind-key "C-x f n" 'find-notes)
(bind-key "C-h n" 'find-notes)
;;;; sudo-edit
(defun sudo-edit-current-file ()
(interactive)
(let ((my-file-name) ; fill this with the file to open
(position)) ; if the file is already open save position
(if (equal major-mode 'dired-mode) ; test if we are in dired-mode
(progn
(setq my-file-name (dired-get-file-for-visit))
(find-alternate-file (prepare-tramp-sudo-string my-file-name)))
(setq my-file-name (buffer-file-name); hopefully anything else is an already opened file
position (point))
(find-alternate-file (prepare-tramp-sudo-string my-file-name))
(goto-char position))))
(defun prepare-tramp-sudo-string (tempfile)
(if (file-remote-p tempfile)
(let ((vec (tramp-dissect-file-name tempfile)))
(tramp-make-tramp-file-name
"sudo"
(tramp-file-name-user nil)
(tramp-file-name-host vec)
(tramp-file-name-localname vec)
(format "ssh:%s@%s|"
(tramp-file-name-user vec)
(tramp-file-name-host vec))))
(concat "/sudo:root@localhost:" tempfile)))
;;;; buffer saving
(defun silent-save-some-buffers ()
"Save buffers..."
(save-window-excursion
(--each (buffer-list)
(and
(buffer-live-p it)
(buffer-modified-p it)
(not (eq major-mode 'messages-buffer-mode))
(not (buffer-base-buffer it))
(buffer-file-name it)
(with-current-buffer it
(save-buffer))))))
(defun save-some-buffers-other-frame ()
"Save-some-buffers, then other frame."
(interactive)
(call-interactively 'other-frame)
(nav-flash-show)
(silent-save-some-buffers))
(defun save-some-buffers-other-window ()
"Save-some-buffers, then other window."
(interactive)
(call-interactively 'other-window)
(nav-flash-show)
(silent-save-some-buffers))
(add-hook 'focus-out-hook 'silent-save-some-buffers)
;;;; touch-file
(defun touch-file ()
"updates mtime on the file for the current buffer"
(interactive)
(shell-command (concat "touch " (shell-quote-argument (buffer-file-name))))
(clear-visited-file-modtime))
;;;; shell command after save
(defvar shell-command-after-save-cmd nil
"This string will be executed as a shell command after saving
the buffer.")
(defun shell-command-after-save-run ()
(unless (s-blank? shell-command-after-save-cmd)
(save-window-excursion
(async-shell-command shell-command-after-save-cmd))))
(add-hook 'after-save-hook 'shell-command-after-save-run)
(defun shell-command-after-save (cmd)
(interactive
(list
(read-string "After save shell command:" shell-command-after-save-cmd)))
(setq-local shell-command-after-save-cmd cmd))
;;;; make-script-executable
(defun my-make-script-executable ()
"If file starts with a shebang, make `buffer-file-name' executable"
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(when (and (looking-at "^#!")
(not (file-executable-p buffer-file-name)))
(set-file-modes buffer-file-name
(logior (file-modes buffer-file-name) #o100))
(message (concat "Made " buffer-file-name " executable"))))))
(when (not noninteractive)
(add-hook 'after-save-hook 'my-make-script-executable))
;;; functions: calling external commands
(defun pip-freeze ()
"Run pip freeze"
(interactive)
(shell-command "pip freeze" "*pip-freeze*")
(with-current-buffer "*pip-freeze*"
(read-only-mode 1)))
(defun image-identify ()
"Run identify on current picture mode bufffer."
(interactive)
(shell-command
(concat "identify -verbose " (buffer-file-name)) "*identify*")
(with-current-buffer "*identify*"
(read-only-mode 1)))
(defun docker-term ()
"Create a docker terminal"
(interactive)
(let ((multi-term-program "dockershell"))
(multi-term)))
;;; functions: faces, themes, fonts, looks
;;;; adding line-prefix
(defun my-set-line-prefix ()
(interactive)
(setq line-prefix (propertize "" 'face 'vertical-border)))
;; (hook-into-modes 'my-set-line-prefix my-prog-mode-hooks)
;;;; setting fonts
(defun fonts-set (fixed-font variable-font &optional frame)
(when window-system
(condition-case nil
(progn
(set-face-attribute 'default frame :font fixed-font)
(set-face-attribute 'fixed-pitch frame :font fixed-font))
(error (message "Cannot set font '%s'" fixed-font)))
(condition-case nil
(set-face-attribute 'variable-pitch frame :font variable-font)
(error (message "Cannot set font '%s'" variable-font)))))
(defun fonts-set-terminus (arg)
"Set Terminus/PT Sans for selected frame."
(interactive "P")
(let ((size (if arg arg 10)))
(fonts-set (format "Terminus-%s" size)
(format "PT Sans-%s" size)
(selected-frame))))
(defun fonts-set-consolas (arg)
"Set Consolas/PT Sans for selected frame."
(interactive "P")
(let ((size (if arg arg 11)))
(fonts-set (format "Consolas-%s" size)
(format "PT Sans-%s" size)
(selected-frame))))
(defun fonts-set-pragmata (arg)
"Set PragmataPro/PT Sans for selected frame."
(interactive "P")
(let ((size (if arg arg 11)))
(fonts-set (format "Pragmata Pro-%s" size)
(format "PT Sans-%s" size)
(selected-frame))))
(defun fonts-set-anonymouspro (arg)
"Set Anonymous Pro/PT Sans for selected frame."
(interactive "P")
(let ((size (if arg arg 11)))
(fonts-set (format "Anonymous Pro-%s" size)
(format "PT Sans-%s" size)
(selected-frame))))
(defun fonts-set-consolas-large ()
"Set Consolas-15 / PT Sans-15 for selected frame."
(interactive)
(fonts-set-consolas 15))
(defun fonts-set-consolas-huge ()
"Set Consolas-20 / PT Sans-20 for selected frame."
(interactive)
(fonts-set-consolas 20))
(defun my-set-text-scale-smaller ()
(let ((amount -1))
(when (and (or
(not (boundp 'text-scale-mode-amount))
(not (equal text-scale-mode-amount amount))))
(text-scale-set amount))))
(hook-into-modes 'my-set-text-scale-smaller
'(ag-mode-hook
flycheck-error-list-mode-hook
go-traceback-mode-hook
ibuffer-mode-hook
magit-commit-mode-hook
python-django-mode-hook
magit-diff-mode-hook
magit-log-mode-hook
magit-status-mode-hook
vc-annotate-mode-hook
pt-search-mode-hook
grep-mode-hook
direx:direx-mode-hook
debugger-mode-hook
prodigy-view-mode-hook
docker-images-mode-hook
compilation-mode-hook
docker-containers-mode-hook))
(use-package helm
:defer
:commands (with-helm-buffer)
:config
(progn
(add-hook 'helm-after-initialize-hook
#'(lambda () (with-helm-buffer (my-set-text-scale-smaller))))))
(defadvice android-logcat (after smaller-font activate)
(with-current-buffer (get-buffer "*android-logcat*")
(my-set-text-scale-smaller)))
(defun my-set-text-scale-smaller-maybe ()
(let ((bn (buffer-name)))
(when
(and
(not my-text-scale-smaller-done)
(s-starts-with? "*[Django: " bn))
(setq-local my-set-text-scale-smaller-done t)
(my-set-text-scale-smaller))))
(defvar my-text-scale-smaller-done nil "smaller font scale")
;; (add-hook 'window-configuration-change-hook 'my-set-text-scale-smaller-maybe)
(add-hook 'comint-mode-hook 'my-set-text-scale-smaller-maybe)
;;;; toggle line spacing
(defun toggle-line-spacing ()
"Toggle line spacing between no extra space to extra half line height."
(interactive)
(if (eq line-spacing nil)
(setq-default line-spacing 0.2)
(setq-default line-spacing nil))
(redraw-display))
;;;; jit-lock-defer-fontification
(defun jit-lock-defer-fontification ()
(interactive)
(make-local-variable 'jit-lock-stealth-timer)
(make-local-variable 'jit-lock-stealth-repeat-timer)
(make-local-variable 'jit-lock-context-timer)
(make-local-variable 'jit-lock-defer-timer)
(setq-local jit-lock-defer-time 0.1)
(font-lock-mode -1)
(font-lock-mode 1))
;;;; scrolling
(hook-into-modes
#'(lambda () (setq-local scroll-margin 3))
my-prog-mode-hooks)
(defun set-browse-scrolling ()
(setq-local scroll-margin 40)
(setq-local scroll-step 60)
(setq-local scroll-down-aggressively nil)
(setq-local scroll-up-aggressively nil)
(setq-local scroll-conservatively 0))
;; (add-hook 'magit-mode-hook 'set-browse-scrolling)
;;;; hide mode line
(defvar hidden-mode-line-mode)
(make-variable-buffer-local 'hidden-mode-line-mode)
(define-minor-mode hidden-mode-line-mode
"Minor mode to hide the mode-line in the current buffer."
:init-value nil
:global n
:group 'editing-basics
(if hidden-mode-line-mode
(progn
(setq-local hide-mode-line mode-line-format)
(setq mode-line-format nil))
(setq mode-line-format hide-mode-line
hide-mode-line nil))
(force-mode-line-update)
;; Apparently force-mode-line-update is not always enough to
;; redisplay the mode-line
(redraw-display)
(when (and (called-interactively-p 'interactive)
hidden-mode-line-mode)
(run-with-idle-timer
0 nil 'message
(concat "Hidden Mode Line Mode enabled. "
"Use M-x hidden-mode-line-mode to make the mode-line appear."))))
(defun hide-fringes ()
"Hides the modeline for this buffer"
(interactive)
(setq mode-line-format nil)
(setq header-line-format nil))
;;;; rename-modeline
(defmacro rename-modeline (package-name mode new-name)
`(eval-after-load ,package-name
'(defadvice ,mode (after rename-modeline activate)
(setq mode-name ,new-name))))
;;;; randomize buffer background
(defun randomize-buffer-background ()
"changes current buffer's background to a random color (close to the defualt of this face)"
(interactive)
(progn
(setq face-symbol (gensym "face-"))
(make-face face-symbol)
(buffer-face-set face-symbol)
(setq rgb (mapcar
(function
(lambda (x) (let ((y (* 0.95 (+ x (/ (- (random 100) 50) 1200.0)))))
(if (> y 1) (- 2 y) (if (< y 0) (- y) y)))))
(color-name-to-rgb (face-background 'default))))
(setq new-color (color-rgb-to-hex (car rgb) (car (cdr rgb)) (car (cdr (cdr rgb)))))
(set-face-background face-symbol new-color) (message (concat "color changed to " new-color))))
(defun color-blend-name (color1 color2 alpha)
"Blends COLOR1 onto COLOR2 using alpha "
(apply 'color-rgb-to-hex
(-zip-with '(lambda (it other)
(+ (* alpha it) (* other (- 1 alpha))))
(color-name-to-rgb color1)
(color-name-to-rgb color2))))
(defun wash-out-color-name (color &optional degree)
"Return a colour string specifying a washed-out version of COLOUR."
(color-blend-name color
(face-attribute 'default :foreground)
(or degree 0.8)))
(defun wash-out-face (face &optional degree base-color)
"Make the foreground colour of FACE appear a bit more pale."
(let* ((prop (if base-color :background :foreground))
(color (face-attribute face prop)))
(unless (eq color 'unspecified)
(set-face-attribute face nil
prop (wash-out-color-name color degree)))))
(defun find-faces (regexp)
"Return a list of all faces whose names match REGEXP."
(delq nil
(mapcar (lambda (face)
(and (string-match regexp
(symbol-name face))
face))
(face-list))))
(defun wash-out-fontlock-faces (degree)
(--each (face-list)
(let ((name (symbol-name it)))
(cond
((s-match "^font-lock-comment" name) t)
((s-match "^isearch" name)
(wash-out-face it (/ degree 4) t))
((s-match "^ahs-\\\|^sp-show-pair-.*match\\\|^font-lock-warning-face\\\|^anzu" name)
(wash-out-face it (/ degree 4)))
((s-match "^font-lock\\\|^org-\\\|^web-mode" name)
(wash-out-face it degree))))))
(defun wash-out-faces ()
(interactive)
(wash-out-fontlock-faces 0.9))
;;;;; cursor-style
(defun cursor-style-update-action ()
(when (bound-and-true-p cua-normal-cursor-color)
(let* ((current-cursor-color (cdr (assq 'cursor-color (frame-parameters))))
(cursor-style (cond
((bound-and-true-p region-bindings-mode) (list "#d33682" '(bar . 8) t))
((bound-and-true-p god-local-mode) (list "#268bd2" 'box nil))
((bound-and-true-p buffer-read-only) (list "#859900" 'box nil))
(t (list cua-normal-cursor-color my-normal-cursor-type t)))))
(unless (equal (nth 0 cursor-style) current-cursor-color)
(set-cursor-color (nth 0 cursor-style)))
(unless (equal (nth 1 cursor-style) cursor-type)
(setq cursor-type (nth 1 cursor-style)))
(unless (equal (nth 2 cursor-style) blink-cursor-mode)
(blink-cursor-mode (or (nth 2 cursor-style) -1))))))
(defvar cursor-style-timer nil)
(defun cursor-style-update ()
(when cursor-style-timer
(cancel-timer cursor-style-timer))
(setq cursor-style-timer
(run-with-idle-timer 0.2 nil 'cursor-style-update-action)))
(hook-into-modes 'cursor-style-update
'(activate-mark-hook
deactivate-mark-hook
region-bindings-mode-hook
window-configuration-change-hook
minibuffer-setup-hook
minibuffer-exit-hook
god-mode-enabled-hook
god-mode-disabled-hook
god-local-mode-hook
read-only-mode-hook
after-change-major-mode-hook
focus-in-hook
focus-out-hook
))
(defadvice hardhat-local-hook (after cursor-style-update activate)
(cursor-style-update))
;;; functions: windows / frames
;;;; windows
;;;;; dedicated-mode
(defvar dedicated-mode nil
"Mode variable for dedicated minor mode.")
(make-variable-buffer-local 'dedicated-mode)
(defun dedicated-mode (&optional arg)
"Dedicated minor mode."
(interactive "P")
(setq dedicated-mode (not dedicated-mode))
(set-window-dedicated-p (selected-window) dedicated-mode)
(if (not (assq 'dedicated-mode minor-mode-alist))
(setq minor-mode-alist
(cons '(dedicated-mode " D")
minor-mode-alist))))
(bind-key "M-o m d" 'dedicated-mode)
;;;;; select next/prev window
(defun select-next-window ()
"Switch to the next window"
(interactive)
(other-window 1))
(defun select-previous-window ()
"Switch to the previous window"
(interactive)
(other-window -1))
;;;;; swap with master
(defun win/master-window ()
"Get the master window, for now equal to the largest window."
(get-largest-window))
;; ?? FIXME also copy point, buffer start pos, etc.
(defun win/swap-with-master (&optional other-window)
"Swap buffers between other window."
(interactive)
(if (> 1 (length (window-list)))
(message "Only one window, nothing to change.")
(let* ((master-win (win/master-window))
(selected-buffer (window-buffer (selected-window))))
(set-window-buffer (selected-window) (window-buffer master-win))
(set-window-buffer master-win selected-buffer)
(select-window master-win))))
(defalias 'w-swap-master 'win/swap-with-master)
;;;; frames
;;;;; creating frames
(defun new-floating-frame ()
"Creates a new floating frame.
This is special to my xmonad configuration which floats windows named floating"
(interactive)
(make-frame '((name . "floating")
(title . "emacs"))))
(defun make-frame-minimal ()
"Some kind of minimal frame, for logs etc"
(interactive)
(let ((frame (make-frame '((name . "minimal-frame")
(minibuffer . nil))))
(size 10))
(select-frame frame)
(fonts-set (format "Anonymous Pro-%s" size)
(format "PT Sans-%s" size)
frame)
(with-selected-frame frame
(hide-fringes)
(hidden-mode-line-mode 1))))
(defun make-frame-no-minibuffer ()
"Some kind of minimal frame, for logs etc"
(interactive)
(let ((frame (make-frame '((name . "minimal-frame")
(minibuffer . nil)))))
(select-frame frame)
(my-set-fonts)))
(bind-key "C-x 5 3" 'make-frame-no-minibuffer)
(defun new-floating-center-frame ()
"Creates a new floating frame.
This is special to my xmonad configuration which floats windows
named floating-center"
(interactive)
(make-frame '((name . "floating-center")
(title . "emacs"))))
(defun new-floating-center-large-frame ()
"Creates a new floating frame.
This is special to my xmonad configuration which floats windows
named floating-center"
(interactive)
(make-frame '((name . "floating-center-large")
(title . "emacs"))))
(defun find-file-in-large-floating-frame (file)
"Find file in large center floating frame."
(interactive)
(when (file-exists-p file)
(let ((frame (new-floating-center-large-frame) ))
(select-frame frame)
(find-file file))))
;;;;; intelligent close frame
(defun intelligent-close ()
"quit a frame the same way no matter what kind of frame you are on.
This method, when bound to C-x C-c, allows you to close an emacs frame the
same way, whether it's the sole window you have open, or whether it's
a \"child\" frame of a \"parent\" frame. If you're like me, and use emacs in
a windowing environment, you probably have lots of frames open at any given
time. Well, it's a pain to remember to do Ctrl-x 5 0 to dispose of a child
frame, and to remember to do C-x C-x to close the main frame (and if you're
not careful, doing so will take all the child frames away with it). This
is my solution to that: an intelligent close-frame operation that works in
all cases (even in an emacs -nw session).
Stolen from http://www.dotemacs.de/dotfiles/BenjaminRutt.emacs.html."
(interactive)
(if (eq (car (visible-frame-list)) (selected-frame))
;;for parent/master frame...
(if (> (length (visible-frame-list)) 1)
;;close a parent with children present
(if (yes-or-no-p "Close window?")
(delete-frame (selected-frame)))
;;close a parent with no children present
(save-buffers-kill-emacs))
;;close a child frame
(if (yes-or-no-p "Close window?")
(delete-frame (selected-frame)))))
;;;;; x urgency hint
;; let emacs blink when something interesting happens.
;; in KDE this marks the active Emacs icon in the tray.
(defun x-urgency-hint (frame arg &optional source)
"Set the x-urgency hint for the frame to arg:
- If arg is nil, unset the urgency.
- If arg is any other value, set the urgency.
If you unset the urgency, you still have to visit the frame to
make the urgency setting disappear (at least in KDE)."
(let* ((wm-hints (append (x-window-property
"WM_HINTS" frame "WM_HINTS"
source nil t) nil))
(flags (car wm-hints)))
;; (message flags)
(setcar wm-hints
(if arg
(logior flags #x00000100)
(logand flags #x1ffffeff)))
(x-change-window-property "WM_HINTS" wm-hints frame "WM_HINTS" 32 t)))
(defun x-urgent (&optional arg)
"Mark the current emacs frame as requiring urgent attention.
With a prefix argument which does not equal a boolean value of
nil, remove the urgency flag (which might or might not change
display, depending on the window manager)."
(interactive "P")
(let (frame (car (car (cdr (current-frame-configuration)))))
(x-urgency-hint frame (not arg))))
(when window-system
;; (unbind-key "C-x C-c")
(bind-key "C-x C-c" 'intelligent-close)
(bind-key "s-w" 'intelligent-close)
)
;;; functions: editing/inserting/in buffer navigation
;;;; enable "regular" backspace behaviour in isearch
(defun isearch-delete-something ()
"Delete non-matching text or the last character."
(interactive)
(if (= 0 (length isearch-string))
(ding)
(setq isearch-string
(substring isearch-string
0
(or (isearch-fail-pos) (1- (length isearch-string)))))
(setq isearch-message
(mapconcat #'isearch-text-char-description isearch-string "")))
(if isearch-other-end (goto-char isearch-other-end))
(isearch-search)
(isearch-push-state)
(isearch-update))
(define-key isearch-mode-map (kbd "<backspace>")
#'isearch-delete-something)
;;;; duplicate line / region
(defun duplicate-line-or-region (arg)
"Duplicates the current line or region ARG times.
If there's no region, the current line will be duplicated. However, if
there's a region, all lines that region covers will be duplicated."
(interactive "p")
(let (beg end (n (abs arg)) (origin (point)))
(if (and mark-active (> (point) (mark)))
(exchange-point-and-mark))
(setq beg (line-beginning-position))
(if mark-active
(exchange-point-and-mark))
(setq end (line-end-position))
(let ((beg beg) (end end) (region (buffer-substring-no-properties beg end)))
(dotimes (i n)
(goto-char end)
(newline)
(insert region)
(setq end (point)))
(goto-char (+ origin (* (length region) n) n)))
(if (< arg 0)
(comment-region beg end))))
(defun duplicate-line-or-region-comment-original ()
"See `duplicate-line-or-region'"
(interactive)
(duplicate-line-or-region -1))
(bind-key "C-x y" 'duplicate-line-or-region)
(bind-key "C-x C-y" 'duplicate-line-or-region-comment-original)
(defun one-shot-keybinding (key command)
(set-temporary-overlay-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd key) command)
map) t))
(defun duplicate-region (&optional num start end)
"Duplicates the region bounded by START and END NUM times.
If no START and END is provided, the current region-beginning and
region-end is used."
(interactive "p")
(save-excursion
(let* ((start (or start (region-beginning)))
(end (or end (region-end)))
(region (buffer-substring start end)))
(goto-char end)
(dotimes (i num)
(insert region)))))
(bind-key "Y" 'duplicate-region region-bindings-mode-map)
;;;; open line above/below
(defun open-line-below ()
"Open a line below the line the point is at.
Then move to that line and indent accordning to mode"
(interactive)
(cond ((or (eq major-mode 'coffee-mode)
(eq major-mode 'feature-mode))
(let ((column
(save-excursion
(back-to-indentation)
(current-column))))
(move-end-of-line 1)
(newline)
(move-to-column column t)))
(t
(move-end-of-line 1)
(newline)
(indent-according-to-mode))))
(defun open-line-above ()
"Open a line above the line the point is at.
Then move to that line and indent accordning to mode"
(interactive)
(cond ((or (eq major-mode 'coffee-mode)
(eq major-mode 'feature-mode))
(let ((column
(save-excursion
(back-to-indentation)
(current-column))))
(move-beginning-of-line 1)
(newline)
(forward-line -1)
(move-to-column column t)))
(t
(move-beginning-of-line 1)
(newline)
(forward-line -1)
(indent-according-to-mode))))
(defun new-line-in-between ()
(interactive)
(newline)
(save-excursion
(newline)
(indent-for-tab-command))
(indent-for-tab-command))
;; (bind-key "C-c C-p" 'open-line-above)
;; (bind-key "C-c C-n" 'open-line-below)
;; (bind-key "C-c C-j" 'new-line-in-between)
(defun new-line-dwim ()
(interactive)
(let ((break-open-pair (or (and (looking-back "{" 1) (looking-at "}"))
(and (looking-back ">" 1) (looking-at "<"))
(and (looking-back "(" 1) (looking-at ")"))
(and (looking-back "\\[" 1) (looking-at "\\]")))))
(newline)
(when break-open-pair
(save-excursion
(newline)
(indent-for-tab-command)))
(indent-for-tab-command)))
(bind-key "<M-return>" 'new-line-dwim)
;;;; join line
(defun my-join-line ()
"Join lines"
(interactive)
(save-excursion
(join-line -1)))
;;;; join-region
(defun join-region (beg end)
"Apply join-line over region."
(interactive "r")
(if mark-active
(let ((beg (region-beginning))
(end (copy-marker (region-end))))
(goto-char beg)
(while (< (point) end)
(join-line 1)))))
;;;; character coding conversion
(defun has-revisit-file-with-coding-windows-1252 ()
"Re-opens currently visited file with the windows-1252 coding. (By: hassansrc at gmail dot com)
Example:
the currently opened file has french accents showing as codes such as:
french: t\342ches et activit\340s (\340 is shown as a unique char)
then execute this function: has-revisit-file-with-coding-windows-1252
consequence: the file is reopened with the windows-1252 coding with no other action on the part of the user.
Hopefully, the accents are now shown properly.
Otherwise, find another coding... "
(interactive)
(let ((coding-system-for-read 'windows-1252)
(coding-system-for-write 'windows-1252)
(coding-system-require-warning t)
(current-prefix-arg nil))
(find-alternate-file buffer-file-name)))
;;;; align
(defun align= (begin end)
"Align region to equal signs"
(interactive "r")
(align-regexp begin end "\\(\\s-*\\)[=|:]" 1 1))
;;;; insert date/time formatted strings
(defvar current-date-time-format "%Y-%m-%d %H:%M"
"Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")
(defvar current-date-time-format-long "%a %b %d %H:%M:%S %Z %Y"
"Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")
(defvar current-date-time-format-compact "%Y%m%d-%H%M%S-%Z"
"Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")
(defun insert-current-date-time ()
"insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
(interactive)
(insert (format-time-string current-date-time-format (current-time))))
(defun insert-current-date-time-long ()
"insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
(interactive)
(insert (format-time-string current-date-time-format-long (current-time))))
(defun insert-current-date-time-compact ()
"insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
(interactive)
(insert (format-time-string current-date-time-format-compact (current-time))))
(defun week-number (date)
(org-days-to-iso-week
(calendar-absolute-from-gregorian date)))
(defun insert-current-week-number ()
(interactive)
(insert (number-to-string (week-number (calendar-current-date)))))
;;;; CamelCase transform
(defun backward-hyphenated-or-underscore-word ()
(interactive)
(backward-word)
(while (looking-back "[-_]") (backward-word)))
(defun camelCase-previous-word ()
"Convert the previous word (including hyphens and underscores) to camelCase."
(interactive)
(let ((case-fold-search nil)
(bound (point)))
(save-excursion
(backward-hyphenated-or-underscore-word)
(while (re-search-forward "[\-_]\\([a-zA-Z]\\)" bound t)
(replace-match (upcase (match-string 1)) nil 'literal)))))
(defun unCamelCase-previous-word (&optional sep)
"If previous word is camelCased, convert it to a word separated by SEP.
Default separator is underscore."
(interactive)
(let ((case-fold-search nil)
(bound (point))
(sep (or sep "_")))
(save-excursion
(backward-hyphenated-or-underscore-word)
(while (re-search-forward "\\([a-z]\\)\\([A-Z]\\)" bound t)
(replace-match (concat (match-string 1) sep
(downcase (match-string 2))) nil 'literal)))))
;;;; eval-and-replace
(defun eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(condition-case nil
(prin1 (eval (read (current-kill 0)))
(current-buffer))
(error (message "Invalid expression")
(insert (current-kill 0)))))
;;;; insert lorem ipsum
(defun lorem (paragraphs)
"Inserts up to 5 paragraphs of lorem ipsum filler text."
(interactive "nParagraphs: ")
(let ((lorems '("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
"\n\nIn non elit turpis, quis accumsan tortor. Vestibulum enim mi, tincidunt eget fringilla a, euismod nec mi. Integer dictum diam sed ante posuere feugiat. Aenean convallis sapien tincidunt leo aliquam posuere. Mauris porta facilisis metus, non commodo mauris interdum sed. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce a diam nec augue tristique placerat eu at odio. Sed fermentum, nunc non condimentum accumsan, dolor nisl mollis quam, sed condimentum massa massa at nisi. Etiam quis ante neque. Mauris feugiat lacus nec lorem vulputate sagittis. Fusce congue ullamcorper nulla, in lacinia felis euismod eu. Integer arcu dolor, tempus eget scelerisque sit amet, fermentum at elit. Maecenas dignissim mollis sapien, nec elementum enim feugiat vel. Mauris lobortis sodales sem vitae venenatis. Aliquam a risus arcu. Aliquam bibendum pretium velit in tempor. Aliquam erat volutpat."
"\n\nSed ut nisi ante. Sed sollicitudin blandit tortor eu cursus. Praesent sem augue, cursus vitae sodales a, aliquam eget enim. Nullam velit nulla, ornare vitae vulputate sit amet, blandit ut nisl. Vivamus sodales blandit pretium. In faucibus risus nec purus dapibus laoreet. Aliquam erat volutpat. Phasellus a sem sit amet metus pharetra euismod. Nunc sit amet vehicula purus. Donec lorem metus, feugiat vel ultrices vel, sagittis nec odio. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In scelerisque, justo eu pretium ultricies, elit eros varius mauris, quis scelerisque lacus lacus sed metus. Phasellus hendrerit, quam in accumsan ullamcorper, magna enim vehicula sem, et vulputate massa dolor eu augue. Pellentesque sed nibh sit amet mi vulputate porttitor at ac tortor. Ut ac augue risus, tincidunt ornare sapien. Suspendisse gravida est lacinia urna interdum scelerisque ut non sem. Sed quis lectus lectus."
"\n\nNam et consectetur nisl. Pellentesque rhoncus velit a elit mollis cursus nec ut orci. Vestibulum a purus ligula. Cras blandit, felis et venenatis interdum, urna libero cursus sapien, at auctor sem purus eget quam. Suspendisse pretium sollicitudin leo, quis imperdiet sem faucibus vel. Vestibulum mollis imperdiet urna, pretium porttitor lorem posuere at. Integer aliquam, velit id luctus lobortis, odio ipsum convallis urna, sit amet eleifend lacus mi et leo. Phasellus quis ante in dolor tincidunt lobortis. Proin in massa purus, vitae dignissim elit. Curabitur non enim sit amet lectus volutpat tristique."
"\n\nPellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed vel neque a nibh tincidunt luctus id a eros. Curabitur leo odio, sodales id malesuada ac, commodo et augue. Aenean auctor justo a nulla lobortis ut tempor mauris mollis. Duis a purus consequat enim vestibulum pretium. Vestibulum diam urna, luctus at pulvinar sed, rhoncus id risus. Maecenas sit amet velit vitae libero viverra aliquet sit amet non mauris. Suspendisse potenti. Duis eu lectus sem. Maecenas aliquam erat vitae tortor congue ut imperdiet lacus consectetur. Praesent nisl ipsum, fermentum id venenatis eu, lobortis eu nunc. Fusce ut enim tellus, ac semper turpis. Proin in ante massa. Curabitur velit lacus, pharetra vel dapibus egestas, posuere quis dui. Morbi aliquet congue nisl, dictum fringilla velit dictum sed. Integer eu consequat nisl. Curabitur aliquam suscipit magna vel pharetra. Duis eget erat vel purus mattis dignissim. Donec mattis, nulla nec imperdiet scelerisque, leo elit tincidunt dui, eget ullamcorper tortor neque nec erat. Aliquam libero augue, suscipit vitae scelerisque vitae, rutrum vitae quam.")))
(loop for p from 0 to (- paragraphs 1)
do (insert (nth p lorems)))))
;;;; beginning of line or indentation
(defun beginning-of-line-or-indentation ()
"move to beginning of line, or indentation"
(interactive)
(if (bolp)
(back-to-indentation)
(beginning-of-line)))
;;;; delete trailing blank lines
(defun my-delete-trailing-blank-lines ()
"Deletes all blank lines at the end of the file, even the last one"
(interactive)
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(delete-blank-lines)
(let ((trailnewlines (abs (skip-chars-backward "\n\t"))))
(if (> trailnewlines 0)
(progn
(delete-char trailnewlines)))))))
;;;; collapse blank lines
(defun collapse-blank-lines (start end)
(interactive "r")
(replace-regexp "^\n\\{2,\\}" "\n" nil start end))
;;;; flush blank lines
(defun flush-blank-lines (start end)
(interactive "r")
(flush-lines "^\\s-*$" start end nil))
;;;; swap-string
(defun swap-string (rit lft)
"Swaps rit to lft."
(interactive "sChange this:
sTo this: ")
(save-excursion
(goto-char (region-beginning))
(while (search-forward-regexp (format "%s\\|%s"
(regexp-quote rit)
(regexp-quote lft)) (region-end) t)
(replace-match (if (equal rit (match-string 0)) lft rit) t nil))))
;;;; clean buffer
(defun cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer."
(interactive)
(save-excursion
(mark-whole-buffer)
(clean-up-buffer-or-region)))
(defun clean-up-buffer-or-region ()
"Untabifies, indents and deletes trailing whitespace from buffer or region."
(interactive)
(save-excursion
(unless (region-active-p)
(mark-whole-buffer))
(untabify (region-beginning) (region-end))
(indent-region (region-beginning) (region-end))
(save-restriction
(narrow-to-region (region-beginning) (region-end))
(delete-trailing-whitespace))))
;;;; cycle characters
;; TODO not quite ready
(defun cycle-characters--delete-and-extract-sexp ()
(let* ((beg (point))
(end (progn (paredit-forward)
(point)))
(contents (buffer-substring beg end)))
(delete-region beg end)
contents))
(defun cycle-brackets ()
"convert expression at (point) from (x) -> {x} -> [x] -> (x) recur"
(interactive)
(save-excursion
(while (and
(> (point) 1)
(not (eq (string-to-char "(") (char-after)))
(not (eq (string-to-char "{") (char-after)))
(not (eq (string-to-char "[") (char-after))))
(backward-char))
(cond
((eq (string-to-char "(") (char-after))
(insert "{" (substring (cycle-characters--delete-and-extract-sexp) 1 -1) "}"))
((eq (string-to-char "{") (char-after))
(insert "[" (substring [cycle-characters--delete-and-extract-sexp] 1 -1) "]"))
((eq (string-to-char "[") (char-after))
(insert "(" (substring (cycle-characters--delete-and-extract-sexp) 1 -1) ")"))
((equal 1 (point))
(message "beginning of file reached, this was probably a mistake.")))))
;;;; sort-words
(defun sort-words (reverse beg end)
"Sort words in region alphabetically, in REVERSE if negative.
Prefixed with negative \\[universal-argument], sorts in reverse.
The variable `sort-fold-case' determines whether alphabetic case
affects the sort order.
See `sort-regexp-fields'."
(interactive "*P\nr")
(sort-regexp-fields reverse "\\w+" "\\&" beg end))
;;;; sort-symbols
(defun sort-symbols (reverse beg end)
"Sort symbols in region alphabetically, in REVERSE if negative.
See `sort-words'."
(interactive "*P\nr")
(sort-regexp-fields reverse "\\(\\sw\\|\\s_\\)+" "\\&" beg end))
;;; functions: MISC
;;;; cycle ispell languages
;; Languages for spellinc cycling
(let ((langs '("svenska" "english")))
(setq lang-ring (make-ring (length langs)))
(dolist (elem langs) (ring-insert lang-ring elem)))
(defun cycle-ispell-languages ()
"Cycle spelling dictionaries from a list"
(interactive)
(let ((lang (ring-ref lang-ring -1)))
(ring-insert lang-ring lang)
(ispell-change-dictionary lang)
(when (and (boundp 'flyspell-mode)
(eq flyspell-mode t))
(flyspell-buffer))))
;;;; goto line with feedback
(defun goto-line-with-feedback ()
"Show line numbers temporarily, while prompting for the line number input"
(interactive)
(unwind-protect
(progn
(linum-mode 1)
(call-interactively 'goto-line))
(linum-mode -1)))
;;;; menu-bar-go
(defvar menu-bar-go-active nil)
(defun menu-bar-go-post ()
(remove-hook 'pre-command-hook 'menu-bar-go-post)
(when (and menu-bar-go-active (not menu-bar-mode))
(set-frame-parameter (selected-frame) 'menu-bar-lines 0)))
(defun menu-bar-go ()
"Open menu bar"
(interactive)
(if (or menu-bar-mode (not window-system))
(menu-bar-open)
(set-frame-parameter (selected-frame) 'menu-bar-lines 1)
;; (menu-bar-mode 1)
(run-with-idle-timer
0.2 nil (lambda ()
(menu-bar-open)
(setq menu-bar-go-active t)
(add-hook 'pre-command-hook 'menu-bar-go-post)))))
(bind-key "M-o M-m" 'menu-bar-go)
;;;; centering margins + easy-read-mode
(defun auto-window-margins ()
"Set window margins according to fill column."
(when (not (or
(windmove-find-other-window 'left)
(windmove-find-other-window 'right)
(window-minibuffer-p)))
(and (boundp 'org-indent-mode)
org-indent-mode
(org-indent-mode -1))
(and (boundp 'page-break-lines-mode)
page-break-lines-mode
(page-break-lines-mode -1))
(set-window-margins nil 0)
(let
((margin (max 0 (/ (- (window-body-width) fill-column) 2))))
(set-window-margins nil margin margin))))
(bind-key "M-o c" 'auto-window-margins)
(define-minor-mode auto-window-margins-mode
"..."
nil nil nil
:group 'easy-read
:global t
(if auto-window-margins-mode
(progn
(--map
(with-selected-window it
(auto-window-margins))
(window-list))
(add-hook 'window-configuration-change-hook 'auto-window-margins))
(remove-hook 'window-configuration-change-hook 'auto-window-margins)
(--map
(set-window-margins it 0)
(window-list))))
(define-minor-mode easy-read-mode
"..."
nil nil nil
:group 'easy-read
:global t
(if easy-read-mode
(progn
(delete-other-windows)
(defvar font-normal-height (face-attribute 'default :height))
(set-face-attribute 'default (selected-frame) :height 135)
(set-face-attribute 'fringe (selected-frame)
:background (frame-parameter nil 'background-color))
(and (boundp 'rainbow-delimiters-mode)
rainbow-delimiters-mode
(rainbow-delimiters-mode -1))
(and (boundp 'yascroll-bar-mode)
yascroll-bar-mode
(yascroll-bar-mode -1))
(auto-window-margins-mode 1)
;; (wash-out-fontlock-faces 0.4)
)
(auto-window-margins-mode -1)
(set-face-attribute 'default (selected-frame) :height font-normal-height)))
;;;; init magit status
(defun init-magit-status (path)
"Magit status, no other windows.
Used to launch magit status from command line."
(interactive)
(magit-status (f-full path))
(delete-other-windows)
(kill-buffer "*scratch*")
(kill-buffer "*Messages*"))
;;;; my notify
(defvar my-notify-method nil)
(defun my-notify-setup nil
(setq my-notify-method
(cond
((and
window-system
;; TODO maybe use dbus on osx later, i do not need it now.
(not (eq system-type 'darwin))
(require 'dbus nil t)
(dbus-ping :session "org.freedesktop.Notifications" 250))
'my-notify-dbus)
(t 'my-notify-message) )))
(defun my-notify-message (summary body)
(message "%s: %s" summary body))
(defun my-notify-dbus (summary body)
(dbus-call-method
:session "org.freedesktop.Notifications"
"/org/freedesktop/Notifications"
"org.freedesktop.Notifications" "Notify"
"shorter"
0
""
summary
body
'(:array)
'(:array :signature "{sv}")
:int32 -1))
(defun my-notify (summary body)
(unless my-notify-method (my-notify-setup))
(funcall my-notify-method summary body))
;;;; invert-shift-number-keys-mode
(define-minor-mode invert-shift-number-keys-mode
"..."
;; The initial value.
nil
;; The indicator for the mode line.
nil
;; The minor mode bindings.
nil
:group 'my
:global t
(if (not invert-shift-number-keys-mode)
(--each us-number-shift-keys
(define-key key-translation-map (kbd (car it) ) nil )
(define-key key-translation-map (kbd (cdr it) ) nil ))
(--each us-number-shift-keys
(define-key key-translation-map (kbd (car it)) (kbd (cdr it)))
(define-key key-translation-map (kbd (cdr it)) (kbd (car it))))
(bind-key "C-x !" 'delete-other-windows)
(bind-key "C-x @" 'split-window-below)
(bind-key "C-x #" 'split-window-right)
(bind-key "C-x $" 'ctl-x-4-prefix)
(bind-key "C-x %" 'ctl-x-5-prefix)))
(bind-key "M-o n" 'invert-shift-number-keys-mode)
(defvar us-number-shift-keys
'(("1" . "!")
("2" . "@")
("3" . "#")
("4" . "$")
("5" . "%")
("6" . "^")
("7" . "&")
("8" . "*")
("9" . "(")
("0" . ")")))
;;;; helm popup frame
(defvar popup-frame--frame nil)
(defun popup-frame--minibuffer-exit ()
(when (and
popup-frame--frame
(frame-live-p popup-frame--frame))
(delete-frame popup-frame--frame t)
(setq popup-frame--frame nil)))
(add-hook 'minibuffer-exit-hook
'popup-frame--minibuffer-exit )
(defun popup-frame (f)
(interactive)
(setq popup-frame--frame (make-frame
'((name . "floating-center-large")
(title . "emacs popup minibuffer"))))
(with-selected-frame popup-frame--frame
(call-interactively f)))
(defun popup-frame-helm-for-files ()
(interactive)
(popup-frame 'helm-for-files))
;; (bind-key "<menu>" 'popup-frame-helm-for-files)
;;;; flash caps lock
(defvar flash-scroll-lock-enabled t)
(defvar flash-scroll-lock-active nil)
(defvar flash-scroll-lock-initialized nil)
(defun flash-scroll-lock ()
(interactive)
(unless flash-scroll-lock-initialized
(unless (and
;; (eq window-system 'x)
(executable-find* "xset"))
(setq flash-scroll-lock-enabled nil))
(setq flash-scroll-lock-initialized t))
(when (and
(not flash-scroll-lock-active)
flash-scroll-lock-enabled)
(setq flash-scroll-lock-active t)
(deferred:$
(deferred:$
(deferred:process "xset" "led" "named" "Scroll Lock")
(deferred:nextc it
(lambda ()
(deferred:wait 300)))
(deferred:nextc it
(lambda ()
(deferred:process "xset" "-led" "named" "Scroll Lock")))
(deferred:nextc it
(lambda ()
(deferred:wait 200)))
(deferred:nextc it
(lambda ()
(setq flash-scroll-lock-active nil))))
(deferred:error it
(lambda (err)
(setq flash-scroll-lock-active nil)
(setq flash-scroll-lock-enabled nil))))))
(setq ring-bell-function #'ignore)
;;;; get-dwim-at-point
(defun get-dwim-at-point ()
"If there's an active selection, return that.
Otherwise, get the symbol at point, as a string."
(cond ((use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end)))
((symbol-at-point)
(substring-no-properties
(symbol-name (symbol-at-point))))))
;;; functions: ////uncategorized////
(defun create-temp-selective-display-keymap ()
(set-temporary-overlay-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "=") 'inc-selective-display)
(define-key map (kbd "+") 'inc-selective-display)
(define-key map (kbd "-") 'dec-selective-display)
(define-key map (kbd "0") 'clear-selective-display)
map))
(message "Type +/= to reveal more, - for less, 0 to reset. (%s)" selective-display))
(defun inc-selective-display (arg)
(interactive "P")
(if (numberp arg)
(set-selective-display arg)
(if (numberp selective-display)
(set-selective-display (+ 2 selective-display))
(set-selective-display 2)))
(create-temp-selective-display-keymap))
(defun dec-selective-display ()
(interactive)
(when (and (numberp selective-display)
(> selective-display 2))
(set-selective-display (- selective-display 2)))
(create-temp-selective-display-keymap))
(defun clear-selective-display ()
(interactive)
(when (numberp selective-display)
(set-selective-display nil)))
(global-set-key (kbd "C-x $") 'inc-selective-display)
(defun buffer-line-position ()
"Current position formatted as file-name:line-number"
(format "%s:%d" (buffer-file-name) (line-number-at-pos)))
(defun position-to-kill-ring ()
"Copy to the kill ring a string in the format \"file-name:line-number\"
for the current buffer's file name, and the line number at point."
(interactive)
(kill-new (buffer-line-position)))
(defun position-pdb-breakpoint-to-kill-ring ()
""
(interactive)
(kill-new (format "break %s" (buffer-line-position))))
(defun position-pdb-breakpoint-to-clipbard ()
""
(interactive)
(kill-new (format "break %s" (buffer-line-position))))
(defun buffer-file-name-to-clipboard ()
""
(interactive)
(simpleclip-set-contents buffer-file-name))
(defun my-scroll-other-window-down ()
"Scrolls other window down one line"
(interactive)
(scroll-other-window-down 1))
(defun my-scroll-other-window-up ()
"Scrolls other window up one line"
(interactive)
(scroll-other-window-down -1))
(defun clone-buffer-and-narrow-to-function ()
(interactive)
(require 'which-func)
(clone-indirect-buffer-other-window (which-function) 'pop-to-buffer)
(mark-defun)
(narrow-to-region (mark) (point))
(pop-mark))
(bind-key "C-x n f" 'clone-buffer-and-narrow-to-function)
(defun narrow-to-region-indirect (start end)
"Restrict editing in this buffer to the current region, indirectly."
(interactive "r")
(deactivate-mark)
(let ((buf (clone-indirect-buffer nil nil)))
(with-current-buffer buf
(narrow-to-region start end))
(switch-to-buffer buf)))
(bind-key "C-x n c" 'narrow-to-region-indirect)
(defun toggle-fold ()
"Toggle fold all lines larger than indentation on current line"
(interactive)
(let ((col 1))
(save-excursion
(back-to-indentation)
(setq col (+ 1 (current-column)))
(set-selective-display
(if selective-display nil (or col 1))))))
;; (bind-key* "C-M-f" 'toggle-fold)
(hook-into-modes #'(lambda () (setq-local fill-column 120))
my-html-like-mode-hooks)
;;; packages: Eearly important order dependent packages
;;;; ensure misc packages
(use-package pcache
:ensure t
:defer
:init
(progn
(setq
pcache-directory
(let ((dir (expand-file-name "pcache/" user-cache-directory)))
(make-directory dir t)
dir))
(eval-when-compile
(setq
pcache-directory
(let ((dir (expand-file-name "pcache/" user-cache-directory)))
(make-directory dir t)
dir)))))
(use-package projectile
:ensure t
:defer 1.4
:commands (projectile-mode
projectile-global-mode
projectile-project-p
projectile-sort-by-recentf-first
projectile-sort-by-recently-active-first)
:bind (("C-x f <SPC>" . projectile-find-file)
("C-x f P" . projectile-find-file-ignored)
("C-x d <SPC>" . projectile-find-dir)
("C-x d p" . projectile-switch-project)
("C-x b <SPC>" . projectile-switch-to-buffer)
("M-o A" . projectile-ag))
:diminish ""
:init
(progn
(setq projectile-project-root-files-child-of
'("~/\.virtualenvs/[^/]+/\\(local/\\)?lib/python[^/]*/site-packages/?$"
"~/\.opt/[^/]+/?$"
"~/\.virtualenvs/[^/]+/?$"
"/var/log/?$"))
(defun projectile-root-child-of (dir &optional list)
(projectile-locate-dominating-file
dir
(lambda (dir)
(--first
(if (and
(s-equals? (file-remote-p it) (file-remote-p dir))
(string-match-p (expand-file-name it) (expand-file-name dir)))
dir)
(or list projectile-project-root-files-child-of (list))))))
(setq
projectile-sort-order 'recently-active
projectile-completion-system 'ido
projectile-require-project-root t
projectile-switch-project-action 'projectile-dired
projectile-enable-caching nil
projectile-verbose nil
projectile-known-projects-file (expand-file-name
"projectile-bookmarks.eld"
user-data-directory)
projectile-cache-file (expand-file-name
"projectile.cache" user-cache-directory)
projectile-file-exists-local-cache-expire nil
projectile-file-exists-remote-cache-expire (* 15 60)
projectile-project-root-files-functions
'(projectile-root-bottom-up
projectile-root-top-down
projectile-root-top-down-recurring
projectile-root-child-of))
(bind-key "A" 'projectile-pt-file-pattern region-bindings-mode-map)
(defadvice projectile-mode (before maybe-use-cache activate)
(when
(--any? (and it (file-remote-p it))
(list
(buffer-file-name)
list-buffers-directory
default-directory))
(setq-local projectile-enable-caching t)))
(use-package helm-projectile
:ensure t
:commands (helm-projectile)
:bind ("C-x f p" . helm-projectile))
(use-package persp-projectile
:ensure t
:commands projectile-persp-switch-project)
(defun projectile-find-file-ignored ()
"Projectile find file without ignore."
(interactive)
(let ((projectile-git-command "git ls-files -zco"))
(call-interactively 'projectile-find-file))))
:config
(progn
(add-to-list 'projectile-globally-ignored-directories "vendor")
(projectile-global-mode)))
(defalias 'project-root-function 'projectile-project-root)
;;;; exec-path-from-shell
(use-package exec-path-from-shell
:ensure t
:commands (exec-path-from-shell-initialize)
:init
(progn
(unless (executable-find* "hsadmin")
(exec-path-from-shell-initialize))))
;;; use-package packages: packages sorted alphabetically by name
(use-package ac-cider
:ensure t
:commands (ac-cider-setup)
:init
(progn
(add-hook 'cider-mode-hook 'ac-flyspell-workaround)
(add-hook 'cider-mode-hook 'ac-cider-setup)
(add-hook 'cider-repl-mode-hook 'ac-cider-setup)
(use-package auto-complete
:defer
:config
(add-to-list 'ac-modes 'cider-mode))))
(use-package adaptive-wrap
:ensure t
:disabled t
:commands adaptive-wrap-prefix-mode
:init
(progn
(hook-into-modes
#'(lambda () (adaptive-wrap-prefix-mode 1))
my-prog-mode-hooks)))
;;(use-package amd-mode
;; :ensure t
;; :commands amd-mode)
(use-package anchored-transpose
:ensure t
:commands anchored-transpose)
(use-package anaphora
:ensure t
:defer)
(use-package arduino-mode
:ensure t
:mode (("\\.ino\\'" . arduino-mode)))
(use-package platformio-mode
:ensure t
:commands (platformio-mode
platformio-build
platformio-upload)
:diminish platformio-mode
:init
(progn
(setq platformio-mode-silent t)
(add-hook 'arduino-mode-hook 'platformio-mode)))
(use-package irony
:ensure t
:commands (irony-mode)
:defer t
:diminish irony-mode
:init
(progn
(setq irony-user-dir (expand-file-name "irony" user-data-directory))
(add-hook 'arduino-mode-hook 'irony-mode)
(use-package flycheck-irony
:after flycheck
:commands flycheck-irony-setup
:config
(progn
(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))))
:config
(progn
(add-to-list 'irony-supported-major-modes 'arduino-mode)
(add-to-list 'irony-lang-compile-option-alist '(arduino-mode . "c++"))
(use-package irony-cdb
:commands (irony-cdb-autosetup-compile-options)
:init
(progn
(add-hook 'arduino-mode-hook 'irony-cdb-autosetup-compile-options)))))
(use-package butler
:ensure t
:commands (butler-status))
(use-package cdnjs
:ensure t
:commands (cdnjs-list-packages
cdnjs-insert-url
cdnjs-select-and-insert-url
cdnjs-install-gocdnjs
cdnjs-update-package-cache))
(use-package clj-refactor
:ensure t
:commands clj-refactor-mode)
(use-package cmake-mode
:ensure t
:mode (("CMakeLists\\.txt\\'" . cmake-mode)
("\\.cmake\\'" . cmake-mode)))
(use-package code-library
:ensure t
:commands code-library-save-code
:config
(progn
(setq code-library-mode-file-alist '((c++-mode . "cpp.org")
(emacs-lisp-mode . "elisp.org")
(python-mode . "python.org")
(perl-mode . "perl.org")
(js2-mode . "javascript.org")
(js-mode . "javascript.org")
(js-jsx-mode . "javascript.org")
(js2-jsx-mode . "javascript.org")
(web-mode . "html.org")
(sh-mode . "sh.org"))
code-library-directory "~/notes/library/"
code-library-use-tags-command nil
code-library-downcased-org-keywords t)))
(use-package color-identifiers-mode
:ensure t
:commands color-identifiers-mode)
(use-package conf-mode
:mode "\\.env\\'")
(use-package csv-mode
:ensure t
:mode (("\\.csv\\'" . csv-mode)))
(use-package debbugs
:ensure t
:commands (debbugs-gnu)
:config
(progn
(require 'debbugs-gnu)
(require 'debbugs-org)
(setq debbugs-gnu-persistency-file (expand-file-name
"debbugs" user-data-directory))))
(use-package delsel
:defer t
:init
(progn
(delete-selection-mode)))
(use-package describe-number
:ensure t
:commands (describe-number
describe-number-at-point))
(use-package cuda-mode
:ensure t
:mode (("\\.cu\\'" . cuda-mode)
("\\.cuh\\'" . cuda-mode)))
(use-package dired-k
:ensure t
:commands dired-k)
(use-package dired-toggle-sudo
:ensure t
:if (not noninteractive)
:commands dired-toggle-sudo)
(use-package docker
:ensure t
:commands (docker-ps
docker-containers
docker-images))
(use-package download-region
:ensure t
:commands download-region-as-url
:init
(setq download-region-max-downloads 5))
(use-package downplay-mode
:ensure t
:commands downplay-mode
:diminish (downplay-mode . "")
:bind (("C-c z" . downplay))
:config
(progn
(downplay-mode 1)))
(use-package dpaste
:commands (dpaste-region dpaste-buffer dpaste-region-or-buffer)
:ensure t)
(use-package dropdown-list
:ensure t
:defer)
(use-package ediff
:defer
:init
(progn
(setq
ediff-diff-options "-w"
ediff-window-setup-function 'ediff-setup-windows-plain
ediff-split-window-function (if (string= system-name "transwhale") 'split-window-vertically
'split-window-horizontally)
ediff-merge-split-window-function ediff-split-window-function )
(defun command-line-diff (switch)
"Usage: emacs -diff file1 file2"
(let ((file1 (pop command-line-args-left))
(file2 (pop command-line-args-left)))
(ediff file1 file2)))
(add-to-list 'command-switch-alist '("diff" . command-line-diff))
)
:config
(progn
(defun ediff-copy-both-to-C ()
(interactive)
(ediff-copy-diff ediff-current-difference nil 'C nil
(concat
(ediff-get-region-contents ediff-current-difference 'A ediff-control-buffer)
(ediff-get-region-contents ediff-current-difference 'B ediff-control-buffer))))
(defun add-d-to-ediff-mode-map ()
(define-key ediff-mode-map "d" 'ediff-copy-both-to-C))
(add-hook 'ediff-keymap-setup-hook 'add-d-to-ediff-mode-map)
;; http://stackoverflow.com/questions/9656311/conflict-resolution-with-emacs-ediff-how-can-i-take-the-changes-of-both-version
;; (require 'ediff-init) ;ensure the macro is defined, so we can override it
;; (defmacro ediff-char-to-buftype (arg)
;; `(cond ((memq ,arg '(?a ?A)) 'A)
;; ((memq ,arg '(?b ?B)) 'B)
;; ((memq ,arg '(?c ?C)) 'C)
;; ((memq ,arg '(?d ?D)) 'D)
;; ))
;; (require 'ediff)
;; ;; Literally copied from ediff-util
;; ;; need to re-evaluate because it uses the macro defined above
;; ;; and the compiled version needs to be re-compiled with the new definition
;; ;; why a macro????
;; (defun ediff-diff-to-diff (arg &optional keys)
;; "Copy buffer-X'th difference region to buffer Y \(X,Y are A, B, or C\).
;; If numerical prefix argument, copy the difference specified in the arg.
;; Otherwise, copy the difference given by `ediff-current-difference'.
;; This command assumes it is bound to a 2-character key sequence, `ab', `ba',
;; `ac', etc., which is used to determine the types of buffers to be used for
;; copying difference regions. The first character in the sequence specifies
;; the source buffer and the second specifies the target.
;; If the second optional argument, a 2-character string, is given, use it to
;; determine the source and the target buffers instead of the command keys."
;; (interactive "P")
;; (ediff-barf-if-not-control-buffer)
;; (or keys (setq keys (this-command-keys)))
;; (if (eq arg '-) (setq arg -1)) ; translate neg arg to -1
;; (if (numberp arg) (ediff-jump-to-difference arg))
;; (let* ((key1 (aref keys 0))
;; (key2 (aref keys 1))
;; (char1 (ediff-event-key key1))
;; (char2 (ediff-event-key key2))
;; ediff-verbose-p)
;; (ediff-copy-diff ediff-current-difference
;; (ediff-char-to-buftype char1)
;; (ediff-char-to-buftype char2))
;; ;; recenter with rehighlighting, but no messages
;; (ediff-recenter)))
;; (defun ediff-copy-D-to-C (arg)
;; "Copy ARGth difference region from both buffers A and B to C.
;; ARG is a prefix argument. If nil, copy the current difference region."
;; (interactive "P")
;; (ediff-diff-to-diff arg "dc"))
;; (defun ediff-copy-diff (n from-buf-type to-buf-type
;; &optional batch-invocation reg-to-copy)
;; (let* ((to-buf (ediff-get-buffer to-buf-type))
;; ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type)))
;; (ctrl-buf ediff-control-buffer)
;; (saved-p t)
;; (three-way ediff-3way-job)
;; messg
;; ediff-verbose-p
;; reg-to-delete reg-to-delete-beg reg-to-delete-end)
;; (setq reg-to-delete-beg
;; (ediff-get-diff-posn to-buf-type 'beg n ctrl-buf))
;; (setq reg-to-delete-end
;; (ediff-get-diff-posn to-buf-type 'end n ctrl-buf))
;; (if (eq from-buf-type 'D)
;; ;; want to copy *both* A and B
;; (if reg-to-copy
;; (setq from-buf-type nil)
;; (setq reg-to-copy (concat (ediff-get-region-contents n 'A ctrl-buf)
;; (ediff-get-region-contents n 'B ctrl-buf))))
;; ;; regular code
;; (if reg-to-copy
;; (setq from-buf-type nil)
;; (setq reg-to-copy (ediff-get-region-contents n from-buf-type ctrl-buf))))
;; (setq reg-to-delete (ediff-get-region-contents
;; n to-buf-type ctrl-buf
;; reg-to-delete-beg reg-to-delete-end))
;; (if (string= reg-to-delete reg-to-copy)
;; (setq saved-p nil) ; don't copy identical buffers
;; ;; seems ok to copy
;; (if (or batch-invocation (ediff-test-save-region n to-buf-type))
;; (condition-case conds
;; (progn
;; (ediff-with-current-buffer to-buf
;; ;; to prevent flags from interfering if buffer is writable
;; (let ((inhibit-read-only (null buffer-read-only)))
;; (goto-char reg-to-delete-end)
;; (insert reg-to-copy)
;; (if (> reg-to-delete-end reg-to-delete-beg)
;; (kill-region reg-to-delete-beg reg-to-delete-end))
;; ))
;; (or batch-invocation
;; (setq
;; messg
;; (ediff-save-diff-region n to-buf-type reg-to-delete))))
;; (error (message "ediff-copy-diff: %s %s"
;; (car conds)
;; (mapconcat 'prin1-to-string (cdr conds) " "))
;; (beep 1)
;; (sit-for 2) ; let the user see the error msg
;; (setq saved-p nil)
;; )))
;; )
;; ;; adjust state of difference in case 3-way and diff was copied ok
;; (if (and saved-p three-way)
;; (ediff-set-state-of-diff-in-all-buffers n ctrl-buf))
;; (if batch-invocation
;; (ediff-clear-fine-differences n)
;; ;; If diff3 job, we should recompute fine diffs so we clear them
;; ;; before reinserting flags (and thus before ediff-recenter).
;; (if (and saved-p three-way)
;; (ediff-clear-fine-differences n))
;; (ediff-refresh-mode-lines)
;; ;; For diff2 jobs, don't recompute fine diffs, since we know there
;; ;; aren't any. So we clear diffs after ediff-recenter.
;; (if (and saved-p (not three-way))
;; (ediff-clear-fine-differences n))
;; ;; Make sure that the message about saving and how to restore is seen
;; ;; by the user
;; (message "%s" messg))
;; ))
;; ;; add keybinding in a hook b/c the keymap isn't defined until the hook is run
;; (add-hook 'ediff-keymap-setup-hook 'add-d-to-ediff-mode-map)
;; (defun add-d-to-ediff-mode-map ()
;; (define-key ediff-mode-map "d" 'ediff-copy-D-to-C))
))
(use-package eval-sexp-fu
:ensure t
:commands (eval-sexp-fu-flash-mode))
(use-package eww
:defer
:init
(progn
(setq eww-search-prefix "http://google.com/search?q=")))
(use-package extempore
:mode ("\\.xtm\\'" . extempore-mode)
:config
(progn
(setq user-extempore-directory
(-first 'file-directory-p
(list
(expand-file-name "~/.opt/extempore/")
"/usr/local/opt/extempore/")))))
(use-package fancy-narrow
:ensure t
:defer)
(use-package feature-mode
:ensure t
:mode (("\\.feature\\'" . feature-mode)))
(use-package flx-isearch
:ensure t
:disabled t
:bind (( "C-s" . flx-isearch-forward)
( "C-r" . flx-isearch-backward)))
(use-package gitlab
:ensure t
:commands (gitlab-version)
:init
(progn
(use-package helm-gitlab
:ensure t
:commands (helm-gitlab-issues
helm-gitlab-projects))))
(use-package git-timemachine
:ensure t
:commands git-timemachine)
(use-package focus
:ensure t
:commands focus-mode)
(use-package ham-mode
:ensure t
:commands (ham-mode))
(use-package helm-chrome
:ensure t
:commands helm-chrome-bookmarks)
(use-package helm-dash
:ensure t
:commands (helm-dash helm-dash-at-point)
:bind (("C-h SPC" . helm-dash-at-point))
:config
(progn
(setq helm-dash-browser-func
(cond ((fboundp 'xwidget-webkit-browse-url) 'xwidget-webkit-browse-url)
((fboundp 'eww) 'eww)
(t 'browse-url)))
(when (eq system-type 'gnu/linux)
(setq helm-dash-docsets-path (format "%s/.local/share/zeal"
(getenv "HOME"))))
(setq helm-dash-many-docsets
'(
"Android"
"Appcelerator Titanium"
"BackboneJS"
"Bash"
"Bootstrap_2"
"Bootstrap_3"
"C++"
"CSS"
"Clojure"
"NET_Framework"
"Redis"
"Swift"
"CoffeeScript"
"OS_X"
"D3JS"
"Django"
"Go"
"Glib"
"Flask"
"OCaml"
"Foundation"
"Go"
"HTML"
"JavaScript"
"Lo-Dash"
"Markdown"
"MySQL"
"Nginx"
"PHP"
"NodeJS"
"PostgreSQL"
"Processing"
"Python 2"
"Python 3"
"SQLite"
"SVG"
"Sass"
"Twisted"
"UnderscoreJS"
"Vagrant"
"XSLT"
"ZeptoJS"
"iOS"
"jQuery"
"jQuery_Mobile"
"jQuery_UI"
))
(setq helm-dash-common-docsets
'(
;; "Bootstrap_3"
"CSS"
;; "Clojure"
"CoffeeScript"
;; "D3JS"
"Django"
;; "Flask"
;; "Foundation"
"Go"
"HTML"
"JavaScript"
"Lo-Dash"
"Markdown"
"MomentJS"
"Nginx"
"NodeJS"
"PostgreSQL"
;; "Processing"
"Python 2"
"Python 3"
"SQLite"
"SVG"
"Sass"
;; "Twisted"
;; "Vagrant"
;; "ZeptoJS"
"jQuery"
"BackboneJS"
))
))
(use-package helm-go-package
:ensure t
:commands helm-go-package
:init
(progn
(use-package go-mode
:defer
:config
(progn
(define-key go-mode-map (kbd "C-c i") 'helm-go-package))))
:config
(progn
(use-package helm)))
(use-package helm-package
:ensure t
:commands helm-package)
(use-package howdoi
:ensure t
:commands (howdoi-query
howdoi-query-region)
:init
(progn
(define-key region-bindings-mode-map "H" 'howdoi-query-region))
:config
(progn
(defun howdoi-query-region()
(interactive)
(let ((query (buffer-substring-no-properties
(region-beginning)
(region-end))))
(howdoi-request query 'howdoi-pop-answer-to-buffer-callback)))))
(use-package ido-completing-read+
:ensure t
:defer t)
(use-package ietf-docs
:ensure t
:commands ietf-docs-open-at-point)
(use-package jumpc
:disabled t
:ensure t
:commands (jumpc)
:bind (("C-<f9>" . jumpc-jump-backward)
("C-<f10>" . jumpc-jump-forward)))
(use-package langtool
:ensure t
:commands (langtool-check langtool-correct-buffer)
:config
(progn
(setq langtool-language-tool-jar "~/.opt/LanguageTool/languagetool-commandline.jar"
langtool-disabled-rules '(
"WHITESPACE_RULE"
;; "EN_UNPAIRED_BRACKETS"
;; "COMMA_PARENTHESIS_WHITESPACE"
"EN_QUOTES"))))
(use-package libmpdee
:ensure t
:defer)
(use-package macrostep
:ensure t
:commands macrostep-expand)
(use-package malabar-mode
:ensure t
:commands (malabar-mode malabar-java-mode malabar-groovy-mode)
:init
(progn
(add-hook 'groovy-mode-hook 'malabar-groovy-mode)
(add-hook 'java-mode-hook 'malabar-java-mode))
:config
(progn
(add-hook 'malabar-mode-hook
(lambda ()
(add-hook 'after-save-hook 'malabar-compile-file-silently
nil t)))))
(use-package manage-minor-mode
:ensure t
:commands manage-minor-mode)
(use-package memory-usage
:ensure t
:commands memory-usage)
(use-package nsm
:defer t
:init
(progn
(setq nsm-settings-file (expand-file-name
"network-security.data" user-data-directory))))
(use-package nxml-mode
:defer t
:config
(progn
(unbind-key "M-h" nxml-mode-map)))
(use-package peep-dired
:ensure t
:commands peep-dired)
(use-package perspective
:ensure t
:commands persp-mode)
(use-package prog-mode
:defer
:init
(progn
(defun my-prettify-symbols-compile-patterns (patterns)
(let ((pretty-patterns))
(loop for (glyph . pairs) in patterns do
(loop for (regexp . major-modes) in pairs do
(loop for mode in major-modes do
(let* ((mode (intern (concat (symbol-name mode)
"-mode")))
(assoc-pair (assoc mode pretty-patterns))
(entry (cons regexp glyph)))
(if assoc-pair
(push entry (cdr assoc-pair))
(push (cons mode (list entry))
pretty-patterns))))))
pretty-patterns))
(defvar my-prettify-symbols-interaction-mode-alist
'((inferior-scheme-mode . scheme-mode)
(lisp-interaction-mode . emacs-lisp-mode)
(inferior-lisp-mode . lisp-mode)
(inferior-ess-mode . ess-mode)
(inf-haskell-mode . haskell-mode)
(tuareg-interactive-mode . tuareg-mode)
(inferior-python-mode . python-mode)
(inferior-octave-mode . octave-mode)
(inferior-ruby-mode . ruby-mode))
"Alist mapping from inferior process interaction modes to their
corresponding script editing modes.")
(defvar my-prettify-symbols-patterns nil)
(setq my-prettify-symbols-patterns
(let* ((lispy '(scheme emacs-lisp lisp clojure))
(mley '(tuareg haskell sml coq))
(c-like '(c c++ perl sh python java ess ruby js js2 coffee go))
(alljs '(js js2))
(all `(,@lispy ,@mley ,@c-like octave latex)))
(my-prettify-symbols-compile-patterns
`(
( (,(rx "not") python ,@lispy haskell coffee)
(,(rx "!") c c++ java ,@alljs go)
(,(rx "~~") coq)
(,(rx "\\neg") latex))
(?≠ (,(rx "!=") ,@c-like scheme octave coq)
(,(rx "<>") tuareg octave)
(,(rx "~=") octave)
(,(rx "/=") haskell emacs-lisp)
(,(rx "\\neq") latex)
(,(rx "not=") clojure))
(?≺ (,(rx "<") ,@all)
(,(rx "\\prec") latex))
(?≻ (,(rx "\\succ") latex))
(?≼ (,(rx "<=") ,@all)
(,(rx "\\leq") latex))
(?≽ (,(rx ">=") ,@all)
(,(rx "\\geq") latex))
(?⁑ (,(rx "**") python))
(?∧ (,(rx "and") emacs-lisp lisp clojure python coffee)
(,(rx "&&") haskell c c++ java perl coq ,@alljs go)
(,(rx "\\wedge") latex)
(,(rx "\\land") latex))
(?∨ (,(rx "or") emacs-lisp lisp clojure python coffee)
(,(rx "||") haskell c c++ java perl coq ,@alljs go)
(,(rx "\\vee") latex)
(,(rx "\\lor") latex))
(?≡ (,(rx "==") ,@all)
(,(rx "=") clojure)
(,(rx "\\equiv") latex))
(?⟵ ;;(,(rx "<-") ,@mley ess)
(,(rx "\\leftarrow") latex))
(?⟶ ;;(,(rx "->") ,@mley ess c c++ perl coffee)
(,(rx "\\rightarrow") latex))
(?↑ (,(rx "\\^") tuareg)
(,(rx "^+") coq))
(?⟹ ;; (,(rx "=>") sml perl ruby haskell coq coffee)
(,(rx "\\Rightarrow") latex))
(?⟷ (,(rx "<->") coq)
(,(rx "\leftrightarrow") latex))
(?↣ (,(rx ">->") coq))
(?↦ (,(rx "\\mapsto") latex))
(?⌀ (,(rx "nil") emacs-lisp clojure ruby go)
(,(rx "null") scheme java ,@alljs coffee)
(,(rx "NULL") c c++)
(,(rx "None") python)
(,(rx "set0") coq)
(,(rx "()") ,@mley)
(,(rx "\\emptyset") latex)
(,(rx "\\varnothing") latex))
;; (?… (,(rx "...") ,@all)
;; (,(rx "..") haskell)
;; (,(rx "\\ldots") latex))
(?⊲ (,(rx "<|") coq))
;;(?√ (,(rx "sqrt") ,@all))
(?∑ ;;(,(rx "sum") python)
(,(rx "\\sum") coq latex)
(,(rx "\\Sigma") latex)
(,(rx "reduce \+") clojure))
(?∪ (,(rx ":|:") coq))
(?∩ (,(rx ":&:") coq))
(?∁ (,(rx "~:") coq))
;; (?α (,(rx "alpha") ,@all)
;; (,(rx "'a") ,@mley)
;; (,(rx "\\alpha") latex))
;; (?β (,(rx "beta") ,@all)
;; (,(rx "'b") ,@mley)
;; (,(rx "\\beta") latex))
;; (?γ (,(rx "gamma") ,@all)
;; (,(rx "'c") ,@mley)
;; (,(rx "\\gamma") latex))
;; (?Δ (,(rx "delta") ,@all)
;; (,(rx "'d") ,@mley)
;; (,(rx "\\Delta") latex))
;; (?ε (,(rx "epsilon") ,@all)
;; (,(rx "\\epsilon") latex))
;; (?ι (,(rx "iota") ,@all)
;; (,(rx "\\iota") latex))
;; (?θ (,(rx "theta") ,@all)
;; (,(rx "\\theta") latex))
;; (?ρ (,(rx "rho") ,@all)
;; (,(rx "\\rho") latex))
;; (?σ ;;(,(rx "sigma") ,@all)
;; (,(rx "filter") python clojure)
;; (,(rx "select") clojure))
;; (?μ (,(rx "mu") ,@all))
( (,(rx "lambda") ,@all)
(,(rx "fn") sml)
(,(rx "fun") tuareg)
(,(rx "\\") haskell)
(,(rx "\\lambda") latex)
)
( (,(rx "\\pi") latex))
( ;;(,(rx "Pi") @all)
(,(rx "\\prod") latex)
(,(rx "\\Pi") latex))
( ;;(,(rx "omega") @all)
(,(rx "\\omega") latex))
( ;;(,(rx "Phi") @all)
(,(rx "\\Phi") latex))
( ;;(,(rx "Ohm") @all)
(,(rx "\\ohm") latex)
(,(rx "\\Omega") latex))
(?℧ ;;(,(rx "Mho") @all)
(,(rx "\\mho") latex))
( ;;(,(rx "phi") ,@all)
(,(rx "\\varphi") latex))
( ;;(,(rx "eta") ,@all)
(,(rx "\\eta") latex))
;;(?∞ (,(rx "HUGE_VAL") c c++))
;;(?∎ (,(rx "Qed.") coq))
;;(?∗ (,(rx "all" (? "()")) python))
;;(?⊢ (,(rx "assert") python))
;;(?≍ (,(rx "is") python))
;;(?𝝈 (,(rx "filter_by") python))
;; (?ℵ (,(rx "count") python clojure))
;; (?⇓(,(rx "order_by") python))
;; (?⤚ (,(rx "group_by") python))
;; (?⟶ (,(rx "def") python))
(?⊤ (,(rx "True") python)
(,(rx "true") go ,@alljs)
)
(?⊥ (,(rx "False") python)
(,(rx "false") go ,@alljs)
)
(?⋂ (,(rx "intersect") python)
(,(rx "\\bigcap") coq)
(,(rx "\\cap") latex)
(,(rx "intersection") clojure))
(?∏ (,(rx "\\prod") coq))
(?⋃ (,(rx "union") python clojure)
(,(rx "\\bigcup") coq)
(,(rx "\\cup") latex))
(?⊎ (,(rx "\\uplus") latex))
(?ℕ (,(rx "nat") coq))
(?∣ (,(rx "%|") coq))
;;(?∈ (,(rx "in") python coffee))
(?∉ ;;(,(rx "not in") python)
(,(rx "\\notin") coq latex))
;;(?⊼ (,(rx "and not") python coffee))
;;(?⊽ (,(rx "or not") python coffee))
(?⊻ (,(rx "(\\+)") coq))
(?∀ ;;(,(rx "for") python coffee)
;;(,(rx "forall") haskell coq)
(,(rx "\\forall") latex))
;;(?∄ (,(rx "not any") python))
;; (?∃ (,(rx "any") python)
;; (,(rx "exists") coq)
;; (,(rx "\\exists") latex)
;; (,(rx "some") clojure))
(?⊂ (,(rx "\\proper") coq)
(,(rx "\\subset") latex))
(?⊆ (,(rx "\\subset") coq)
(,(rx "\\subseteq") latex))
(?∖ (,(rx ":\\:") coq)
(,(rx "\\setminus") latex)
(,(rx "difference") clojure))
(?⋊ (,(rx "><|") coq))
( (,(rx "\\times") latex))
(?〈 (,(rx "\\langle") latex))
(?〉 (,(rx "\\rangle") latex))))))
(defun my-prettify-symbols-hook-fn (&optional mode)
(let* ((mode (or mode major-mode))
(kwds (cdr-safe
(or (assoc mode my-prettify-symbols-patterns)
(assoc (cdr-safe
(assoc mode my-prettify-symbols-interaction-mode-alist))
my-prettify-symbols-patterns)))))
(mapc #'(lambda (v)
(push v prettify-symbols-alist))
kwds)))
(unless noninteractive
(add-hook 'prog-mode-hook 'my-prettify-symbols-hook-fn)))
:config
(progn
(global-prettify-symbols-mode)))
(use-package protobuf-mode
:ensure t
:mode (("\\.proto\\'" . protobuf-mode)))
(use-package region-bindings-mode
:if (and
(not noninteractive)
(not degrade-p-minimalism))
:ensure t
:commands (region-bindings-mode-enable)
:init
(progn
(setq region-bindings-mode-disabled-modes
'(
dired-efap-mode
magit-status-mode
term-mode
transmission-mode
transmission-files-mode
))
(region-bindings-mode-enable))
:config
(progn
(defun my-mark-word (N)
(interactive "p")
;; (when (< (point) (mark))
;; (exchange-point-and-mark))
(forward-word N))
(defun my-mark-word-backward (N)
(interactive "p")
;; (when (< (mark) (point))
;; (exchange-point-and-mark))
(backward-word N))
(defun my-mark-char (N)
(interactive "p")
(forward-char N))
(defun my-mark-char-backward (N)
(interactive "p")
(backward-char N))
(define-key region-bindings-mode-map "F" 'my-mark-char)
(define-key region-bindings-mode-map "B" 'my-mark-char-backward)
(define-key region-bindings-mode-map "f" 'my-mark-word)
(define-key region-bindings-mode-map "b" 'my-mark-word-backward)
(define-key region-bindings-mode-map "y" 'yank)
(define-key region-bindings-mode-map "k" 'copy-region-as-kill)
(define-key region-bindings-mode-map "w" 'kill-region)
(define-key region-bindings-mode-map "x" 'exchange-dot-and-mark)
(define-key region-bindings-mode-map "d" 'er/mark-defun)
(define-key region-bindings-mode-map "g" 'keyboard-quit)
(define-key region-bindings-mode-map "s" search-map))
)
(use-package rings
:ensure t
:if (not noninteractive)
:init
(progn
(setq rings-protect-buffers-in-rings nil)
(defun my-rings-setup ()
;; f1
(global-set-key (kbd "<f1>") (lambda nil (interactive) (rings-cycle 1)))
(global-set-key (kbd "S-<f1>") (lambda nil (interactive) (rings-toggle-buffer 1)))
(global-set-key (kbd "C-<f1>") (lambda nil (interactive) (rings-remove-buffer 1)))
;; f2
(global-set-key (kbd "<f2>") (lambda nil (interactive) (rings-cycle 2)))
(global-set-key (kbd "S-<f2>") (lambda nil (interactive) (rings-toggle-buffer 2)))
(global-set-key (kbd "C-<f2>") (lambda nil (interactive) (rings-remove-buffer 2)))
;; f3
(global-set-key (kbd "<f3>") (lambda nil (interactive) (rings-cycle 3)))
(global-set-key (kbd "S-<f3>") (lambda nil (interactive) (rings-toggle-buffer 3)))
(global-set-key (kbd "C-<f3>") (lambda nil (interactive) (rings-remove-buffer 3)))
;; f4
(global-set-key (kbd "<f4>") (lambda nil (interactive) (rings-cycle 4)))
(global-set-key (kbd "S-<f4>") (lambda nil (interactive) (rings-toggle-buffer 4)))
(global-set-key (kbd "C-<f4>") (lambda nil (interactive) (rings-remove-buffer 4)))
)
(add-hook 'after-init-hook 'my-rings-setup t)))
(use-package org-ehtml
:disabled t
:ensure t
:defer)
(use-package org-import-icalendar
:commands org-icalendar-import-buffer)
(use-package org-screenshot
:commands org-screenshot-take)
(use-package osc
:defer
:ensure t)
(use-package pip-requirements
:ensure t
:mode (("\\.pip\\'" . pip-requirements-mode)
("requirements\\.txt\\'" . pip-requirements-mode)))
(use-package pushbullet
:ensure t
:commands pushbullet)
(use-package rainbow-blocks
:ensure t
:commands rainbow-blocks-mode)
(use-package rainbow-identifiers
:ensure t
:commands rainbow-identifiers-mode
:init
(progn
(defun rainbow-identifiers-turn-on-maybe ()
(when
(or
(hardhat-buffer-included-p (current-buffer)))
(rainbow-identifiers-mode)))
;; (add-hook 'prog-mode-hook 'rainbow-identifiers-turn-on-maybe)
))
(use-package scroll-restore
:ensure t
:if (not noninteractive)
:commands scroll-restore-mode
:config
(progn
(setq
scroll-restore-recenter nil
scroll-restore-commands '(handle-select-window
handle-switch-frame
mwheel-scroll
scroll-bar-drag
scroll-bar-scroll-down
scroll-bar-scroll-up
scroll-bar-toolkit-scroll
scroll-down scroll-down-command
scroll-down-command-flash
scroll-other-window
scroll-other-window-down
scroll-up scroll-up-command
scroll-up-command-flash))
(scroll-restore-mode 1)))
(use-package shr
:defer
:init
(progn
(setq shr-external-browser 'browse-url-generic)))