Email: abesto0@gmail.com
Twitter: @abesto

Emacs usecases 0 - Intro


RSS 2.0RSS 2.0 feed
Published: 2008-03-09
Tags: emacs
Next in series: 1 - Python

No more VIM for me. I tried out Emacs for a few days and I absolutely love it. It's got all the features I need, some features I don't need, and numerous features I didn't even know I needed. Also, with elisp, you can make it do whatever you want it to do.
This n-part series will describe the things I use Emacs for at the moment (where n is expected to be in the interval [2; 10]).

DotEmacs

My setup is based on this post. The .emacs file loads or autoloads third-party scripts and my own files.

Autoload
Define a function as available from a file, possibly with a help string, to be loaded from disk only if and when the function is called. This makes startup faster, but can introduce lags when the file is first loaded.

The .emacs.d directory contains everything Emacs-related. My own scripts are here, and third-party scripts are in .emacs.d/lisp. My own customizations are split into two parts. One, my-generic.el, is loaded on startup. It contains everything I want loaded on startup. The rest are stuff for certain modes. For example, my-python-init.el is loaded when the Python mode is started. (Done with hooks.)

My .emacs:
;; Based on McGeary's init: http://www.emacsblog.org/2007/10/07/declaring-emacs-bankruptcy/

;; paths
(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))

;; Third-party stuff
(require 'doremi-cmd)


;; Preferences
(load "my-generic")

;; Autoload hook functions
(autoload 'my-python-init "my-python-init")
(autoload 'my-ruby-init "my-ruby-init")
(autoload 'my-latex-init "my-latex-init")

;; Hooks
;; (add-hook 'python-mode-hook 'my-python-init)

(add-hook 'LaTeX-mode-hook 'my-latex-init)
(add-hook 'ruby-mode-hook 'my-ruby-init)

;; Customize
(custom-set-variables
'(inhibit-splash-screen t)
 '(nuke-trailing-whitespace-in-hooks
   (quote (write-file-hooks mail-send-hook)) nil (nuke-trailing-whitespace)))
(custom-set-faces
 )

An example of what the autoloaded files look like is provided below. They'll all be discussed in the post related to their mode.

my-python-init.el:
;;;###autoload
(defun my-python-init ()
    ;; Python must always be indented, so why not bind Return to that?
    (local-set-key "\r" 'newline-and-indent)
)

Also, my-generic.el:
(load "toggle-fullscreen")

(color-theme-ld-dark)  ;; Nice, dark, easy on the eyes
(tool-bar-mode -1)     ;; No toolbar, thanks
(set-default 'fill-column 80) ;; 80. standard. good.
(setq visible-bell t);; Can't go beeping around at midnight, now can I?
(toggle-fullscreen)  ;; Start maximized


(setq-default indent-tabs-mode nil)  ;; I always want spaces instead of tabs

(global-set-key "\C-x\C-m" 'execute-extended-command)  ;; for M-x
(global-set-key "\C-w" 'backward-kill-word)  ;; instead of backspacing

(global-set-key "\C-x\C-k" 'kill-region)  ;; rebind kill-region

(setq default-tab-width 4)

;; mode-compile
(autoload 'mode-compile "mode-compile"
"Command to compile current buffer file based on the major mode" t)
(global-set-key "\C-cc" 'mode-compile)
(autoload 'mode-compile-kill "mode-compile"

"Command to kill a compilation launched by `mode-compile'" t)
(global-set-key "\C-ck" 'mode-compile-kill)
(setq mode-compile-expert-p t)

And finally toggle-fullscreen.el:
;; Maximizes the window; Found on the Ubuntu forums.
(defun toggle-fullscreen ()
  (interactive)
  (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
                         '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
  (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
                         '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
)
Btw, the listings were made by the Emacs command "htmlize-file".

Comments

Post a comment Name:
Url (optional):
Message (max. 500 characters):

[code] and [/code] will be converted to <pre> and </pre> tags. Tags with < and > will be left intact. Go ahead and break the layout, if you can. I need an excuse to rewrite the comment filter.

Tags

blogging (3)
emacs (14)
latex (3)
org-mode (2)
php (3)
python (3)
vim (3)
window-manager (2)
Fueled by CodeIgniter Valid XHTML 1.1 Valid CSS! [Valid RSS] Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Hungary License.
Page generated in 0.3996 seconds