From 9da019d7e8394076c9c5e19b2842fb7fd1123c6b Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 22 Mar 2013 13:34:32 +0100 Subject: Emacs: Rewrite part of index.org --- emacs/init.org | 238 +++++++++++++++++++-------------------------------------- 1 file changed, 80 insertions(+), 158 deletions(-) (limited to 'emacs/init.org') diff --git a/emacs/init.org b/emacs/init.org index 7fc6a8d..62656f2 100644 --- a/emacs/init.org +++ b/emacs/init.org @@ -4,164 +4,86 @@ #+PROPERTY: tangle init2.el #+STARTUP: showall -* GUI - - These things should happen early, so that Emacs will look the way I - want it to as quickly as is possible. - -** menu-bar-mode - - Disable =menu-bar-mode= since I haven't used the menu bar much ever, - even when I first started using Emacs. - - #+BEGIN_SRC emacs-lisp - (menu-bar-mode -1) - #+END_SRC - -** scroll-bar-mode - - Since Emacs gives a pretty good indication of where in the buffer - I'm working I really don't need to have the scroll bar visible. - - #+BEGIN_SRC emacs-lisp - (scroll-bar-mode -1) - #+END_SRC - -** tool-bar-mode - - I've never used the tool bar much, so remove it. - - #+BEGIN_SRC emacs-lisp - (tool-bar-mode -1) - #+END_SRC - -* load-path - - Before doing anything else I should make sure that both the - directories ~/usr/local/emacs/share/emacs/site-lisp~ and - ~/usr/share/emacs/site-list~ are included in =load-path=, along with - their subdirectories, but only if they haven't already been added - and exist. Place them at the end of =load-path= so they don't mess up - package precedence. - - #+BEGIN_SRC emacs-lisp - (eval-and-compile - (defun oni:path-init (dir) - "Add DIR to `load-path' and all its subdirectories, unless - DIR is already in `load-path'." - (unless (or (member dir load-path) (not (file-exists-p dir))) - (let ((default-directory dir)) - (add-to-list 'load-path dir t) - (normal-top-level-add-subdirs-to-load-path)))) - (oni:path-init "/usr/share/emacs/site-lisp") - (oni:path-init "/usr/local/emacs/share/emacs/site-lisp")) - #+END_SRC - - Load my preferred theme after emacs has finished starting up. Use - the ~emacs-startup-hook~ to wait until we're sure all ELPA packages - have been loaded. - - #+BEGIN_SRC emacs-lisp - (add-hook 'emacs-startup-hook (lambda () (load-theme 'yoshi t))) - #+END_SRC - - Add any other interesting paths to =load-path= and, if it exists, - load the ~loaddefs.el~ file from these directories. - - #+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)))) - '("~/projects/emacs/mode-icons" "~/.emacs.d/site-lisp" - "~/projects/emacs/pony-mode/src" "~/projects/emacs/php-mode" - "/usr/local/org-mode/share/emacs/site-lisp/org")) - #+END_SRC - -* y-or-n-p - - Don't ask ~yes~ or ~no~, ask ~y~ or ~n~, I've never had an accidental ~y~ so - far. - - #+BEGIN_SRC emacs-lisp - (defalias 'yes-or-no-p 'y-or-n-p) - #+END_SRC - -* ibuffer - - Use =ibuffer= instead of the default =list-buffers= because it has many - more features. - - #+BEGIN_SRC emacs-lisp - (defalias 'list-buffers 'ibuffer) - #+END_SRC - -* hippie-expand - - Do the same with =hippie-expand= and =dabbrev-expand=. - - #+BEGIN_SRC emacs-lisp - (defalias 'dabbrev-expand 'hippie-expand) - #+END_SRC - -* eldoc - - Don't show it when ~eldoc~ is running, I almost assume that it is - whenever I'm working in a mode that supports it anyway. This should - only execute once ~eldoc~ has been loaded. - - #+BEGIN_SRC emacs-lisp - (eval-after-load "eldoc" '(diminish 'eldoc-mode)) - #+END_SRC - -* emms - - Use the standard EMMS configuration and add some MPD settings. - - #+BEGIN_SRC emacs-lisp - (defun oni:emms-init () - "Initialization function for EMMS." - (require 'emms-setup) - (require 'emms-player-mpd) - - (emms-standard) - - (add-to-list 'emms-info-functions 'emms-info-mpd) - (add-to-list 'emms-player-list 'emms-player-mpd) - - (setq emms-player-mpd-server-name "localhost") - (setq emms-player-mpd-server-port "6600") - (setq emms-player-mpd-music-directory "/mnt/music/mp3")) - - (eval-after-load "emms-source-file" '(oni:emms-init)) - (setq emms-source-file-default-directory "/mnt/music/") - #+END_SRC - - Add some keybindings for EMMS. - - #+BEGIN_SRC emacs-lisp - (defun oni:emms-toggle-playing () - "Toggle between playing/paused states." - (interactive) - (if (eq emms-player-playing-p nil) - (emms-start) - (emms-pause))) - - (defun oni:start-emms () - "Check to see if the function `emms' exists, if not call - `emms-player-mpd-connect' and assume that will have loaded it." - (interactive) - (unless (fboundp 'emms) - (emms-player-mpd-connect)) - (emms)) - - (global-set-key (kbd "") 'emms-next) - (global-set-key (kbd "") 'oni:emms-toggle-playing) - (global-set-key (kbd "") 'emms-previous) - (global-set-key (kbd "") 'emms-stop) - (global-set-key (kbd "") 'oni:start-emms) - #+END_SRC +Disable the ~menu-bar-mode~, ~tool-bar-mode~ and ~scroll-bar-mode~ early on +so the disappear quickly after emacs starts up. + +#+BEGIN_SRC emacs-lisp + (menu-bar-mode -1) + (scroll-bar-mode -1) + (tool-bar-mode -1) +#+END_SRC + +Define a macro for deferring code until after emacs has started up. + +#+BEGIN_SRC emacs-lisp + (defmacro eval-after-init (&rest body) + "Defer execution of BODY until after Emacs init." + `(add-hook 'emacs-startup-hook #'(lambda () ,@body))) +#+END_SRC + +Add ~/usr/share/emacs/site-lisp~ and +~/usr/local/emacs/share/emacs/site-lisp~ and all their sub-directories +to the ~load-path~ so I can use modules from both Emacs from the +official repository *and* the self-compiled one. + +This should be done both when compiling the elisp file and when +loading it so it doesn't complain about missing modules and such. + +#+BEGIN_SRC emacs-lisp + (eval-and-compile + (defun oni:path-init (dir) + "Add DIR to `load-path' and all its subdirectories, unless + DIR is already in `load-path'." + (unless (or (member dir load-path) (not (file-exists-p dir))) + (let ((default-directory dir)) + (add-to-list 'load-path dir t) + (normal-top-level-add-subdirs-to-load-path)))) + (oni:path-init "/usr/share/emacs/site-lisp") + (oni:path-init "/usr/local/emacs/share/emacs/site-lisp")) +#+END_SRC + +Defer loading my theme until after emacs initialization. This is +because it has been installed with ~package.el~, and the packages aren't +added to the ~load-path~ until _after_ ~init.el~ has been run through. + +#+BEGIN_SRC emacs-lisp + (eval-after-init (load-theme 'yoshi t)) +#+END_SRC + +Add some of my project directories and other important directories +into ~load-path~ so I can easily load libraries in them. Also, if it +exists, load ~loaddefs.el~ in each directory for 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)))) + '("~/projects/emacs/mode-icons" "~/.emacs.d/site-lisp" + "~/projects/emacs/pony-mode/src" "~/projects/emacs/php-mode" + "/usr/local/org-mode/share/emacs/site-lisp/org")) +#+END_SRC + +Replace the question of ~yes~ or ~no~ with just ~y~ or ~n~, I have never (yet) +accidentally typed a ~y~ or ~n~ when asked and typing ~yes~ or ~no~ is just +too much work. + +#+BEGIN_SRC emacs-lisp + (defalias 'yes-or-no-p 'y-or-n-p) +#+END_SRC + +Replace these functions with better alternatives. They offer the same +functionality, plus more. + +#+BEGIN_SRC emacs-lisp + (defalias 'list-buffers 'ibuffer) + (defalias 'dabbrev-expand 'hippie-expand) +#+END_SRC + +#+BEGIN_SRC emacs-lisp + (setq compilation-scroll-output t) +#+END_SRC * flymake -- cgit v1.2.3-54-g00ecf