Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spacemacs config
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
;; `+distribution'. For now available distributions are `spacemacs-base'
;; or `spacemacs'. (default 'spacemacs)
dotspacemacs-distribution 'spacemacs-base
;; Lazy installation of layers (i.e. layers are installed only when a file
;; with a supported type is opened). Possible values are `all', `unused'
;; and `nil'. `unused' will lazy install only unused layers (i.e. layers
;; not listed in variable `dotspacemacs-configuration-layers'), `all' will
;; lazy install any layer that support lazy installation even the layers
;; listed in `dotspacemacs-configuration-layers'. `nil' disable the lazy
;; installation feature and you have to explicitly list a layer in the
;; variable `dotspacemacs-configuration-layers' to install it.
;; (default 'unused)
dotspacemacs-enable-lazy-installation 'unused
;; If non-nil then Spacemacs will ask for confirmation before installing
;; a layer lazily. (default t)
dotspacemacs-ask-for-lazy-installation t
;; If non-nil layers with lazy install support are lazy installed.
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (i.e. `~/.mycontribs/')
dotspacemacs-configuration-layer-path '()
;; List of configuration layers to load.
dotspacemacs-configuration-layers
'(
sql
yaml
javascript
html
;; ----------------------------------------------------------------
;; Example of useful layers you may want to use right away.
;; Uncomment some layer names and press <SPC f e R> (Vim style) or
;; <M-m f e R> (Emacs style) to install them.
;; ----------------------------------------------------------------
;; helm
ivy
;; auto-completion
;; better-defaults
emacs-lisp
;; git
markdown
org
;; (shell :variables
;; shell-default-height 30
;; shell-default-position 'bottom)
;; spell-checking
;; syntax-checking
;; version-control
(spacemacs-evil :packages (evil-surround evil-anzu vi-tilde-fringe hs-minor-mode))
(spacemacs-ui-visual :packages (spaceline smooth-scrolling))
(spacemacs-ui :packages window-numbering)
(spacemacs-editing :packages smartparens)
(spacemacs-editing-visual :packages (rainbow-delimiters volatile-highlights adaptive-wrap))
(spacemacs-layouts :packages (persp-mode eyebrowse))
;;(spacemacs-org :packages default-org-config)
(clojure :packages (smartparens clojure-mode cider cider-nrepl))
(themes-megapack :package (spacemacs-dark spacemacs-light
twilight-anti-bright twilight-bright
sanityinc-solarized-light-theme sanityinc-solarized-dark-theme
)) ;; <http://themegallery.robdor.com/>
fsharp
;;nlinum
evil-commentary
evil-quickscope
git-gutter-fringe
)
;; List of additional packages that will be installed without being
;; wrapped in a layer. If you need some configuration for these
;; packages, then consider creating a layer. You can also put the
;; configuration in `dotspacemacs/user-config'.
dotspacemacs-additional-packages '(editorconfig
;;git-gutter
neotree)
;; A list of packages that cannot be updated.
dotspacemacs-frozen-packages '()
;; A list of packages that will not be installed and loaded.
dotspacemacs-excluded-packages '(browse-url
evil-visualstar
evil-escape ;; causes `fd' to go straight to normal mode
;;linum
;;linum-relative
nlinum
js2-mode)
;; Defines the behaviour of Spacemacs when installing packages.
;; Possible values are `used-only', `used-but-keep-unused' and `all'.
;; `used-only' installs only explicitly used packages and uninstall any
;; unused packages as well as their unused dependencies.
;; `used-but-keep-unused' installs only the used packages but won't uninstall
;; them if they become unused. `all' installs *all* packages supported by
;; Spacemacs and never uninstall them. (default is `used-only')
dotspacemacs-install-packages 'used-only))
(defun dotspacemacs/init ()
"Initialization function.
This function is called at the very startup of Spacemacs initialization
before layers configuration.
You should not put any user code in there besides modifying the variable
values."
;; This setq-default sexp is an exhaustive list of all the supported
;; spacemacs settings.
(setq-default
;; If non nil ELPA repositories are contacted via HTTPS whenever it's
;; possible. Set it to nil if you have no way to use HTTPS in your
;; environment, otherwise it is strongly recommended to let it set to t.
;; This variable has no effect if Emacs is launched with the parameter
;; `--insecure' which forces the value of this variable to nil.
;; (default t)
dotspacemacs-elpa-https t
;; Maximum allowed time in seconds to contact an ELPA repository.
dotspacemacs-elpa-timeout 5
;; If non nil then spacemacs will check for updates at startup
;; when the current branch is not `develop'. Note that checking for
;; new versions works via git commands, thus it calls GitHub services
;; whenever you start Emacs. (default nil)
dotspacemacs-check-for-update t
;; If non-nil, a form that evaluates to a package directory. For example, to
;; use different package directories for different Emacs versions, set this
;; to `emacs-version'.
dotspacemacs-elpa-subdirectory nil
;; One of `vim', `emacs' or `hybrid'.
;; `hybrid' is like `vim' except that `insert state' is replaced by the
;; `hybrid state' with `emacs' key bindings. The value can also be a list
;; with `:variables' keyword (similar to layers). Check the editing styles
;; section of the documentation for details on available variables.
;; (default 'vim)
dotspacemacs-editing-style 'vim
;; If non nil output loading progress in `*Messages*' buffer. (default nil)
dotspacemacs-verbose-loading nil
;; Specify the startup banner. Default value is `official', it displays
;; the official spacemacs logo. An integer value is the index of text
;; banner, `random' chooses a random text banner in `core/banners'
;; directory. A string value must be a path to an image format supported
;; by your Emacs build.
;; If the value is nil then no banner is displayed. (default 'official)
dotspacemacs-startup-banner 'official
;; List of items to show in startup buffer or an association list of
;; the form `(list-type . list-size)`. If nil then it is disabled.
;; Possible values for list-type are:
;; `recents' `bookmarks' `projects' `agenda' `todos'."
;; List sizes may be nil, in which case
;; `spacemacs-buffer-startup-lists-length' takes effect.
dotspacemacs-startup-lists '((recents . 15)
(projects . 2))
;; True if the home buffer should respond to resize events.
dotspacemacs-startup-buffer-responsive t
;; Default major mode of the scratch buffer (default `text-mode')
dotspacemacs-scratch-mode 'text-mode
;; List of themes, the first of the list is loaded when spacemacs starts.
;; Press <SPC> T n to cycle to the next theme in the list (works great
;; with 2 themes variants, one dark and one light)
dotspacemacs-themes '(;; spacemacs-dark spacemacs-light
;; apropospriate-light
twilight-bright
twilight-anti-bright
spacemacs-light
spacemacs-dark
)
;; If non nil the cursor color matches the state color in GUI Emacs.
dotspacemacs-colorize-cursor-according-to-state t
;; Default font, or prioritized list of fonts. `powerline-scale' allows to
;; quickly tweak the mode-line size to make separators look not too crappy.
dotspacemacs-default-font '("Hack" ; "Source Code Pro"
:size 12 ; 13
:weight normal
:width normal
:powerline-scale 1.1)
;; The leader key
dotspacemacs-leader-key "SPC"
;; The key used for Emacs commands (M-x) (after pressing on the leader key).
;; (default "SPC")
dotspacemacs-emacs-command-key "SPC"
;; The key used for Vim Ex commands (default ":")
dotspacemacs-ex-command-key ":"
;; The leader key accessible in `emacs state' and `insert state'
;; (default "M-m")
dotspacemacs-emacs-leader-key "M-m"
;; Major mode leader key is a shortcut key which is the equivalent of
;; pressing `<leader> m`. Set it to `nil` to disable it. (default ",")
dotspacemacs-major-mode-leader-key ","
;; Major mode leader key accessible in `emacs state' and `insert state'.
;; (default "C-M-m")
dotspacemacs-major-mode-emacs-leader-key "C-M-m"
;; These variables control whether separate commands are bound in the GUI to
;; the key pairs C-i, TAB and C-m, RET.
;; Setting it to a non-nil value, allows for separate commands under <C-i>
;; and TAB or <C-m> and RET.
;; In the terminal, these pairs are generally indistinguishable, so this only
;; works in the GUI. (default nil)
dotspacemacs-distinguish-gui-tab nil
;; If non nil `Y' is remapped to `y$' in Evil states. (default nil)
dotspacemacs-remap-Y-to-y$ nil
;; If non-nil, the shift mappings `<' and `>' retain visual state if used
;; there. (default t)
dotspacemacs-retain-visual-state-on-shift t
;; If non-nil, J and K move lines up and down when in visual mode.
;; (default nil)
dotspacemacs-visual-line-move-text nil
;; If non nil, inverse the meaning of `g' in `:substitute' Evil ex-command.
;; (default nil)
dotspacemacs-ex-substitute-global nil
;; Name of the default layout (default "Default")
dotspacemacs-default-layout-name "Default"
;; If non nil the default layout name is displayed in the mode-line.
;; (default nil)
dotspacemacs-display-default-layout nil
;; If non nil then the last auto saved layouts are resume automatically upon
;; start. (default nil)
dotspacemacs-auto-resume-layouts nil
;; Size (in MB) above which spacemacs will prompt to open the large file
;; literally to avoid performance issues. Opening a file literally means that
;; no major mode or minor modes are active. (default is 1)
dotspacemacs-large-file-size 1
;; Location where to auto-save files. Possible values are `original' to
;; auto-save the file in-place, `cache' to auto-save the file to another
;; file stored in the cache directory and `nil' to disable auto-saving.
;; (default 'cache)
dotspacemacs-auto-save-file-location 'cache
;; Maximum number of rollback slots to keep in the cache. (default 5)
dotspacemacs-max-rollback-slots 5
;; If non nil, `helm' will try to minimize the space it uses. (default nil)
dotspacemacs-helm-resize t
;; if non nil, the helm header is hidden when there is only one source.
;; (default nil)
dotspacemacs-helm-no-header nil
;; define the position to display `helm', options are `bottom', `top',
;; `left', or `right'. (default 'bottom)
dotspacemacs-helm-position 'bottom
;; Controls fuzzy matching in helm. If set to `always', force fuzzy matching
;; in all non-asynchronous sources. If set to `source', preserve individual
;; source settings. Else, disable fuzzy matching in all sources.
;; (default 'always)
dotspacemacs-helm-use-fuzzy 'always
;; If non nil the paste micro-state is enabled. When enabled pressing `p`
;; several times cycle between the kill ring content. (default nil)
dotspacemacs-enable-paste-transient-state nil
;; Which-key delay in seconds. The which-key buffer is the popup listing
;; the commands bound to the current keystroke sequence. (default 0.4)
dotspacemacs-which-key-delay 0.4
;; Which-key frame position. Possible values are `right', `bottom' and
;; `right-then-bottom'. right-then-bottom tries to display the frame to the
;; right; if there is insufficient space it displays it at the bottom.
;; (default 'bottom)
dotspacemacs-which-key-position 'bottom
;; If non nil a progress bar is displayed when spacemacs is loading. This
;; may increase the boot time on some systems and emacs builds, set it to
;; nil to boost the loading time. (default t)
dotspacemacs-loading-progress-bar t
;; If non nil the frame is fullscreen when Emacs starts up. (default nil)
;; (Emacs 24.4+ only)
dotspacemacs-fullscreen-at-startup nil
;; If non nil `spacemacs/toggle-fullscreen' will not use native fullscreen.
;; Use to disable fullscreen animations in OSX. (default nil)
dotspacemacs-fullscreen-use-non-native nil
;; If non nil the frame is maximized when Emacs starts up.
;; Takes effect only if `dotspacemacs-fullscreen-at-startup' is nil.
;; (default nil) (Emacs 24.4+ only)
dotspacemacs-maximized-at-startup t
;; A value from the range (0..100), in increasing opacity, which describes
;; the transparency level of a frame when it's active or selected.
;; Transparency can be toggled through `toggle-transparency'. (default 90)
dotspacemacs-active-transparency 90
;; A value from the range (0..100), in increasing opacity, which describes
;; the transparency level of a frame when it's inactive or deselected.
;; Transparency can be toggled through `toggle-transparency'. (default 90)
dotspacemacs-inactive-transparency 90
;; If non nil show the titles of transient states. (default t)
dotspacemacs-show-transient-state-title t
;; If non nil show the color guide hint for transient state keys. (default t)
dotspacemacs-show-transient-state-color-guide t
;; If non nil unicode symbols are displayed in the mode line. (default t)
dotspacemacs-mode-line-unicode-symbols t
;; If non nil smooth scrolling (native-scrolling) is enabled. Smooth
;; scrolling overrides the default behavior of Emacs which recenters point
;; when it reaches the top or bottom of the screen. (default t)
dotspacemacs-smooth-scrolling t
;; Control line numbers activation.
;; If set to `t' or `relative' line numbers are turned on in all `prog-mode' and
;; `text-mode' derivatives. If set to `relative', line numbers are relative.
;; This variable can also be set to a property list for finer control:
;; '(:relative nil
;; :disabled-for-modes dired-mode
;; doc-view-mode
;; markdown-mode
;; org-mode
;; pdf-view-mode
;; text-mode
;; :size-limit-kb 1000)
;; (default nil)
dotspacemacs-line-numbers t
;; Code folding method. Possible values are `evil' and `origami'.
;; (default 'evil)
dotspacemacs-folding-method 'evil
;; If non-nil smartparens-strict-mode will be enabled in programming modes.
;; (default nil)
dotspacemacs-smartparens-strict-mode nil
;; If non-nil pressing the closing parenthesis `)' key in insert mode passes
;; over any automatically added closing parenthesis, bracket, quote, etc…
;; This can be temporary disabled by pressing `C-q' before `)'. (default nil)
dotspacemacs-smart-closing-parenthesis nil
;; Select a scope to highlight delimiters. Possible values are `any',
;; `current', `all' or `nil'. Default is `all' (highlight any scope and
;; emphasis the current one). (default 'all)
dotspacemacs-highlight-delimiters 'all
;; If non nil, advise quit functions to keep server open when quitting.
;; (default nil)
dotspacemacs-persistent-server nil
;; List of search tool executable names. Spacemacs uses the first installed
;; tool of the list. Supported tools are `ag', `pt', `ack' and `grep'.
;; (default '("ag" "pt" "ack" "grep"))
dotspacemacs-search-tools '("ag" "pt" "ack" "grep")
;; The default package repository used if no explicit repository has been
;; specified with an installed package.
;; Not used for now. (default nil)
dotspacemacs-default-package-repository nil
;; Delete whitespace while saving buffer. Possible values are `all'
;; to aggressively delete empty line and long sequences of whitespace,
;; `trailing' to delete only the whitespace at end of lines, `changed'to
;; delete only whitespace for changed lines or `nil' to disable cleanup.
;; (default nil)
dotspacemacs-whitespace-cleanup nil
))
(defun dotspacemacs/user-init ()
"Initialization function for user code.
It is called immediately after `dotspacemacs/init', before layer configuration
executes.
This function is mostly useful for variables that need to be set
before packages are loaded. If you are unsure, you should try in setting them in
`dotspacemacs/user-config' first."
)
(defun dotspacemacs/user-config ()
"Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
;; (global-evil-search-highlight-persist -1)
;; (global-evil-quickscope-mode 1)
(defun hook-for-modes (f hooks)
(mapc (lambda (hook-name) (add-hook hook-name f)) hooks))
;;(mapc (lambda (hook-name) (add-hook hook-name (lambda () (hs-minor-mode))))
;; '(clojure-mode-hook
;; clojurescript-mode-hook
;; css-mode-hook
;; js-mode-hook))
(hook-for-modes
(lambda () (hs-minor-mode))
'(clojure-mode-hook
clojurescript-mode-hook
css-mode-hook
js-mode-hook))
(hook-for-modes
(lambda () (smartparens-strict-mode 1))
'(clojure-mode-hook
clojurescript-mode-hook))
(editorconfig-mode 1)
(show-paren-mode t)
(setq spaceline-minor-modes-p nil
spaceline-evil-state-p t
spaceline-highlight-face-func 'spaceline-highlight-face-evil-state
spaceline-hud-p t
spaceline-window-number-p nil
show-paren-style 'parenthesis
show-paren-delay 0
evil-search-module 'evil-search
evil-auto-balance-windows nil
create-lockfiles nil
eyebrowse-new-workspace "*spacemacs*"
;; linum-format "%5d" ;; Needed for git-gutter
;; linum-format 'dynamic
linum-format "%4d"
org-cycle-separator-lines 1
ivy-re-builds-alist '(t . ivy--regex-fuzzy)
neo-theme 'ascii
powerline-default-separator 'slant ;; Vim-style: 'arrow, Spacemacs default: 'wave
max-mini-window-height 6
)
(setq css-indent-offset 2)
;; (global-git-gutter-mode +1)
;; (custom-set-variables
;; '(git-gutter:unchanged-sign " ")
;; '(git-gutter:modified-sign "~")
;; '(git-gutter:added-sign "+")
;; '(git-gutter:deleted-sign "-")
;; '(git-gutter:window-width 1))
;; (set-face-foreground 'git-gutter:modified "gold")
;; (set-face-background 'git-gutter:modified nil)
;; (set-face-foreground 'git-gutter:added "green")
;; (set-face-foreground 'git-gutter:deleted "red")
;; (set-face-background 'git-gutter:unchanged nil)
;; Match my vim-powerline theme
(set-face-background 'spaceline-evil-normal "royal blue")
(set-face-foreground 'spaceline-evil-normal "white")
(set-face-background 'spaceline-evil-insert "medium sea green")
(set-face-foreground 'spaceline-evil-insert "white")
(set-face-background 'spaceline-evil-replace "coral2")
(set-face-foreground 'spaceline-evil-replace "white")
(set-face-background 'spaceline-evil-visual "goldenrod2")
(set-face-foreground 'spaceline-evil-visual "white")
(defun set-paren-match-colors ()
(interactive)
(set-face-foreground 'show-paren-match "white")
(set-face-background 'show-paren-match "dodger blue")
(set-face-attribute 'show-paren-match nil :underline t))
;; Rainbow-delimiters colors; try M-x list-colors-display
(setq dotspacemacs-rainbow-delimiters-set nil)
(add-hook 'rainbow-delimiters-mode-hook
(lambda ()
(when (not dotspacemacs-rainbow-delimiters-set)
(setq dotspacemacs-rainbow-delimiters-set t)
(mapc (lambda (c) (set-face-foreground (car c) (cdr c)))
'((rainbow-delimiters-depth-1-face . "dark orange")
(rainbow-delimiters-depth-2-face . "deep pink")
(rainbow-delimiters-depth-3-face . "medium sea green")
(rainbow-delimiters-depth-4-face . "cornflower blue")
(rainbow-delimiters-depth-5-face . "goldenrod")
(rainbow-delimiters-depth-6-face . "orchid")
(rainbow-delimiters-depth-7-face . "light sea green")
(rainbow-delimiters-depth-8-face . "sienna1")
(rainbow-delimiters-unmatched-face . "white")
(rainbow-delimiters-mismatched-face . "white")))
(set-face-background 'rainbow-delimiters-unmatched-face "red")
(set-face-background 'rainbow-delimiters-mismatched-face "orange")
(set-paren-match-colors))))
(add-hook 'spacemacs-post-theme-change-hook (lambda () (set-paren-match-colors)))
(defun buffer-local-set-keys (local-keys &optional buffer)
"Given a list of cons cells LOCAL-KEYS where the car is a key and the cdr is a
function, map each key to its respective function in a clone of the current keymap.
That cloned keymap is set as the given BUFFER's keymap (or the current buffer)."
(with-current-buffer (or buffer (current-buffer))
(use-local-map (copy-keymap (or (current-local-map) (current-global-map))))
(mapc (lambda (key) (local-set-key (kbd (car key)) (cdr c)))
local-keys)))
(defun buffer-local-set-key (key f &optional buffer)
"Set a single KEY to execute a function F, but only in BUFFER (or the current
buffer). Will override any mapping for KEY in the current local/global keymaps."
(with-current-buffer (or buffer (current-buffer))
(use-local-map (copy-keymap (or (current-local-map) (current-global-map))))
(local-set-key (kbd key) f)))
(defun true-evil-quit (&optional force)
"Closes the current window, current frame, Emacs.
If the current frame belongs to some client the client connection
is closed.
This is the original `evil-quit' implementation."
(interactive "<!>")
(condition-case nil
(delete-window)
(error
(if (and (boundp 'server-buffer-clients)
(fboundp 'server-edit)
(fboundp 'server-buffer-done)
server-buffer-clients)
(if force
(server-buffer-done (current-buffer))
(server-edit))
(condition-case nil
(delete-frame)
(error
(if force
(kill-emacs)
(save-buffers-kill-emacs))))))))
(evil-define-command evil-quit (&optional force)
"Custom version of `evil-quit' that will close the current window
first; if this is the last window in the frame but we have other frames,
close the current frame; if this is the last frame and we have other
eyebrowse window configs, close the current config. Failing that, defer
to the original `evil-quit' behavior."
:repeat nil
(interactive "<!>")
(let* ((eyebrowse-window-configs (eyebrowse--get 'window-configs))
(eyebrowse-current-slot (eyebrowse--get 'current-slot))
(eyebrowse-config-count (length eyebrowse-window-configs))
(emacs-frame-count (length (frame-list))))
(condition-case nil
(delete-window)
(error
(cond
((> emacs-frame-count 1) (delete-frame))
((> eyebrowse-config-count 1) (eyebrowse-close-window-config))
(t (true-evil-quit force)))))))
(evil-ex-define-cmd "tabn[ext]" 'eyebrowse-next-window-config)
(evil-ex-define-cmd "tabp[rev]" 'eyebrowse-prev-window-config)
(evil-ex-define-cmd "tabnew" 'eyebrowse-create-window-config)
(evil-ex-define-cmd "tabc[lose]" 'eyebrowse-close-window-config)
(evil-ex-define-cmd "tab" 'eyebrowse-switch-to-window-config)
(define-key evil-normal-state-map (kbd "SPC :") 'eval-expression)
;; Default behavior of parens in normal mode is pretty atrocious, this makes
;; them slightly better.
(defun evil-prev-sexp-or-paren (&optional count)
"Go to the beginning of the sexp if in a LISP-like mode, or to the previous opening parenthesis."
(interactive)
(with-current-buffer (current-buffer)
(if (derived-mode-p 'clojure-mode
'clojurescript-mode
'lisp-mode
'emacs-lisp-mode
'inferior-emacs-lisp-mode)
(progn (sp-beginning-of-sexp)
(backward-char))
(evil-previous-open-paren))))
(defun evil-next-sexp-or-paren (&optional count)
"Go to the end of the sexp if in a LISP-like mode, or to the next closing parenthesis."
(interactive)
(with-current-buffer (current-buffer)
(if (derived-mode-p 'clojure-mode
'clojurescript-mode
'lisp-mode
'emacs-lisp-mode
'inferior-emacs-lisp-mode)
(sp-end-of-sexp)
(evil-next-close-paren))))
(define-key evil-normal-state-map (kbd "(") 'evil-prev-sexp-or-paren)
(define-key evil-normal-state-map (kbd ")") 'evil-next-sexp-or-paren)
(define-key evil-normal-state-map (kbd "<C-up>") 'text-scale-increase)
(define-key evil-normal-state-map (kbd "<C-down>") 'text-scale-decrease)
(defun evil-window-minimize ()
"Set the height of the window to the minimum allowed value."
(interactive)
(evil-window-set-height 0))
(define-key evil-window-map (kbd "m") 'evil-window-minimize)
;; sexp manipulation bindings inspired by tpope's Vim plugin
;; `vim-sexp-mappings-for-regular-people`. Maybe I should extract
;; this to a layer? Not a 1:1 clone, it's a bit more limited.
(defun evil-sexp-insert-at-end ()
(interactive)
(evil-set-marker ?`)
(sp-end-of-sexp)
(evil-insert-state))
(defun evil-sexp-insert-at-start ()
(interactive)
(evil-set-marker ?`)
(sp-beginning-of-sexp)
(evil-insert-state))
(defun evil-sexp-raise-sexp ()
(interactive)
(sp-backward-up-sexp)
(sp-raise-sexp)
(forward-char))
(defun evil-sexp--get-wrap-char-and-closing-p (user-char)
"Detect if a USER-CHAR is a closing paren/brace/bracket. Return a cons cell
containing the correct opening character (or USER-CHAR if that already is one),
and either `t' or `nil' to denote whether USER-CHAR was a closing character."
(let ((wrap-char (cond ((= user-char ?\)) "(")
((= user-char ?\]) "[")
((= user-char ?\}) "{")
(t (string user-char))))
(closing-p (or (= user-char ?\))
(= user-char ?\])
(= user-char ?\}))))
`(,wrap-char . ,closing-p)))
(defun evil-sexp-wrap-element (user-char)
"Wrap the current symbol with a character pair determined by USER-CHAR. If a
closing character is provided, after wrapping the point will be at the end of the
new sexp; otherwise, it will be at the beginning."
(interactive "c")
(let* ((wrap-and-closing-p (evil-sexp--get-wrap-char-and-closing-p user-char))
(wrap-char (car wrap-and-closing-p))
(closing-p (cdr wrap-and-closing-p)))
(sp-wrap-with-pair wrap-char)
(when closing-p
(evil-forward-WORD-end))))
(defun evil-sexp-wrap-sexp (user-char)
"Wrap the current sexp with a character pair determiend by USER-CHAR, and then
enter `evil-insert-state'. If USER-CHAR is a closing character, the point will be
at the end of the new sexp; otherwise, at the beginning. A space between the point
and the next/previous element of the sexp is automatically inserted."
(interactive "c")
(let* ((c (char-after))
(wrap-and-closing-p (evil-sexp--get-wrap-char-and-closing-p user-char))
(wrap-char (car wrap-and-closing-p))
(closing-p (cdr wrap-and-closing-p))
(quote-p (= c ?\")))
(when (not (or (= c ?\()
(= c ?\[)
(= c ?\{)))
(progn
(sp-beginning-of-sexp)
(backward-char)))
(sp-wrap-with-pair wrap-char)
(if (not closing-p)
(progn
(when (not quote-p) (insert " "))
(backward-char)
(evil-insert-state))
(progn
(sp-end-of-sexp)
(insert " ")
(evil-insert-state)))))
(defun evil-sexp-unwrap-sexp ()
(interactive)
(sp-beginning-of-sexp)
(backward-char)
(sp-unwrap-sexp))
(defun evil-sexp-transpose-symbol (backward &optional n)
(interactive "p")
(let ((m (if backward (* -1 n) n)))
(when (not (sp--looking-at-p "\\sw\\|\\s_"))
(sp-backward-symbol))
(forward-char)
(sp-transpose-sexp m)
(sp-backward-symbol)))
(defun evil-sexp-transpose-sexp (backward &optional n)
(interactive "p")
(if backward
(progn
(sp-transpose-sexp n)
(sp-backward-sexp 2))
(progn
(sp-next-sexp (when n (+ n 1)))
(sp-transpose-sexp n))))
(defun evil-sexp-transpose (backward &optional n)
(interactive "p")
(let* ((c (char-after))
(wrap-and-closing-p (evil-sexp--get-wrap-char-and-closing-p c))
(wrap-char (string-to-char (car wrap-and-closing-p)))
(closing-p (cdr wrap-and-closing-p))
(wrap-p (or (= wrap-char ?\() (= wrap-char ?\[) (= wrap-char ?\{))))
(if wrap-p
(progn
(when closing-p
(sp-beginning-of-sexp)
(backward-char))
(evil-sexp-transpose-sexp backward n))
(evil-sexp-transpose-symbol backward n))))
(defun evil-sexp-transpose-backward (&optional n)
(interactive "p")
(evil-sexp-transpose t n))
(defun evil-sexp-transpose-forward (&optional n)
(interactive "p")
(evil-sexp-transpose nil n))
(defun evil-sexp-indent-list ()
(interactive)
(let ((sexp-plist (sp-get-enclosing-sexp)))
(evil-indent (plist-get sexp-plist :beg) (plist-get sexp-plist :end))))
(defun re-search-bidirectional (re &optional forward-first)
"Call `re-search-backward' with the regexp RE; if there are no results, use RE
to call `re-search-forward'. If FORWARD-FIRST is non-nil, switch the order of the
calls."
(condition-case nil
(if forward-first (re-search-forward re) (re-search-backward re))
(error
(if forward-first (re-search-backward re) (re-search-forward re)))))
(defun evil-sexp-jump-definition ()
"Jump to the definition of the word under the point, where a definition can have
any of these shapes:
- `(def word'
- `(defn word'
- `(defn- word'
- `word (fn'"
(interactive)
(let ((sym (thing-at-point 'symbol t)))
(re-search-bidirectional (concat "\\((def\\(n-?\\)? \\<" sym "\\>\\|\\<" sym "\\> (fn\\)"))))
(defun evil-sexp-jump-call ()
"Jump to the next or previous (in that order) use of the sym under the point as
a function, which can be any of these shapes:
- `(sym '
- `(sym)'
- `(partial sym
- `(apply sym'"
(interactive)
(let ((sym (thing-at-point 'symbol t)))
(re-search-bidirectional (concat "(\\(apply \\|\\.\\|partial \\)?\\<" sym "\\>[ )]") t)))
(defun evil-sexp-jump-rf-subscription ()
"Jump to the definition of the subscription currently under the point"
(interactive)
(let ((sym (thing-at-point 'symbol t)))
(re-search-bidirectional (concat "\\(reg-sub\\(-\\w+\\)?\\|simple-sub\\)[ \n]*\\<" sym "\\>") t)))
(defun evil-sexp-jump-rf-event ()
"Jump to the definition of the subscription currently under the point"
(interactive)
(let ((sym (thing-at-point 'symbol t)))
(re-search-bidirectional (concat "reg-event\\(-\\w+\\)?[ \n\r]+\\<" sym "\\>") t)))
(defun evil-sexp-comment-sexp ()
"Comment th current sexp"
(interactive)
(let ((current-char (char-after)))
(when (or (= current-char ?\()
(= current-char ?\[)
(= current-char ?\{))
(forward-char)))
(let ((sexp (sp-get-enclosing-sexp)))
(comment-region (sp-get sexp :beg) (sp-get sexp :end))))
(defun evil-sexp-uncomment-sexp ()
"Comment th current sexp"
(interactive)
(let ((current-char (char-after)))
(when (or (= current-char ?\()
(= current-char ?\[)
(= current-char ?\{))
(forward-char)))
(let ((sexp (sp-get-enclosing-sexp)))
(uncomment-region (sp-get sexp :beg) (sp-get sexp :end))))
;; (defun evil-sexp-jump-namespace ()
;; (interactive)
;; (let ((target-ns (thing-at-point 'word t)))
;; (projectile-find-matching-file (string-join (s-split "\\." target-ns) "/"))))
(let ((evil-sexp-map-list `(("b" . sp-forward-barf-sexp)
("B" . sp-backward-barf-sexp)
("c" . evil-sexp-comment-sexp)
("C" . evil-sexp-uncomment-sexp)
("e" . evil-sexp-wrap-element)
("i" . evil-sexp-insert-at-end)
("I" . evil-sexp-insert-at-start)
("o" . evil-sexp-raise-sexp)
("O" . sp-raise-sexp)
("s" . sp-forward-slurp-sexp)
("S" . sp-backward-slurp-sexp)
("w" . evil-sexp-wrap-sexp)
("W" . evil-sexp-unwrap-sexp)
("=" . evil-sexp-indent-list)
(">" . evil-sexp-transpose-forward)
("<" . evil-sexp-transpose-backward)))
(evil-sexp-jump-map-list `(("d" . evil-sexp-jump-definition)
("c" . evil-sexp-jump-call)
("s" . evil-sexp-jump-rf-subscription)
("e" . evil-sexp-jump-rf-event)))
(evil-sexp-mappings (make-sparse-keymap))
(evil-sexp-jump-mappings (make-sparse-keymap)))
(dolist (current-mapping evil-sexp-jump-map-list)
(let ((key (car current-mapping))
(cmd (cdr current-mapping)))
(define-key evil-sexp-jump-mappings (kbd key) cmd)))
(dolist (current-mapping evil-sexp-map-list)
(let ((key (car current-mapping))
(cmd (cdr current-mapping)))
(define-key evil-sexp-mappings (kbd key) cmd)))
(spacemacs/set-leader-keys "k" evil-sexp-mappings)
(spacemacs/set-leader-keys "kj" evil-sexp-jump-mappings))
(evil-define-text-object evil-outer-sexp-form (count &optional beg end type)
(let ((current-char (char-after)))
(when (or (= current-char ?\()
(= current-char ?\[)
(= current-char ?\{))
(forward-char)))
(let ((sexp (sp-get-enclosing-sexp)))
(list (sp-get sexp :beg) (sp-get sexp :end))))
(define-key evil-outer-text-objects-map "f" 'evil-outer-sexp-form)
(evil-define-text-object evil-inner-sexp-form (count &optional beg end type)
(let ((current-char (char-after)))
(when (or (= current-char ?\()
(= current-char ?\[)
(= current-char ?\{))
(forward-char)))
(let ((sexp (sp-get-enclosing-sexp)))
(list (+ (sp-get sexp :beg) 1) (- (sp-get sexp :end) 1))))
(define-key evil-inner-text-objects-map "f" 'evil-inner-sexp-form)
(defun kill-dired-buffers ()
(interactive)
(mapc (lambda (buffer)
(when (eq 'dired-mode (buffer-local-value 'major-mode buffer))
(kill-buffer buffer)))
(buffer-list)))
(defun make-buffer (&optional window)
"Generate a new buffer like `*new*' and set it to be the buffer for either
WINDOW or the currently-selected window."
(interactive)
(let ((target-window (or window (selected-window))))
(set-window-buffer target-window (generate-new-buffer "*new*"))))
(defun make-markdown-buffer (&optional window)
"Generate a new buffer like `*new*' and set it to be the buffer for either
WINDOW or the currently-selected window, then set `markdown-mode'"
(interactive)
(let ((target-window (or window (selected-window)))
(target-buffer (generate-new-buffer "*new*")))
(set-window-buffer target-window target-buffer)
(with-current-buffer target-buffer
(markdown-mode))))
(defun make-org-buffer (&optional window)
"Generate a new buffer like `*new*' and set it to be the buffer for either
WINDOW or the currently-selected window, then set `markdown-mode'"
(interactive)
(let ((target-window (or window (selected-window)))
(target-buffer (generate-new-buffer "*new*")))
(set-window-buffer target-window target-buffer)
(with-current-buffer target-buffer
(org-mode))))
(defun make-frame-with-new-buffer ()
"Create a new frame displaying only a `*new*' buffer. The window for that
buffer is in its own, new eyebrowse window config."
(interactive)
(select-frame (make-frame))
(eyebrowse-create-window-config)
(make-buffer (selected-window)))
(defun make-frame-with-new-markdown-buffer ()
"Identical to `make-frame-with-new-buffer', but the created buffer is set
to use `markdown-mode'."
(interactive)
(select-frame (make-frame))
(eyebrowse-create-window-config)
(make-markdown-buffer (selected-window)))
(defun org-mode-with-hard-wrap ()
"Activate both org-mode and auto-fill-mode, setting the text width to 80."
(interactive)
(org-mode 1)
(setq fill-column 80)
(turn-on-auto-fill))
(defun git-diff-project ()
(interactive)
(let ((git-buffer (or (get-buffer "*git*") (generate-new-buffer "*git*"))))
(with-current-buffer git-buffer
(read-only-mode 0)
(erase-buffer)
(diff-mode)
(read-only-mode 1)
(buffer-local-set-key "q" 'quit-window) )
(start-process "git-diff" git-buffer "git" "diff")
(split-window)
(switch-to-buffer git-buffer)
(evil-goto-first-line)))
(defun git-diff-file (&optional buffer)
(interactive)
(let ((target-file (buffer-file-name (or buffer (current-buffer))))
(git-buffer (or (get-buffer "*git*") (generate-new-buffer "*git*"))))
(with-current-buffer git-buffer
(read-only-mode 0)
(erase-buffer)
(diff-mode)
(read-only-mode 1)
(buffer-local-set-key "q" (lambda () (quit-window t)) git-buffer))
(start-process "git-diff" git-buffer "git" "diff" target-file)
(split-window)
(switch-to-buffer git-buffer)
(evil-goto-first-line)))
(let ((evil-git-map-list `(("d" . git-diff-file)
("D" . git-diff-project)
("n" . git-gutter:next-hunk)
("p" . git-gutter-previous-hunk)))
(evil-git-mappings (make-sparse-keymap)))
(dolist (current-mapping evil-git-map-list)
(let ((key (car current-mapping))
(cmd (cdr current-mapping)))
(define-key evil-git-mappings (kbd key) cmd)))
(spacemacs/set-leader-keys "g" evil-git-mappings))
(use-package smartparens
:config
(sp-pair "`" nil :actions :rem))
(use-package rainbow-delimiters
:config
(progn
(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode)
(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)
(add-hook 'clojurescript-mode-hook 'rainbow-delimiters-mode)))
(use-package volatile-highlights
:config
(set-face-background 'vhl/default-face "khaki1"))
(use-package evil-quickscope
:config
(progn
(set-face-foreground 'evil-quickscope-first-face "dodger blue")
(set-face-foreground 'evil-quickscope-second-face "medium slate blue")))
(setq ivy-count-format ""
ivy-on-del-error-function nil) ;; default: 'minibuffer-keyboard-quit; don't need it
;; TBH I have no idea why [escape] works but (kbd "ESC") does not; but it works.
(mapc (lambda (km) (define-key km [escape] 'minibuffer-keyboard-quit))
(list ivy-minibuffer-map
counsel-describe-map
minibuffer-local-map
minibuffer-local-ns-map
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-map))
;; Ensure _ and - are not word boundaries, the latter only in LISP modes
(let ((add-underscore-as-word (lambda () (modify-syntax-entry ?_ "w"))))
(mapc (lambda (h) (add-hook h add-underscore-as-word))
'(text-mode-hook
prog-mode-hook)))
(let ((add-lisp-symbols-to-words #'(lambda ()
(modify-syntax-entry ?< "w")
(modify-syntax-entry ?> "w")
(modify-syntax-entry ?? "w")
(modify-syntax-entry ?! "w")
(modify-syntax-entry ?: "w")
(modify-syntax-entry ?/ "w")
(modify-syntax-entry ?- "w"))))
(add-hook 'clojure-mode-hook add-lisp-symbols-to-words)
(add-hook 'emacs-lisp-mode-hook add-lisp-symbols-to-words)
(add-hook 'lisp-mode-hook add-lisp-symbols-to-words))
(add-hook 'prog-mode-hook (lambda () (adaptive-wrap-prefix-mode)))
;; Expand all org-mode links, so =[[some-link]]= doesn't end up being rendered as just =some-link=
(defun turn-on-org-mode-literal-links ()
"Enable literal link display in org-mode."
(interactive)
(org-remove-from-invisibility-spec '(org-link)))
(add-hook 'org-mode-hook 'turn-on-org-mode-literal-links)
;; Change how dired handles mouse clicks -- clicking a dir and browsing it in another window instead of
;; the one you're currently in is super obnoxious, because it just leaves windows all over the place.
;; So here is a new function, based on the "other window" version, and then it replaces the original in
;; the `dired-mode-map'
(defun dired-mouse-find-file (event)
"In Dired, visit the file or directory name you clicked on. Unlike `dired-mouse-find-file-other-window',
this function uses the current window."
(interactive "e")
(let (window pos file)
(save-excursion
(setq window (posn-window (event-end event))
pos (posn-point (event-end event)))
(if (not (windowp window))
(error "No file chosen"))
(set-buffer (window-buffer window))
(goto-char pos)
(setq file (dired-get-file-for-visit)))
(if (file-directory-p file)
(or (and (cdr dired-subdir-alist)
(dired-goto-subdir file))
(dired file))
(find-file (file-name-sans-versions file t)))))
(define-key dired-mode-map [mouse-2] 'dired-mouse-find-file)
)
;; Do not write anything past this comment. This is where Emacs will
;; auto-generate custom variable definitions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment