Q:

Create a minor mode that sets tab space

I want to have minor mode that, when enabled, changes the tab space from 4 to 2 (and when disabled returns the tab space back to 4). I haven't written a mode before so I'm not sure how to go about this.

A:

No need to create a minor mode. tab-width is already a buffer-local variable:
(defvar my-tab-toggle-values '(2 4))

(defun my-toggle-tab-width ()
  (interactive)
  (setq tab-width 
    (if  (= tab-width (first my-tab-toggle-values))
        (second my-tab-toggle-values)
      (first my-tab-toggle-values))))

