Skip to content

Instantly share code, notes, and snippets.

@alterecco
Created July 21, 2010 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alterecco/484475 to your computer and use it in GitHub Desktop.
Save alterecco/484475 to your computer and use it in GitHub Desktop.
;; http://www.gnu.org/software/emacs/manual/html_node/elisp/index.html#Top
;; http://www.chemie.fu-berlin.de/chemnet/use/info/elisp/elisp_toc.html
;; turn off menu bar as the first thing,
;; so we don't get an annoying flash
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;; add local dir to load path
(add-to-list 'load-path "~/.emacs.d")
(add-to-list 'load-path "~/.emacs.d/vendor")
(load-library "egomode")
;; load some generic modes
(load-library "generic-modes")
(load-library "htmlize")
;; sometimes we need to debug
;(setq debug-on-error t)
;; ----------------------------------------------------------------------------
;; DEFAULTS
;; always utf-8
(prefer-coding-system 'utf-8)
;; 'y' or 'n', not 'yes' or 'no'
(defalias 'yes-or-no-p 'y-or-n-p)
;; quiet startup
(setq inhibit-startup-screen t)
;; empty scratch buffer
(setq initial-scratch-message nil)
;; i don't like autosave (it litters working dir)
;(setq auto-save-default nil)
;; auto-save to tmp dir
(setq auto-save-file-name-transforms
'((".*" "~/tmp/emacstmp/autosave/\\2" t)))
;; save after 100 input events
(setq auto-save-interval 100)
;; don't let indentation insert tabs (only spaces)
(setq-default indent-tabs-mode nil)
;; always leave a newline at the end of the file
(setq require-final-newline t)
;; merge with x clipboard
(setq x-select-enable-clipboard t)
;; don't wrap lines by default
(setq default-truncate-lines t)
;; what to do when calling a browser
(setq browse-url-generic-program "uzbl-browser")
(setq browse-url-browser-function 'browse-url-generic)
;; don't let bookmarks and abbrevs litter
(setq bookmark-default-file "~/.emacs.d/system/bookmark")
(setq abbrev-file-name "~/.emacs.d/system/abbrev")
;; where to auto-save
(setq auto-save-list-file-prefix "~/.emacs.d/system/auto-save-list/saves-")
;; use european date formats
(setq european-calendar-style t)
;; disable vc-mode
(setq vc-handled-backends nil)
(setq tab-stop-list '(2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108))
;; ----------------------------------------------
;; SCROLLING
;; scroll one line at a time
(setq scroll-step 1)
;; but scroll some lines away from the margin
(setq scroll-margin 6)
;; try to avoid great 'jumps' in scrolling
;(setq scroll-conservatively 6)
;; ----------------------------------------------
;; BACKUPS
;; i want backups, but not littering everywhere
(setq backup-directory-alist '(("." . "~/tmp/emacsbackup/")))
(setq backup-by-copying t)
;; version backup files
(setq version-control t)
;; but don't keep unlimited versions
(setq delete-old-versions t)
;; ----------------------------------------------------------------------------
;; INITIAL MODES
(setq default-major-mode 'text-mode)
;; show column and line information
(column-number-mode t)
;; ----------------------------------------------
;; SAVE PLACE MODE - save cursor buffer position
(setq-default save-place t)
(setq-default save-place-file "~/tmp/emacstmp/places")
(require 'saveplace)
;; ----------------------------------------------
;; SAVE HIST MODE - save minibuffer history
(require 'savehist)
(setq savehist-file "~/tmp/emacstmp/minibuffer-history")
(savehist-mode t)
;; ----------------------------------------------
;; IDO MODE
(setq ido-save-directory-list-file "~/.emacs.d/system/ido.last")
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(setq ido-max-prospects 7)
(ido-mode t)
;; ----------------------------------------------
;; ISPELL MODE
(setq-default ispell-program-name "aspell")
(setq-default ispell-extra-args '("--sug-mode=ultra"))
(setq-default ispell-dictionary "en_GB")
;; ----------------------------------------------
;; FONT LOCK MODE
(font-lock-mode t)
(setq font-lock-maximum-decoration t)
(load-library "theme")
;; ----------------------------------------------
;; WHITESPACE MODE
;; whitespace mode is not enabled by default, but when
;; it is, I don't want to see everything
(setq whitespace-style '(tabs trailing lines-tail))
(add-hook 'whitespace-mode-hook
(lambda nil
(set-face-background 'whitespace-tab "red")
(set-face-background 'whitespace-trailing "red")
))
;; ----------------------------------------------
;; CUA MODE
(setq cua-enable-cua-keys nil)
(add-hook 'cua-mode-hook
(lambda nil
(set-face-background 'cua-rectangle "#2a002a")
))
(cua-mode t)
;; ----------------------------------------------
;; GIST MODE
(add-to-list 'load-path "~/.emacs.d/vendor/gist.el")
(require 'gist)
;; ----------------------------------------------
;; MAGIT MODE
(add-to-list 'load-path "~/.emacs.d/vendor/magit")
(add-to-list 'Info-default-directory-list "~/.emacs.d/vendor/magit/")
(require 'magit)
;; ----------------------------------------------
;; ORG MODE
;; http://cheat.errtheblog.com/s/orgmode/
;; http://nflath.com/2010/03/org-mode-2/
;; work with git
(add-to-list 'load-path "~/.emacs.d/vendor/org-mode/lisp")
;; add doc to info-mode
(add-to-list 'Info-default-directory-list "~/.emacs.d/vendor/org-mode/doc/")
(require 'org-install)
;; set up default locations
(setq org-directory "~/note/")
(setq org-id-locations-file "~/.emacs.d/system/org-id-locations")
(setq org-archive-location (concat org-directory "archive/%s::"))
;; use ido for everything!
(setq org-completion-use-ido t)
;; don't split current heading when creating new
(setq org-M-RET-may-split-line nil)
;; no blank lines before new entries
(setq org-blank-before-new-entry '((heading) (plain-list-item)))
;; show blank lines in outline
(setq org-cycle-separator-lines 1)
;; indent content to heading
(setq org-adapt-indentation t)
;; hit return to follow a link
(setq org-return-follows-link t)
;; handle C-a C-e C-k specially
(setq org-special-ctrl-a/e t)
(setq org-special-ctrl-k t)
;; adjust trees when pasting and yanking
(setq org-yank-adjusted-subtrees t)
;; give plenty of warning for dealines
(setq org-deadline-warning-days 30)
;; disable priority commands
(setq org-enable-priority-commands nil)
;; hide block views at startup
(setq org-hide-block-startup t)
;; log to the LOGBOOK drawer
(setq org-log-into-drawer t)
;; use TAB a bob to cycle global visibility
(setq org-cycle-global-at-bob t)
(setq org-global-properties
'(("Effort_ALL" . "0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00")))
;; CLOCKING
;; from http://doc.norang.ca/org-mode.html#sec-3_3
(defun ego/clock-in-to-next (kw)
"Switch task from TODO to NEXT when clocking in"
(if (and (string-equal kw "TODO")
;(not (string-match "^CAPTURE-.*\.org" (buffer-name)))
(and (boundp 'org-capture-mode) (not org-capture-mode)))
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
(has-subtask nil))
(save-excursion
(forward-line 1)
(while (and (not has-subtask)
(< (point) subtree-end)
(re-search-forward "^\*+ " subtree-end t))
(message "Found todo keyword %s" (org-get-todo-state))
(when (member (org-get-todo-state) org-not-done-keywords)
(setq has-subtask t))))
(when (not has-subtask)
"NEXT"))))
;; Resume clocks when emacs is restarted
(org-clock-persistence-insinuate)
;; clock into drawers
(setq org-clock-into-drawer "CLOCK")
;; remove zero time clocks
(setq org-clock-out-remove-zero-time-clocks t)
;; clock out when moving to done state
(setq org-clock-out-when-done t)
;; save entire clock history on exit
(setq org-clock-persist t)
;; save clocks to this file
(setq org-clock-persist-file "~/.emacs.d/system/org-clock-save.el")
;; include current clocking task in reports
(setq org-clock-report-include-clocking-task t)
;; resume open clocks in tasks
(setq org-clock-in-resume t)
;; change state on clock in
(setq org-clock-in-switch-to-state 'ego/clock-in-to-next)
(setq org-use-speed-commands t)
;; COLUMNS
(setq org-columns-default-format "%80ITEM(Task) %10Effort(Effort){:} %10CLOCKSUM")
;; AGENDA
;; use agenda files as refile targets
(setq org-refile-targets '((org-agenda-files :maxlevel . 5) (nil :maxlevel . 5)))
(setq org-refile-use-outline-path 'file)
(setq org-outline-path-complete-in-steps t)
(setq org-refile-allow-creating-parent-nodes 'confirm)
;; TODO
(setq org-use-fast-todo-selection t)
(setq org-todo-keywords
'((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!/!)")
(sequence "RECUR(r)" "|" "OVER(o!/!)")
(sequence "WAITING(w@/!)" "SOMEDAY(s!)" "|" "CANCELLED(c@/!)")
))
(setq org-todo-keyword-faces
'(("TODO" :foreground "red" :weight bold)
("NEXT" :foreground "blue" :weight bold)
("DONE" :foreground "forest green" :weight bold)
("WAITING" :foreground "yellow" :weight bold)
("SOMEDAY" :foreground "goldenrod" :weight bold)
("CANCELLED" :foreground "orangered" :weight bold)
))
;; ORG-CAPTURE
(setq org-default-notes-file "~/note/refile.org")
(setq org-capture-templates
'(
("c" "Create Todo" entry (file+headline "~/note/journal.org" "Refile") (file "~/note/template/todo.org") :clock-in t :clock-resume t)
("n" "Note" entry (file "~/note/journal.org") (file "~/note/template/note.org"))
("s" "Shop" entry (file+headline "~/note/journal.org" "Shopping") "** SHOP %?")
))
;; TAGS
;; tags are lowecase
(setq org-tag-alist
'(("note" . ?n)
))
(setq org-fast-tag-selection-single-key 'expert)
(setq org-agenda-diary-file "~/note/journal.org")
(setq org-agenda-include-diary t)
(setq org-clock-idle-time 10)
;(setq org-startup-indented t)
;(setq org-odd-levels-only t)
;(setq org-insert-heading-respect-content t)
;(setq org-use-speed-commands t)
;(setq org-cycle-emulate-tab 'exc-hl-bol)
;; ----------------------------------------------------------------------------
;; GNUS - This is common gnus so we can send mail from outside gnus
(setq user-mail-address "mail@alterecco.net")
(setq user-full-name "Johan Friis")
;; don't clutter home dir
(setq gnus-init-file "~/.emacs.d/mail.el")
(setq gnus-startup-file "~/.emacs.d/system/newsrc")
(setq gnus-dribble-directory "~/.emacs.d/system/")
(setq gnus-directory "~/lib/data/news/")
(setq message-directory "~/lib/data/mail/")
;; needs to be specified before the (require)
(setq smtpmail-default-smtp-server "mail.gandi.net")
(require 'smtpmail)
(setq send-mail-function 'smtpmail-send-it)
(setq message-send-mail-function 'smtpmail-send-it)
;(setq smtpmail-local-domain "alterecco.net")
;(setq smtpmail-sendto-domain "alterecco.net")
(setq smtpmail-auth-credentials "~/.authinfo")
;(setq smtpmail-debug-verb t)
;; ----------------------------------------------------------------------------
;; FUNCTIONS
(defun untabify-buffer nil
(interactive)
(untabify (point-min) (point-max)))
(defun indent-buffer nil
(interactive)
(indent-region (point-min) (point-max)))
(defun clean-buffer nil
"Clean up buffer whitespace"
(interactive)
(indent-buffer)
(untabify-buffer)
(delete-trailing-whitespace))
(defun sudo-edit (&optional arg)
(interactive "p")
(if (or arg (not buffer-file-name))
(find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
(defun what-face (pos)
(interactive "d")
(let ((face (or (get-char-property (point) 'read-face-name)
(get-char-property (point) 'face))))
(if face (message "Face: %s" face) (message "No face at %d" pos))))
;; ----------------------------------------------------------------------------
;; MODE HOOKS
;; ----------------------------------------------
;; coding mode - a custom mode for coding
(defun ego/coding-mode-hook nil
;; indentation
(setq c-indent-level 4)
(setq c-basic-offset 4)
(setq tab-width 4)
;; paren matching
(require 'autopair)
(autopair-mode t)
(show-paren-mode t)
(setq autopair-blink nil)
(cua-mode t)
(set-face-foreground 'show-paren-match-face "#0055d4")
(set-face-background 'show-paren-match-face nil)
(set-face-bold-p 'show-paren-match-face t)
(set-face-background 'show-paren-mismatch nil)
(set-face-foreground 'show-paren-mismatch "red")
(set-face-bold-p 'show-paren-mismatch t)
)
(add-hook 'php-mode-hook 'ego/coding-mode-hook)
(add-hook 'lisp-mode-hook 'ego/coding-mode-hook)
(add-hook 'emacs-lisp-mode-hook 'ego/coding-mode-hook)
(add-hook 'python-mode-hook 'ego/coding-mode-hook)
(add-hook 'lua-mode-hook 'ego/coding-mode-hook)
(add-hook 'ruby-mode-hook 'ego/coding-mode-hook)
(add-hook 'sh-mode-hook 'ego/coding-mode-hook)
;; ----------------------------------------------
;; PHP MODE
(autoload 'php-mode "php-mode" "PHP mode" t)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
;; NOTE: this customization might be useful across multiple languages
(defun ego/php-mode-hook nil
;; mostly change indentation rules
(c-set-offset 'topmost-intro-cont 4)
(c-set-offset 'class-open 0)
(c-set-offset 'inline-open 0)
(c-set-offset 'substatement-open 0)
(c-set-offset 'arglist-intro '+)
(c-set-offset 'arglist-close 0)
)
(add-hook 'php-mode-hook 'ego/php-mode-hook)
;; ----------------------------------------------------------------------------
;; TURN ON EGO MODE!
;; ----------------------------------------------------------------------------
(ego-mode t)
;; ----------------------------------------------------------------------------
;; END MANUAL CONFIG
;; ----------------------------------------------------------------------------
;;
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(canlock-password "a467651c8c19b7332b594814f99e54ce4b9760c2")
'(org-agenda-files (quote ("~/note/hack.org" "~/note/journal.org"))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment