Skip to content

Latest commit

 

History

History
1262 lines (964 loc) · 31.1 KB

bew_config.org

File metadata and controls

1262 lines (964 loc) · 31.1 KB

Brett Witty’s Emacs configuration

Configuration

This is inspired by Sacha Chua’s configuration file.

To load this, run (org-babel-load-file "~/bew_config.org").

About me

Personal information

(setq user-full-name "Brett Witty"
      user-mail-address "[email protected]")

Startup

Add my emacs directories

These are my standard add-on library paths

(add-to-list 'load-path (expand-file-name "~/"))
(add-to-list 'load-path (expand-file-name "~/libraries/"))
(add-to-list 'load-path "~/elisp")
(add-to-list 'load-path "~/libraries/")
(require 'color-theme)

Start up configuration

Get rid of the startup screen.

(setq inhibit-startup-screen t)
(setq magit-last-seen-setup-instructions "1.4.0")

Emacs customize

It’s better to just chuck everything into this file, but sometimes Customize is too easy to use.

(setq custom-file "~/bew_custom.el")
(load-file custom-file)

Global configuration

BrettW custom settings

(defvar brettw/default-screen-width 120)
(defvar brettw/default-screen-height 70)

Global mode

We like these global modes.

(global-font-lock-mode t)
(delete-selection-mode t)
(auto-compression-mode t)
(display-time-mode t)
(line-number-mode t)
(show-paren-mode t)
(transient-mark-mode t)
(recentf-mode t)
(global-ede-mode t)
(hl-line-mode t)
(ido-mode t)

YASnippet needs some of its own customization.

(require 'yasnippet)
;(setq yas/snippet-dirs '("~/snippets" "~/libraries/yasnippet/snippets/" ))
(yas/global-mode 1)

Packages

(add-to-list 'package-archives
  '("melpa" . "http://melpa.milkbox.net/packages/") t)

Coding systems

We only like UTF-8 because the alternatives are rubbish.

(prefer-coding-system 'utf-8)
(setq coding-system-for-read 'utf-8
      coding-system-for-write 'utf-8)

Display options

Color theme

Use my custom color theme.

;;(load-theme 'tangotango t)
(load-theme 'leuven t)

Window decorations

Set the window up how we like it.

(setq-default cursor-type 'bar)

(setq scroll-bar-mode 'right
      use-dialog-box nil
        use-file-dialog nil
        cursor-type 'bar
  )

Snappier updates

This hack apparently makes things snappier.

(setq redisplay-dont-pause 1)

Input

Clipboard

Let Emacs play with the clipboard.

(setq x-select-enable-clipboard t)

Parentheses

Use the shiny autopair module.

(require 'autopair)
(autopair-global-mode 1)

Keyboard settings

I’d like these Windows keys to work, but they don’t.

(setq w32-pass-lwindow-to-system nil)
(setq w32-lwindow-modifier 'super) ; Left Windows key

(setq w32-pass-rwindow-to-system nil)
(setq w32-rwindow-modifier 'super) ; Right Windows key

;(setq w32-pass-apps-to-system nil)
;(setq w32-apps-modifier 'hyper) ; Menu/App key

;(w32-register-hot-key [A-tab])
;(w32-register-hot-key [s-o])

Mouse settings

Get the right amount of mouse scrolling.

(setq mouse-wheel-scroll-amount '(1)
      mouse-wheel-scroll-progressive-speed nil)

Backups

We want to control and minimize Emacs backups.

(setq backup-directory-alist `(("." . "~/backup/")))
(setq backup-by-copying t
      delete-old-versions t
      kept-new-versions 6
      kept-old-versions 2
      version-control t)

Recent files

Set up the recent files.

(setq recentf-menu-path nil
      recentf-menu-title "Recent files"
      recentf-max-saved-items 100)

(add-to-list 'recentf-exclude "\\.ido\\.last\\'")
(add-to-list 'recentf-exclude ".*\\.el\\'")
(add-to-list 'recentf-exclude "archive-contents\\'")
(add-to-list 'recentf-exclude "checksums\\.dat\\'")

Help

We customize help just a tad.

(setq apropos-compact-layout t
      apropos-do-all t
      help-window-select t)

General completion

(add-hook 'minibuffer-exit-hook
          '(lambda ()
             (let ((buffer "*Completions*"))
               (and (get-buffer buffer)
                    (kill-buffer buffer)))
))

Filename completion

Ignored extensions

Ignore these files because we’re unlikely to open them in Emacs.

(setq completion-ignored-extensions
      '(".o" ".elc" "~" ".bin" ".dvi" ".toc" ".aux" ".ps" ".blg" ".bbl" ".idx" ".pyc"))

Miscellaneous editing options

Disabled warnings

(put 'downcase-region 'disabled nil)

Don’t kill scratch

(defadvice kill-buffer (around kill-buffer-around-advice activate)
  (let ((buffer-to-kill (ad-get-arg 0)))
    (if (equal buffer-to-kill "*scratch*")
        (bury-buffer)
      ad-do-it))
)

Default directory

(setq default-directory "~/")

Change “yes or no” to “y or n”

(fset 'yes-or-no-p 'y-or-n-p)

Feedback

Don’t flash at me.

(setq visible-bell t)

Don’t truncate lines in the message log.

(setq message-log-max t)

Keys

Unbindings

Out of the box, I find these distasteful.

(global-unset-key (kbd "C-x C-n"))
(global-unset-key (kbd "C-_"))
(global-unset-key (kbd "<C-next>"))
(global-unset-key (kbd "<C-previous>"))
(global-unset-key (kbd "C-z"))

Bindings

These are globally useful things.

(global-set-key (kbd "<M-up>") 'move-text-up)
(global-set-key (kbd "<M-down>") 'move-text-down)

(global-set-key (kbd "C-x C-M-f") 'find-file-at-point)

(global-set-key (kbd "<C-kp-add>") 'text-scale-increase)
(global-set-key (kbd "<C-kp-subtract>") 'text-scale-decrease)

(global-set-key (kbd "C-`") 'brettw/widescreen)
(global-set-key (kbd "C-c d") 'brettw/duplicate-line-or-region)

(global-set-key (kbd "<home>") 'smart-beginning-of-line)

I use these on Linux systems, but can’t on Windows.

(global-set-key (kbd "<s-up>") 'windmove-up)
(global-set-key (kbd "<s-down>") 'windmove-down)
(global-set-key (kbd "<s-left>") 'windmove-left)
(global-set-key (kbd "<s-right>") 'windmove-right)

Run an eshell from anywhere.

(global-set-key (kbd "C-M-s") 'eshell)

Helper functions

Here’s a bunch of minimal, globally-useful functions.

Byte-compile emacs-lisp files to speed up Emacs loading

(defun brettw/byte-recompile ()
  (interactive)
  (byte-recompile-directory "~/emacs" 0)
)

insert-current-timestamp

Insert the current timestamp in Year-month-day format.

(defun insert-current-timestamp ()
  "Spit out the current time in Y-m-d format."
  (interactive)
  (insert (format-time-string "%Y-%m-%d"))
)

insert-signature

Insert a textual signature into a file.

(defun insert-signature ()
  "Spit out my name, email and current time."
  (interactive)
  (insert "-- " user-full-name " (" user-mail-address ")  ")
  (insert-current-timestamp)
)

insert-file-name

Ask/browse for a filename and insert it into the buffer at the point.

(defun insert-file-name (file &optional relativep)
  "Read file name and insert it at point.
With a prefix argument, insert only the non-directory part."
  (interactive "fFile: \nP")
  (when relativep (setq file (file-name-nondirectory file)))
  (insert file))

insert-current-directory-name

Insert the name of the current directory.

(defun insert-current-directory-name ()
  "Insert the name of the current directory."
  (interactive)
  (insert (file-name-directory (buffer-file-name)))
)

rename-file-and-buffer

I’ve stolen this from Steve Yegge. It renames the current file and buffer.

(defun rename-file-and-buffer (new-name)
  "Rename both current buffer and file it's visiting to NEW-NAME."
  (interactive "sNew name: ")
  (let ((name (buffer-name))
        (filename (buffer-file-name)))
    (if (not filename)
        (message "Buffer '%s' is not visiting a file!" name)
      (if (get-buffer new-name)
          (message "A buffer named '%s' already exists!" new-name)
        (progn
          (rename-file name new-name 1)
          (rename-buffer new-name)
          (set-visited-file-name new-name)
          (set-buffer-modifier-p nil)
          ))))
)

reload-buffer

This reverts a buffer without confirmation.

(defun reload-buffer ()
  "revert-buffer without confirmation."
  (interactive)
  (revert-buffer t t))

string-strip-chars

Take a string and strip out all the characters from a second string.

(defun string-strip-chars (string strip)
  "Take STRING and remove characters in STRIP."
  (while (> (length strip) 0)
    (let ((pos 0))
      (setq pos (string-match (substring strip 0 1) string pos))
      (while (not (eq pos nil))
        (setq string (concat (substring string 0 pos)
                             (substring string (+ pos 1))))
        (setq pos (string-match (substring strip 0 1) string pos)))
      (setq strip (substring strip 1))))
  string)

brettw/resize-window

This resizes the current window to the “correct” size.

(defun brettw/resize-window ()
  "Resize the frame to defaults."
  (interactive)
  (if (window-system)
      (set-frame-size (selected-frame) brettw/default-screen-width brettw/default-screen-height)
    )
  )

brettw/widescreen

Resize the current window to double the normal width.

(defun brettw/widescreen ()
  "Resize the frame to defaults."
  (interactive)
  (if (= (frame-width) brettw/default-screen-width)
      (progn
        (set-frame-size (selected-frame) (* 2 brettw/default-screen-width) brettw/default-screen-height)
        (split-window-horizontally)
        )
    (progn 
      (set-frame-size (selected-frame) brettw/default-screen-width brettw/default-screen-height)
      (delete-other-windows)
      )
    )
  )

Startup

We typically want this during startup, so let’s call it now.

(brettw/resize-window)

duplicate-line-or-region

(defun brettw/duplicate-line-or-region (&optional n)
  "Duplicate current line, or region if active.
With argument N, make N copies.
With negative N, comment out original line and use the absolute value."
  (interactive "*p")
  (let ((use-region (use-region-p)))
    (save-excursion
      (let ((text (if use-region
                      (buffer-substring (region-beginning) (region-end))
                    (prog1 (thing-at-point 'line)
                      (end-of-line)
                      (if (< 0 (forward-line 1))
                          (newline))))))
        (dotimes (i (abs (or n 1)))
          (insert text))))
    (if use-region nil
      (let ((pos (- (point) (line-beginning-position))))
        (if (> 0 n)
            (comment-region (line-beginning-position) (line-end-position)))
        (forward-line 1)
        (forward-char pos)))))

smart-beginning-of-line

I stole this from http://stackoverflow.com/a/145359

(defun smart-beginning-of-line ()
  "Move point to first non-whitespace character or beginning-of-line.

Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
  (interactive "^")
  (let ((oldpos (point)))
    (back-to-indentation)
    (and (= oldpos (point))
         (beginning-of-line))))

align-repeat

(defun align-repeat (start end regexp)
    "Repeat alignment with respect to 
     the given regular expression."
    (interactive "r\nsAlign regexp: ")
    (align-regexp start end 
        (concat "\\(\\s-*\\)" regexp) 1 1 t))

Text editing

General options

Sentences should only have a single space at the end.

(setq sentence-end-double-space nil)

Spellcheck

(setq-default ispell-program-name "C:/Program Files (x86)/Aspell/bin/aspell.exe")

Diary and calendar

Diary

My diary is at ~/diary/main.txt, and anything in the /diary/ directory is also diary-related.

(setq diary-file "~/diary/main.txt")
(add-to-list 'auto-mode-alist `(,(expand-file-name "~/org/diary/") . diary-mode))

General settings

(setq calendar-date-style 'european)

(add-hook 'diary-list-entries-hook 'diary-sort-entries t)
(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
(add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)

Org

Modules

(setq org-modules '(
                    org-bibtex
                    org-e-beamer
                    org-expiry
                    org-habit
                    org-info
                    org-interactive-query
                    org-mouse
                    org-toc
                    )
      )
(add-to-list 'org-export-backends 'org)
(add-to-list 'org-export-backends 'md)

We require the mighty org-babel module.

(require 'ob)

General settings

These are a few miscellaneous settings to make things work how I like them.

(setq org-log-into-drawer t
      org-log-states-order-reversed nil
      org-support-shift-select t
      org-tags-sort-function (quote string<)
      org-yank-adjusted-subtrees t
      org-startup-with-inline-images nil
      org-startup-folded nil

      org-export-allow-bind-keywords t

      org-attach-store-link-p t

      org-export-copy-to-kill-ring nil

      org-log-reschedule 'time

      org-completion-use-ido t

      org-use-speed-commands t
)

Comments

(add-to-list 'org-structure-template-alist '("C" "#+BEGIN_COMMENT\n\n#+END_COMMENT" "<!--\n\n-->"))

Faces

(eval-after-load 'org-faces
 '(progn
    (defcustom org-todo-keyword-faces nil
      "Faces for specific TODO keywords.
This is a list of cons cells, with TODO keywords in the car and
faces in the cdr.  The face can be a symbol, a color, or a
property list of attributes, like (:foreground \"blue\" :weight
bold :underline t)."
      :group 'org-faces
      :group 'org-todo
      :type '(repeat
              (cons
               (string :tag "Keyword")
               (choice color (sexp :tag "Face")))))))

(eval-after-load 'org
 '(progn
    (defun org-get-todo-face-from-color (color)
      "Returns a specification for a face that inherits from org-todo
 face and has the given color as foreground. Returns nil if
 color is nil."
      (when color
        `(:inherit org-warning :foreground ,color)))

    (defun org-get-todo-face (kwd)
      "Get the right face for a TODO keyword KWD.
If KWD is a number, get the corresponding match group."
      (if (numberp kwd) (setq kwd (match-string kwd)))
      (or (let ((face (cdr (assoc kwd org-todo-keyword-faces))))
            (if (stringp face)
                (org-get-todo-face-from-color face)
              face))
          (and (member kwd org-done-keywords) 'org-done)
          'org-todo))))

Now the actual settings:

(setq org-todo-keyword-faces
      '(("STARTED" . "dark orange")
        ("WAITING" . "red4")
        ("CANCELLED" . "saddle brown"))
)

Functions

Many of these functions are taken from Worg.

Fix broken schedule/deadline markup

This will repair broken SCHEDULED and DEADLINE markup.

(defun org-check-misformatted-subtree ()
  "Check misformatted entries in the current buffer."
  (interactive)
  (show-all)
  (org-map-entries
   (lambda ()
     (when (and (move-beginning-of-line 2)
                (not (looking-at org-heading-regexp)))
       (if (or (and (org-get-scheduled-time (point))
                    (not (looking-at (concat "^.*" org-scheduled-regexp))))
               (and (org-get-deadline-time (point))
                    (not (looking-at (concat "^.*" org-deadline-regexp)))))
           (when (y-or-n-p "Fix this subtree? ")
             (message "Call the function again when you're done fixing this subtree.")
             (recursive-edit))
         (message "All subtrees checked."))))))

Mark a headline done when all its checkboxes are checked

(eval-after-load 'org-list
  '(add-hook 'org-checkbox-statistics-hook (function brettw/checkbox-list-complete)))

(defun brettw/checkbox-list-complete ()
  (save-excursion
    (org-back-to-heading t)
    (let ((beg (point)) end)
      (end-of-line)
      (setq end (point))
      (goto-char beg)
      (if (re-search-forward "\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t)
            (if (match-end 1)
                (if (equal (match-string 1) "100%")
                    ;; all done - do the state change
                    (org-todo 'done)
                  (org-todo 'todo))
              (if (and (> (match-end 2) (match-beginning 2))
                       (equal (match-string 2) (match-string 3)))
                  (org-todo 'done)
                (org-todo 'todo)))))))

Jump to journal

(defun brettw/jump-to-journal ()
  (interactive)
  (find-file brettw/org-journal-file)
)

Evaluate time range

(defun brettw/org-evaluate-time-range (&optional to-buffer)
  (interactive)
  (if (org-at-date-range-p t)
      (org-evaluate-time-range to-buffer)
    (let ((headline (buffer-substring (point-at-bol) (point-at-eol))))
      (with-temp-buffer
        (insert headline)
        (goto-char (point-at-bol))
        (re-search-forward org-ts-regexp (point-at-eol) t)
        (if (not (org-at-timestamp-p t))
            (error "No timestamp here"))
        (goto-char (match-beginning 0))
        (org-insert-time-stamp (current-time) nil nil)
        (insert "--")
        (org-evaluate-time-range to-buffer)))))

Recalculate Effort properties

(defun recalculate-effort-property ()
  "Recalculate the Effort property if it exists."
  (interactive)
  (if (org-entry-get (point) "Effort")
      (save-excursion
        (save-restriction
          (org-narrow-to-element)
          (search-forward ":Effort:")
          (org-compute-property-at-point)
          )
        )
    )
)

capture-report-date-file

(defun capture-retro-date-file (path)
  (expand-file-name (format "retro-%s.org"
                              (format-time-string "%Y-%m-%d")) path))

Files and directories

We typically work out of the ~/org/ directory for the universal stuff.

(setq org-directory "~/org")
(setq brettw/org-journal-file "~/org/journal.org")
(setq org-agenda-files (list "~/org/" "~/"))
(setq org-default-notes-file (concat org-directory "/notes.org"))

Global keyboard shortcuts

So org-mode can be accessed from anywhere!

(global-set-key (kbd "\C-c l") 'org-store-link)
(global-set-key (kbd "\C-c a") 'org-agenda)
(global-set-key (kbd "\C-c b") 'org-iswitchb)
(global-set-key (kbd "\C-c c") 'org-capture)
(global-set-key (kbd "C-M-j") 'brettw/jump-to-journal)

Babel

Languages

We’ll usually only work on my favourite languages.

(org-babel-do-load-languages
 'org-babel-load-languages
 '(
   (C . t)
   (dot . t)
   (emacs-lisp . t)
   (latex . t)
   (python . t)
   (sh . t)
   )
)

Settings

I’d prefer zero indentation.

(setq org-edit-src-content-indentation 0)

I also like to live dangerously (don’t ask me if I want to evaluate org-babel code)

(setq org-confirm-babel-evaluate nil)

Hyperlinks

Settings

(setq org-return-follows-link t
      org-tab-follows-link t)

(setq org-link-frame-setup '((vm . vm-visit-folder-other-frame)
                             (vm-imap . vm-visit-imap-folder-other-frame)
                             (gnus . org-gnus-no-new-news)
                             (file . find-file)
                             (wl . wl-other-frame))
)

Youtube

Taken from Endless Parentheses:

(defvar youtube-iframe-format
  ;; You may want to change your width and height.
  (concat "<iframe width=\"440\""
          " height=\"335\""
          " src=\"https://www.youtube.com/embed/%s\""
          " frameborder=\"0\""
          " allowfullscreen>%s</iframe>"))

(org-add-link-type
 "youtube"
 (lambda (handle)
   (browse-url
    (concat "https://www.youtube.com/embed/"
            handle)))
 (lambda (path desc backend)
   (cl-case backend
     (html (format youtube-iframe-format
                   path (or desc "")))
     (latex (format "\href{%s}{%s}"
                    path (or desc "video"))))))

Quicklinks

(setq org-link-abbrev-alist
      '(
        ("wikipedia" . "http://en.wikipedia.org/index.php?search=%h")
        ("contact" . "file:~/org/contacts.org::%s")
        )
)

Contacts

;  (require 'org-contacts)
;  (add-to-list 'org-contacts-files (expand-file-name "~/org/contacts.org"))

Agenda

Settings

(setq org-agenda-skip-unavailable-files t
      org-include-diary t
      org-agenda-align-tags-to-column -100
      org-agenda-skip-additional-timestamps-same-entry nil
      org-agenda-skip-scheduled-if-done t
)

On load up

Show the agenda straight after Emacs initialization.

;(add-hook 'after-init-hook 'org-agenda-to-appt)
;(add-hook 'after-init-hook 'org-agenda-list)

To-do

Settings

(setq org-enforce-todo-checkbox-dependencies t
      org-enforce-todo-dependencies t
      org-log-done t)
(setq org-todo-keywords (list "TODO(t)" "STARTED(s)" "WAITING(w!)" "|" "DONE(d)" "CANCELLED(c@)"))

Refile

Basic settings

(setq org-refile 'time
      org-refile-use-outline-path t)

Our slightly complicated refile targets

(setq org-refile-targets '((nil . (:maxlevel . 3))) )

org2blog

Make sure we autoload the required stuff.

(require 'org2blog-autoloads)

Customization

We want to make sure before we post anything.

(setq org2blog/wp-confirm-post t)

I don’t like how it strips newlines.

(setq org2blog/wp-keep-new-lines t)

Set the source code syntax.

(setq org2blog/wp-use-sourcecode-shortcode t)
(setq org2blog/wp-sourcecode-default-params "")

Capture

I capture bugs, todo and dev journal entries for my main project.

(setq org-capture-templates
      '(
        ("t" "To-Do" entry (file "~/org/todo.org")
         "* TODO %?%i %^g\nDEADLINE: %^t\n%t \n\n" :empty-lines 1)
        ("T" "TDA Task" entry (id "6d821dba-c5d1-4088-9623-dd7ae8e2196b")
         (file "e:/Projects/theDayAfter/doc/dev/template/task-template.org") :empty-lines 1 )
        ("r" "TDA Retrospective" plain (file (capture-retro-date-file "e:/Projects/theDayAfter/doc/dev/retro/"))
         (file "e:/Projects/theDayAfter/doc/dev/template/retro.org"))
        ("B" "TDA Bug" entry (id "ff05c4cd-249c-4316-8f1d-c74a32489d03")
         (file "e:/Projects/theDayAfter/doc/dev/template/bug-template.org") :empty-lines 1)
        ("J" "TDA Dev Journal" entry (file+datetree "e:/Projects/thedayafter/doc/org/devjournal.org")
         "* %i%? :tda:\n%t\n" :empty-lines 1)
        )
)

Hooks

(defun brettw/my-org-mode-hook ()
    (local-set-key (kbd "\M-n") 'outline-next-visible-heading)
    (local-set-key (kbd "\M-p") 'outline-previous-visible-heading)
    (visual-line-mode)
  )

(add-hook 'org-mode-hook 'brettw/my-org-mode-hook)

(eval-after-load 'org-list
  '(add-hook 'org-checkbox-statistics-hook (function brettw/checkbox-list-complete)))

Programming

General options

Company mode

Maybe company mode is less fiddly than CEDET.

(require 'company)
(add-hook 'after-init-hook 'global-company-mode)

(defun check-expansion ()
  (save-excursion
    (if (looking-at "\\_>") t
      (backward-char 1)
      (if (looking-at "\\.") t
        (backward-char 1)
        (if (looking-at "->") t nil)))))

(defun do-yas-expand ()
  (let ((yas/fallback-behavior 'return-nil))
    (yas/expand)))

(defun tab-indent-or-complete ()
  (interactive)
  (if (minibufferp)
      (minibuffer-complete)
    (if (or (not yas/minor-mode)
            (null (do-yas-expand)))
        (if (check-expansion)
            (company-complete-common)
          (indent-for-tab-command)))))

(global-set-key [tab] 'tab-indent-or-complete)

Tabs and indents

Tab width is always, always, always 4, and indents are only spaces.

(setq tab-width 4)
(set-default 'indent-tabs-mode nil)

Compilation

When a compile finishes correctly, we automatically close the compilation window.

(defun compilation-exit-autoclose (status code msg)
  ;; If M-x compile exists with a 0
  (when (and (eq status 'exit) (zerop code))
    (bury-buffer)
    (delete-window (get-buffer-window (get-buffer "*compilation*"))))
  (cons msg code))

(setq compilation-exit-message-function 'compilation-exit-autoclose)

(setq compilation-scroll-output t)

Keys

(add-hook 'c-mode-common-hook '( lambda ()
                                 (local-set-key (kbd "<S-f5>") 'compile)
                                 (local-set-key (kbd "<f5>") 'recompile)
                                 (local-set-key (kbd "RET") 'reindent-then-newline-and-indent)
                                 (local-set-key (kbd "C-M-o") 'ff-find-other-file)
                                 (local-set-key (kbd "<C-return>") 'complete-symbol)
))

LaTeX

(load "auctex.el" nil t t)
(add-to-list 'auto-mode-alist '("\\.tex?\\'" . latex-mode))

Lisp

HTML

(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.php?\\'" . web-mode))
(defun brettw/web-mode-hook () 
  (local-set-key (kbd "RET") 'newline-and-indent)
)

(add-hook 'web-mode-hook 'brettw/web-mode-hook)

Python

Filenames

Use python mode for SCons files.

(setq auto-mode-alist (cons '("SConstruct" . python-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("SConscript" . python-mode) auto-mode-alist))

Hook

When we “compile” in Python, we typically mean to invoke SCons (because we are usually editing SCons files!)

(defun brettw/my-python-hook ()
  (setq compile-command "scons.py -D")
  (local-set-key (kbd "<S-f5>") 'compile)
  (local-set-key (kbd "<f5>") 'recompile)
  (local-set-key (kbd "RET") 'newline-and-indent)
  (local-set-key (kbd "s-o") 'ff-find-other-file)
  (local-set-key (kbd "<C-return>") 'complete-symbol)
)

(add-hook 'python-mode-hook 'brettw/my-python-hook)

C++

Filenames

CUDA is C++, so make Emacs aware of it.

(add-to-list 'auto-mode-alist '("\\.cu\\'" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.cuh\\'" . c++-mode))

Style

This is my C/C++ style.

(setq c-basic-offset 4
      c-doc-comment-style (quote javadoc))

(defconst brettw/my-c-style
  '((c-tab-always-indent         . t)
    (c-hanging-braces-alist      . ((substatement-open after)
                                    (brace-list-open)))
    (c-hanging-colons-alist      . ((member-init-intro before)
                                    (inher-intro)
                                    (case-label after)
                                    (label after)
                                    (access-label after)))
    (c-cleanu-list               . (scope-operator
                                    empty-defun-braces
                                    defun-close-semi))
    (c-offsets-alist             . ((arglist-close . c-lineup-arglist)
                                    (substatement-open . 0)
                                    (case-label        . +)
                                    (block-open        . 0)
                                    (access-label      . -)
                                    (knr-argdecl-intro . -)))
    )
  "BEW C Programming Style")

(c-add-style "brettw" brettw/my-c-style)

Hooks

Set a bunch of my defaults.

(defun brettw/my-c-mode-common-hook ()
  ;(global-set-key (kbd "<M-return>") 'semantic-ia-complete-symbol)
  (c-set-style "brettw")
  (setq compile-command "scons.py -D")
  )

(add-hook 'c-mode-common-hook 'brettw/my-c-mode-common-hook)
(add-hook 'c++-mode-hook 'brettw/my-c-mode-common-hook)

Projects

I put project-specific settings here (especially semantic-add-system-include settings)

Octave

(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))

The Day After

(require 'tdascript)

Utilities

Twitter

twittering-mode is pretty awesome. That’ll keep.

(setq twittering-use-master-password t
      twittering-icon-mode t
      twittering-timer-interval 300
      twittering-use-icon-storage t)

Webjump

Webjump is neat and gives us very quick access to search.

(require 'webjump)

(global-set-key '[f2] 'webjump)
(setq webjump-sites '(
                      ("Urban Dictionary" .
                       [simple-query "www.urbandictionary.com"
                                     "http://www.urbandictionary.com/define.php?term=" ""])
                      ("Reddit Search" .
                       [simple-query "www.reddit.com"
                                     "http://www.reddit.com/search?q=" ""])
                      ("Google Image Search" .
                       [simple-query "images.google.com" "images.google.com/images?hl=en&q=" ""])
                      ("Google" .
                       [simple-query "google.com" "www.google.com.au/search?q=" ""])
                      ("StackOverflow" .
                       [simple-query "stackoverflow.com" "stackoverflow.com/search?q=" ""])
                      ("EmacsOverflow" .
                       [simple-query "emacs.stackexchange.com" "emacs.stackexchange.com/search?q=" ""])
                      ("Wikipedia" .
                       [simple-query "https://en.wikipedia.org/" "https://en.wikipedia.org/wiki/Special:Search/" ""])

                      ))