From b6c38b0d62100bd20c3e4249537ccfe61b8e9de1 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 30 Dec 2013 16:54:14 +0100 Subject: Reorder functions --- .emacs.d/init.el | 2162 +++++++++++++++++++++++++++--------------------------- 1 file changed, 1078 insertions(+), 1084 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 6eff826..7f5c07c 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -110,219 +110,195 @@ MODE1 is enabled and vice-versa." (defvar sql-prompt-regexp) (defvar whitespace-style) -;;;; defun -(eval-and-compile - (defun loadpath-add-and-autoload (path) - "Add PATH to `load-path' and load a `loaddefs.el' if it exists." - (add-to-list 'load-path path) - (let ((loaddefs (concat path "/loaddefs.el"))) - (when (file-exists-p loaddefs) - (load loaddefs)))) - - (mapc #'loadpath-add-and-autoload - '("~/.emacs.d/site-lisp" "~/projects/emacs/pony-mode/src" - "~/.emacs.d/vendor-lisp/org/lisp" - "~/.emacs.d/vendor-lisp/org/contrib/lisp" - "~/.emacs.d/vendor-lisp/mozrepl" - "~/.emacs.d/vendor-lisp/eap" "/usr/share/emacs/site-lisp"))) - -;;;; aliases +;;;; Functions -(defalias 'yes-or-no-p 'y-or-n-p) -(defalias 'dabbrev-expand 'hippie-expand) - -;;;; uniquify - -(require 'uniquify) +(defun oni:after-save-func () + "Function for `after-save-hook'." + (executable-make-buffer-file-executable-if-script-p) + (let* ((dom-dir (locate-dominating-file (buffer-file-name) "Makefile")) + (TAGSp (not (string= "" (shell-command-to-string + (concat "grep \"^TAGS:\" " dom-dir "Makefile")))))) + (when (and dom-dir TAGSp) + (shell-command + (concat "make -C " dom-dir " TAGS >/dev/null 2>&1"))))) -(stante-after uniquify - (setq uniquify-buffer-name-style 'post-forward)) +(defun oni:appt-display-window-and-jabber (min-to-app new-time appt-msg) + "Send a message to my phone jabber account." + (jabber-send-message (car jabber-connections) "phone@ryuslash.org" + nil (format "%s%s (in %s minutes)" + new-time appt-msg min-to-app) nil) + (appt-disp-window min-to-app new-time appt-msg)) -;;;; gnus +(defun init-augment-sql-prompt () + "Add the MariaDB prompt to the `sql-prompt-regexp'." + (if (eq sql-product 'mysql) + (setq sql-prompt-regexp + (rx (and line-start + (or "mysql" + (and "MariaDB [" (1+ nonl) "]")) + "> "))))) -(setq gnus-init-file "~/.emacs.d/site-lisp/gnus-init") +(defun oni:before-save-func () + "Function for `before-save-hook'." + (if (eq major-mode 'html-mode) + (oni:replace-html-special-chars)) + (if (not (eq major-mode 'markdown-mode)) + (delete-trailing-whitespace))) -;;;; Visual cues +(defun oni:c-mode-func () + "Function for `c-mode-hook'." + (local-set-key [f9] 'compile) + (local-set-key "\C-j" 'oni:newline-and-indent)) -(turn-off menu-bar-mode scroll-bar-mode tool-bar-mode blink-cursor-mode - column-number-mode line-number-mode tooltip-mode) +(defun change-number-at-point (change-func) + "Use CHANGE-FUNC to change the number at `point'." + (let ((num (number-to-string (funcall change-func (number-at-point)))) + (bounds (bounds-of-thing-at-point 'word))) + (save-excursion + (delete-region (car bounds) (cdr bounds)) + (insert num)))) -(let ((theme (if (equal system-name "drd") 'yoshi 'leuven))) - (let ((setp (not (daemonp)))) - (defun init-set-theme (frame) - "Try to set the theme for the current (first) frame." - (ignore frame) - (unless setp - (run-at-time .1 nil (lambda () (setq setp (load-theme theme t))))))) +(defun oni:change-prev-case (num dir) + (let ((regfunc (if (eq dir 'up) 'upcase-region 'downcase-region)) + (wordfunc (if (eq dir 'up) 'upcase-word 'downcase-word))) + (if (> num 1) + (funcall regfunc (point) (- (point) num)) + (funcall wordfunc -1)))) - (if (daemonp) - (add-hook 'after-make-frame-functions #'init-set-theme) - (eval-after-init (load-theme theme t)))) +(defun oni:close-client-window () + "Close a client's frames." + (interactive) + (server-save-buffers-kill-terminal nil)) -;;;; eww +(defun oni:color-for (object) + "Generate a hex color by taking the first 6 characters of OBJECT's MD5 sum." + (format "#%s" (substring (md5 object) 0 6))) -(stante-after eww - (setq eww-download-path ; Don't go to ~/Downloads - "~/downloads/")) +(defun oni:css-mode-func () + "Function for `css-mode-hook'." + (local-set-key "\C-j" 'oni:newline-and-indent)) -;;;; Typography +(defun oni:current-dir-in-buffer-name () + (let ((branch + (shell-command-to-string + "git branch --contains HEAD 2>/dev/null | sed -e '/^[^*]/d'"))) + (rename-buffer + (setq eshell-buffer-name + (format "%s%s:%s" system-name + (if (not (string= branch "")) + (format "(%s)" (substring branch 2 -1)) + "") + (oni:shorten-dir + (abbreviate-file-name (eshell/pwd)))))))) -(defun init-locally-enable-double-spaces () - "Specify that two spaces end a sentence in the current buffer." - (setq-local sentence-end-double-space t)) +(defun oni:current-jabber-status () + "Return a string representing the current jabber status." + (or (and (not *jabber-connected*) "Offline") + (and (not (string= *jabber-current-status* "")) + *jabber-current-status*) + "Online")) -;; Use double spaces to end lines in Emacs Lisp. The checkdoc -;; function starts complaining if you don't. -(add-hook 'emacs-lisp-mode-hook #'init-locally-enable-double-spaces) +(defun decrease-number-at-point () + "Take the number at `point' and replace it with it decreased by 1." + (interactive) + (change-number-at-point #'1-)) -;;;; Symbols +(defun oni:diary-display-func () + "Function for `diary-display-hook'." + (diary-fancy-display)) -(defun init-set-emacs-lisp-symbols () - "Set a few extra UTF-8 symbols for use in emacs-lisp." - (when (boundp 'prettify-symbols-alist) - (setq prettify-symbols-alist - (append prettify-symbols-alist - '(("<=" . ?≤) - (">=" . ?≥) - ("sqrt" . ?√)))))) +(defun oni:downcase-prev (num) + (interactive "p") + (oni:change-prev-case num 'down)) +(defun enable (functions) + "Set the `disabled' property for each item in FUNCTIONS to nil." + (mapc #'(lambda (f) (put f 'disabled nil)) functions)) -(defun init-set-python-symbols () - "Set a few extra UTF-8 symbols for use in python." - (when (boundp 'prettify-symbols-alist) - (setq prettify-symbols-alist - '(("lambda" . ?λ) - ("<=" . ?≤) - (">=" . ?≥) - ("!=" . ?≠))))) +(defun oni:eshell-handle-url () + (save-excursion + (goto-char eshell-last-output-start) + (while (re-search-forward + "http://[^ \n]+" eshell-last-output-end :noerror) + (make-button (match-beginning 0) (match-end 0) + 'action (lambda (button) + (browse-url (button-label button))))))) -(add-hook 'emacs-lisp-mode-hook #'init-set-emacs-lisp-symbols) -(add-hook 'lisp-mode-hook #'init-set-emacs-lisp-symbols) -(add-hook 'python-mode-hook #'init-set-python-symbols) +(defun oni-eshell-prompt () + "Show a pretty shell prompt." + (let ((status (if (zerop eshell-last-command-status) ?+ ?-))) + (concat + (propertize (char-to-string status) + 'face `(:foreground ,(if (= status ?+) + "green" + "red"))) + "> "))) -(when (fboundp 'prettify-symbols-mode) - (add-hook 'prog-mode-hook 'prettify-symbols-mode)) +(defun oni:go-mode-func () + "Function for `go-mode-hook'." + (setq indent-tabs-mode nil) + (local-set-key "\C-j" 'oni:newline-and-indent)) -(stante-after slime - (setq slime-lisp-implementations - '((sbcl ("sbcl" "--noinform") :coding-system utf-8-unix) - (clisp ("clisp") :coding-system utf-8-unix)) - slime-default-lisp 'sbcl)) +(defun oni:haskell-mode-func () + "Function for `haskell-mode-hook'." + (turn-on-haskell-indentation)) -(set-fontset-font "fontset-default" 'unicode - (font-spec :family "Liberation Mono" - :width 'normal - :size 12.4 - :weight 'normal)) +(defun increase-number-at-point () + "Take the number at `point' and replace it with it increased by 1." + (interactive) + (change-number-at-point #'1+)) -(defun sort-imports () - "Sort python multiline imports using `()'." +(defun indent-defun () + "Indent the current defun." (interactive) (save-excursion - (sort-lines nil (1+ (search-backward "(")) - (1- (search-forward ")"))))) + (mark-defun) + (indent-region (region-beginning) (region-end)))) -(stante-after simple - (define-key special-mode-map "z" #'kill-this-buffer)) +(defun oni:indent-shift-left (start end &optional count) + "Rigidly indent region. +Region is from START to END. Move +COUNT number of spaces if it is non-nil otherwise use +`tab-width'." + (interactive + (if mark-active + (list (region-beginning) (region-end) current-prefix-arg) + (list (line-beginning-position) + (line-end-position) + current-prefix-arg))) + (if count + (setq count (prefix-numeric-value count)) + (setq count tab-width)) + (when (> count 0) + (let ((deactivate-mark nil)) + (save-excursion + (goto-char start) + (while (< (point) end) + (if (and (< (current-indentation) count) + (not (looking-at "[ \t]*$"))) + (error "Can't shift all lines enough")) + (forward-line)) + (indent-rigidly start end (- count)))))) -(defun stumpwm-command (cmd) - "Execute CMD in stumpwm." - (call-process init-stumpish-program nil nil nil cmd)) +(defun oni:indent-shift-right (start end &optional count) + "Indent region between START and END rigidly to the right. +If COUNT has been specified indent by that much, otherwise look at +`tab-width'." + (interactive + (if mark-active + (list (region-beginning) (region-end) current-prefix-arg) + (list (line-beginning-position) + (line-end-position) + current-prefix-arg))) + (let ((deactivate-mark nil)) + (if count + (setq count (prefix-numeric-value count)) + (setq count tab-width)) + (indent-rigidly start end count))) -(defadvice windmove-do-window-select - (around init-windmove-stumpwm activate) - "If no window can be moved to, move stumpwm." - (condition-case err - ad-do-it - (error (stumpwm-command (format "move-focus %s" (ad-get-arg 0)))))) - -(global-set-key (kbd "C-c S") #'split-window-right) -(global-set-key (kbd "C-c s") #'split-window-below) -(global-set-key (kbd "C-c Q") #'delete-other-windows) -(global-set-key (kbd "C-c R") #'delete-window) - -(add-to-list 'load-path "/usr/lib/node_modules/tern/emacs/") -(autoload 'tern-mode "tern" nil t) - -(stante-after tern - (require 'tern-auto-complete) - (tern-ac-setup)) - -(add-hook 'js2-mode-hook #'tern-mode) - -(defun init-switch-to-other-buffer () - "Switch to the most recently viewed buffer." - (interactive) - (switch-to-buffer (other-buffer))) - -(global-set-key (kbd "C-. C-.") #'init-switch-to-other-buffer) - -(stante-after woman - (setq woman-fill-column 72)) - -(add-hook 'c-mode-hook #'smartparens-strict-mode) - -(autoload 'moz-minor-mode "moz" nil t) -(add-hook 'javascript-mode-hook 'moz-minor-mode) - -(defun change-number-at-point (change-func) - "Use CHANGE-FUNC to change the number at `point'." - (let ((num (number-to-string (funcall change-func (number-at-point)))) - (bounds (bounds-of-thing-at-point 'word))) - (save-excursion - (delete-region (car bounds) (cdr bounds)) - (insert num)))) - -(defun decrease-number-at-point () - "Take the number at `point' and replace it with it decreased by 1." - (interactive) - (change-number-at-point #'1-)) - -(defun increase-number-at-point () - "Take the number at `point' and replace it with it increased by 1." - (interactive) - (change-number-at-point #'1+)) - -(global-set-key (kbd "C-c -") #'decrease-number-at-point) -(global-set-key (kbd "C-c +") #'increase-number-at-point) - -(autoload 'jabber-connect "jabber" nil t) -(autoload 'jabber-message-libnotify "jabber-libnotify") -(autoload 'jabber-muc-libnotify "jabber-libnotify") -(autoload 'jabber-send-message "jabber-chat") -(autoload 'notifications-notify "notifications") -(autoload 'php-mode "php-mode" nil t) -(autoload 'po-mode "po-mode" nil t) -(autoload 'pony-mode "pony-mode" nil t) -(autoload 'sawfish-mode "sawfish" nil t) -(autoload 'server-running-p "server") -(autoload 'tagedit-mode "tagedit" nil t) -(autoload 'w3m-bookmark-view "w3m" nil t) -(autoload 'w3m-goto-url "w3m" nil t) -(autoload 'xmodmap-mode "xmodmap-mode" nil t) - -(defadvice org-agenda-redo (after ext:org-agenda-redo-add-appts) - "Pressing `r' on the agenda will also add appointments." - (progn - (setq appt-time-msg-list nil) - (org-agenda-to-appt))) - -(defadvice term-handle-exit (after oni:kill-buffer-after-exit activate) - "Kill the term buffer if the process finished." - (kill-buffer (current-buffer))) - -(defun init-augment-sql-prompt () - "Add the MariaDB prompt to the `sql-pomrpt-regexp'." - (if (eq sql-product 'mysql) - (setq sql-prompt-regexp - (rx (and line-start - (or "mysql" - (and "MariaDB [" (1+ nonl) "]")) - "> "))))) - -(defun init-eshell-C-d () - "Either call `delete-char' interactively or quit." - (interactive) +(defun init-eshell-C-d () + "Either call `delete-char' interactively or quit." + (interactive) (condition-case err (call-interactively #'delete-char) (error (if (and (eq (car err) 'end-of-buffer) @@ -330,74 +306,76 @@ MODE1 is enabled and vice-versa." (kill-buffer) (signal (car err) (cdr err)))))) +(defun oni:java-mode-func () + "Function for `java-mode-hook'." + (local-set-key "\C-j" 'oni:newline-and-indent)) + +(defun oni:js-mode-func () + "Function for `js-mode-hook'." + (local-set-key "\C-j" 'oni:newline-and-indent)) + +(defun oni:js2-mode-func () + "Function for `js2-mode-hook'." + (oni:js-mode-func)) + +(defun init-locally-enable-double-spaces () + "Specify that two spaces end a sentence in the current buffer." + (setq-local sentence-end-double-space t)) + +(defun oni:lua-mode-func() + "Function for `lua-mode-hook'." + (local-unset-key (kbd ")")) + (local-unset-key (kbd "]")) + (local-unset-key (kbd "}"))) + (defun init-make-readable () "Make non-programming buffers a little more readable." (setq line-spacing .2)) +(defun oni:markdown-mode-func () + "Function for `markdown-mode-hook'." + (setq-local whitespace-style '(face trailing))) + (defun init-maybe-fci-mode () "Turn on `fci-mode' if there is a filename for the buffer." (when (buffer-file-name) (fci-mode))) -(defun init-set-keys-for-dired () - "Set somee keybindings for `dired'." - (local-set-key (kbd "E") #'wdired-change-to-wdired-mode)) - -(defun init-set-keys-for-eshell () - "Set some keybindings for `eshell'." - (local-set-key (kbd "C-d") #'init-eshell-C-d)) - -(defun init-set-keys-for-hy () - "Set some keybindings for `hy-mode'." - (local-set-key (kbd "{") #'paredit-open-curly) - (local-set-key (kbd "}") #'paredit-close-curly)) - -(defun init-set-keys-for-tagedit () - "Set some keybindings for `tagedit-mode'." - (local-set-key (kbd "M-k") #'tagedit-kill-attribute)) - -(defun init-set-python-imenu-function () - "Set the `imenu-create-index-function' variable. - -For `python-mode' I prefer `python-imenu-create-flat-index'." - (setq imenu-create-index-function #'python-imenu-create-flat-index)) - -(eval-and-compile - (defun add-hooks (hooks function &optional append local) - "`add-hook' for each in HOOKS." - (mapcar (lambda (h) - `(add-hook (quote ,h) ,function ,append ,local)) - hooks)) - - (defun add-mode-hooks (modes function &optional append local) - "`add-hooks' with MODES renamed to mode-mode-hook." - (let ((mode-names (mapcar #'make-mode-hook-name modes))) - (add-hooks mode-names function append local)))) - -(defun enable (functions) - "Set the `disabled' property for each item in FUNCTIONS to nil." - (mapc #'(lambda (f) (put f 'disabled nil)) functions)) - -(defun hostname () - "Get the current machine's hostname." - (substring (shell-command-to-string "hostname") 0 -1)) - -(defun indent-defun () - "Indent the current defun." - (interactive) - (save-excursion - (mark-defun) - (indent-region (region-beginning) (region-end)))) +(defun oni:mini-fix-timestamp-string (date-string) + "A minimal version of Xah Lee's `fix-timestamp-string'. +Turn DATE-STRING into something else that can be worked with in +code. Found at http://xahlee.org/emacs/elisp_parse_time.html" + (setq date-string (replace-regexp-in-string "Jan" "01" date-string) + date-string (replace-regexp-in-string "Feb" "02" date-string) + date-string (replace-regexp-in-string "Mar" "03" date-string) + date-string (replace-regexp-in-string "Apr" "04" date-string) + date-string (replace-regexp-in-string "May" "05" date-string) + date-string (replace-regexp-in-string "Jun" "06" date-string) + date-string (replace-regexp-in-string "Jul" "07" date-string) + date-string (replace-regexp-in-string "Aug" "08" date-string) + date-string (replace-regexp-in-string "Sep" "09" date-string) + date-string (replace-regexp-in-string "Oct" "10" date-string) + date-string (replace-regexp-in-string "Nov" "11" date-string) + date-string (replace-regexp-in-string "Dec" "12" date-string)) + (string-match + "^\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{4\\}\\)$" + date-string) + (format "%s-%s-%s" + (match-string 3 date-string) + (match-string 2 date-string) + (match-string 1 date-string))) -(eval-and-compile - (defun level (lst) - (let ((lsts (mapcar (lambda (l) (if (listp l) l (list l))) lst))) - (apply #'append lsts)))) +(defun oni:mode-line-current-song () + "Extract current song information from a path. -(eval-and-compile - (defun make-mode-hook-name (mode) - "Get the hook name for MODE." - (intern (concat (symbol-name mode) "-mode-hook")))) +EMMS only shows me the absolute path of a song, this function +extracts the parts I want to know about." + (let ((song (emms-track-name (emms-playlist-current-selected-track)))) + (if (string-match "\\([^/]+\\)/\\([0-9]\\{4\\}\\) - \\(.+\\)/\\([0-9]\\{2,3\\}\\) - \\(.+\\)\\..\\{3,4\\}$" song) + (let ((band (substring song (match-beginning 1) (match-end 1))) + (title (substring song (match-beginning 5) (match-end 5)))) + (format "[%s - %s]" band title)) + song))) (defun move-beginning-of-dwim () "Move to beginning of line either after indentation or before." @@ -407,935 +385,998 @@ For `python-mode' I prefer `python-imenu-create-flat-index'." (if (= start (point)) (move-beginning-of-line 1)))) -(defun oni-eshell-prompt () - "Show a pretty shell prompt." - (let ((status (if (zerop eshell-last-command-status) ?+ ?-))) - (concat - (propertize (char-to-string status) - 'face `(:foreground ,(if (= status ?+) - "green" - "red"))) - "> "))) +(defun oni:move-end-of-dwim () + "Move to end of line, either before any comments or after." + (interactive) + (let ((start (point)) + (eolpos (line-end-position))) + (beginning-of-line) + (if (and comment-start + (not (looking-at (regexp-quote comment-start))) + (comment-search-forward eolpos t)) + (progn + (search-backward-regexp (concat "[^ \t" comment-start "]")) + (forward-char) -(defun raise-eshell () - "Start or switch back to `eshell'. + (when (or (bolp) + (= start (point))) + (end-of-line))) + (end-of-line)))) -Also change directories to current working directory." - (interactive) - (let ((dir (file-name-directory - (or (buffer-file-name) "~/"))) - (hasfile (not (eq (buffer-file-name) nil))) - (started (and (boundp 'eshell-buffer-name) eshell-buffer-name - (buffer-live-p (get-buffer eshell-buffer-name))))) - (eshell) - (when (and hasfile (eq eshell-process-list nil)) - (eshell/cd dir) - (when started - (eshell-reset))))) +(defun oni:myepisodes-formatter (plist) + "Format RSS items from MyEpisodes as org tasks. +PLIST contains all the pertinent information." + (let ((str (plist-get plist :title))) + (string-match + "^\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]$" + str) + (let* ((title (match-string 1 str)) + (episode (match-string 2 str)) + (name (match-string 3 str)) + (date (oni:mini-fix-timestamp-string (match-string 4 str)))) + (format "* ACQUIRE %s %s - %s \n SCHEDULED: <%s>" + title episode name date)))) -(defun reload-buffer () - "Reload current buffer." +(defun oni:newline-and-indent () + "`newline-and-indent', but with a twist. +When dealing with braces, add another line and indent that too." (interactive) - (revert-buffer nil t nil)) + (if (and (not (or (= (point) (point-max)) + (= (point) (point-min)))) + (or (and (char-equal (char-before) ?{) + (char-equal (char-after) ?})) + (and (char-equal (char-before) ?\() + (char-equal (char-after) ?\))))) + (save-excursion (newline-and-indent))) + (newline-and-indent)) -(defun set-emacs-lisp-keys () - "Set some keys for `emacs-lisp-mode'." - (local-set-key (kbd "C-.") 'find-function)) +(defun oni:php-mode-func () + "Function for `php-mode-hook'." + (local-set-key "\C-j" 'oni:newline-and-indent) + (c-set-offset 'arglist-intro '+) + (c-set-offset 'arglist-close '0) + (setq-local fci-rule-column 80)) -(defun set-smartparens-keys () - "Set some keys for `smartparens-mode'." - (local-set-key [remap backward-delete-char] 'sp-backward-delete-char) - (local-set-key [remap delete-char] 'sp-delete-char) - (local-set-key [remap kill-word] 'sp-kill-word) - (local-set-key [remap backward-kill-word] 'sp-backward-kill-word) - (local-set-key (kbd "") 'sp-forward-barf-sexp) - (local-set-key (kbd "") 'sp-forward-slurp-sexp) - (local-set-key (kbd "M-J") 'sp-join-sexp) - (local-set-key (kbd "M-S") 'sp-split-sexp)) +(defun oni:prog-mode-func () + "Function for `prog-mode-hook'." + (setq-local comment-auto-fill-only-comments t)) -(defun turn-on-compilation-shell-for-pony () - "Turn on option `compilation-shell-minor-mode' for `pony-minor-mode'." - (add-hook 'pony-minor-mode-hook 'compilation-shell-minor-mode nil t)) +(defun oni:python-mode-func () + "Function for `python-mode-hook'." + (local-set-key (kbd "C->") 'python-indent-shift-right) + (local-set-key (kbd "C-<") 'python-indent-shift-left) + (set (make-local-variable 'electric-indent-chars) nil) + (setq fci-rule-column 79 + fill-column 72) + (setq-local whitespace-style '(tab-mark))) -(stante-after appt - (setq appt-disp-window-function #'oni:appt-display-window-and-jabber) - (setq appt-display-diary nil)) +(defun oni:raise-ansi-term (arg) + "Create or show an `ansi-term' buffer." + (interactive "P") + (let ((buffer (get-buffer "*ansi-term*"))) + (if (and buffer (not arg)) + (switch-to-buffer buffer) + (ansi-term (getenv "SHELL"))))) -(stante-after "bindings" - (setq mode-line-default-help-echo "")) +(defun raise-eshell () + "Start or switch back to `eshell'. -(stante-after auto-complete - (add-to-list 'ac-modes 'slime-repl-mode) - (setq-default ac-sources '(ac-source-imenu - ac-source-abbrev - ac-source-yasnippet - ac-source-words-in-buffer - ac-source-words-in-same-mode-buffers - ac-source-dictionary - ac-source-functions - ac-source-symbols - ac-source-variables - ac-source-features)) - (setq ac-auto-show-menu nil - ac-use-quick-help nil)) +Also change directories to current working directory." + (interactive) + (let ((dir (file-name-directory + (or (buffer-file-name) "~/"))) + (hasfile (not (eq (buffer-file-name) nil))) + (started (and (boundp 'eshell-buffer-name) eshell-buffer-name + (buffer-live-p (get-buffer eshell-buffer-name))))) + (eshell) + (when (and hasfile (eq eshell-process-list nil)) + (eshell/cd dir) + (when started + (eshell-reset))))) -(stante-after browse-url - (setq browse-url-browser-function 'browse-url-generic) - (setq browse-url-generic-program (getenv "BROWSER"))) +(defun oni:raise-scratch (&optional mode) + "Show the *scratch* buffer. +If called with a universal argument, ask the user which mode to +use. If MODE is not nil, open a new buffer with the name +*MODE-scratch* and load MODE as its major mode." + (interactive (list (if current-prefix-arg + (read-string "Mode: ") + nil))) + (let* ((bname (if mode + (concat "*" mode "-scratch*") + "*scratch*")) + (buffer (get-buffer bname)) + (mode-sym (intern (concat mode "-mode")))) -(stante-after cc-vars - (setq-default c-basic-offset 4) - (setq c-offsets-alist - '((statement-block-intro . +) - (knr-argdecl-intro . 5) - (substatement-open . +) - (substatement-label . 0) - (label . 0) - (statement-case-open . +) - (statement-cont . +) - (arglist-intro . +) - (arglist-close . 0) - (inline-open . 0) - (brace-list-open . +) - (topmost-intro-cont first c-lineup-topmost-intro-cont - c-lineup-gnu-DEFUN-intro-cont)))) + (unless buffer + (setq buffer (generate-new-buffer bname)) + (with-current-buffer buffer + (when (fboundp mode-sym) + (funcall mode-sym)))) -(stante-after compile - (setq compilation-scroll-output t)) + (select-window (display-buffer buffer)))) -(stante-after custom - (setq custom-theme-directory "~/.emacs.d/themes") - ;; (eval-after-init (load-theme 'yoshi t)) - ) +(defun reload-buffer () + "Reload current buffer." + (interactive) + (revert-buffer nil t nil)) -(stante-after desktop - (setq desktop-restore-frames nil) - (setq desktop-load-locked-desktop t) - (setq desktop-clear-preserve-buffers - (append (list (rx (and bol (or (and "+" (1+ nonl)) - "dailies" "work" "tasks" "org" - (or "bookmarks.org" - "contacts.org")) eol)) - (rx (or "*ielm*" "*-jabber-roster-*" "*eshell*" - "*ansi-term*" "*slime-repl sbcl*" - "*slime-events*")) - (rx (and "*" (or "magit" "scratch-") (1+ nonl) - "*")) - (rx (or "irc.freenode.net:6667" - (and "#" (1+ nonl))))) - desktop-clear-preserve-buffers)) - (setq desktop-files-not-to-save - (rx (or (regexp "\\(^/[^/:]*:\\|(ftp)$\\)") - (and "/" (or "dailies" "tasks" "org" "bookmarks.org" - "contacts.org" "work") eol)))) - (add-to-list 'desktop-globals-to-clear 'desktop-dirname)) +(defun oni:replace-html-special-chars () + "Replace special characters with HTML escaped entities." + (oni:replace-occurrences "é" "é")) -(stante-after dired - (add-hook 'dired-mode-hook #'init-set-keys-for-dired)) +(defun oni:replace-occurrences (from to) + "Replace all occurrences of FROM with TO in the current buffer." + (save-excursion + (goto-char (point-min)) + (while (search-forward from nil t) + (replace-match to)))) -(stante-after eap - (setq eap-music-library "/mnt/music") - (setq eap-playlist-library "~/music/playlists")) +(defun oni:request-pull () + "Start a mail to request pulling from a git repository." + (interactive) + (let* ((default-directory + (expand-file-name + (or (locate-dominating-file default-directory ".git") + (magit-read-top-dir nil)))) + (refs (magit-list-interesting-refs magit-uninteresting-refs)) + (from (cdr (assoc (completing-read "From: " refs) refs))) + (url (read-from-minibuffer "Pull URL: ")) + (to (symbol-name (read-from-minibuffer "Up to (HEAD): " + nil nil t nil "HEAD"))) + (patchp (and current-prefix-arg (listp current-prefix-arg)))) + (message "Requesting pull for %s from %s to %s at %s with%s patch" + default-directory from to url (if patchp "" "out")) -(stante-after ediff-wind - (setq ediff-window-setup-function 'ediff-setup-windows-plain)) + (compose-mail + nil (concat + "Requesting pull for " + (file-name-base (directory-file-name default-directory)))) -(stante-after eltuki - (setq eltuki-blog-dir "~/documents/blog")) + (save-excursion + (goto-char (point-max)) + (insert + (shell-command-to-string + (concat "git --git-dir='" default-directory ".git' --work-tree='" + default-directory "' request-pull " (when patchp "-p ") + from " " url " " to)))))) -(stante-after em-prompt - (setq eshell-highlight-prompt nil) - (setq eshell-prompt-function 'oni-eshell-prompt) - (setq eshell-prompt-regexp "^[+-]> ")) +(defun oni:scroll-down-or-prev-page (arg) + "Either scroll down or go to the previous page. -(stante-after em-term - (add-to-list 'eshell-visual-commands "unison")) +Depending on the value of `buffer-narrowed-p'." + (interactive "^P") + (if (buffer-narrowed-p) + (let ((scroll-error-top-bottom nil)) + (condition-case nil + (scroll-down-command arg) + (beginning-of-buffer + (narrow-to-page -1) + (goto-char (point-min))))) + (scroll-down-command arg))) -(stante-after emms - (emms-minimalistic) - (emms-default-players) +(defun oni:scroll-up-or-next-page (arg) + "Either scroll up or go to the next page. - (require 'emms-player-mpd) - (require 'emms-mode-line)) +Depending on the value of `buffer-narrowed-p'." + (interactive "^P") + (if (buffer-narrowed-p) + (let ((scroll-error-top-bottom nil)) + (condition-case nil + (scroll-up-command arg) + (end-of-buffer + (narrow-to-page 1) + (goto-char (point-min))))) + (scroll-up-command arg))) -(stante-after emms-mode-line - (setq emms-mode-line-mode-line-function 'oni:mode-line-current-song) - (emms-mode-line 1)) +(defun oni:self-insert-dwim () + "Execute self insert, but when the region is active call self +insert at the end of the region and at the beginning." + (interactive) + (if (region-active-p) + (let ((electric-pair-mode nil) + (beginning (region-beginning)) + (end (region-end))) + (goto-char end) + (self-insert-command 1) + (save-excursion + (goto-char beginning) + (self-insert-command 1))) + (self-insert-command 1))) -(stante-after emms-player-mpd - (add-to-list 'emms-player-list 'emms-player-mpd) - (setq emms-player-mpd-music-directory "/mnt/music/mp3")) +(defun set-emacs-lisp-keys () + "Set some keys for `emacs-lisp-mode'." + (local-set-key (kbd "C-.") 'find-function)) -(stante-after erc - (setq erc-hide-list '("PART")) - (setq erc-nick "ryuslash")) +(defun init-set-emacs-lisp-symbols () + "Set a few extra UTF-8 symbols for use in emacs-lisp." + (when (boundp 'prettify-symbols-alist) + (setq prettify-symbols-alist + (append prettify-symbols-alist + '(("<=" . ?≤) + (">=" . ?≥) + ("sqrt" . ?√)))))) -(stante-after erc-join - (setq erc-autojoin-channels-alist - '(("freenode.net" "#ninthfloor" "#emacs" "#dispass")))) -(stante-after erc-stamp - (setq erc-insert-timestamp-function 'erc-insert-timestamp-left) - (setq erc-timestamp-format "[%H:%M] ") - (setq erc-timestamp-only-if-changed-flag nil)) +(defun init-set-keys-for-dired () + "Set somee keybindings for `dired'." + (local-set-key (kbd "E") #'wdired-change-to-wdired-mode)) -(stante-after files - (setq-default require-final-newline t) - (setq auto-mode-case-fold nil) - (setq auto-save-file-name-transforms - `((".*" "~/.local/share/emacs/autosave/" t))) - (setq backup-directory-alist - `((".*" . "~/.local/share/emacs/backup/"))) - (setq auto-mode-alist - (append '(("/PKGBUILD$" . sh-mode) - (".install$" . sh-mode) - ("\\.jl$" . sawfish-mode) - ("\\.js\\(on\\)?$" . js2-mode) - ("\\.m\\(ark\\)?d\\(?:o?wn\\)?$" . markdown-mode) - ("\\.php[345]?$" . php-mode) - ("\\.po\\'\\|\\.po\\." . po-mode) - ("\\.tpl$" . html-mode) - ("^\\.Xmodmap$" . xmodmap-mode)) - auto-mode-alist))) +(defun init-set-keys-for-eshell () + "Set some keybindings for `eshell'." + (local-set-key (kbd "C-d") #'init-eshell-C-d)) -(stante-after fill-column-indicator - (setq-default fci-rule-column 73)) +(defun init-set-keys-for-hy () + "Set some keybindings for `hy-mode'." + (local-set-key (kbd "{") #'paredit-open-curly) + (local-set-key (kbd "}") #'paredit-close-curly)) -(stante-after fiplr - (add-to-list 'fiplr-root-markers ".emacs.desktop") - (push "*.pyc" (cadr (assoc 'files fiplr-ignored-globs))) - (push "migrations" (cadr (assoc 'directories fiplr-ignored-globs)))) +(defun init-set-keys-for-jabber-chat () + "Set certain keys for `jabber-chat-mode'." + (local-set-key (kbd "M-!") #'shell-command-with-command)) -(stante-after flycheck - (mapc (lambda (c) (delq c flycheck-checkers)) - '(python-pylint python-pyflakes)) - (setf flycheck-highlighting-mode 'columns)) +(defun init-set-keys-for-tagedit () + "Set some keybindings for `tagedit-mode'." + (local-set-key (kbd "M-k") #'tagedit-kill-attribute)) -(stante-after geiser-repl - (setq geiser-repl-history-filename "~/.emacs.d/geiser-history")) +(defun init-set-python-imenu-function () + "Set the `imenu-create-index-function' variable. -(stante-after gnutls - (add-to-list - 'gnutls-trustfiles - (expand-file-name "~/ssl_20130810/sub.class1.server.ca.pem"))) +For `python-mode' I prefer `python-imenu-create-flat-index'." + (setq imenu-create-index-function #'python-imenu-create-flat-index)) -(stante-after grep - (add-to-list 'grep-find-ignored-directories "migrations") - (add-to-list 'grep-find-ignored-files "TAGS")) +(defun init-set-python-symbols () + "Set a few extra UTF-8 symbols for use in python." + (when (boundp 'prettify-symbols-alist) + (setq prettify-symbols-alist + '(("lambda" . ?λ) + ("<=" . ?≤) + (">=" . ?≥) + ("!=" . ?≠))))) -(stante-after help-at-pt - (setq help-at-pt-display-when-idle t)) +(defun set-smartparens-keys () + "Set some keys for `smartparens-mode'." + (local-set-key [remap backward-delete-char] 'sp-backward-delete-char) + (local-set-key [remap delete-char] 'sp-delete-char) + (local-set-key [remap kill-word] 'sp-kill-word) + (local-set-key [remap backward-kill-word] 'sp-backward-kill-word) + (local-set-key (kbd "") 'sp-forward-barf-sexp) + (local-set-key (kbd "") 'sp-forward-slurp-sexp) + (local-set-key (kbd "M-J") 'sp-join-sexp) + (local-set-key (kbd "M-S") 'sp-split-sexp)) -(stante-after ido - (setq ido-ignore-buffers - (list "^\\` " "^irc\\." "^\\#" "^\\*Customize Option:" - (rx (or "*-jabber-roster-*" "*Messages*" "*fsm-debug*" - "*magit-process*" "*magit-edit-log*" "*Backtrace*" - "*Ibuffer*")))) - (setq ido-auto-merge-work-directories-length -1) - (setq ido-default-buffer-method 'selected-window) - (setq ido-max-window-height 1) - (setq ido-save-directory-list-file nil)) +(defun init-set-tab-maybe-toggle-outline () + "Wrap the current function mapped to `TAB'." + (let ((func (or (lookup-key (current-local-map) (kbd "TAB")) + (lookup-key (current-global-map) (kbd "TAB"))))) + (local-set-key (kbd "TAB") + (lambda () + (interactive) + (if (outline-on-heading-p) + (if (outline-invisible-p (line-end-position)) + (show-entry) + (hide-entry)) + (call-interactively func)))))) -(stante-after imenu - (setq imenu-auto-rescan t)) +(let ((theme (if (equal system-name "drd") 'yoshi 'leuven))) + (let ((setp (not (daemonp)))) + (defun init-set-theme (frame) + "Try to set the theme for the current (first) frame." + (ignore frame) + (unless setp + (run-at-time .1 nil (lambda () (setq setp (load-theme theme t))))))) -(stante-after jabber (load "jabber-init")) + (if (daemonp) + (add-hook 'after-make-frame-functions #'init-set-theme) + (eval-after-init (load-theme theme t)))) -(stante-after jedi - (setcar jedi:server-command "python2") - (setq jedi:tooltip-method nil)) +(defun shell-command-with-command (command &optional output-buffer) + "Print both COMMAND and the output into OUTPUT-BUFFER." + (interactive (list (read-shell-command "Shell command: " nil nil) + current-prefix-arg)) + (when output-buffer + (insert "`" command "':\n")) + (shell-command command output-buffer)) -(stante-after jit-lock - (setq jit-lock-defer-time 0.2)) +(defun oni:shorten-dir (dir) + "Shorten a directory, (almost) like fish does it." + (while (string-match "\\(\\.?[^./]\\)[^/]+/" dir) + (setq dir (replace-match "\\1/" nil nil dir))) + dir) -(stante-after magit - (setq magit-repo-dirs '("~/projects/")) - (setq magit-diff-refine-hunk 'all)) +(defun oni:show-buffer-position () + "Show the position in the current buffer." + (interactive) + (message (format "%d:%d" (line-number-at-pos) (current-column)))) -(stante-after message - (setq message-send-mail-function 'message-send-mail-with-sendmail) - (setq message-sendmail-extra-arguments '("-a" "ryuslash"))) +(defun oni:show-org-index () + "Show the index of my org files." + (interactive) + (find-file "~/documents/org/index.org")) -(stante-after minibuf-eldef - (setq minibuffer-eldef-shorten-default t)) +(defun sort-imports () + "Sort python multiline imports using `()'." + (interactive) + (save-excursion + (sort-lines nil (1+ (search-backward "(")) + (1- (search-forward ")"))))) -(stante-after mouse - (setq mouse-yank-at-point t)) +(defun oni:split-window-interactive (dir) + "Split windows in direction DIR. -(stante-after org - (setq org-special-ctrl-a/e t)) +Can also delete or switch to another window." + (interactive + (list (read-char "Direction (h,v,q,d,o): "))) + (case dir + ((?v) (split-window-vertically)) + ((?h) (split-window-horizontally)) + ((?q) (delete-other-windows)) + ((?d) (delete-window)) + ((?o) (other-window 1)))) -(stante-after org2blog - (setq org2blog/wp-blog-alist - '(("ryublog" - :url "https://ryuslash.org/blog/xmlrpc.php" - :username "ryuslash")))) +(defun oni:split-window-interactively (window) + "Ask for a direction and split WINDOW that way. -(stante-after package - (setq package-archives - '(("melpa" . "http://melpa.milkbox.net/packages/") - ("marmalade" . "http://marmalade-repo.org/packages/") - ("gnu" . "http://elpa.gnu.org/packages/"))) - (setq package-load-list '((dispass "1.1.2.2") - all))) +If no direction is given, don't split." + (let ((dir (read-char "Direction (h,v): "))) + (case dir + ((?v) (split-window-vertically)) + ((?h) (split-window-horizontally)) + (t window)))) -(stante-after "paragraphs" - (setq sentence-end-double-space nil)) +(defun oni:start-python-test-mail-server () + "Run the python test mailserver." + (interactive) + (start-process "python-test-mail-server" "*py-mail-server*" "python" "-m" + "smtpd" "-n" "-c" "DebuggingServer" "localhost:1025")) -(stante-after php-mode - (setq-default php-mode-warn-if-mumamo-off nil) - (setq php-function-call-face 'font-lock-function-name-face) - (setq php-mode-force-pear t)) +(defun oni:stop-python-test-mail-server () + "Stop the python test mailserver." + (interactive) + (kill-process "python-test-mail-server")) -(stante-after sendmail - (setq send-mail-function 'sendmail-send-it) - (setq sendmail-program "/usr/bin/msmtp")) +(defun stumpwm-command (cmd) + "Execute CMD in stumpwm." + (call-process init-stumpish-program nil nil nil cmd)) -(stante-after simple - (setq read-mail-command 'gnus)) +(defun init-switch-to-other-buffer () + "Switch to the most recently viewed buffer." + (interactive) + (switch-to-buffer (other-buffer))) -(stante-after smartparens - (setq sp-cancel-autoskip-on-backward-movement nil - sp-autoskip-closing-pair 'always)) +(defun oni:term-mode-func () + "Function for `term-mode-hook'." + (setq truncate-lines nil)) -(stante-after smex - (setq smex-key-advice-ignore-menu-bar t) - (setq smex-save-file "~/.emacs.d/smex-items")) +(defun turn-on-compilation-shell-for-pony () + "Turn on option `compilation-shell-minor-mode' for `pony-minor-mode'." + (add-hook 'pony-minor-mode-hook 'compilation-shell-minor-mode nil t)) -(stante-after "startup" - (setq inhibit-default-init t) - (setq inhibit-startup-message t) - (setq initial-major-mode 'emacs-lisp-mode) - (setq initial-scratch-message nil) - (setq user-mail-address "tom@ryuslash.org")) +(defun oni:upcase-prev (num) + (interactive "p") + (oni:change-prev-case num 'up)) -(stante-after time-stamp - (setq time-stamp-active t) - (setq time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)")) +(defun oni:vala-mode-func () + "Function for `vala-mode-hook'." + (setq indent-tabs-mode nil)) -(stante-after type-break - (setq type-break-good-rest-interval (* 60 10)) - (setq type-break-interval (* 60 50)) - (setq type-break-keystroke-threshold '(nil . nil))) +(defun oni:write-file-func () + "Function for `write-file-hooks'." + (time-stamp)) -(stante-after w3m - (setq w3m-fill-column 72)) +(defun oni:yas-minor-mode-func () + "Function for `yas-minor-mode-hook'." + (define-key yas-minor-mode-map (kbd "TAB") nil) + (define-key yas-minor-mode-map [(tab)] nil) + (define-key yas-minor-mode-map (kbd "C-\\") 'yas-expand)) -(stante-after "window" - (setq split-height-threshold 40) - (add-to-list - 'display-buffer-alist - '("^\\*\\(?:.+-\\)?scratch\\*$" display-buffer-same-window)) - (add-to-list - 'display-buffer-alist - '("^\\*git-project-list\\*$" git-project-show-window)) - (add-to-list - 'display-buffer-alist - '("^\\*magit: .*\\*$" display-buffer-same-window))) +;;;; Macro support -(stante-after yasnippet - (setq yas-fallback-behavior nil) - (setq yas-prompt-functions '(yas-ido-prompt))) +(eval-and-compile + (defun add-hooks (hooks function &optional append local) + "`add-hook' for each in HOOKS." + (mapcar (lambda (h) + `(add-hook (quote ,h) ,function ,append ,local)) + hooks)) -(mode-hooks - ((clojure emacs-lisp lisp sawfish scheme ielm geiser-repl slime-repl) - paredit-mode) - ((comint) turn-on-compilation-shell-for-pony) - ((css) rainbow-mode) - ((emacs-lisp go html lua perl php python rst ruby rust sh) - flycheck-mode) - ((emacs-lisp ielm) eldoc-mode) - ((emacs-lisp ielm) set-emacs-lisp-keys) - ((eshell) buffer-disable-undo) - ((eshell) init-set-keys-for-eshell) - ((git-commit text) auto-fill-mode) - ((git-commit text) flyspell-mode) - ((html org prog) yas-minor-mode) - ((html prog) init-maybe-fci-mode) - ((html) tagedit-mode) - ((html) turn-off-flyspell) - ((html) turn-off-auto-fill) - ((hy) paredit-mode) - ((hy) init-set-keys-for-hy) - ((js2 python) smartparens-strict-mode) - ((markdown python) whitespace-mode) - ((message org gnus-summary gnus-article gnus-group magit-log-edit Info - info org-agenda jabber-chat) - init-make-readable) - ((prog) rainbow-delimiters-mode) - ((python) init-set-python-imenu-function) - ((python) jedi:setup) - ((python) subword-mode) - ((slime slime-repl) set-up-slime-ac) - ((smartparens) set-smartparens-keys) - ((sql-interactive) init-augment-sql-prompt) - ((tagedit) tagedit-add-experimental-features) - ((tagedit) tagedit-add-paredit-like-keybindings) - ((tagedit) init-set-keys-for-tagedit) - ((vala) oni:vala-mode-func)) + (defun add-mode-hooks (modes function &optional append local) + "`add-hooks' with MODES renamed to mode-mode-hook." + (let ((mode-names (mapcar #'make-mode-hook-name modes))) + (add-hooks mode-names function append local))) + (defun level (lst) + (let ((lsts (mapcar (lambda (l) (if (listp l) l (list l))) lst))) + (apply #'append lsts))) -(setq-default bidi-paragraph-direction 'left-to-right) -(setq-default tab-width 4) -(setq-default indent-tabs-mode nil) -(setq-default truncate-lines t) -(setq custom-file "~/.emacs.d/custom.el") -(setq default-frame-alist - `((border-width . 0) - (internal-border-width . 0) - (vertical-scroll-bars . nil) - (menu-bar-lines . nil) - (tool-bar-lines . nil) - (font . "Cosmic Sans Neue Mono:pixelsize=17"))) -(setq frame-title-format '(:eval (concat "emacs: " (buffer-name)))) -(setq message-log-max 1000) -(setq redisplay-dont-pause t) -(setq use-dialog-box nil) -(setq user-full-name "Tom Willemse") -(setq window-combination-resize t) -(setq scroll-preserve-screen-position t) -(add-to-list 'debug-ignored-errors "^Can't shift all lines enough") -;; Can't be put in an eval-after-load or such because by then it will -;; be too late. -(setq elnode-do-init nil) + (defun loadpath-add-and-autoload (path) + "Add PATH to `load-path' and load a `loaddefs.el' if it exists." + (add-to-list 'load-path path) + (let ((loaddefs (concat path "/loaddefs.el"))) + (when (file-exists-p loaddefs) + (load loaddefs)))) -(enable '(downcase-region narrow-to-page narrow-to-region scroll-left - upcase-region)) + (defun make-mode-hook-name (mode) + "Get the hook name for MODE." + (intern (concat (symbol-name mode) "-mode-hook")))) -(eval-after-init (ido-ubiquitous-mode)) +;;;; aliases -(eval-after-load "org" '(require 'org-init)) +(defalias 'yes-or-no-p 'y-or-n-p) +(defalias 'dabbrev-expand 'hippie-expand) -(eval-after-init - (require 'auto-complete-config) - (ac-config-default)) +;;;; uniquify -(when (equal system-name "drd") - (eval-after-init - (load (expand-file-name "~/.local/share/quicklisp/slime-helper.el"))) - (load "eap-autoloads")) +(require 'uniquify) -(eval-after-init (smex-initialize)) -(eval-after-init (global-diff-hl-mode)) -(eval-after-init (mode-icons-mode)) -(eval-after-init (desktop-registry-auto-register)) +(stante-after uniquify + (setq uniquify-buffer-name-style 'post-forward)) +;;;; gnus -;; (setq pony-tpl-indent-moves t) -;; (setq rainbow-delimiters-max-face-count 12) +(setq gnus-init-file "~/.emacs.d/site-lisp/gnus-init") -(add-hook 'after-save-hook 'oni:after-save-func t) -(add-hook 'before-save-hook 'oni:before-save-func) -(add-hook 'c-mode-hook 'oni:c-mode-func) -(add-hook 'css-mode-hook 'oni:css-mode-func) -(add-hook 'diary-display-hook 'oni:diary-display-func) -(add-hook 'go-mode-hook 'oni:go-mode-func) -(add-hook 'haskell-mode-hook 'oni:haskell-mode-func) -(add-hook 'java-mode-hook 'oni:java-mode-func) -(add-hook 'js-mode-hook 'oni:js-mode-func) -(add-hook 'js2-mode-hook 'oni:js2-mode-func) -(add-hook 'lua-mode-hook 'oni:lua-mode-func) -(add-hook 'markdown-mode-hook 'oni:markdown-mode-func) -(add-hook 'php-mode-hook 'oni:php-mode-func) -(add-hook 'prog-mode-hook 'oni:prog-mode-func) -(add-hook 'python-mode-hook 'oni:python-mode-func) -(add-hook 'term-mode-hook 'oni:term-mode-func) -(add-hook 'write-file-hooks 'oni:write-file-func) -(add-hook 'yas-minor-mode-hook 'oni:yas-minor-mode-func) +;;;; Visual cues -(global-set-key (kbd "'") 'oni:self-insert-dwim) -(global-set-key (kbd "") 'oni:raise-scratch) -(global-set-key (kbd "") 'gnus) -(global-set-key (kbd "") 'git-project-show-files) -(global-set-key (kbd "") 'reload-buffer) -(global-set-key (kbd "") 'magit-status) -(global-set-key (kbd "") 'raise-eshell) -(global-set-key (kbd "") 'oni:show-org-index) -(global-set-key (kbd "C-<") 'oni:indent-shift-left) -(global-set-key (kbd "C->") 'oni:indent-shift-right) -(global-set-key (kbd "C-M-4") 'split-window-vertically) -(global-set-key (kbd "C-M-SPC") 'er/expand-region) -(global-set-key (kbd "C-M-d") 'kill-word) -(global-set-key (kbd "C-M-w") 'backward-kill-word) -(global-set-key (kbd "C-M-x") 'smex-major-mode-commands) -(global-set-key (kbd "C-M-z") 'indent-defun) -(global-set-key (kbd "C-S-k") 'kill-whole-line) -(global-set-key (kbd "C-c a") 'org-agenda) -(global-set-key (kbd "C-c c") 'org-capture) -(global-set-key (kbd "C-c d c") 'desktop-clear) -(global-set-key (kbd "C-c d d") 'desktop-registry-change-desktop) -(global-set-key (kbd "C-c d s") 'desktop-save-in-desktop-dir) -(global-set-key (kbd "C-c i p") 'identica-update-status-interactive) -(global-set-key (kbd "C-c p") 'oni:show-buffer-position) -(global-set-key (kbd "C-c t") 'oni:raise-ansi-term) -(global-set-key (kbd "C-c w d") 'oni:downcase-prev) -(global-set-key (kbd "C-c w u") 'oni:upcase-prev) -(global-set-key (kbd "C-e") 'oni:move-end-of-dwim) -(global-set-key (kbd "M-0") 'delete-window) -(global-set-key (kbd "M-1") 'delete-other-windows) -(global-set-key (kbd "M-2") 'split-window-below) -(global-set-key (kbd "M-3") 'split-window-right) -(global-set-key (kbd "M-4") 'split-window-horizontally) -(global-set-key (kbd "M-n") 'idomenu) -(global-set-key (kbd "M-o") 'other-window) -(global-set-key (kbd "M-x") 'smex) -(global-set-key (kbd "\"") 'oni:self-insert-dwim) -(global-set-key [remap move-beginning-of-line] 'move-beginning-of-dwim) -(global-set-key (kbd "C-x f") 'fiplr-find-file) -(global-set-key (kbd "C-c m") 'gnus) -(global-set-key (kbd "C-c g s") 'magit-status) -(global-set-key (kbd "C-c g i") 'magit-init) -(global-set-key (kbd "C-c g b") 'magit-checkout) -(global-set-key (kbd "C-c g f") 'magit-fetch) -(global-set-key (kbd "C-c h r") 'hypo-region) -(global-set-key (kbd "C-x C-b") 'bs-show) +(turn-off menu-bar-mode scroll-bar-mode tool-bar-mode blink-cursor-mode + column-number-mode line-number-mode tooltip-mode) -(if (daemonp) - (global-set-key "\C-x\C-c" 'oni:close-client-window)) +;;;; eww -(when (or window-system (daemonp)) - (global-unset-key "\C-z")) +(stante-after eww + (setq eww-download-path ; Don't go to ~/Downloads + "~/downloads/")) -(ido-mode) -(minibuffer-electric-default-mode) -(auto-insert-mode) -(savehist-mode) -(show-paren-mode) -(winner-mode) -(help-at-pt-set-timer) -(windmove-default-keybindings) +;;;; Typography -(defun oni:scroll-down-or-prev-page (arg) - "Either scroll down or go to the previous page. +;; Use double spaces to end lines in Emacs Lisp. The checkdoc +;; function starts complaining if you don't. +(add-hook 'emacs-lisp-mode-hook #'init-locally-enable-double-spaces) -Depending on the value of `buffer-narrowed-p'." - (interactive "^P") - (if (buffer-narrowed-p) - (let ((scroll-error-top-bottom nil)) - (condition-case nil - (scroll-down-command arg) - (beginning-of-buffer - (narrow-to-page -1) - (goto-char (point-min))))) - (scroll-down-command arg))) +;;;; Symbols -(defun oni:scroll-up-or-next-page (arg) - "Either scroll up or go to the next page. +(eval-and-compile + (mapc #'loadpath-add-and-autoload + '("~/.emacs.d/site-lisp" "~/projects/emacs/pony-mode/src" + "~/.emacs.d/vendor-lisp/org/lisp" + "~/.emacs.d/vendor-lisp/org/contrib/lisp" + "~/.emacs.d/vendor-lisp/mozrepl" + "~/.emacs.d/vendor-lisp/eap" "/usr/share/emacs/site-lisp"))) -Depending on the value of `buffer-narrowed-p'." - (interactive "^P") - (if (buffer-narrowed-p) - (let ((scroll-error-top-bottom nil)) - (condition-case nil - (scroll-up-command arg) - (end-of-buffer - (narrow-to-page 1) - (goto-char (point-min))))) - (scroll-up-command arg))) +(add-hook 'emacs-lisp-mode-hook #'init-set-emacs-lisp-symbols) +(add-hook 'lisp-mode-hook #'init-set-emacs-lisp-symbols) +(add-hook 'python-mode-hook #'init-set-python-symbols) -(global-set-key (kbd "") 'oni:scroll-down-or-prev-page) -(global-set-key (kbd "") 'oni:scroll-up-or-next-page) - -;;; Finally, load any `customize' settings. -(load custom-file) +(when (fboundp 'prettify-symbols-mode) + (add-hook 'prog-mode-hook 'prettify-symbols-mode)) +(stante-after slime + (setq slime-lisp-implementations + '((sbcl ("sbcl" "--noinform") :coding-system utf-8-unix) + (clisp ("clisp") :coding-system utf-8-unix)) + slime-default-lisp 'sbcl)) -(defun oni:after-save-func () - "Function for `after-save-hook'." - (executable-make-buffer-file-executable-if-script-p) - (let* ((dom-dir (locate-dominating-file (buffer-file-name) "Makefile")) - (TAGSp (not (string= "" (shell-command-to-string - (concat "grep \"^TAGS:\" " dom-dir "Makefile")))))) - (when (and dom-dir TAGSp) - (shell-command - (concat "make -C " dom-dir " TAGS >/dev/null 2>&1"))))) +(set-fontset-font "fontset-default" 'unicode + (font-spec :family "Liberation Mono" + :width 'normal + :size 12.4 + :weight 'normal)) -(defun oni:appt-display-window-and-jabber (min-to-app new-time appt-msg) - "Send a message to my phone jabber account." - (jabber-send-message (car jabber-connections) "phone@ryuslash.org" - nil (format "%s%s (in %s minutes)" - new-time appt-msg min-to-app) nil) - (appt-disp-window min-to-app new-time appt-msg)) -;; (jabber-send-message (car jabber-connections) -;; "aethon@muc.ryuslash.org" nil "Hi, I'm a programmatic message; this -;; upens up possibilities :)" "groupchat") -(defun oni:before-save-func () - "Function for `before-save-hook'." - (if (eq major-mode 'html-mode) - (oni:replace-html-special-chars)) - (if (not (eq major-mode 'markdown-mode)) - (delete-trailing-whitespace))) +(stante-after simple + (define-key special-mode-map "z" #'kill-this-buffer)) -(defun oni:c-mode-func () - "Function for `c-mode-hook'." - (local-set-key [f9] 'compile) - (local-set-key "\C-j" 'oni:newline-and-indent)) +(defadvice windmove-do-window-select + (around init-windmove-stumpwm activate) + "If no window can be moved to, move stumpwm." + (condition-case err + ad-do-it + (error (stumpwm-command (format "move-focus %s" (ad-get-arg 0)))))) -(defun oni:change-prev-case (num dir) - (let ((regfunc (if (eq dir 'up) 'upcase-region 'downcase-region)) - (wordfunc (if (eq dir 'up) 'upcase-word 'downcase-word))) - (if (> num 1) - (funcall regfunc (point) (- (point) num)) - (funcall wordfunc -1)))) +(global-set-key (kbd "C-c S") #'split-window-right) +(global-set-key (kbd "C-c s") #'split-window-below) +(global-set-key (kbd "C-c Q") #'delete-other-windows) +(global-set-key (kbd "C-c R") #'delete-window) -(defun oni:close-client-window () - "Close a client's frames." - (interactive) - (server-save-buffers-kill-terminal nil)) +(add-to-list 'load-path "/usr/lib/node_modules/tern/emacs/") +(autoload 'tern-mode "tern" nil t) -(defun oni:color-for (object) - "Generate a hex color by taking the first 6 characters of OBJECT's MD5 sum." - (format "#%s" (substring (md5 object) 0 6))) +(stante-after tern + (require 'tern-auto-complete) + (tern-ac-setup)) -(defun oni:css-mode-func () - "Function for `css-mode-hook'." - (local-set-key "\C-j" 'oni:newline-and-indent)) +(add-hook 'js2-mode-hook #'tern-mode) -(defun oni:current-jabber-status () - "Return a string representing the current jabber status." - (or (and (not *jabber-connected*) "Offline") - (and (not (string= *jabber-current-status* "")) - *jabber-current-status*) - "Online")) +(global-set-key (kbd "C-. C-.") #'init-switch-to-other-buffer) -(defun oni:diary-display-func () - "Function for `diary-display-hook'." - (diary-fancy-display)) +(stante-after woman + (setq woman-fill-column 72)) -(defun oni:downcase-prev (num) - (interactive "p") - (oni:change-prev-case num 'down)) +(add-hook 'c-mode-hook #'smartparens-strict-mode) -(defun oni:go-mode-func () - "Function for `go-mode-hook'." - (setq indent-tabs-mode nil) - (local-set-key "\C-j" 'oni:newline-and-indent)) +(autoload 'moz-minor-mode "moz" nil t) +(add-hook 'javascript-mode-hook 'moz-minor-mode) -(defun oni:haskell-mode-func () - "Function for `haskell-mode-hook'." - (turn-on-haskell-indentation)) +(global-set-key (kbd "C-c -") #'decrease-number-at-point) +(global-set-key (kbd "C-c +") #'increase-number-at-point) -(defun oni:indent-shift-left (start end &optional count) - "Rigidly indent region. -Region is from START to END. Move -COUNT number of spaces if it is non-nil otherwise use -`tab-width'." - (interactive - (if mark-active - (list (region-beginning) (region-end) current-prefix-arg) - (list (line-beginning-position) - (line-end-position) - current-prefix-arg))) - (if count - (setq count (prefix-numeric-value count)) - (setq count tab-width)) - (when (> count 0) - (let ((deactivate-mark nil)) - (save-excursion - (goto-char start) - (while (< (point) end) - (if (and (< (current-indentation) count) - (not (looking-at "[ \t]*$"))) - (error "Can't shift all lines enough")) - (forward-line)) - (indent-rigidly start end (- count)))))) +(autoload 'jabber-connect "jabber" nil t) +(autoload 'jabber-message-libnotify "jabber-libnotify") +(autoload 'jabber-muc-libnotify "jabber-libnotify") +(autoload 'jabber-send-message "jabber-chat") +(autoload 'notifications-notify "notifications") +(autoload 'php-mode "php-mode" nil t) +(autoload 'po-mode "po-mode" nil t) +(autoload 'pony-mode "pony-mode" nil t) +(autoload 'sawfish-mode "sawfish" nil t) +(autoload 'server-running-p "server") +(autoload 'tagedit-mode "tagedit" nil t) +(autoload 'w3m-bookmark-view "w3m" nil t) +(autoload 'w3m-goto-url "w3m" nil t) +(autoload 'xmodmap-mode "xmodmap-mode" nil t) -(defun oni:indent-shift-right (start end &optional count) - "Indent region between START and END rigidly to the right. -If COUNT has been specified indent by that much, otherwise look at -`tab-width'." - (interactive - (if mark-active - (list (region-beginning) (region-end) current-prefix-arg) - (list (line-beginning-position) - (line-end-position) - current-prefix-arg))) - (let ((deactivate-mark nil)) - (if count - (setq count (prefix-numeric-value count)) - (setq count tab-width)) - (indent-rigidly start end count))) +(defadvice org-agenda-redo (after ext:org-agenda-redo-add-appts) + "Pressing `r' on the agenda will also add appointments." + (progn + (setq appt-time-msg-list nil) + (org-agenda-to-appt))) -(defun oni:java-mode-func () - "Function for `java-mode-hook'." - (local-set-key "\C-j" 'oni:newline-and-indent)) +(defadvice term-handle-exit (after oni:kill-buffer-after-exit activate) + "Kill the term buffer if the process finished." + (kill-buffer (current-buffer))) -(defun oni:js-mode-func () - "Function for `js-mode-hook'." - (local-set-key "\C-j" 'oni:newline-and-indent)) +(stante-after appt + (setq appt-disp-window-function #'oni:appt-display-window-and-jabber) + (setq appt-display-diary nil)) -(defun oni:js2-mode-func () - "Function for `js2-mode-hook'." - (oni:js-mode-func)) +(stante-after "bindings" + (setq mode-line-default-help-echo "")) -(defun oni:lua-mode-func() - "Function for `lua-mode-hook'." - (local-unset-key (kbd ")")) - (local-unset-key (kbd "]")) - (local-unset-key (kbd "}"))) +(stante-after auto-complete + (add-to-list 'ac-modes 'slime-repl-mode) + (setq-default ac-sources '(ac-source-imenu + ac-source-abbrev + ac-source-yasnippet + ac-source-words-in-buffer + ac-source-words-in-same-mode-buffers + ac-source-dictionary + ac-source-functions + ac-source-symbols + ac-source-variables + ac-source-features)) + (setq ac-auto-show-menu nil + ac-use-quick-help nil)) -(defun oni:markdown-mode-func () - "Function for `markdown-mode-hook'." - (setq-local whitespace-style '(face trailing))) +(stante-after browse-url + (setq browse-url-browser-function 'browse-url-generic) + (setq browse-url-generic-program (getenv "BROWSER"))) -(defun oni:mini-fix-timestamp-string (date-string) - "A minimal version of Xah Lee's `fix-timestamp-string'. -Turn DATE-STRING into something else that can be worked with in -code. Found at http://xahlee.org/emacs/elisp_parse_time.html" - (setq date-string (replace-regexp-in-string "Jan" "01" date-string) - date-string (replace-regexp-in-string "Feb" "02" date-string) - date-string (replace-regexp-in-string "Mar" "03" date-string) - date-string (replace-regexp-in-string "Apr" "04" date-string) - date-string (replace-regexp-in-string "May" "05" date-string) - date-string (replace-regexp-in-string "Jun" "06" date-string) - date-string (replace-regexp-in-string "Jul" "07" date-string) - date-string (replace-regexp-in-string "Aug" "08" date-string) - date-string (replace-regexp-in-string "Sep" "09" date-string) - date-string (replace-regexp-in-string "Oct" "10" date-string) - date-string (replace-regexp-in-string "Nov" "11" date-string) - date-string (replace-regexp-in-string "Dec" "12" date-string)) - (string-match - "^\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{4\\}\\)$" - date-string) - (format "%s-%s-%s" - (match-string 3 date-string) - (match-string 2 date-string) - (match-string 1 date-string))) +(stante-after cc-vars + (setq-default c-basic-offset 4) + (setq c-offsets-alist + '((statement-block-intro . +) + (knr-argdecl-intro . 5) + (substatement-open . +) + (substatement-label . 0) + (label . 0) + (statement-case-open . +) + (statement-cont . +) + (arglist-intro . +) + (arglist-close . 0) + (inline-open . 0) + (brace-list-open . +) + (topmost-intro-cont first c-lineup-topmost-intro-cont + c-lineup-gnu-DEFUN-intro-cont)))) -(defun oni:mode-line-current-song () - "Extract current song information from a path. +(stante-after compile + (setq compilation-scroll-output t)) -EMMS only shows me the absolute path of a song, this function -extracts the parts I want to know about." - (let ((song (emms-track-name (emms-playlist-current-selected-track)))) - (if (string-match "\\([^/]+\\)/\\([0-9]\\{4\\}\\) - \\(.+\\)/\\([0-9]\\{2,3\\}\\) - \\(.+\\)\\..\\{3,4\\}$" song) - (let ((band (substring song (match-beginning 1) (match-end 1))) - (title (substring song (match-beginning 5) (match-end 5)))) - (format "[%s - %s]" band title)) - song))) +(stante-after custom + (setq custom-theme-directory "~/.emacs.d/themes") + ;; (eval-after-init (load-theme 'yoshi t)) + ) -(defun oni:move-end-of-dwim () - "Move to end of line, either before any comments or after." - (interactive) - (let ((start (point)) - (eolpos (line-end-position))) - (beginning-of-line) - (if (and comment-start - (not (looking-at (regexp-quote comment-start))) - (comment-search-forward eolpos t)) - (progn - (search-backward-regexp (concat "[^ \t" comment-start "]")) - (forward-char) +(stante-after desktop + (setq desktop-restore-frames nil) + (setq desktop-load-locked-desktop t) + (setq desktop-clear-preserve-buffers + (append (list (rx (and bol (or (and "+" (1+ nonl)) + "dailies" "work" "tasks" "org" + (or "bookmarks.org" + "contacts.org")) eol)) + (rx (or "*ielm*" "*-jabber-roster-*" "*eshell*" + "*ansi-term*" "*slime-repl sbcl*" + "*slime-events*")) + (rx (and "*" (or "magit" "scratch-") (1+ nonl) + "*")) + (rx (or "irc.freenode.net:6667" + (and "#" (1+ nonl))))) + desktop-clear-preserve-buffers)) + (setq desktop-files-not-to-save + (rx (or (regexp "\\(^/[^/:]*:\\|(ftp)$\\)") + (and "/" (or "dailies" "tasks" "org" "bookmarks.org" + "contacts.org" "work") eol)))) + (add-to-list 'desktop-globals-to-clear 'desktop-dirname)) - (when (or (bolp) - (= start (point))) - (end-of-line))) - (end-of-line)))) +(stante-after dired + (add-hook 'dired-mode-hook #'init-set-keys-for-dired)) -(defun oni:myepisodes-formatter (plist) - "Format RSS items from MyEpisodes as org tasks. -PLIST contains all the pertinent information." - (let ((str (plist-get plist :title))) - (string-match - "^\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]$" - str) - (let* ((title (match-string 1 str)) - (episode (match-string 2 str)) - (name (match-string 3 str)) - (date (oni:mini-fix-timestamp-string (match-string 4 str)))) - (format "* ACQUIRE %s %s - %s \n SCHEDULED: <%s>" - title episode name date)))) +(stante-after eap + (setq eap-music-library "/mnt/music") + (setq eap-playlist-library "~/music/playlists")) -(defun oni:newline-and-indent () - "`newline-and-indent', but with a twist. -When dealing with braces, add another line and indent that too." - (interactive) - (if (and (not (or (= (point) (point-max)) - (= (point) (point-min)))) - (or (and (char-equal (char-before) ?{) - (char-equal (char-after) ?})) - (and (char-equal (char-before) ?\() - (char-equal (char-after) ?\))))) - (save-excursion (newline-and-indent))) - (newline-and-indent)) +(stante-after ediff-wind + (setq ediff-window-setup-function 'ediff-setup-windows-plain)) -(defun oni:php-mode-func () - "Function for `php-mode-hook'." - (local-set-key "\C-j" 'oni:newline-and-indent) - (c-set-offset 'arglist-intro '+) - (c-set-offset 'arglist-close '0) - (setq-local fci-rule-column 80)) +(stante-after eltuki + (setq eltuki-blog-dir "~/documents/blog")) -(defun oni:prog-mode-func () - "Function for `prog-mode-hook'." - (setq-local comment-auto-fill-only-comments t)) +(stante-after em-prompt + (setq eshell-highlight-prompt nil) + (setq eshell-prompt-function 'oni-eshell-prompt) + (setq eshell-prompt-regexp "^[+-]> ")) -(defun oni:python-mode-func () - "Function for `python-mode-hook'." - (local-set-key (kbd "C->") 'python-indent-shift-right) - (local-set-key (kbd "C-<") 'python-indent-shift-left) - (set (make-local-variable 'electric-indent-chars) nil) - (setq fci-rule-column 79 - fill-column 72) - (setq-local whitespace-style '(tab-mark))) +(stante-after em-term + (add-to-list 'eshell-visual-commands "unison")) -(defun oni:raise-ansi-term (arg) - "Create or show an `ansi-term' buffer." - (interactive "P") - (let ((buffer (get-buffer "*ansi-term*"))) - (if (and buffer (not arg)) - (switch-to-buffer buffer) - (ansi-term (getenv "SHELL"))))) +(stante-after emms + (emms-minimalistic) + (emms-default-players) -(defun oni:raise-scratch (&optional mode) - "Show the *scratch* buffer. -If called with a universal argument, ask the user which mode to -use. If MODE is not nil, open a new buffer with the name -*MODE-scratch* and load MODE as its major mode." - (interactive (list (if current-prefix-arg - (read-string "Mode: ") - nil))) - (let* ((bname (if mode - (concat "*" mode "-scratch*") - "*scratch*")) - (buffer (get-buffer bname)) - (mode-sym (intern (concat mode "-mode")))) + (require 'emms-player-mpd) + (require 'emms-mode-line)) - (unless buffer - (setq buffer (generate-new-buffer bname)) - (with-current-buffer buffer - (when (fboundp mode-sym) - (funcall mode-sym)))) +(stante-after emms-mode-line + (setq emms-mode-line-mode-line-function 'oni:mode-line-current-song) + (emms-mode-line 1)) - (select-window (display-buffer buffer)))) +(stante-after emms-player-mpd + (add-to-list 'emms-player-list 'emms-player-mpd) + (setq emms-player-mpd-music-directory "/mnt/music/mp3")) -(defun oni:replace-html-special-chars () - "Replace special characters with HTML escaped entities." - (oni:replace-occurrences "é" "é")) +(stante-after erc + (setq erc-hide-list '("PART")) + (setq erc-nick "ryuslash")) -(defun oni:replace-occurrences (from to) - "Replace all occurrences of FROM with TO in the current buffer." - (save-excursion - (goto-char (point-min)) - (while (search-forward from nil t) - (replace-match to)))) +(stante-after erc-join + (setq erc-autojoin-channels-alist + '(("freenode.net" "#ninthfloor" "#emacs" "#dispass")))) -(defun oni:request-pull () - "Start a mail to request pulling from a git repository." - (interactive) - (let* ((default-directory - (expand-file-name - (or (locate-dominating-file default-directory ".git") - (magit-read-top-dir nil)))) - (refs (magit-list-interesting-refs magit-uninteresting-refs)) - (from (cdr (assoc (completing-read "From: " refs) refs))) - (url (read-from-minibuffer "Pull URL: ")) - (to (symbol-name (read-from-minibuffer "Up to (HEAD): " - nil nil t nil "HEAD"))) - (patchp (and current-prefix-arg (listp current-prefix-arg)))) - (message "Requesting pull for %s from %s to %s at %s with%s patch" - default-directory from to url (if patchp "" "out")) +(stante-after erc-stamp + (setq erc-insert-timestamp-function 'erc-insert-timestamp-left) + (setq erc-timestamp-format "[%H:%M] ") + (setq erc-timestamp-only-if-changed-flag nil)) - (compose-mail - nil (concat - "Requesting pull for " - (file-name-base (directory-file-name default-directory)))) +(stante-after files + (setq-default require-final-newline t) + (setq auto-mode-case-fold nil) + (setq auto-save-file-name-transforms + `((".*" "~/.local/share/emacs/autosave/" t))) + (setq backup-directory-alist + `((".*" . "~/.local/share/emacs/backup/"))) + (setq auto-mode-alist + (append '(("/PKGBUILD$" . sh-mode) + (".install$" . sh-mode) + ("\\.jl$" . sawfish-mode) + ("\\.js\\(on\\)?$" . js2-mode) + ("\\.m\\(ark\\)?d\\(?:o?wn\\)?$" . markdown-mode) + ("\\.php[345]?$" . php-mode) + ("\\.po\\'\\|\\.po\\." . po-mode) + ("\\.tpl$" . html-mode) + ("^\\.Xmodmap$" . xmodmap-mode)) + auto-mode-alist))) + +(stante-after fill-column-indicator + (setq-default fci-rule-column 73)) + +(stante-after fiplr + (add-to-list 'fiplr-root-markers ".emacs.desktop") + (push "*.pyc" (cadr (assoc 'files fiplr-ignored-globs))) + (push "migrations" (cadr (assoc 'directories fiplr-ignored-globs)))) + +(stante-after flycheck + (mapc (lambda (c) (delq c flycheck-checkers)) + '(python-pylint python-pyflakes)) + (setf flycheck-highlighting-mode 'columns)) + +(stante-after geiser-repl + (setq geiser-repl-history-filename "~/.emacs.d/geiser-history")) + +(stante-after gnutls + (add-to-list + 'gnutls-trustfiles + (expand-file-name "~/ssl_20130810/sub.class1.server.ca.pem"))) + +(stante-after grep + (add-to-list 'grep-find-ignored-directories "migrations") + (add-to-list 'grep-find-ignored-files "TAGS")) + +(stante-after help-at-pt + (setq help-at-pt-display-when-idle t)) + +(stante-after ido + (setq ido-ignore-buffers + (list "^\\` " "^irc\\." "^\\#" "^\\*Customize Option:" + (rx (or "*-jabber-roster-*" "*Messages*" "*fsm-debug*" + "*magit-process*" "*magit-edit-log*" "*Backtrace*" + "*Ibuffer*")))) + (setq ido-auto-merge-work-directories-length -1) + (setq ido-default-buffer-method 'selected-window) + (setq ido-max-window-height 1) + (setq ido-save-directory-list-file nil)) + +(stante-after imenu + (setq imenu-auto-rescan t)) + +(stante-after jabber (load "jabber-init")) + +(stante-after jedi + (setcar jedi:server-command "python2") + (setq jedi:tooltip-method nil)) + +(stante-after jit-lock + (setq jit-lock-defer-time 0.2)) + +(stante-after magit + (setq magit-repo-dirs '("~/projects/")) + (setq magit-diff-refine-hunk 'all)) + +(stante-after message + (setq message-send-mail-function 'message-send-mail-with-sendmail) + (setq message-sendmail-extra-arguments '("-a" "ryuslash"))) + +(stante-after minibuf-eldef + (setq minibuffer-eldef-shorten-default t)) + +(stante-after mouse + (setq mouse-yank-at-point t)) + +(stante-after org + (setq org-special-ctrl-a/e t)) + +(stante-after org2blog + (setq org2blog/wp-blog-alist + '(("ryublog" + :url "https://ryuslash.org/blog/xmlrpc.php" + :username "ryuslash")))) + +(stante-after package + (setq package-archives + '(("melpa" . "http://melpa.milkbox.net/packages/") + ("marmalade" . "http://marmalade-repo.org/packages/") + ("gnu" . "http://elpa.gnu.org/packages/"))) + (setq package-load-list '((dispass "1.1.2.2") + all))) + +(stante-after "paragraphs" + (setq sentence-end-double-space nil)) + +(stante-after php-mode + (setq-default php-mode-warn-if-mumamo-off nil) + (setq php-function-call-face 'font-lock-function-name-face) + (setq php-mode-force-pear t)) + +(stante-after sendmail + (setq send-mail-function 'sendmail-send-it) + (setq sendmail-program "/usr/bin/msmtp")) + +(stante-after simple + (setq read-mail-command 'gnus)) + +(stante-after smartparens + (setq sp-cancel-autoskip-on-backward-movement nil + sp-autoskip-closing-pair 'always)) + +(stante-after smex + (setq smex-key-advice-ignore-menu-bar t) + (setq smex-save-file "~/.emacs.d/smex-items")) + +(stante-after "startup" + (setq inhibit-default-init t) + (setq inhibit-startup-message t) + (setq initial-major-mode 'emacs-lisp-mode) + (setq initial-scratch-message nil) + (setq user-mail-address "tom@ryuslash.org")) + +(stante-after time-stamp + (setq time-stamp-active t) + (setq time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)")) + +(stante-after type-break + (setq type-break-good-rest-interval (* 60 10)) + (setq type-break-interval (* 60 50)) + (setq type-break-keystroke-threshold '(nil . nil))) + +(stante-after w3m + (setq w3m-fill-column 72)) + +(stante-after "window" + (setq split-height-threshold 40) + (add-to-list + 'display-buffer-alist + '("^\\*\\(?:.+-\\)?scratch\\*$" display-buffer-same-window)) + (add-to-list + 'display-buffer-alist + '("^\\*git-project-list\\*$" git-project-show-window)) + (add-to-list + 'display-buffer-alist + '("^\\*magit: .*\\*$" display-buffer-same-window))) + +(stante-after yasnippet + (setq yas-fallback-behavior nil) + (setq yas-prompt-functions '(yas-ido-prompt))) + +(mode-hooks + ((clojure emacs-lisp lisp sawfish scheme ielm geiser-repl slime-repl) + paredit-mode) + ((comint) turn-on-compilation-shell-for-pony) + ((css) rainbow-mode) + ((emacs-lisp go html lua perl php python rst ruby rust sh) + flycheck-mode) + ((emacs-lisp ielm) eldoc-mode) + ((emacs-lisp ielm) set-emacs-lisp-keys) + ((eshell) buffer-disable-undo) + ((eshell) init-set-keys-for-eshell) + ((git-commit text) auto-fill-mode) + ((git-commit text) flyspell-mode) + ((html org prog) yas-minor-mode) + ((html prog) init-maybe-fci-mode) + ((html) tagedit-mode) + ((html) turn-off-flyspell) + ((html) turn-off-auto-fill) + ((hy) paredit-mode) + ((hy) init-set-keys-for-hy) + ((js2 python) smartparens-strict-mode) + ((markdown python) whitespace-mode) + ((message org gnus-summary gnus-article gnus-group magit-log-edit Info + info org-agenda jabber-chat) + init-make-readable) + ((prog) rainbow-delimiters-mode) + ((python) init-set-python-imenu-function) + ((python) jedi:setup) + ((python) subword-mode) + ((slime slime-repl) set-up-slime-ac) + ((smartparens) set-smartparens-keys) + ((sql-interactive) init-augment-sql-prompt) + ((tagedit) tagedit-add-experimental-features) + ((tagedit) tagedit-add-paredit-like-keybindings) + ((tagedit) init-set-keys-for-tagedit) + ((vala) oni:vala-mode-func)) - (save-excursion - (goto-char (point-max)) - (insert - (shell-command-to-string - (concat "git --git-dir='" default-directory ".git' --work-tree='" - default-directory "' request-pull " (when patchp "-p ") - from " " url " " to)))))) -(defun oni:self-insert-dwim () - "Execute self insert, but when the region is active call self -insert at the end of the region and at the beginning." - (interactive) - (if (region-active-p) - (let ((electric-pair-mode nil) - (beginning (region-beginning)) - (end (region-end))) - (goto-char end) - (self-insert-command 1) - (save-excursion - (goto-char beginning) - (self-insert-command 1))) - (self-insert-command 1))) +(setq-default bidi-paragraph-direction 'left-to-right) +(setq-default tab-width 4) +(setq-default indent-tabs-mode nil) +(setq-default truncate-lines t) +(setq custom-file "~/.emacs.d/custom.el") +(setq default-frame-alist + `((border-width . 0) + (internal-border-width . 0) + (vertical-scroll-bars . nil) + (menu-bar-lines . nil) + (tool-bar-lines . nil) + (font . "Cosmic Sans Neue Mono:pixelsize=17"))) +(setq frame-title-format '(:eval (concat "emacs: " (buffer-name)))) +(setq message-log-max 1000) +(setq redisplay-dont-pause t) +(setq use-dialog-box nil) +(setq user-full-name "Tom Willemse") +(setq window-combination-resize t) +(setq scroll-preserve-screen-position t) +(add-to-list 'debug-ignored-errors "^Can't shift all lines enough") +;; Can't be put in an eval-after-load or such because by then it will +;; be too late. +(setq elnode-do-init nil) -(defun oni:shorten-dir (dir) - "Shorten a directory, (almost) like fish does it." - (while (string-match "\\(/\\.?[^./]\\)[^/]+/" dir) - (setq dir (replace-match "\\1/" nil nil dir))) - dir) +(enable '(downcase-region narrow-to-page narrow-to-region scroll-left + upcase-region)) -(defun oni:show-buffer-position () - "Show the position in the current buffer." - (interactive) - (message (format "%d:%d" (line-number-at-pos) (current-column)))) +(eval-after-init (ido-ubiquitous-mode)) -(defun oni:show-org-index () - "Show the index of my org files." - (interactive) - (find-file "~/documents/org/index.org")) +(eval-after-load "org" '(require 'org-init)) -(defun oni:split-window-interactive (dir) - "Split windows in direction DIR. +(eval-after-init + (require 'auto-complete-config) + (ac-config-default)) -Can also delete or switch to another window." - (interactive - (list (read-char "Direction (h,v,q,d,o): "))) - (case dir - ((?v) (split-window-vertically)) - ((?h) (split-window-horizontally)) - ((?q) (delete-other-windows)) - ((?d) (delete-window)) - ((?o) (other-window 1)))) +(when (equal system-name "drd") + (eval-after-init + (load (expand-file-name "~/.local/share/quicklisp/slime-helper.el"))) + (load "eap-autoloads")) -(defun oni:split-window-interactively (window) - "Ask for a direction and split WINDOW that way. +(eval-after-init (smex-initialize)) +(eval-after-init (global-diff-hl-mode)) +(eval-after-init (mode-icons-mode)) +(eval-after-init (desktop-registry-auto-register)) -If no direction is given, don't split." - (let ((dir (read-char "Direction (h,v): "))) - (case dir - ((?v) (split-window-vertically)) - ((?h) (split-window-horizontally)) - (t window)))) -(defun oni:start-python-test-mail-server () - "Run the python test mailserver." - (interactive) - (start-process "python-test-mail-server" "*py-mail-server*" "python" "-m" - "smtpd" "-n" "-c" "DebuggingServer" "localhost:1025")) +;; (setq pony-tpl-indent-moves t) +;; (setq rainbow-delimiters-max-face-count 12) -(defun oni:stop-python-test-mail-server () - "Stop the python test mailserver." - (interactive) - (kill-process "python-test-mail-server")) +(add-hook 'after-save-hook 'oni:after-save-func t) +(add-hook 'before-save-hook 'oni:before-save-func) +(add-hook 'c-mode-hook 'oni:c-mode-func) +(add-hook 'css-mode-hook 'oni:css-mode-func) +(add-hook 'diary-display-hook 'oni:diary-display-func) +(add-hook 'go-mode-hook 'oni:go-mode-func) +(add-hook 'haskell-mode-hook 'oni:haskell-mode-func) +(add-hook 'java-mode-hook 'oni:java-mode-func) +(add-hook 'js-mode-hook 'oni:js-mode-func) +(add-hook 'js2-mode-hook 'oni:js2-mode-func) +(add-hook 'lua-mode-hook 'oni:lua-mode-func) +(add-hook 'markdown-mode-hook 'oni:markdown-mode-func) +(add-hook 'php-mode-hook 'oni:php-mode-func) +(add-hook 'prog-mode-hook 'oni:prog-mode-func) +(add-hook 'python-mode-hook 'oni:python-mode-func) +(add-hook 'term-mode-hook 'oni:term-mode-func) +(add-hook 'write-file-hooks 'oni:write-file-func) +(add-hook 'yas-minor-mode-hook 'oni:yas-minor-mode-func) -(defun oni:term-mode-func () - "Function for `term-mode-hook'." - (setq truncate-lines nil)) +(global-set-key (kbd "'") 'oni:self-insert-dwim) +(global-set-key (kbd "") 'oni:raise-scratch) +(global-set-key (kbd "") 'gnus) +(global-set-key (kbd "") 'git-project-show-files) +(global-set-key (kbd "") 'reload-buffer) +(global-set-key (kbd "") 'magit-status) +(global-set-key (kbd "") 'raise-eshell) +(global-set-key (kbd "") 'oni:show-org-index) +(global-set-key (kbd "C-<") 'oni:indent-shift-left) +(global-set-key (kbd "C->") 'oni:indent-shift-right) +(global-set-key (kbd "C-M-4") 'split-window-vertically) +(global-set-key (kbd "C-M-SPC") 'er/expand-region) +(global-set-key (kbd "C-M-d") 'kill-word) +(global-set-key (kbd "C-M-w") 'backward-kill-word) +(global-set-key (kbd "C-M-x") 'smex-major-mode-commands) +(global-set-key (kbd "C-M-z") 'indent-defun) +(global-set-key (kbd "C-S-k") 'kill-whole-line) +(global-set-key (kbd "C-c a") 'org-agenda) +(global-set-key (kbd "C-c c") 'org-capture) +(global-set-key (kbd "C-c d c") 'desktop-clear) +(global-set-key (kbd "C-c d d") 'desktop-registry-change-desktop) +(global-set-key (kbd "C-c d s") 'desktop-save-in-desktop-dir) +(global-set-key (kbd "C-c i p") 'identica-update-status-interactive) +(global-set-key (kbd "C-c p") 'oni:show-buffer-position) +(global-set-key (kbd "C-c t") 'oni:raise-ansi-term) +(global-set-key (kbd "C-c w d") 'oni:downcase-prev) +(global-set-key (kbd "C-c w u") 'oni:upcase-prev) +(global-set-key (kbd "C-e") 'oni:move-end-of-dwim) +(global-set-key (kbd "M-0") 'delete-window) +(global-set-key (kbd "M-1") 'delete-other-windows) +(global-set-key (kbd "M-2") 'split-window-below) +(global-set-key (kbd "M-3") 'split-window-right) +(global-set-key (kbd "M-4") 'split-window-horizontally) +(global-set-key (kbd "M-n") 'idomenu) +(global-set-key (kbd "M-o") 'other-window) +(global-set-key (kbd "M-x") 'smex) +(global-set-key (kbd "\"") 'oni:self-insert-dwim) +(global-set-key [remap move-beginning-of-line] 'move-beginning-of-dwim) +(global-set-key (kbd "C-x f") 'fiplr-find-file) +(global-set-key (kbd "C-c m") 'gnus) +(global-set-key (kbd "C-c g s") 'magit-status) +(global-set-key (kbd "C-c g i") 'magit-init) +(global-set-key (kbd "C-c g b") 'magit-checkout) +(global-set-key (kbd "C-c g f") 'magit-fetch) +(global-set-key (kbd "C-c h r") 'hypo-region) +(global-set-key (kbd "C-x C-b") 'bs-show) -(defun oni:upcase-prev (num) - (interactive "p") - (oni:change-prev-case num 'up)) +(if (daemonp) + (global-set-key "\C-x\C-c" 'oni:close-client-window)) -(defun oni:vala-mode-func () - "Function for `vala-mode-hook'." - (setq indent-tabs-mode nil)) +(when (or window-system (daemonp)) + (global-unset-key "\C-z")) -(defun oni:write-file-func () - "Function for `write-file-hooks'." - (time-stamp)) +(ido-mode) +(minibuffer-electric-default-mode) +(auto-insert-mode) +(savehist-mode) +(show-paren-mode) +(winner-mode) +(help-at-pt-set-timer) +(windmove-default-keybindings) -(defun oni:yas-minor-mode-func () - "Function for `yas-minor-mode-hook'." - (define-key yas-minor-mode-map (kbd "TAB") nil) - (define-key yas-minor-mode-map [(tab)] nil) - (define-key yas-minor-mode-map (kbd "C-\\") 'yas-expand)) +(global-set-key (kbd "") 'oni:scroll-down-or-prev-page) +(global-set-key (kbd "") 'oni:scroll-up-or-next-page) + +;;; Finally, load any `customize' settings. +(load custom-file) ;;;; Connected modes @@ -1344,64 +1385,17 @@ If no direction is given, don't split." ;;;; Make toggling outlines easier -(defun init-set-tab-maybe-toggle-outline () - "Wrap the current function mapped to `TAB'." - (let ((func (or (lookup-key (current-local-map) (kbd "TAB")) - (lookup-key (current-global-map) (kbd "TAB"))))) - (local-set-key (kbd "TAB") - (lambda () - (interactive) - (if (outline-on-heading-p) - (if (outline-invisible-p (line-end-position)) - (show-entry) - (hide-entry)) - (call-interactively func)))))) - (add-hook 'outline-minor-mode-hook #'init-set-tab-maybe-toggle-outline) ;;;; Share the output AND the command -(defun shell-command-with-command (command &optional output-buffer) - "Print both COMMAND and the output into OUTPUT-BUFFER." - (interactive (list (read-shell-command "Shell command: " nil nil) - current-prefix-arg)) - (when output-buffer - (insert "`" command "':\n")) - (shell-command command output-buffer)) - -(defun init-set-keys-for-jabber-chat () - "Set certain keys for `jabber-chat-mode'." - (local-set-key (kbd "M-!") #'shell-command-with-command)) - (add-hook 'jabber-chat-mode-hook #'init-set-keys-for-jabber-chat) (electric-indent-mode -1) -(defun oni:eshell-handle-url () - (save-excursion - (goto-char eshell-last-output-start) - (while (re-search-forward - "http://[^ \n]+" eshell-last-output-end :noerror) - (make-button (match-beginning 0) (match-end 0) - 'action (lambda (button) - (browse-url (button-label button))))))) - (stante-after esh-mode (add-to-list 'eshell-output-filter-functions #'oni:eshell-handle-url)) -(defun oni:current-dir-in-buffer-name () - (let ((branch - (shell-command-to-string - "git branch --contains HEAD 2>/dev/null | sed -e '/^[^*]/d'"))) - (rename-buffer - (setq eshell-buffer-name - (format "%s%s:%s" system-name - (if (not (string= branch "")) - (format "(%s)" (substring branch 2 -1)) - "") - (oni:shorten-dir - (abbreviate-file-name (eshell/pwd)))))))) - (stante-after em-dirs (add-hook 'eshell-directory-change-hook #'oni:current-dir-in-buffer-name)) -- cgit v1.2.3-54-g00ecf