summaryrefslogtreecommitdiffstats
path: root/.emacs.d/init.org
blob: 2041f5a79e42a6593848b6cc5bf18d070a613039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#+TITLE: Emacs init
#+STYLE: <link href="http://ryuslash.ninth.su/test2.css" rel="stylesheet">
#+OPTIONS: author:nil

* Startup

  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" "~/var/src/emacs/mode-icons"
              "~/.emacs.d/site-lisp"))
    #+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
        <<add-all>>

        <<add-with-loaddefs>>

        <<add-themes>>

        <<package-initialize>>
        <<load-site-lisps>>
        <<load-projects>>
        <<load-themes>>)
    #+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

  There are some functions that are just better than others, no
  matter how politically incorrect it might be to admit.

  #+BEGIN_SRC emacs-lisp :tangle init2.el
    (defalias 'yes-or-no-p 'y-or-n-p)
    (defalias 'list-buffers 'ibuffer)
    (defalias 'dabbrev-expand 'hippie-expand)
  #+END_SRC

* Faces

  Define faces for use with ~magit~ log edit mode.

  #+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)

    (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)
  #+END_SRC

* Keys

  With the awesome power of Emacs comes the need for lots of
  keybindings.

** Translation

   Since the ~C-l~ combination is so much easier than ~C-j~ when using
   the [[http://colemak.com][colemak]] keyboard layout and ~C-j~ is used so 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
* Footnotes

[fn:1] Though it doesn't happen often that ~trunk~ is so messed up that
I can't use it.

[fn:2] Or perhaps all.

[fn:3] I think it was ~slime-js-minor-mode~, but I'm not sure.