Skip to content

Instantly share code, notes, and snippets.

@pkkm
pkkm / init.el
Last active December 14, 2015 10:29
Recursively load all Elisp files in a directory.
(defun load-recursively (dir-to-load &optional exclude-list)
"Load all .el files in DIR-TO-LOAD and its subdirectories (and their subdirectories, ...).
Exclude files (or directories) that are in EXCLUDE-LIST."
(let ((excluded-file-names (append exclude-list '("." ".."))))
(dolist (file (directory-files dir-to-load 'absolute-file-names))
(unless (member (file-relative-name file dir-to-load) excluded-file-names)
(cond
((file-directory-p file) (load-recursively file exclude-list))
((string= (file-name-extension file) "el") (load file)))))))
@pkkm
pkkm / init.el
Last active December 14, 2015 17:48
Make ESC quit prompts in minibuffer.
(mapc (lambda (keymap) (define-key keymap [escape] 'keyboard-escape-quit))
(list minibuffer-local-map
minibuffer-local-ns-map
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-map))
@pkkm
pkkm / modeline.el
Created March 28, 2013 16:53
My modeline config.
; Modeline with left, center and right aligned parts (using powerline).
(package-ensure-installed 'powerline)
(setq-default mode-line-format
'((:eval
(let*
;;; Modeline sections.
@pkkm
pkkm / add-hook-one-time.el
Created April 21, 2013 11:48
The `add-hook-one-time` macro that doesn't work and some evaluation results.
;;; The macro:
(defmacro add-hook-one-time (hook function)
"Add FUNCTION to HOOK. Remove it after its first execution."
(let ((wrapper-function (make-symbol "wrapper-function-symbol")))
`(progn
(defun ,wrapper-function ()
"Wrapper function that will be executed only once, and then removed from the hook."
(funcall ,function)
(remove-hook ,hook ,wrapper-function))
(add-hook ,hook ,wrapper-function))))
@pkkm
pkkm / ido-sort-by-mtime.el
Created April 24, 2013 19:35
Sort Ido's file list by modification time.
;;; Utilities for file modification time.
(require 'cl)
(defun file-modtime (file)
"Get the last modification time of FILE.
If FILE cannot be read, return nil."
(let ((attributes (file-attributes file)))
(if attributes
(cl-sixth attributes)
nil)))
@pkkm
pkkm / ido-sort-mtime.el
Last active December 16, 2015 16:19
Minor mode for sorting Ido's file list by modification time.
;;; ido-sort-mtime.el --- Sort Ido's file list by modification time
;; Copyright (C) 2013 Paweł Kraśnicki
;; Author: Paweł Kraśnicki
;; Created: 24 Apr 2013
;; Version: 0.1
;; Keywords: convenience, files
;; This program is free software; you can redistribute it and/or modify
@pkkm
pkkm / clipboard.el
Created May 5, 2013 20:53
When running in a terminal, use the `xclip' utility for copying from and pasting to the X clipboard.
;; Terminal (with XClip): Use CLIPBOARD for explicit cuts. Don't use PRIMARY.
(when (and (not window-system)
(getenv "DISPLAY")
(executable-find "xclip"))
;; On explicit yank, copy to CLIPBOARD.
(defun xclip-copy-to-clipboard (text)
"Copy TEXT to X's clipboard, using the `xclip` utility."
(let* ((process-connection-type nil)
(proc (start-process "xclip" nil "xclip" "-selection" "clipboard")))
(process-send-string proc text)
@pkkm
pkkm / cleaner-minor-modes.el
Last active December 17, 2015 01:49
Change certain minor mode names in the modeline.
;;; Change certain minor mode names.
(defvar mode-line-cleaner-minor-mode-alist
;; Some greek characters: ς ε ρ τ υ θ ι ο π α σ δ φ γ η ξ κ λ ζ χ ψ ω β ν μ
`((writegood-mode " WriteGood")
(auto-complete-mode " α")
(yas-minor-mode " γ")
(paredit-mode " Φ")
(volatile-highlights-mode " υ")
(undo-tree-mode ""))
@pkkm
pkkm / vim-dvorak.el
Created May 12, 2013 11:56
Vim motions for the Dvorak keyboard.
;;; Remap basic motions to [htns] (for a Dvorak keyboard).
;;; Also remap some related keys.
(require 'conf/evil)
;; Left, down, up, right: [htns] (previously: [hjkl]).
(define-key evil-motion-state-map "h" 'evil-backward-char)
(define-key evil-motion-state-map "t" 'evil-next-line)
(define-key evil-motion-state-map "n" 'evil-previous-line)
(define-key evil-motion-state-map "s" 'evil-forward-char) (define-key evil-normal-state-map "s" nil)
@pkkm
pkkm / smartparens.el
Created July 25, 2013 13:05
My bindings for smartparens.
;;; Bindings.
(define-key sp-keymap (kbd "C-M-f") 'sp-forward-sexp)
(define-key sp-keymap (kbd "C-M-b") 'sp-backward-sexp)
(define-key sp-keymap (kbd "C-M-d") 'sp-down-sexp)
(define-key sp-keymap (kbd "C-M-a") 'sp-backward-down-sexp)
(define-key sp-keymap (kbd "C-S-a") 'sp-beginning-of-sexp)
(define-key sp-keymap (kbd "C-S-d") 'sp-end-of-sexp)