From 35fc2e3378a3b91547b43b2d0fef28f8d88c1e37 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 25 Jan 2013 00:32:30 +0100 Subject: emacs: Redo again --- .emacs.d/init.el | 66 +++++--- .emacs.d/init.org | 392 ++++++---------------------------------------- .emacs.d/site-lisp/oni.el | 39 +++-- 3 files changed, 121 insertions(+), 376 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index b4b6b73..dddef30 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -8,6 +8,23 @@ (load (concat user-emacs-directory "init2")) +(defface git-commit-summary-face + '((t (:inherit org-level-1))) + "Face for the git title line." + :group 'local) + +(defface git-commit-overlong-summary-face + '((t (:background "#873732"))) + "Face for commit titles that are too long." + :group 'local) + +(defface git-commit-nonempty-second-line-face + '((t (:inherit git-commit-overlong-summary-face))) + "Face for the supposedly empty line in commit messages." + :group 'local) + +(eval-after-load "eldoc" '(diminish 'eldoc-mode)) +(eval-after-load "em-term" '(add-to-list 'eshell-visual-commands "unison")) (eval-after-load "emms-source-file" '(oni:emms-init)) (eval-after-load "flymake" '(oni:flymake-init)) (eval-after-load "ido" '(oni:ido-init)) @@ -18,6 +35,24 @@ (eval-after-load "smex" '(oni:smex-init)) (eval-after-load "yasnippet" '(oni:yasnippet-init)) +(autoload 'define-slime-contrib "slime") +(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 'xmodmap-mode "xmodmap-mode" nil t) +(autoload 'w3m-bookmark-view "w3m" nil t) +(autoload 'w3m-goto-url "w3m" nil t) + +(require 'geiser-install) +(require 'uniquify) +(require 'ext) +(require 'oni) + (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) (put 'narrow-to-region 'disabled nil) @@ -36,11 +71,9 @@ (setq appt-disp-window-function #'oni:appt-display-window-and-jabber) (setq appt-display-diary nil) (setq auto-mode-case-fold nil) -(setq auto-save-file-name-transforms - `((".*" ,temporary-file-directory t))) +(setq auto-save-file-name-transforms oni:auto-save-name-transforms) (setq avandu-article-render-function #'avandu-view-w3m) -(setq backup-directory-alist - `((".*" . ,temporary-file-directory))) +(setq backup-directory-alist oni:backup-directory-alist) (setq browse-url-browser-function 'browse-url-generic) (setq browse-url-generic-program (getenv "BROWSER")) (setq c-offsets-alist '((statement-block-intro . +) @@ -66,6 +99,7 @@ (menu-bar-lines . nil) (tool-bar-lines . nil) (font . "Monaco-12"))) +(setq elnode-do-init nil) (setq emms-source-file-default-directory "/mnt/music/") (setq erc-autojoin-channels-alist '(("freenode.net" "#ninthfloor" "#emacs"))) @@ -153,6 +187,7 @@ (setq jabber-chat-local-prompt-format "%t >\n") (setq jabber-chatstates-confirm nil) (setq jabber-history-dir "~/.emacs.d/jabber") +(setq jabber-muc-autojoin '("aethon@muc.ryuslash.org")) (setq jabber-roster-show-bindings nil) (setq jit-lock-defer-time 0.2) (setq magit-repo-dirs '("~/projects/" "~/var/src/")) @@ -226,6 +261,9 @@ (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 "") 'emms-next) (global-set-key (kbd "") 'oni:emms-toggle-playing) @@ -293,24 +331,15 @@ 'display-buffer-alist '("^\\*magit: .*\\*$" . ((display-buffer-same-window . nil)))) -(unless (oni:required-packages-installed-p) - (message "%s" "Refreshing package database...") - (package-refresh-contents) - (message "%s" " done.") - (mapc #'(lambda (package) - (when (not (package-installed-p package)) - (package-install package))) - oni:required-packages)) - (blink-cursor-mode -1) (column-number-mode -1) (line-number-mode -1) -(menu-bar-mode -1) -(scroll-bar-mode -1) -(tool-bar-mode -1) (tooltip-mode -1) +(package-initialize) + (auto-insert-mode) +(cua-selection-mode t) (electric-indent-mode) (electric-pair-mode) (ido-mode) @@ -321,8 +350,8 @@ (smex-initialize) (help-at-pt-set-timer) - -(load-theme 'yoshi t) +(windmove-default-keybindings) +(global-diff-hl-mode) (load custom-file) ;; (load "rudel-loaddefs.el") @@ -335,7 +364,6 @@ (server-start)) (diminish 'auto-fill-function "_") -(ac-config-default) (provide 'init) diff --git a/.emacs.d/init.org b/.emacs.d/init.org index b3f3c31..ac7f7c1 100644 --- a/.emacs.d/init.org +++ b/.emacs.d/init.org @@ -2,365 +2,75 @@ #+STYLE: #+OPTIONS: author:nil #+STARTUP: showall +#+LINK: yoshi-theme http://ryuslash.org/projects/yoshi-theme.html -* Startup +* Emacs init - Startup requires a bit of customization to handle all my - customizations. - -** Load paths - - I have two versions of Emacs installed on my main computer. I have - a daily build of Emacs's ~trunk~ (or currently ~emacs-24~) branch from - bazaar and I have the official ~emacs~ package from archlinux - installed. I keep that second one around so that the occasional - emacs package that I install using ~pacman~ will recognize it as a - dependency and so that if there has been some horrible mistake in - the ~trunk~ branch I still have a stable version to fall back - on[fn:1]. - -*** Package initialization - - In order for packages installed through ELPA to be included - without having to mess with load paths and such, use: - - #+NAME: package-initialize - #+BEGIN_SRC emacs-lisp - (package-initialize) - #+END_SRC - -*** site-lisp - - Because of the setup I wrote about I need to have both the - self-built ~site-lisp~ directory in my load path *and* the "official" - one. - - #+NAME: load-site-lisps - #+BEGIN_SRC emacs-lisp - (mapc #'oni:add-all-to-load-path - '("/usr/share/emacs/site-lisp" - "/usr/local/emacs/share/emacs/site-lisp")) - #+END_SRC - - The =oni:add-all-to-load-path= function just binds =default-directory= - to the given directory and calls - =normal-top-level-add-subdirs-to-load-path= to add it and all its - subdirectories to the load path. - - #+NAME: add-all - #+BEGIN_SRC emacs-lisp - (defun oni:add-all-to-load-path (dir) - (add-to-list 'load-path dir) - (let ((default-directory dir)) - (normal-top-level-add-subdirs-to-load-path))) - #+END_SRC - -**** TODO Add load paths in different order depending on version - - The officially installed version should load - =/usr/share/emacs/site-lisp= before - =/usr/local/emacs/share/emacs/sit-lisp= and the bzr version should - do the reversed. - -*** Projects - - Then there are some projects I'm working on, which I use on a - daily basis, these should also be added so I don't have to - constantly remove and re-install them through ~package.el~ when - working on them. And there is the ~load-defs.el~ in my personal - ~site-lisp~ directory of course. - - #+NAME: load-projects - #+BEGIN_SRC emacs-lisp - (mapc #'oni:add-to-load-path-maybe-load-defs - '("~/projects/emacs/dispass.el" "~/projects/emacs/mode-icons" - "~/.emacs.d/site-lisp" "~/projects/emacs/pony-mode/src" - "~/projects/emacs/php-mode")) - #+END_SRC - - The =oni:add-to-load-path-maybe-load-defs= function just adds the - given directory to the load path and then looks for a file named - ~loaddefs.el~ within that directory, if it exists it loads it. - - #+NAME: add-with-loaddefs - #+BEGIN_SRC emacs-lisp - (defun oni:add-to-load-path-maybe-load-defs (dir) - (add-to-list 'load-path dir) - (let ((loaddefs (concat dir "/loaddefs.el"))) - (when (file-exists-p loaddefs) - (load loaddefs)))) - #+END_SRC - -*** Themes - - And, finally, I'm also working on a color theme for emacs, this - should be added to ~custom-theme-load-path~. By using =mapc= here as - well I'm keeping in mind that this isn't the first theme I've - worked on and it might not be the last either. - - #+NAME: load-themes - #+BEGIN_SRC emacs-lisp - (mapc #'oni:add-to-custom-theme-load-path - '("~/projects/emacs/yoshi-theme")) - #+END_SRC - - The =oni:add-to-custom-theme-load-path= just adds the given - directory to the cutom theme load path. - - #+NAME: add-themes - #+BEGIN_SRC emacs-lisp - (defun oni:add-to-custom-theme-load-path (dir) - (add-to-list 'custom-theme-load-path dir)) - #+END_SRC - -*** Evaluation - - Because during byte-compilation certain parts loaded so far might - also be required I put it in an =eval-and-compile= form, so that all - components are loaded with ~emacs -Q~ as well. Without this - compilation might fail at certain points. - - #+BEGIN_SRC emacs-lisp :tangle init2.el :noweb yes - (eval-and-compile - <> - - <> - - <> - - <> - <> - <> - <>) - #+END_SRC - -** Modules - - While I try to use =eval-after-load= and =autoload= as much as - possible, some things require direct =require='ing to be of use. - -*** Require - - - ~auto-complete-config~ :: This sets up some default settings to - make ~auto-complete~ work for most[fn:2] of the modes it - supports. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (require 'auto-complete-config) - #+END_SRC - - - ~geiser-install~ :: Sets up geiser autoloads and such. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (require 'geiser-install) - #+END_SRC - - - ~uniquify~ :: Provides more helpful buffer name uniquification. - The default of using ~buffer-name<2>~ is boring and - uninformative, ~uniquify~ fixes this. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (require 'uniquify) - #+END_SRC - - - ~ext~ :: Functions from external sources. - - ~oni~ :: Functions written personally. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (require 'ext) - (require 'oni) - #+END_SRC - -*** Autoload - - These might not be used at all in a session, so they should only - be loaded when necessary. - - =define-slime-contrib= was used by some module that didn't autoload - or require it[fn:3]. But since I don't use whichever model it - was every day, it is of no use to load it every single time. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'define-slime-contrib "slime") - #+END_SRC - - I installed ~global~ with ~pacman~, but this doesn't add anything to - any =loaddefs.el=, so doesn't create any autoloads. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'gtags-mode "gtags" nil t) - #+END_SRC - - ~jabber.el~ does create ~jabber-autoloads.el~, but I only ever start - using it through ~jabber-connect~, so anything else isn't really - necessary. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'jabber-connect "jabber" nil t) - #+END_SRC - - I used to work a bit on ~php-mode~, but that was a while ago, so - it's still in my ~site-lisp~ directory. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'php-mode "php-mode" nil t) - #+END_SRC - - The same that goes for ~gtags.el~ also goes for ~po-mode.el~. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'po-mode "po-mode" nil t) - #+END_SRC - - And the same that went for ~php-mode~ also goes for ~pony-mode~, - except I'm still working on it and I was too lazy to put it with - my other projects. I should still do that. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'pony-mode "pony-mode" nil t) - #+END_SRC - - ~sawfish.el~ has the same problem that ~gtags.el~ and ~po-mode.el~ have. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'sawfish-mode "sawfish" nil t) - #+END_SRC - - I use =server-running-p= to check whether or not I should start a - new server, but this function isn't autoloaded by default. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'server-running-p "server") - #+END_SRC - - I was starting to try ~slime-js~ to make JavaScript programming - more interesting, but I haven't gotten around to trying it out - fully, yet. It shares issues with ~gtags.el~, ~po-mode.el~ and - ~sawfish.el~. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'slime-js-minor-mode "slime-js" nil t) - #+END_SRC - - I found ~xmodmap-mode~ on the [[http://emacswiki.org][EmacsWiki]] some time ago, it was - simple and a good example of how to use ~define-generic-mode~, but - since it's not really my project and it's really small it just - sits in my ~site-lisp~ directory. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'xmodmap-mode "xmodmap-mode" nil t) - #+END_SRC - - ~w3m~ also has a setup module like ~geiser-install~, but since I only - ever use these two functions to start it, there is no real need - for anything else. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (autoload 'w3m-bookmark-view "w3m" nil t) - (autoload 'w3m-goto-url "w3m" nil t) - #+END_SRC - -* Aliases - - I've never had any trouble with accidentally pressing ~y~ while being - asked a question, so I've never had any reason to prefer ~yes-or-no-p~ - over ~y-or-n-p~. - - #+begin_src emacs-lisp :tangle init2.el - (defalias 'yes-or-no-p 'y-or-n-p) - #+end_src - - ~ibuffer~ is a drop-in replacement for ~list-buffers~, but with more - features. - - #+begin_src emacs-lisp :tangle init2.el - (defalias 'list-buffers 'ibuffer) - #+end_src - - I don't know if replacing ~dabbrev-expand~ with ~hippie-expand~, but at - least ~hippie-expand~ doesn't use ~dabbrev-expand~, and I haven't - noticed anything wrong so far, and ~hippie-expand~ does so much more - than ~dabbrev-expand~. + 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 :tangle init2.el - (defalias 'dabbrev-expand 'hippie-expand) + (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 -* Faces - - Define a face to how the summary line of git commits as the first - headline of an ~org-mode~ file. - - #+begin_src emacs-lisp :tangle init2.el - (defface git-commit-summary-face - '((t (:inherit org-level-1))) - "Face for the git title line." - :group 'local) - #+end_src - - Define a face to show characters that have been placed beyond the - maximum length of a summary line. - - #+begin_src emacs-lisp :tangle init2.el - (defface git-commit-overlong-summary-face - '((t (:background "#873732"))) - "Face for commit titles that are too long." - :group 'local) - #+end_src - - Define a face to show characters that have been placed on the second - line of a git commit. Those should always remain empty. + Add my project [[yoshi-theme]] to =custom-theme-load-path= and load it. #+BEGIN_SRC emacs-lisp :tangle init2.el - (defface git-commit-nonempty-second-line-face - '((t (:inherit git-commit-overlong-summary-face))) - "Face for the supposedly empty line in commit messages." - :group 'local) + (add-to-list 'custom-theme-load-path "~/projects/emacs/yoshi-theme/") + (load-theme 'yoshi t) #+END_SRC -* Keys - - Since the ~C-l~ combination is so much easier than ~C-j~ when using the - [[http://colemak.com][colemak]] keyboard layout and I use ~C-j~ much more, switch them. - - #+BEGIN_SRC emacs-lisp :tangle init2.el - (define-key key-translation-map (kbd "C-j") (kbd "C-l")) - (define-key key-translation-map (kbd "C-l") (kbd "C-j")) - #+END_SRC - -* eldoc - - Diminish ~eldoc~'s lighter to nothing after it loads to keep the - mode-line clean. - - #+begin_src emacs-lisp :tangle init2.el - (eval-after-load "eldoc" - '(diminish 'eldoc-mode)) - #+end_src - -* eshell + Remove the ~menu-bar~, ~tool-bar~ and ~scroll-bar~ from the UI since I + don't use them at all. - After ~em-term.el~ loads add ~unison~ to the ~eshell-visual-commands~ to - make sure it gets unbuffered input. + #+BEGIN_SRC emacs-lisp :tangle init2.el + (menu-bar-mode -1) + (scroll-bar-mode -1) + (tool-bar-mode -1) + #+END_SRC - #+begin_src emacs-lisp :tangle init2.el - (eval-after-load "em-term" - '(add-to-list 'eshell-visual-commands "unison")) - #+end_src + Add any other interesting paths to =load-path= and, if it exists, + load the ~loaddefs.el~ file from these directories. -* Window movement + #+BEGIN_SRC emacs-lisp :tangle init2.el + (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")) + #+END_SRC - Make it easier to move through windows by using ~windmove~. + Don't ask ~yes~ or ~no~, ask ~y~ or ~n~, I've never had an accidental ~y~ so + far. #+BEGIN_SRC emacs-lisp :tangle init2.el - (windmove-default-keybindings) + (defalias 'yes-or-no-p 'y-or-n-p) #+END_SRC -* Footnotes + Use =ibuffer= instead of the default =list-buffers= because it has many + more features. -[fn:1] Though it doesn't happen often that ~trunk~ is so messed up that -I can't use it. + #+BEGIN_SRC emacs-lisp :tangle init2.el + (defalias 'list-buffers 'ibuffer) + #+END_SRC -[fn:2] Or perhaps all. + Do the same with =hippie-expand= and =dabbrev-expand=. -[fn:3] I think it was ~slime-js-minor-mode~, but I'm not sure. + #+BEGIN_SRC emacs-lisp :tangle init2.el + (defalias 'dabbrev-expand 'hippie-expand) + #+END_SRC diff --git a/.emacs.d/site-lisp/oni.el b/.emacs.d/site-lisp/oni.el index a8d36e9..91c4e27 100644 --- a/.emacs.d/site-lisp/oni.el +++ b/.emacs.d/site-lisp/oni.el @@ -87,6 +87,10 @@ DOT are intentionally being skipped." (interactive) (server-save-buffers-kill-terminal nil)) +(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))) + (defun oni:compile-el () "Compile the current buffer file if it is an .el file." (let* ((full-file-name (buffer-file-name)) @@ -563,16 +567,6 @@ use. If MODE is not nil, open a new buffer with the name default-directory "' request-pull " (when patchp "-p ") from " " url " " to)))))) -(defun oni:required-packages-installed-p () - "Check if all the packages I need are installed." - (let ((tmp-packages oni:required-packages) - (result t)) - (while (and tmp-packages result) - (if (not (package-installed-p (car tmp-packages))) - (setq result nil)) - (setq tmp-packages (cdr tmp-packages))) - result)) - (defun oni:rst-mode-func () "Function for `rst-mode-hook'." (auto-fill-mode)) @@ -639,6 +633,17 @@ If no direction is given, don't split." (emms-player-mpd-connect)) (emms)) +(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")) + +(defun oni:stop-python-test-mail-server () + "Stop the python test mailserver." + (interactive) + (kill-process "python-test-mail-server")) + (defun oni:term-mode-func () "Function for `term-mode-hook'." (setq truncate-lines nil)) @@ -676,6 +681,14 @@ for easy selection." "Initialization function for yasnippet." (diminish 'yas-minor-mode)) +(defvar oni:auto-save-name-transforms + `((".*" ,temporary-file-directory t)) + "Place all auto-save files in `temporary-file-directory'.") + +(defvar oni:backup-directory-alist + `((".*" . ,temporary-file-directory)) + "Palce all backup files in `temporary-file-directory'.") + (defvar oni:mailbox-map '("top" ("menu" ("ryulash.org" . "ryuslash") @@ -684,11 +697,5 @@ for easy selection." ("aethon" . "aethon"))) "A mailbox map for use with `tmm-prompt'.") -(defvar oni:required-packages - '(graphviz-dot-mode htmlize magit rainbow-delimiters rainbow-mode - yasnippet markdown-mode flymake flymake-cursor sauron expand-region - git-auto-commit-mode idomenu magit smex) - "List of all the packages I have (want) installed.") - (provide 'oni) ;;; oni.el ends here -- cgit v1.2.3-54-g00ecf