834 lines
31 KiB
Org Mode
834 lines
31 KiB
Org Mode
#+TITLE: Emacs Init
|
||
#+STARTUP: showall
|
||
#+HTML_HEAD: <link href="http://ryuslash.org/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||
#+PROPERTy: tangle init.el
|
||
#+OPTIONS: num:nil
|
||
|
||
* Setup load-path :load_path:
|
||
|
||
Not everything can be installed with ~package.el~. Or some things can,
|
||
but I prefer installing them manually because it's easier. Anyway,
|
||
some additions should be made to =load-path= and if the file
|
||
~loaddefs.el~ exists, load it for the autoloads.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(mapc #'(lambda (dir)
|
||
(add-to-list 'load-path dir)
|
||
(let ((loaddefs (concat dir "/loaddefs.el")))
|
||
(when (file-exists-p loaddefs)
|
||
(load loaddefs))))
|
||
'("~/.emacs.d/site-lisp" "~/projects/emacs/pony-mode/src"
|
||
"~/projects/emacs/php-mode" "~/.emacs.d/vendor-lisp/org/lisp"
|
||
"~/.emacs.d/vendor-lisp/org/contrib/lisp"))
|
||
#+END_SRC
|
||
|
||
* Load other functions
|
||
|
||
Including all the functions being used here would make this file
|
||
immens and perhaps also somewhat unclear. In any case there are a
|
||
number of functions that I have found on the web in ~ext.el~, and a
|
||
number that I have written myself in ~oni.el~. So load them.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(require 'ext)
|
||
(require 'oni)
|
||
#+END_SRC
|
||
|
||
* Load theme :theme:
|
||
|
||
I have been experimenting with my own color theme for quite a while
|
||
now. I use ~package.el~ to install it, so to load it I need to wait
|
||
until after it has been loaded to enable it. Some of these settings
|
||
have also been specified in my [[file:../.Xdefaults][Xdefaults]] so that it doesn't start
|
||
with a completely white background (for too long).
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(oni:eval-after-init (load-theme 'yoshi t))
|
||
#+END_SRC
|
||
|
||
* Replace yes or no with y or n :y_or_n_p:
|
||
|
||
I have never had the trouble of accidentally pressing ~y~ at the
|
||
moment Emacs wants to ask me something. And having to type ~yes <RET>~
|
||
for a simple question gets in the way of things, so I prefer
|
||
=y-or-n-p=.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defalias 'yes-or-no-p 'y-or-n-p)
|
||
#+END_SRC
|
||
|
||
* Replace list-buffers with ibuffer :ibuffer:
|
||
|
||
~ibuffer~ offers some excellent ways to manage buffers. One of which
|
||
is the function to filter the buffer list on (almost) any predicate,
|
||
including the buffer's mode. ~list-buffers~ is simplistic compared to
|
||
this.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defalias 'list-buffers 'ibuffer)
|
||
#+END_SRC
|
||
|
||
* Replace dabbrev with hippie-expand :hippie_expand:
|
||
|
||
=hippie-expand= has an expansion that functions the same as
|
||
=dabbrev-expand= and it also has many more. I cannot think of a reason
|
||
why =dabbrev-expand= should be used when =hippie-expand= is also an
|
||
option.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defalias 'dabbrev-expand 'hippie-expand)
|
||
#+END_SRC
|
||
|
||
* Hide compilation window after success :compilation:
|
||
|
||
If compilation was succesfull I really don't need to see the
|
||
compilation window. So if either ~*Compilation*~ or ~*compilation*~
|
||
finishes correctly, delete the windows and show a message instead.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defun ext:comp-finish-function (buf str)
|
||
"Close the compilation buffer quickly if everything went OK."
|
||
(if (string-match "exited abnormally" str)
|
||
;; there were errors
|
||
(message "compilation errors, press C-x ` to visit")
|
||
;; no errors, make the compilation window go away in 0.5 seconds
|
||
(when (member (buffer-name) '("*Compilation*" "*compilation*"))
|
||
(delete-windows-on buf)
|
||
(message "No compilation errors!"))))
|
||
|
||
(add-to-list 'compilation-finish-functions 'ext:comp-finish-function)
|
||
#+END_SRC
|
||
|
||
* Enable auto-fill-mode :auto_fill:
|
||
|
||
=auto-fill-mode= automatically inserts newlines when a line becomes
|
||
too long. This is useful for both text modes and the comments in
|
||
programming modes. What it takes for a line to become too long is
|
||
specified by the =fill-column= variable.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'prog-mode-hook 'auto-fill-mode)
|
||
(add-hook 'text-mode-hook 'auto-fill-mode)
|
||
#+END_SRC
|
||
|
||
* Enable eldoc-mode :eldoc:
|
||
|
||
=eldoc-mode= shows the arguments for the function call at point in the
|
||
minibuffer, or in the mode-line if you're in the minibuffer. This is
|
||
very useful when writing Emacs Lisp code.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
|
||
(add-hook 'ielm-mode-hook 'eldoc-mode)
|
||
#+END_SRC
|
||
|
||
* Enable fill-column-indicator :fill_column_indicator:
|
||
|
||
Emacs has many packages that try to deal with showing a right
|
||
margin, the 80th column which your code should not go beyond. None
|
||
of these packages get it quite right, but =fill-column-indicator= gets
|
||
pretty close.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'html-mode-hook 'fci-mode)
|
||
(add-hook 'prog-mode-hook 'fci-mode)
|
||
#+END_SRC
|
||
|
||
* Enable flycheck-mode :flycheck:
|
||
|
||
Flycheck is a modern version of Flymake. They're not actually
|
||
related, but Flycheck did come from the idea of Flymake. Flycheck
|
||
has some interesting graphical elements (uses the fringe) and seems
|
||
to have a pretty flexible way of creating new checkers. I enable it
|
||
for all the modes that I use it supports.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'css-mode-hook 'flycheck-mode)
|
||
(add-hook 'emacs-lisp-mode-hook 'flycheck-mode)
|
||
(add-hook 'go-mode-hook 'flycheck-mode)
|
||
(add-hook 'html-mode-hook 'flycheck-mode)
|
||
(add-hook 'js2-mode-hook 'flycheck-mode)
|
||
(add-hook 'lua-mode-hook 'flycheck-mode)
|
||
(add-hook 'php-mode-hook 'flycheck-mode)
|
||
(add-hook 'python-mode-hook 'flycheck-mode)
|
||
(add-hook 'rst-mode-hook 'flycheck-mode)
|
||
(add-hook 'ruby-mode-hook 'flycheck-mode)
|
||
(add-hook 'rust-mode-hook 'flycheck-mode)
|
||
(add-hook 'sh-mode-hook 'flycheck-mode)
|
||
#+END_SRC
|
||
|
||
* Enable flyspell-mode :flyspell:
|
||
|
||
What Flymake and Flycheck are to compilation, Flyspell is to
|
||
spelling. Runs spell checking in the background and highlights
|
||
spelling errors. It might be useful in programming mode comments,
|
||
but that seems a bit over the top for me, I care about the code, not
|
||
so much about the words used. So I only enable it in =text-mode=.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'text-mode-hook 'flyspell-mode)
|
||
#+END_SRC
|
||
|
||
* Enable paredit-mode :paredit:
|
||
|
||
I had long thought of =paredit-mode= as overly complex and not very
|
||
useful. Though maybe I did try it out last before I started writing
|
||
so much Lisp code. In any case, I was wrong, it is one of the best
|
||
modes to use when editing Lisp and Lisp-like languages, changes your
|
||
whole perspective on the code.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'clojure-mode-hook 'paredit-mode)
|
||
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
|
||
(add-hook 'lisp-mode-hook 'paredit-mode)
|
||
(add-hook 'sawfish-mode-hook 'paredit-mode)
|
||
(add-hook 'scheme-mode-hook 'paredit-mode)
|
||
(add-hook 'ielm-mode-hook 'paredit-mode)
|
||
#+END_SRC
|
||
|
||
* Enable rainbow-delimiters-mode :rainbow_delimiters:
|
||
|
||
Any language can have quite deeply nested "delimeters", meaning
|
||
parentheses, brackets, curly braces. It helps to see their depth
|
||
visually. Not just in Lisp.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
|
||
#+END_SRC
|
||
|
||
* Enable rainbow-mode :rainbow:
|
||
|
||
When editing color-heavy "code", like CSS, it's useful to be able to
|
||
see color you're specifying. =rainbow-mode= does this.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'css-mode-hook 'rainbow-mode)
|
||
#+END_SRC
|
||
|
||
* Enable slime-js-minor-mode :js2:
|
||
|
||
SLIME is one of the coolest things about using Emacs to edit Lisp
|
||
code, so if there is something similar for JavaScript, even makes it
|
||
worth it to use the seemingly over-engineered =js2-mode=.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'js2-mode-hook 'slime-js-minor-mode)
|
||
#+END_SRC
|
||
|
||
* Enable smartparens-mode :smartparens:
|
||
|
||
=smartparens-mode= is a less strict and less lisp-focused mode that
|
||
tries to do something similar to =paredit-mode=. It is nice to use if
|
||
you're not writing in a Lisp-like language.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'html-mode-hook 'smartparens-mode)
|
||
(add-hook 'python-mode-hook 'smartparens-mode)
|
||
#+END_SRC
|
||
|
||
* Enable visual-line-mode :visual_line:
|
||
|
||
Having words run off the screen in a chat session is unpleasant.
|
||
Having the words cut-off wherever the line ends is even worse! Use
|
||
=visual-line-mode= to get some proper word wrapping behaviour in these
|
||
buffers.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'jabber-chat-mode-hook 'visual-line-mode)
|
||
(add-hook 'erc-mode-hook 'visual-line-mode)
|
||
#+END_SRC
|
||
|
||
* Enable whitespace-mode :whitespace:
|
||
|
||
In most programming languages whitespace is pretty unimportant. As
|
||
long as the readers can stand it the compilers/interpreters usually
|
||
don't care. Of course this is not true for Python, and Markdown also
|
||
has special meanings for some whitespace in some places, so enabling
|
||
=whitespace-mode= is a good idea, just for these two situations.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'markdown-mode-hook 'whitespace-mode)
|
||
(add-hook 'python-mode-hook 'whitespace-mode)
|
||
#+END_SRC
|
||
|
||
* Enable yas-minor-mode :yas:
|
||
|
||
I still need to figure out where this mode comes in in my workflow.
|
||
I try to limit code-repetition as much as I can and anything that
|
||
does repeat often is so trivial that it doesn't benefit from
|
||
snippets. And using snippets for =if= statements and such doesn't
|
||
strike me as terribly useful either. But perhaps I haven't seen the
|
||
magic of it yet. I do know that it is an interesting tool and I wish
|
||
to find a use for it at some point.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'html-mode-hook 'yas-minor-mode)
|
||
(add-hook 'org-mode-hook 'yas-minor-mode)
|
||
(add-hook 'prog-mode-hook 'yas-minor-mode)
|
||
#+END_SRC
|
||
|
||
* Enable tagedit-mode :tagedit:
|
||
|
||
=tagedit-mode= tries to be for XML/HTML what =paredit-mode= is for Lisp.
|
||
And because of this, it *rocks*. It almost makes me feel sorry that I
|
||
don't write all that much XML or HTML nowadays. Enable the
|
||
experimental features as well, so it's really close to =paredit-mode=.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defun oni:turn-on-tagedit-mode ()
|
||
(require 'tagedit)
|
||
(tagedit-mode)
|
||
(tagedit-add-paredit-like-keybindings)
|
||
(tagedit-add-experimental-features))
|
||
|
||
(add-hook 'html-mode-hook 'oni:turn-on-tagedit-mode)
|
||
#+END_SRC
|
||
|
||
* Make ^L look pretty :ppcL:
|
||
|
||
This mode should be activated each time a frame is made, since it
|
||
uses certain frame properties.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'emacs-startup-hook 'pretty-control-l-mode)
|
||
(add-hook 'after-make-frame-functions
|
||
'(lambda (arg) (pretty-control-l-mode)))
|
||
#+END_SRC
|
||
|
||
* Customize eshell prompt :eshell:
|
||
|
||
Create a prompt that shows the following:
|
||
|
||
- The exit code of the previous command: a green ~+~ for exit code ~0~
|
||
and a red ~-~ for any non-zero exit code.
|
||
|
||
- The hostname of the device running the current Emacs instance.
|
||
|
||
- An abbreviated indication of the current directory. To keep things
|
||
short this abbreviation is the first letter of each parent
|
||
directory and the full name of the current directory, still
|
||
separated by ~/~, though.
|
||
|
||
- Which branch (if any) the current directory has been checked-out
|
||
of. This is not shown if the current directory is not a git
|
||
directory.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defun oni:eshell-prompt-function ()
|
||
"Show a pretty shell prompt."
|
||
(let ((status (if (zerop eshell-last-command-status) ?+ ?-))
|
||
(hostname (oni:hostname))
|
||
(dir (abbreviate-file-name (eshell/pwd)))
|
||
(branch
|
||
(shell-command-to-string
|
||
"git branch --contains HEAD 2>/dev/null | sed -e '/^[^*]/d'")))
|
||
(concat
|
||
(propertize (char-to-string status)
|
||
'face `(:foreground ,(if (= status ?+)
|
||
"green"
|
||
"red")))
|
||
" "
|
||
(propertize hostname 'face 'mode-line-buffer-id)
|
||
" "
|
||
(propertize (oni:shorten-dir dir) 'face 'font-lock-string-face)
|
||
" "
|
||
(when (not (string= branch ""))
|
||
(propertize
|
||
;; Cut off "* " and "\n"
|
||
(substring branch 2 -1)
|
||
'face 'font-lock-function-name-face))
|
||
" \n> ")))
|
||
#+END_SRC
|
||
|
||
* Add a pop-up function for eshell :eshell:
|
||
|
||
When working I often need to switch to a shell to issue some quick
|
||
commands and then be on my merry way again, to help with this I have
|
||
added a function which tries to move the current working directory
|
||
to that of the file being worked on and shows eshell. I bind this
|
||
function to ~f8~ for easy access.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defun oni:raise-eshell ()
|
||
"Start or switch back to `eshell'.
|
||
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)))))
|
||
|
||
(global-set-key (kbd "<f8>") 'oni:raise-eshell)
|
||
#+END_SRC
|
||
|
||
* Disable undo in eshell buffers :eshell:
|
||
|
||
Eshell buffers can get big and undo does not serve any real purpose
|
||
in these buffers. Instead of getting boundary limit popups all the
|
||
time, which I do want to keep for other buffers, it's easier to
|
||
just turn off undo information for such buffers.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'eshell-mode-hook 'buffer-disable-undo)
|
||
#+END_SRC
|
||
|
||
* Enable some "advanced" functions
|
||
|
||
These functions are disabled by default, because beginners find them
|
||
confusing, apparently. Though I won't say I'm an Emacs master or
|
||
guru, I *can* say that I'm not a beginner, and these functions have
|
||
not confused me yet. So enable them.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(put 'downcase-region 'disabled nil)
|
||
(put 'narrow-to-page 'disabled nil)
|
||
(put 'narrow-to-region 'disabled nil)
|
||
(put 'scroll-left 'disabled nil)
|
||
(put 'upcase-region 'disabled nil)
|
||
#+END_SRC
|
||
|
||
* Don't echo status changes for jabber :jabber:
|
||
|
||
If I'm talking to someone I'll see their status and if they're
|
||
offline and I want to say something I can say it anyway, I don't
|
||
need constant updates in my echo-area on the status of my jabber
|
||
buddies. But since this relies on something from the ~jabber~ module,
|
||
only run it after that module has been loaded.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(eval-after-load "jabber"
|
||
'(remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo))
|
||
#+END_SRC
|
||
|
||
* Use libnotify for jabber notifications :jabber:
|
||
|
||
The functions don't seem to be loaded automatically, so add
|
||
autoloads for the libnotify functions.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(autoload 'jabber-message-libnotify "jabber-libnotify")
|
||
(autoload 'jabber-muc-libnotify "jabber-libnotify")
|
||
|
||
(add-hook 'jabber-alert-message-hooks 'jabber-message-libnotify)
|
||
(add-hook 'jabber-alert-muc-hooks 'jabber-muc-libnotify)
|
||
#+END_SRC
|
||
|
||
* Enable idomenu :idomenu:
|
||
|
||
Imenu is an awesome feature, but since I don't use any menus it is
|
||
a little lost on me. =idomenu= uses Imenu, but shows it in an
|
||
ido-like way, which works perfectly. Bind it to ~M-n~.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(global-set-key (kbd "M-n") 'idomenu)
|
||
#+END_SRC
|
||
|
||
* Enable jedi :jedi:
|
||
|
||
jedi is an interesting auto-completion program for the Python
|
||
programming language. On archlinux the program you usually want to
|
||
use is ~python2~, so change the =jedi:server-command= accordingly and
|
||
run =jedi:setup= when =python-mode= starts to enable it.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'python-mode-hook 'jedi:setup)
|
||
#+END_SRC
|
||
|
||
* Org initialization :org:
|
||
|
||
Since my intialization for =org-mode= got so big, I moved it to a
|
||
separate file. This file should be loaded after the =org= module
|
||
loads.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(eval-after-load "org" '(require 'org-init))
|
||
#+END_SRC
|
||
|
||
* Indent-defun
|
||
|
||
The emacsredux website had an interesting [[http://emacsredux.com/blog/2013/03/28/indent-defun/][tip]].
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(global-set-key (kbd "C-M-z") 'ext:indent-defun)
|
||
#+END_SRC
|
||
|
||
* Close term buffer after exit :term:
|
||
|
||
When quitting the process in a term buffer, in other words, when
|
||
quitting the shell, kill the buffer. Killing the shell, but not
|
||
killing the buffer is a pain, it keeps you from quickly starting a
|
||
term and quickly closing it too. This advice should be disabled if
|
||
ever the shell crashes, because it doesn't look at the exit code,
|
||
since the standard exit code is that of the last run command.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defadvice term-handle-exit (after oni:kill-buffer-after-exit activate)
|
||
"Kill the term buffer if the process finished."
|
||
(kill-buffer (current-buffer)))
|
||
#+END_SRC
|
||
|
||
* Changing case
|
||
|
||
I have no capslock key, and holding shift whilst typing big words
|
||
is annoying, so I wrote a couple of functions to help with that and
|
||
bind them to ~C-c u~ and ~C-c d~.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(global-set-key (kbd "C-c u") 'oni:upcase-prev)
|
||
(global-set-key (kbd "C-c d") 'oni:downcase-prev)
|
||
#+END_SRC
|
||
|
||
* Turn off usage of tabs for vala-mode :vala:
|
||
|
||
Somehow =vala-mode= thinks it's ok for it to decide that it's users
|
||
should always use tabs. As far as I'm aware the vala compiler has
|
||
no such restriction, so turn it off.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(add-hook 'vala-mode-hook 'oni:vala-mode-func)
|
||
#+END_SRC
|
||
|
||
* Use smex :smex:
|
||
|
||
Smex is to command selection what ido is to file selection. Very
|
||
similar too, it was written with ido specifically in mind.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(global-set-key (kbd "M-x") 'smex)
|
||
(global-set-key (kbd "C-M-x") 'smex-major-mode-commands)
|
||
#+END_SRC
|
||
|
||
* Autoload define-slime-contrib :js2:
|
||
|
||
=slime-js-minor-mode= uses this function but forgets to require its
|
||
module, so I set up an autoload function for when I need it and
|
||
haven't yet used slime.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(autoload 'define-slime-contrib "slime")
|
||
#+END_SRC
|
||
|
||
* Autoload some other functions
|
||
|
||
These need to have autoloads specified for various reasons, mostly
|
||
because they're installed manually or because they're old.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(autoload 'gtags-mode "gtags" nil t)
|
||
(autoload 'jabber-connect "jabber" nil t)
|
||
(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 'slime-js-minor-mode "slime-js" nil t)
|
||
(autoload 'w3m-bookmark-view "w3m" nil t)
|
||
(autoload 'w3m-goto-url "w3m" nil t)
|
||
(autoload 'xmodmap-mode "xmodmap-mode" nil t)
|
||
#+END_SRC
|
||
|
||
* Uniquify buffers better :uniquify:
|
||
|
||
The default way to make sure buffer names are unique is rather
|
||
uninformative, =uniquify= has a few better options.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(require 'uniquify)
|
||
#+END_SRC
|
||
|
||
* Don't warn about mumamo :php:
|
||
|
||
I haven't yet seen a mode that offers good multiple major modes
|
||
support. And so I don't use any, so don't warn me that I don't.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq-default php-mode-warn-if-mumamo-off nil)
|
||
#+END_SRC
|
||
|
||
* Automatically determine browser :browse:
|
||
|
||
Use the =BROWSER= environment variable to figure out which browser to
|
||
call for =browse-url=.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq browse-url-generic-program (getenv "BROWSER"))
|
||
#+END_SRC
|
||
|
||
* Move customize settings into their own file :custom:
|
||
|
||
Any settings I change using the customize interface should go into
|
||
a separate file. My ~init.el~ is under version control and I don't
|
||
want each local change made in this way to be recorded in the VCS.
|
||
Plus the code generated by customize is an eyesore.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq custom-file "~/.emacs.d/custom.el")
|
||
#+END_SRC
|
||
|
||
* Stop elnode from running automatically :elnode:
|
||
|
||
I like elnode, but it really should stop starting itself up every
|
||
time I start emacs. Not only can this cause problems with trying
|
||
to run on the same port, but also this starts running programs that
|
||
I have no idea of, whatever I was testing last.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq elnode-do-init nil)
|
||
#+END_SRC
|
||
|
||
* Mention the buffer in the frame title
|
||
|
||
Having 5 Emacs frames all named "emacs" doesn't help to identify
|
||
them, so add the opened buffer name to the title.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq frame-title-format '(:eval (concat "emacs: " (buffer-name))))
|
||
#+END_SRC
|
||
|
||
* Store geiser history under .emacs.d
|
||
|
||
Everything Emacs related should be stored under ~HOME/.emacs.d~ so as
|
||
not to fill my home directory with a bunch of directories.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq geiser-repl-history-filename "~/.emacs.d/geiser-history")
|
||
#+END_SRC
|
||
|
||
* Set inferior lisp program to SBCL :lisp:
|
||
|
||
SBCL seems like a very good Lisp implementation to use, widely
|
||
supported by packagers too.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq inferior-lisp-program "sbcl")
|
||
#+END_SRC
|
||
|
||
* Turn on compilation-shell-minor-mode for pony buffers :pony:
|
||
|
||
Turn on =compilation-shell-minor-mode= whenever =pony-minor-mode= starts
|
||
in a =comint-mode= buffer. Since buffers like ~*ponymanage*~ and
|
||
~*ponyserver*~ don't have their own specialized modes, but use
|
||
=comint-mode= and turn on =pony-minor-mode=, and I don't want to enable
|
||
=compilation-shell-minor-mode= for *every* =comint-mode= buffer, we can
|
||
add a hook that adds a local hook.
|
||
|
||
I use =compilation-shell-minor-mode= because some pony mode buffers
|
||
are interactive, such as the pony-shell buffer.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defun turn-on-compilation-shell-for-pony ()
|
||
(add-hook 'pony-minor-mode-hook 'compilation-shell-minor-mode nil t))
|
||
(add-hook 'comint-mode-hook 'turn-on-compilation-shell-for-pony)
|
||
#+END_SRC
|
||
|
||
* Make smartparens a little stricter :smartparens:
|
||
|
||
Set the delete and backspace keys to some smartparens keybindings
|
||
that should make pair balancing a little stricter. These key
|
||
bindings refuse to delete pair delimeters or skip over them if they
|
||
still have content.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(defun oni:smartparens-set-keys ()
|
||
(local-set-key (kbd "DEL") 'sp-backward-delete-char)
|
||
(local-set-key (kbd "<deletechar>") 'sp-delete-char)
|
||
(local-set-key (kbd "C-d") 'sp-delete-char))
|
||
|
||
(add-hook 'smartparens-mode-on-hook 'oni:smartparens-set-keys)
|
||
#+END_SRC
|
||
|
||
* Initialize EMMS :emms:
|
||
|
||
Initialize a minimal EMMS setup. Load the default players so we can
|
||
use mplayer or any of the generic mp3 and ogg players.
|
||
|
||
Load the MPD player so we can connect to MPD and use that if
|
||
possible, set the music directory to MPD's music directory so it
|
||
knows how to translate filenames to something MPD understands.
|
||
|
||
Load the =emms-mode-line= module so we can display some information in
|
||
the mode-line about which song is playing and set my preferred
|
||
function for extracting this information. The =emms-info-mpd= function
|
||
doesn't seem to return anything, so I've had to improvise to turn
|
||
absolute file names into something nicer.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(eval-after-load "emms"
|
||
`(progn
|
||
(emms-minimalistic)
|
||
(emms-default-players)
|
||
|
||
(require 'emms-player-mpd)
|
||
(add-to-list 'emms-player-list 'emms-player-mpd)
|
||
|
||
(require 'emms-mode-line)
|
||
(emms-mode-line 1)))
|
||
#+END_SRC
|
||
|
||
* All the rest
|
||
|
||
This still needs to be sorted out and documented, haven't had time
|
||
for it yet.
|
||
|
||
#+BEGIN_SRC emacs-lisp
|
||
(setq php-function-call-face 'font-lock-function-name-face)
|
||
(setq php-mode-force-pear t)
|
||
(setq pony-tpl-indent-moves t)
|
||
(setq redisplay-dont-pause t)
|
||
(setq w3m-fill-column 72)
|
||
|
||
(add-hook 'after-change-major-mode-hook 'set-current-mode-icon)
|
||
(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 'emacs-startup-hook 'oni:emacs-startup-func)
|
||
(add-hook 'go-mode-hook 'oni:go-mode-func)
|
||
(add-hook 'gtags-mode-hook 'oni:gtags-mode-func)
|
||
(add-hook 'haskell-mode-hook 'oni:haskell-mode-func)
|
||
(add-hook 'jabber-roster-mode-hook 'oni:jabber-roster-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)
|
||
|
||
(define-key key-translation-map (kbd "C-j") (kbd "C-l"))
|
||
(define-key key-translation-map (kbd "C-l") (kbd "C-j"))
|
||
|
||
(global-set-key (kbd "'") 'oni:self-insert-dwim)
|
||
(global-set-key (kbd "<XF86HomePage>") 'oni:raise-scratch)
|
||
(global-set-key (kbd "<XF86Mail>") 'gnus)
|
||
(global-set-key (kbd "<f10>") 'git-project-show-files)
|
||
(global-set-key (kbd "<f5>") 'ext:reload-buffer)
|
||
(global-set-key (kbd "<f6>") 'jabber-switch-to-roster-buffer)
|
||
(global-set-key (kbd "<f7>") 'magit-status)
|
||
(global-set-key (kbd "<hiragana>") '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-S-k") 'kill-whole-line)
|
||
(global-set-key (kbd "C-a") 'oni:move-beginning-of-dwim)
|
||
(global-set-key (kbd "C-c a") 'org-agenda)
|
||
(global-set-key (kbd "C-c c") 'org-capture)
|
||
(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-d") 'oni:kill-region-or-forward-char)
|
||
(global-set-key (kbd "C-e") 'oni:move-end-of-dwim)
|
||
(global-set-key (kbd "C-k") 'oni:kill-region-or-line)
|
||
(global-set-key (kbd "C-w") 'oni:kill-region-or-backward-char)
|
||
(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-o") 'other-window)
|
||
(global-set-key (kbd "\"") 'oni:self-insert-dwim)
|
||
|
||
(if (daemonp)
|
||
(global-set-key "\C-x\C-c" 'oni:close-client-window))
|
||
|
||
(when (or window-system (daemonp))
|
||
(global-unset-key "\C-z"))
|
||
|
||
(add-to-list 'auto-mode-alist '("\\.jl$" . sawfish-mode))
|
||
(add-to-list 'auto-mode-alist '("\\.js\\(on\\)?$" . js2-mode))
|
||
(add-to-list 'auto-mode-alist
|
||
'("\\.m\\(ark\\)?d\\(?:o?wn\\)?$" . markdown-mode))
|
||
(add-to-list 'auto-mode-alist '("\\.php[345]?$" . php-mode))
|
||
(add-to-list 'auto-mode-alist '("\\.po\\'\\|\\.po\\." . po-mode))
|
||
(add-to-list 'auto-mode-alist '("\\.tpl$" . html-mode))
|
||
(add-to-list 'auto-mode-alist '("^PKGBUILD$" . shell-script-mode))
|
||
(add-to-list 'auto-mode-alist '("^\\.Xmodmap$" . xmodmap-mode))
|
||
|
||
(package-initialize)
|
||
|
||
(oni:eval-after-init (ido-ubiquitous-mode))
|
||
(smex-initialize)
|
||
(help-at-pt-set-timer)
|
||
(windmove-default-keybindings)
|
||
(global-diff-hl-mode)
|
||
|
||
;;; Diminish lighter for a bunch of minor modes that should be on in
|
||
;;; certain modes and usually just clogg up the mode line.
|
||
(diminish 'auto-fill-function)
|
||
|
||
(eval-after-load "auto-complete" '(diminish 'auto-complete-mode))
|
||
(eval-after-load "eldoc" '(diminish 'eldoc-mode))
|
||
(eval-after-load "flycheck" '(diminish 'flycheck-mode))
|
||
(eval-after-load "paredit" '(diminish 'paredit-mode))
|
||
(eval-after-load "rainbow-mode" '(diminish 'rainbow-mode))
|
||
(eval-after-load "smartparens" '(diminish 'smartparens-mode))
|
||
(eval-after-load "yasnippet" '(diminish 'yas-minor-mode))
|
||
|
||
|
||
(defun oni:scroll-down-or-prev-page (arg)
|
||
"Either scroll down or go to the previous page.
|
||
|
||
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)))
|
||
|
||
(defun oni:scroll-up-or-next-page (arg)
|
||
"Either scroll up or go to the next page.
|
||
|
||
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)))
|
||
|
||
(global-set-key (kbd "<prior>") 'oni:scroll-down-or-prev-page)
|
||
(global-set-key (kbd "<next>") 'oni:scroll-up-or-next-page)
|
||
|
||
;;; Emacs Alsa Player
|
||
(add-to-list 'load-path "~/.emacs.d/site-lisp/eap")
|
||
(load "eap-autoloads")
|
||
|
||
;;;; Auto-complete
|
||
|
||
(setq-default ac-sources '(ac-source-imenu
|
||
ac-source-gtags
|
||
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))
|
||
|
||
;;; Finally, load any `customize' settings and slime.
|
||
(load custom-file)
|
||
(load (expand-file-name "~/quicklisp/slime-helper.el"))
|
||
#+END_SRC
|