SiteMap Search ElispArea HowTo Glossary RecentChanges News Problems Suggestions
Cameroon, National Day

JeremyMooreInitEl

Download

;;;-*- coding: utf-8 -*--------------------------------------------------------------------
; Emacs environment initialisation
; Time-stamp: <31-Oct-2011 12:50:51>
;------------------------------------------------------------------------------------------

(add-to-list 'load-path "~/.emacs.d/misc-lisp")

;; Packages
(require 'ansi-color)
(require 'cc-mode)
(require 'cl)
(require 'compile)
(require 'ctypes)
(require 'font-lock)
(require 'fm)
(require 'goto-last-change)
(require 'highlight)
(require 'iswitchb)
(require 'lusty-explorer)
(require 'mcomplete)
(require 'mediawiki)
(require 'misc)
(require 'recentf)
(require 'vc-git)
(require 'which-func)
(require 'whitespace)
(require 'xcscope)

(when (> emacs-major-version 21) 
  (require 'anything-config))

;------------------------------------------------------------------------------------------
; File names
;------------------------------------------------------------------------------------------

;; Persistent settings
(setq abbrev-file-name "~/.emacs.d/persist/.abbrev_defs")
(setq ctypes-file-name "~/.emacs.d/persist/.ctypes")
(setq strokes-file "~/.emacs.d/persist/.strokes")

;; Session information
(setq anything-c-adaptive-history-file "~/.emacs.d/transient/.anything-c-adaptive-history")
(setq auto-save-list-file-prefix "~/.emacs.d/transient/auto-save-list/.saves-")
(setq bookmark-default-file "~/.emacs.d/transient/.bookmarks")
(setq desktop-base-file-name ".desktop")
(setq desktop-base-lock-name ".desktop.lock")
(setq desktop-dirname "~/.emacs.d/transient/")
(setq eshell-history-file-name "~/.emacs.d/transient/.eshell-history")
(setq org-id-locations-file "~/.emacs.d/transient/.org-id-locations")
(setq recentf-save-file "~/.emacs.d/transient/.recentf")
(setq savehist-file "~/.emacs.d/transient/.history")

;; Org files
(when (file-exists-p "~/org/")
  (setq org-directory "~/org/")
  (setq org-default-notes-file (concat org-directory "Notes.org"))
  (setq org-archive-location (concat org-directory "Archive.org::"))
  (setq org-agenda-files (directory-files org-directory t "\.org$")))

;------------------------------------------------------------------------------------------
; System variables
;------------------------------------------------------------------------------------------

;; Miscellaneous
(setq-default cursor-in-non-selected-windows nil)
(setq-default fill-column 100)
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq-default truncate-lines t)

(setq blink-matching-paren nil)
(setq bookmark-save-flag 1)
(setq case-replace nil)
(setq completion-ignore-case t)
(setq frame-title-format '((:eval (if compilation-in-progress "[Compiling]  " nil)) "%b"))
(setq hippie-expand-try-functions-list
      '(try-expand-all-abbrevs
        try-expand-dabbrev
        try-expand-line
        try-expand-dabbrev-all-buffers
        try-expand-dabbrev-from-kill
        try-complete-lisp-symbol-partially
        try-complete-lisp-symbol))
(setq large-file-warning-threshold 20000000)
(setq make-backup-files nil)
(setq recentf-max-saved-items 500)
(setq save-abbrevs nil)
(setq save-interprogram-paste-before-kill t)
(setq sentence-end-double-space nil)
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80))
(setq tags-revert-without-query t)
(setq time-stamp-format "%02d-%3b-%:y %02H:%02M:%02S")

(when window-system
  (set-fringe-mode '(8 . 0)))

;; Emacs 23
(when (>= emacs-major-version 23)
  (setq split-height-threshold 60)
  (setq split-width-threshold nil)
  (setq read-buffer-completion-ignore-case t))

;; Enable things
(put 'downcase-region 'disabled nil)
(put 'dired-find-alternate-file 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'upcase-region 'disabled nil)

;; Splash!
(setq inhibit-splash-screen t)
(add-hook 'after-init-hook 'my-scratch-message)
(add-hook 'window-setup-hook 'maximize-frame t)

;------------------------------------------------------------------------------------------
; Faces
;------------------------------------------------------------------------------------------

;; Main
(set-face-attribute  'default nil :family "bitstream vera sans mono" :height 80)
(set-face-background 'cursor "firebrick")

;; Compilation
(when (facep 'compilation-error) (set-face-attribute 'compilation-error nil :weight 'bold :foreground "firebrick"))
(when (facep 'compilation-info) (set-face-attribute 'compilation-info nil :weight 'bold :foreground "MediumSeaGreen"))

;; Font lock
(set-face-attribute  'font-lock-comment-face nil :slant 'italic :foreground "sea green")
(set-face-foreground 'font-lock-constant-face "steel blue")
(set-face-attribute  'font-lock-doc-face nil :inherit 'font-lock-comment-face)
(set-face-attribute  'font-lock-function-name-face nil :weight 'bold :foreground "SystemWindowText")
(set-face-attribute  'font-lock-keyword-face nil :weight (if window-system 'bold 'normal) :foreground "dark blue")
(set-face-foreground 'font-lock-string-face "blue")
(set-face-foreground 'font-lock-type-face "dark blue")
(set-face-foreground 'font-lock-variable-name-face "dark blue")
(when (facep 'font-lock-preprocessor-face) (set-face-foreground 'font-lock-preprocessor-face "dark red"))

;; Highlighting
(defface highlight-line-face '((t (:background "peach puff"))) "Line highlighting.")
(defface highlight-expression-face '((t (:background "yellow"))) "Expression highlighting.")
(hlt-choose-default-face 'highlight-line-face)

;; Ibuffer
(defface ibuffer-help-buffer-face '((t (:foreground "sea green"))) "Used to mark help buffers.")
(defface ibuffer-system-buffer-face '((t (:foreground "dark blue"))) "Used to mark *named* buffers.")

;; Iswitchb
(when (facep 'iswitchb-current-match) (set-face-attribute 'iswitchb-current-match nil :inherit font-lock-keyword-face))
(when (facep 'iswitchb-single-match) (set-face-attribute 'iswitchb-single-match nil :slant 'normal :foreground "forest green"))

;; Line numbers
(defface my-line-number-face '((t (:foreground "DarkOrange4"))) "Mode line font for line and column numbers.")

;; Mcomplete
(set-face-attribute 'mcomplete-prefix-method-alternative-part-face nil :weight 'normal :foreground "SystemWindowText")
(set-face-attribute 'mcomplete-prefix-method-fixed-part-face nil :weight 'normal :foreground "SystemWindowText")
(set-face-attribute 'mcomplete-substr-method-alternative-part-face nil :weight 'normal :foreground "SystemWindowText")
(set-face-attribute 'mcomplete-substr-method-fixed-part-face nil :weight 'normal :foreground "SystemWindowText")

;; Which-func
(when (facep 'which-func) (set-face-attribute 'which-func nil :weight 'normal :foreground "RoyalBlue4"))

;; Whitespace
(when (facep 'whitespace-tab) (set-face-attribute 'whitespace-tab nil :foreground "beige" :background "cornsilk2"))

;------------------------------------------------------------------------------------------
; Global keystrokes
;------------------------------------------------------------------------------------------

;; Global commands
(global-set-key "\C-x\C-m" 'execute-extended-command)
(global-set-key "\C-xm" 'execute-extended-command)
(global-set-key "\C-x\C-g" 'ignore)
(global-set-key "\C-c\C-g" 'ignore)
(global-set-key "\C-h\C-g" 'ignore)
(global-unset-key [(control ?\\)])

;; Function keys
(global-set-key [f1] 'eval-expression)
(global-set-key [f2] 'shell-command)
(global-set-key [(control f2)] 'shell-command-on-region)
(global-set-key [f3] 'longlines-mode)
(global-set-key [f4] 'call-last-kbd-macro)
(global-set-key [(meta f4)] 'kill-frame)

(global-set-key [f5] 'recompile)
(global-set-key [(control f5)] 'compile)
(global-set-key [(meta f5)] 'compile-with-temp-command)
(global-set-key [f6] 'global-whitespace-mode)
(global-set-key [f7] 'project-check-out)
(global-set-key [(control f7)] 'project-check-out-dlg)
(global-set-key [(meta f7)] 'project-undo-check-out)
(global-set-key [f8] 'anything-command-map)

(global-set-key [f9] 'mode-line-other-buffer)
(global-set-key [f10] 'sync-frames)
(global-set-key [f11] 'revert-buffer)
(global-set-key [(control f11)] (lambda () (interactive) (revert-buffer t t) (goto-char (point-max))))
(global-set-key [(meta f11)] 'redraw-display)
(global-set-key [f12] 'kill-this-buffer)
(global-set-key [(control f12)] 'bury-buffer)

;; Mouse buttons
(global-set-key [down-mouse-3] 'strokes-do-stroke)

;; Navigation
(global-set-key "\C-x\C-f" 'lusty-file-explorer)
(global-set-key "\C-xt" 'beginning-of-buffer)
(global-set-key "\C-xe" 'end-of-buffer)
(global-set-key [(control shift ?n)] (lambda () (interactive) (scroll-up 1)))
(global-set-key [(control shift ?p)] (lambda () (interactive) (scroll-down 1)))
(global-set-key [(meta \')] 'project-grep-with-prompt)
(global-set-key [(control meta \')] (lambda () (interactive) (project-grep (current-word))))
(global-set-key "\M-g" 'goto-line)
(global-set-key [(control ?x) (control ?b)] 'my-buffer-menu-launch)
(global-set-key [(control ?x) (control ?a)] 'anything-my-default)
(when window-system (global-set-key [(control ?x) (control ?z)] 'goto-last-change-with-auto-marks))

;; Editing
(global-set-key "\C-z" 'undo)
(global-set-key [(control \;)] 'kill-whole-line)
(global-set-key [(control meta \;)] 'copy-line)
(global-set-key [(meta backspace)] 'kill-word)
(global-set-key [(control meta y)] (lambda () (interactive) (yank) (delete-sexp)))
(global-set-key "\C-c\C-v" 'copy-word)
(global-set-key [(control \#)] 'query-replace-regexp)
(global-set-key [(meta \#)] 'replace-regexp)
(global-set-key [(control return)] 'hippie-expand)
(global-set-key [(shift tab)] 'indent-relative)
(global-set-key [(control tab)] 'align)
(global-set-key [(control shift ?u)] 'delete-indentation)
(global-set-key [(meta ?z)] 'zap-up-to-char-case-sensitive)
(global-set-key [(meta ?l)] 'downcase-previous-word)
(global-set-key [(meta ?u)] 'upcase-previous-word)
(global-set-key [(control ?x) (meta ?w)] 'copy-region-without-quotes)
(global-set-key [(control ?c) (control ?e)] 'fc-eval-and-replace)
(global-set-key [(control shift ?y)] 'anything-show-kill-ring)
(global-set-key [(control ?c) (control ?t)] 'transpose-chars)
(global-set-key [(control ?c) (meta ?t)] 'transpose-words)

;; Window management
(global-set-key [(control \,)] 'force-other-window)
(global-set-key [(control \<)] 'force-other-frame)
(global-set-key [(control \.)] 'delete-other-windows)
(global-set-key [(control \/)] 'delete-window)
(global-set-key [(meta \,)] 'swap-windows)
(global-set-key [(meta \.)] 'kill-other-buffer-and-window)
(global-set-key [(meta \/)] 'kill-buffer-and-window)
(global-set-key [(control meta \,)] 'divide-window)

;; Tags
(global-set-key [(control t)] 'find-tag-or-header-at-point)
(global-set-key [(meta t)] 'pop-tag-mark)
(global-set-key "\C-c\C-f" 'find-tag)

;; Highlighting
(global-set-key [(control ?x) (control ?y)] 'highlight-line)
(global-set-key [(control ?x) (meta ?y)] 'highlight-symbol)
(global-set-key [(meta ?n)] (lambda () "Go to next highlighted line" (interactive) (hlt-next-highlight (point-min) (point-max) 'highlight-line-face)))
(global-set-key [(meta ?p)] (lambda () "Go to previous highlighted line" (interactive) (hlt-previous-highlight (point-min) (point-max) 'highlight-line-face)))
(global-set-key [(control meta ?n)] (lambda () "Go to next highlighted expression "(interactive) (hlt-next-highlight (point-min) (point-max) 'highlight-expression-face)))
(global-set-key [(control meta ?p)] (lambda () "Go to previous highlighted expression" (interactive) (hlt-previous-highlight (point-min) (point-max) 'highlight-expression-face)))

;------------------------------------------------------------------------------------------
; Global functions
;------------------------------------------------------------------------------------------

;; Window management
(defun force-other-window ()
  "If there is a second window visible, switch to it. If not, create a
second window, set it to some interesting buffer, and switch to the
new window"
  (interactive)
  (if (> (count-windows) 1)
      (other-window 1)
    (split-window-vertically)
    (other-window 1)
    (switch-to-buffer (other-buffer))))

(defun force-other-frame ()
  "If there is a second frame visible, switch to it. If not, create a
second frame"
  (interactive)
  (if (> (length (frame-list)) 1)
      (other-frame 1)
    (new-frame)))

(defun swap-windows ()
  "Swap the buffers displayed in the two current windows"
  (interactive)
  (when (> (count-windows) 1)
    (let (buf1 buf2)
      (setq buf1 (buffer-name))
      (other-window 1)
      (setq buf2 (buffer-name))
      (switch-to-buffer buf1)
      (other-window 1)
      (switch-to-buffer buf2))))

(defun sync-frames ()
  "Make two frames show the same thing"
  (interactive)
  (let ((buf (current-buffer)))
    (setq start (window-start))
    (select-frame (next-frame nil nil))
    (switch-to-buffer buf)
    (set-window-start (selected-window) start t)))

(defun divide-window ()
  "Divide this window into two which collectively show the same thing"
  (interactive)
  (let* ((start (window-start))
         (in-bottom-half (>= (point) (/ (+ start (window-end nil t)) 2))))
    (split-window-vertically)
    (set-window-start nil start)
    (set-window-start (next-window) (window-end nil t))
    (when in-bottom-half (other-window 1))))

(defun kill-buffer-and-window ()
  "Kill the current buffer (prompting if it is modified) and destroy its window (unless it is the only window)."
  (interactive)
  (kill-this-buffer)
  (when (> (count-windows) 1) (delete-window)))

(defun kill-other-buffer-and-window ()
  "Kill the buffer in the other window (prompting if it is modified), then destroy the window."
  (interactive)
  (other-window 1)
  (kill-buffer-and-window))

(defun kill-frame ()
  "Kill the current frame, and exit Emacs if it is the only remaining frame (prompts to save first)."
  (interactive)
  (if (> (length (frame-list)) 1)
      (delete-frame)
    (save-buffers-kill-emacs)))

;; Editing
(defun copy-word ()
  "Add the word under point to the kill ring."
  (interactive)
  (kill-new (current-word)))

(defun copy-line ()
  "Add the current line to the kill ring."
  (interactive)
  (kill-ring-save (line-beginning-position) (line-beginning-position 2)))

(defun copy-buffer ()
  "Add the entire buffer to the kill ring."
  (interactive)
  (copy-region-as-kill (point-min) (point-max)))

(defun copy-region-without-quotes (beg end)
  "Add the contents of the region to the kill ring with all quotes stripped out."
  (interactive "r")
  (kill-new
   (replace-regexp-in-string "\"" "" (buffer-substring beg end)))
  (deactivate-mark))

(defun delete-sexp ()
  "Delete the sexp following point without saving it to the kill ring."
  (save-excursion
    (let (start end)
      (setq start (point))
      (forward-sexp)
      (setq end (point))
      (delete-region start end))))

(defun zap-up-to-char-case-sensitive (arg char)
  "Variation of zap-up-to-char that overrides the local setting of case-fold-search."
  (interactive "p\ncZap up to char: ")
  (let ((case-fold-search nil))
    (zap-up-to-char arg char)))

(defun downcase-previous-word (arg)
  "Downcase previous word."
  (interactive "p")
  (downcase-word (* -1 arg)))

(defun upcase-previous-word (arg)
  "Upcase previous word."
  (interactive "p")
  (upcase-word (* -1 arg)))

(defun uniquify-lines (start end)
  "Remove duplicate adjacent lines in the given region"
  (interactive "r")
  (goto-char start)
  (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
    (replace-match "\\1" nil nil)))

(defun uniquify-buffer ()
  "Remove duplicate adjacent lines from the entire buffer"
  (interactive)
  (uniquify-lines (point-min) (point-max)))

(defalias 'uniq 'uniquify-buffer)

(defun fc-eval-and-replace ()
  "Replace the preceding elisp with its value."
  (interactive)
  (backward-kill-sexp)
  (condition-case nil
      (prin1 (eval (read (current-kill 0)))
             (current-buffer))
    (error (message "Invalid expression")
           (insert (current-kill 0)))))

;; Navigation
(defun find-tag-or-header-at-point (arg)
  (interactive "P")
  (let (first-word)
    (save-excursion
      (beginning-of-line)
      (setq first-word (current-word)))
    (if (equal first-word "include")
        (find-tag (concat (current-word) ".h") arg)
      (find-tag (current-word) arg))))

(defadvice find-tag (before strip-whitespace)
  "Strip leading and trailing whitespace from the input before trying to find a tag."
  (when (ad-get-arg 0)
    (ad-set-arg 0 (replace-regexp-in-string "\\(^[[:space:]]*\\|[[:space:]]*$\\)" "" (ad-get-arg 0)))))
(ad-activate 'find-tag)
  
(defun pwd (&optional arg)
  "Display the file name of the current buffer in the echo area.
With single C-u prefix argument, also add it to the kill ring.
With double C-u prefix, add it to the kill ring using windows slashes.
With triple C-u prefix, add just the directory to the kill ring using windows slashes."
  (interactive "p")
  (when arg
    (case arg
      (4 (kill-new buffer-file-name))
      (16 (kill-new (replace-regexp-in-string "/" "\\" buffer-file-name nil t)))
      (64 (kill-new (replace-regexp-in-string "/" "\\" (file-name-directory buffer-file-name) nil t)))))
  (message buffer-file-name))

;; Highlighting
(defun highlight-line (&optional arg)
  "Highlight the current line. With C-u prefix, unhighlight it. With C-u C-u prefix,
unhighlight the whole buffer."
  (interactive "p")
  (let ((start (line-beginning-position))
        (end (line-beginning-position 2)))
    (if arg
        (case arg
          (1 (hlt-highlight-region start end 'highlight-line-face))
          (4 (hlt-unhighlight-region start end 'highlight-line-face))
          (16 (hlt-unhighlight-region (point-min) (point-max) 'highlight-line-face)))
      (hlt-highlight-region start end 'highlight-line-face))))

(defun highlight-symbol (&optional arg)
  "Highlight the symbol at point throughout the current buffer."
  (interactive "p")
  (if (>= arg 4)
      (hlt-unhighlight-region (point-min) (point-max) 'highlight-expression-face)
    (hlt-highlight-regexp-region
     (point-min)
     (point-max)
     (concat "[^a-zA-Z0-9_]\\(" (symbol-name (symbol-at-point)) "\\)[^a-zA-Z0-9_]")
     'highlight-expression-face
     nil
     nil
     1)))

;; Miscellaneous functions
(defun my-scratch-message ()
  "Construct a string to display at startup"
  ; Temporarily override definition of (frame-width) so that (sunrise-sunset) doesn't use a temp window
  (fset 'frame-width-bak (symbol-function 'frame-width))
  (fset 'frame-width '(lambda () 10000))
  (erase-buffer)
  (insert ";;\n;; "
          (substring (emacs-version) 0 16)
          (format-time-string "\n;; Invoked on %a %d %b %Y, %T\n;; " (current-time))
          (cadr (split-string (sunrise-sunset) ": "))
          "\n;;\n\n")
  (fset 'frame-width (symbol-function 'frame-width-bak))
  (fmakunbound 'frame-width-bak)
  (setq buffer-undo-list nil))

(defun new-scratch-buffer ()
  "Destroy the existing scratch buffer and create a new one"
  (interactive)
  (switch-to-buffer "*scratch*")
  (my-scratch-message))

(defun ascii-table ()
  "Display basic ASCII table (0 thru 128)."
  (interactive)
  (switch-to-buffer "*ASCII*")
  (erase-buffer)
  (save-excursion
    (let ((i -1))
      (insert "ASCII characters 0 thru 127.\n\n")
      (insert " Hex  Dec  Char  |  Hex  Dec  Char  |  Hex  Dec  Char  |  Hex  Dec  Char\n")
      (while (< i 31)
        (insert (format "%4X %4d %4s   | %4X %4d %4s   | %4X %4d %4s   | %4X %4d %4s\n"
                        (setq i (+ 1  i)) i (single-key-description i)
                        (setq i (+ 32 i)) i (single-key-description i)
                        (setq i (+ 32 i)) i (single-key-description i)
                        (setq i (+ 32 i)) i (single-key-description i)))
        (setq i (- i 96))))))

;------------------------------------------------------------------------------------------
; Windows stuff
;------------------------------------------------------------------------------------------

(when (eq system-type 'windows-nt)
  (global-unset-key "\C-x\C-c")
  (set-message-beep 'silent)

  (when (and project-find-executable (file-exists-p project-find-executable))
    (setq find-program project-find-executable)
    (setq find-dired-find-program find-program)
    (setq grep-find-command (concat find-program " . -type f -print0 | xargs -0 -e grep -n ")))

  (defun make-writable ()
    (interactive)
    (shell-command (format "cmd /c attrib -R %s" buffer-file-name))
    (revert-buffer))

  (defun maximize-frame ()
    "Maximize the current frame"
    (interactive)
    (w32-send-sys-command 61488))
)

;------------------------------------------------------------------------------------------
; Linux stuff
;------------------------------------------------------------------------------------------

(when (eq system-type 'gnu/linux)
  (when window-system (setq visible-bell t))

  (defun make-writable ()
    (interactive)
    (shell-command (format "chmod +w %s" buffer-file-name))
    (revert-buffer))

  (defun maximize-frame ()
    "Not available"
    nil)
)

;------------------------------------------------------------------------------------------
; Init file management
;------------------------------------------------------------------------------------------

(defun edit-init-file ()
  (interactive)
  (find-file user-init-file))

(defun edit-project-file ()
  (interactive)
  (find-file user-project-file))

(defun commit-init-files (commit-message)
  (interactive "sCommit message: ")
  (with-temp-buffer
    (setq default-directory "~/.emacs.d/")
    (shell-command (concat "git commit -a -m \"" commit-message "\" && git push backup"))))

;------------------------------------------------------------------------------------------
; C mode
;------------------------------------------------------------------------------------------

(define-key c-mode-map "\C-x\C-l" 'c-view-function)
(define-key c-mode-map "\C-ch" 'c-jump-to-header)
(define-key c-mode-map [(control shift a)] 'c-copy-function-name)
(define-key c-mode-map [tab] 'c-indent-line-or-region)
(define-key c-mode-map [(control c) (control \;) (control h)] 'hs-hide-block)
(define-key c-mode-map [(control c) (control \;) (control s)] 'hs-show-block)
(define-key c-mode-map [(control meta h)] 'hs-hide-all)
(define-key c-mode-map [(control meta s)] 'hs-show-all)
(define-key c-mode-map [(control c) (control e)] 'fc-eval-and-replace)

(defun my-c-setup ()
  "Set up for C mode editing and display"
  (c-set-style "stroustrup")
  (c-set-offset 'case-label '+)
  (c-set-offset 'inextern-lang 0)
  (hs-minor-mode t)
  (add-hook 'before-save-hook 'delete-trailing-whitespace nil t))
(add-hook 'c-mode-common-hook 'my-c-setup)

(defalias 'link 'c-insert-link-header)
(defalias 'doxy 'c-insert-doxy-header)

(defun c-view-function ()
  "Scroll window to place the header of the current function at the top of the screen.
Keeps point in its original position if possible."
  (interactive)
  (let ((pos (point)))
    (c-end-of-defun)
    (c-beginning-of-defun)
    (if (c-backward-single-comment)
        (recenter 0)
      (c-end-of-defun)
      (c-beginning-of-defun)
      (recenter 0))
    (when (pos-visible-in-window-p pos)
      (set-window-point (selected-window) pos))))

(defun c-get-function-name ()
  "Return the name of the current function."
  (save-excursion
    (beginning-of-defun)
    (search-forward "(")
    (backward-word)
    (symbol-name (symbol-at-point))))

(defun c-copy-function-name ()
  "Add the name of the current function to the kill ring."
  (interactive)
  (kill-new (c-get-function-name)))

(defun c-jump-to-header ()
  "Visit the header file for the c file in the current buffer, and place point at the definition of the current function."
  (interactive)
  (let (word)
    (save-excursion
      (c-beginning-of-defun)
      (skip-chars-forward "^ ")
      (forward-char 1)
      (setq word (current-word)))
    (find-tag (concat (file-name-nondirectory (file-name-sans-extension buffer-file-name)) ".h"))
    (search-forward word)
    (beginning-of-line)))

(defun c-insert-link-header ()
  "Add a function header linking to the one for its prototype"
  (interactive)
  (let ((function-name (c-get-function-name)))
    (save-excursion
      (beginning-of-defun)
      (open-line 1)
      (insert "/** @link " function-name "() " function-name "() @endlink */"))))

(defun c-insert-doxy-header-default ()
  "Insert a doxygen header for a function"
  (interactive)
  (let (func-start param-start (params '()) has-return end-pos)
    (save-excursion
      (if (equal (file-name-extension (buffer-file-name)) "h")
          (re-search-backward "^[^ ]")
        (beginning-of-defun))
      (setq func-start (point))
      (search-forward "(")
      (setq param-start (point))
      (backward-word)
      (search-backward " ")
      (backward-word)
      (setq has-return (not (string-equal (symbol-at-point) "void")))
      (goto-char param-start)
      (search-forward ")")
      (backward-word)
      (unless (string-equal (symbol-at-point) "void")
        (add-to-list 'params (symbol-name (symbol-at-point))))
      (while (search-backward "," param-start t)
        (backward-word)
        (add-to-list 'params (symbol-name (symbol-at-point))))
      (goto-char func-start)
      (open-line 1)
      (insert "/**\n * @brief ")
      (setq end-pos (point))
      (if (car params)
          (insert "\n *\n")
        (insert "\n"))
      (while (car params)
        (insert " * @param[in] " (car params) "  \n")
        (setq params (cdr params)))
      (when has-return
        (insert " *\n * @retval \n * @retval \n"))
      (insert " */"))
    (goto-char end-pos)))
(defalias 'c-insert-doxy-header 'c-insert-doxy-header-default)

(define-skeleton c-my-debug-printf
  "Insert a printf statement starting with \"JM:\""
  nil
  "printf(\"JM: " _ "\\n\");")

;; Ctypes
(ctypes-read-file nil nil t t)
(setq ctypes-write-types-at-exit t)

;; Cscope
(defun cscope-unix-index-files-internal (top-directory header-text args)
  "Core function to call the indexing script - modified to call sh rather than executing the script directly."
  (let ()
    (save-excursion
      (setq top-directory (cscope-canonicalize-directory top-directory))
      (setq cscope-unix-index-process-buffer (get-buffer-create cscope-unix-index-process-buffer-name))
      (set-buffer cscope-unix-index-process-buffer)
      (setq buffer-read-only nil)
      (setq default-directory top-directory)
      (buffer-disable-undo)
      (erase-buffer)
      (when header-text (insert header-text))
      (setq args (append (list cscope-indexing-script (when cscope-index-recursively "-r"))
                         args
                         (list "-v"
                               "-i" cscope-index-file
                               "-f" cscope-database-file
                               (if cscope-use-relative-paths "." top-directory))))
      (setq cscope-unix-index-process
            (apply 'start-process "cscope-indexer" cscope-unix-index-process-buffer "sh" args))
      (set-process-sentinel cscope-unix-index-process 'cscope-unix-index-files-sentinel)
      (process-kill-without-query cscope-unix-index-process))))

;------------------------------------------------------------------------------------------
; Buffer menu mode / Ibuffer mode
;------------------------------------------------------------------------------------------

(setq Buffer-menu-mode-width 16)
(setq Buffer-menu-buffer+size-width 40)
(setq Buffer-menu-use-frame-buffer-list nil)

(define-key Buffer-menu-mode-map [return] 'Buffer-menu-select)

(defun my-buffer-menu-launch ()
  (interactive)
  (let ((new-window (equal (count-windows) 1)))
    (list-buffers)
    (other-window 1)
    (if new-window
        (progn
          (local-set-key "q" 'kill-buffer-and-window)
          (local-set-key "\C-g" 'kill-buffer-and-window))
      (local-set-key "q" 'kill-this-buffer)
      (local-set-key "\C-g" 'kill-this-buffer))))

;; Ibuffer mode (when available)
(when (>= emacs-major-version 22)
  (require 'ibuffer)

  ;; Variables
  (setq ibuffer-expert t)
  (setq ibuffer-use-other-window t)
  (setq ibuffer-formats
        '((mark modified read-only " " (name 40 40 :left :elide) " " (size 9 -1 :right) " " (mode 16 16 :left :elide) " " filename-and-process)))

  ;; Fontification
  (setq ibuffer-fontification-alist
        '((10 buffer-read-only font-lock-constant-face)
          (15 (and buffer-file-name (string-match ibuffer-compressed-file-name-regexp buffer-file-name)) font-lock-doc-face)
          (20 (string-match "^*" (buffer-name)) ibuffer-system-buffer-face)
          (25 (and (string-match "^ " (buffer-name)) (null buffer-file-name)) italic)
          (30 (memq major-mode ibuffer-help-buffer-modes) ibuffer-help-buffer-face)
          (35 (eq major-mode (quote dired-mode)) font-lock-function-name-face)))

  ;; Keystrokes
  (global-set-key [(control ?x) (control ?b)] 'ibuffer)
  (define-key ibuffer-mode-map [(control ?g)] 'ibuffer-quit)
  (define-key ibuffer-mode-map [return] 'my-ibuffer-do-view)
  (define-key ibuffer-mode-map [?V] 'my-ibuffer-do-revert)
  (define-key ibuffer-mode-map [?* ?*] 'my-ibuffer-unmark-all)
  (define-key ibuffer-mode-map [?/ ?w] 'ibuffer-filter-writable-files)
  (define-key ibuffer-mode-map [?/ ?c] 'ibuffer-filter-c-files)
  (define-key ibuffer-mode-map [?\z] 'ibuffer-revert-all-and-redisplay)

  ;; Functions
  (defun my-ibuffer-do-view ()
    "Visit the buffer at point and bury the ibuffer"
    (interactive)
    (let ((ibuf (current-buffer)))
      (ibuffer-do-view)
      (bury-buffer ibuf)))

  (defun my-ibuffer-do-revert ()
    "Revert all marked buffers, then unmark all buffers"
    (interactive)
    (ibuffer-do-revert)
    (my-ibuffer-unmark-all))

  (defun my-ibuffer-unmark-all ()
    "Unmark all buffers with default mark"
    (interactive)
    (ibuffer-unmark-all ibuffer-marked-char))

  (defun ibuffer-filter-writable-files ()
    "Filter out read-only files and emacs system buffers"
    (interactive)
    (ibuffer-filter-by-predicate '(not buffer-read-only))
    (ibuffer-filter-by-name "^[^\\*]"))

  (defun ibuffer-filter-c-files ()
    "Filter for all files in C mode"
    (interactive)
    (ibuffer-filter-by-mode 'c-mode))

  (defun ibuffer-revert-all-and-redisplay ()
    "Revert all displayed buffers, then remove all filters"
    (interactive)
    (ibuffer-mark-dissociated-buffers)
    (ibuffer-toggle-marks)
    (my-ibuffer-do-revert)
    (ibuffer-filter-disable))

  (add-hook 'ibuffer-hook (lambda () (goto-line 4)))
)

;------------------------------------------------------------------------------------------
; Isearch mode
;------------------------------------------------------------------------------------------

(setq isearch-allow-scroll t)
(setq search-upper-case nil)
(setq hs-isearch-open nil)

(defun isearch-yank-symbol ()
  "*Put symbol at current point into search string."
  (interactive)
  (let ((sym (symbol-at-point)))
    (if sym
        (progn
          (setq isearch-string (symbol-name sym)
                isearch-message (mapconcat 'isearch-text-char-description isearch-string "")
                isearch-yank-flag t))
      (ding)))
  (isearch-search-and-update))

(defun isearch-exit-other-end (rbeg rend)
  "Exit isearch, but at the other end of the search string.
  This is useful when followed by an immediate kill."
  (interactive "r")
  (isearch-exit)
  (goto-char isearch-other-end))

(defun isearch-search-from-top ()
  "Jump to the top of the buffer and continue searching."
  (interactive)
  (goto-char (point-min))
  (when (not (equal isearch-string ""))
    (isearch-repeat 'forward)))

(defun isearch-highlight-phrase ()
  "Highlight the current search term in this buffer."
  (interactive)
  (let ((case-fold-search isearch-case-fold-search))
    (hlt-highlight-regexp-region
     (point-min)
     (point-max)
     (if isearch-regexp
         isearch-string
       (regexp-quote isearch-string))
     'highlight-expression-face))
  (isearch-exit))

(define-key isearch-mode-map [(shift return)] 'isearch-exit-other-end)
(define-key isearch-mode-map [(control ?c)] 'isearch-yank-symbol)
(define-key isearch-mode-map [(control ?t)] 'isearch-toggle-case-fold)
(define-key isearch-mode-map [(control ?v)] 'isearch-search-from-top)
(define-key isearch-mode-map [(control ?y)] 'isearch-yank-kill)
(define-key isearch-mode-map [(control ?o)] 'isearch-occur)
(define-key isearch-mode-map [(control ?h)] 'isearch-highlight-phrase)

;------------------------------------------------------------------------------------------
; Compilation mode
;------------------------------------------------------------------------------------------

(setq compilation-scroll-output t)

(defun compile-with-temp-command ()
  "Compile without retaining the compile command used."
  (interactive)
  (let ((compile-command compile-command))
    (call-interactively 'compile)))

(defun find-buffer-visiting-nondirectory (filename)
  "Return the buffer visiting filename. Like find-buffer-visiting, but filename is not expanded."
  (let ((buffer nil)
        (buf-list (buffer-list))
        buf-filename)
    (while (and buf-list (null buffer))
      (setq buf-filename (buffer-file-name (car buf-list)))
      (cond
       ((null buf-filename)
        (setq buf-list (cdr buf-list)))
       ((equal (file-name-nondirectory buf-filename) filename)
        (setq buffer (car buf-list)))
       (t
        (setq buf-list (cdr buf-list)))))
    buffer))

(defun compilation-find-file (marker filename directory &rest formats)
  "Find a buffer for file FILENAME.
Modified from the default in compile.el to use the tags table.
Search the directories in `compilation-search-path'.
A nil in `compilation-search-path' means to try the
\"current\" directory, which is passed in DIRECTORY.
If DIRECTORY. is relative, it is combined with `default-directory'.
If DIRECTORY. is nil, that means use `default-directory'.
If FILENAME is not found in the search path, check the currently open buffers.
If FILENAME is still not found, try to find it in the tags table.
If FILENAME is not found at all, ask the user where to find it.
Pop up the buffer containing MARKER and scroll to MARKER if we ask the user."
  (or formats (setq formats '("%s")))
  (let ((dirs compilation-search-path)
        (spec-dir (if directory
                      (expand-file-name directory)
                    default-directory))
        buffer thisdir fmts name)
    (if (file-name-absolute-p filename)
        ;; The file name is absolute.  Use its explicit directory as
        ;; the first in the search path, and strip it from FILENAME.
        (setq filename (abbreviate-file-name (expand-file-name filename))
              dirs (cons (file-name-directory filename) dirs)
              filename (file-name-nondirectory filename)))
    ;; Now search the path.
    (while (and dirs (null buffer))
      (setq thisdir (or (car dirs) spec-dir)
            fmts formats)
      ;; For each directory, try each format string.
      (while (and fmts (null buffer))
        (setq name (expand-file-name (format (car fmts) filename) thisdir)
              buffer (and (file-exists-p name)
                          (find-file-noselect name))
              fmts (cdr fmts)))
      (setq dirs (cdr dirs)))
    ;; Strip out any partial path
    (setq filename (car (last (split-string filename "/"))))
    ;; Check whether an existing buffer contains the file
    (when (null buffer)
      (setq buffer (find-buffer-visiting-nondirectory filename)))
    ;; If still not found, try the tags table
    (when (null buffer)
      (setq buffer (find-tag-noselect filename)))
    (while (null buffer)    ;Repeat until the user selects an existing file.
      ;; The file doesn't exist.  Ask the user where to find it.
      (save-excursion            ;This save-excursion is probably not right.
        (let ((pop-up-windows t))
          (compilation-set-window (display-buffer (marker-buffer marker))
                                  marker)
          (let* ((name (read-file-name
                        (format "Find this %s in (default %s): "
                                compilation-error filename)
                        spec-dir filename t nil))
                 (origname name))
            (cond
             ((not (file-exists-p name))
              (message "Cannot find file `%s'" name)
              (ding) (sit-for 2))
             ((and (file-directory-p name)
                   (not (file-exists-p
                         (setq name (expand-file-name filename name)))))
              (message "No `%s' in directory %s" filename origname)
              (ding) (sit-for 2))
             (t
              (setq buffer (find-file-noselect name))))))))
    ;; Make intangible overlays tangible.
    ;; This is weird: it's not even clear which is the current buffer,
    ;; so the code below can't be expected to DTRT here.  -- Stef
    (dolist (ov (overlays-in (point-min) (point-max)))
      (when (overlay-get ov 'intangible)
        (overlay-put ov 'intangible nil)))
    buffer))

;------------------------------------------------------------------------------------------
; Organiser
;------------------------------------------------------------------------------------------

(when (or (> emacs-major-version 22) (and (= emacs-major-version 22) (>= emacs-minor-version 1)))
  (setq org-return-follows-link t)
  (setq org-archive-default-command 'org-toggle-archive-tag)
  (require 'org)

  ;; Faces
  (set-face-attribute 'org-level-1 nil :inherit nil :foreground "IndianRed4")
  (set-face-attribute 'org-level-2 nil :inherit nil :foreground "DarkBlue")
  (set-face-attribute 'org-level-3 nil :inherit nil :foreground "MediumOrchid3")
  (set-face-attribute 'org-level-4 nil :inherit nil :foreground "sienna3")

  ;; Global keys
  (global-set-key "\C-co" 'open-org-file)

  ;; Org mode keys
  (define-key org-mode-map [(control ?,)] 'force-other-window)
  (define-key org-mode-map [(control meta n)] 'outline-next-visible-heading)
  (define-key org-mode-map [(control meta p)] 'outline-previous-visible-heading)
  (define-key org-mode-map [(control meta f)] 'outline-forward-same-level)
  (define-key org-mode-map [(control meta b)] 'outline-backward-same-level)
  (define-key org-mode-map [(control meta u)] 'outline-up-heading)
  (define-key org-mode-map [(control ?c) (control ?f)] 'find-tag)
  (define-key org-mode-map [(control ?c) (control ?v)] 'copy-word)
  (define-key org-mode-map [(control ?c) (control ?e)] 'fc-eval-and-replace)
  (define-key org-mode-map [(control return)] 'hippie-expand)

  ;; Functions
  (defun open-org-file ()
    (interactive)
    (find-file org-default-notes-file))
)

;------------------------------------------------------------------------------------------
; Desktop
;------------------------------------------------------------------------------------------

(load "desktop")
(desktop-load-default)

(setq desktop-enable-save-on-exit nil)
(setq desktop-files-not-to-save "\\(\\.org\\|\\.el\\)$")
(setq desktop-globals-to-save 
      '(desktop-missing-file-warning
        search-ring
        regexp-search-ring
        register-alist
        project-root
        project-exclude-files
        project-sub-project-file
        compile-command))
(setq desktop-lazy-verbose nil)
(setq desktop-load-locked-desktop t)
(setq desktop-path (list "." desktop-dirname))
(setq desktop-restore-eager 10)

(defun my-desktop-read ()
  "Extra actions to perform after loading the desktop."
  (let (compile-command)
    (project-set project-root)))
(add-hook 'desktop-after-read-hook 'my-desktop-read)

;------------------------------------------------------------------------------------------
; Mcomplete
;------------------------------------------------------------------------------------------

(mcomplete-mode 1)
(setq mcomplete-default-exhibit-start-chars 2)

(when (and (>= emacs-major-version 23) (>= emacs-minor-version 2))
  ; Hack mcomplete a little bit to take advantage of the in-built "initials" 
  ; completion-style if prefix completion fails
  (add-to-list 'completion-styles 'initials)

  (defun mcomplete-do-completion ()
    "Perform completion in the minibuffer."
    (let* ((str        (mcomplete-minibuffer-string))
           (completion (mcomplete-try-completion str))
           (status     '(t))
           (last       mcomplete-last-exact-completion))
      (setq mcomplete-last-exact-completion nil)
      (when (null completion)
        (setq completion (minibuffer-complete)))
      (cond
       ((null completion)
        (mcomplete-message " [No match]")
        nil)                              ; nil: no possible completion
       ((eq completion t) t)              ; t:   was already an exact and
                                          ;      unique completion
       (t
        (when (> (length completion) (length str)) ; completed
          (add-to-list 'status 'completed)
          (mcomplete-clear-minibuffer)
          (insert completion))
        (when (mcomplete-exact-match-p str
                                       minibuffer-completion-table
                                       minibuffer-completion-predicate)
          (add-to-list 'status 'exact)
          (unless (memq 'completed status)
            (setq mcomplete-last-exact-completion str)
            (when (equal last str)
              (mcomplete-completion-help))))
        (when (equal status '(t))
          (if completion-auto-help
              (mcomplete-completion-help)
            (mcomplete-message " [Next char not unique]")))
        status))))
)

;------------------------------------------------------------------------------------------
; Anything
;------------------------------------------------------------------------------------------

(defvar anything-c-source-cscope-files
  '((name . "Cscope Files")
    (candidates . (lambda ()
                    (let ((index-file (concat cscope-initial-directory cscope-index-file)) candidate-string)
                      (when (file-exists-p index-file)
                        (with-current-buffer (find-file-noselect index-file t)
                          (dolist (f (split-string (buffer-string))) 
                            (push (concat cscope-initial-directory f) candidate-string))
                          (bury-buffer))
                        candidate-string))))
    (match anything-c-match-on-file-name anything-c-match-on-directory-name)
    (type . file)
    (candidate-number-limit . 50)
    (requires-pattern . 4))
  "Anything source to browse all files in a project.")

(defvar anything-c-source-tags-location-ring
  '((name . "Tag History")
    (candidates . anything-c-source-tags-location-ring-candidates)
    (action . (("Goto line"
                . (lambda (candidate)
                    (let ((items (split-string candidate ":")))
                      (switch-to-buffer (second items))
                      (anything-goto-line (string-to-number (car items))))))))
    (persistent-action . (lambda (candidate)
                           (let ((items (split-string candidate ":")))
                             (switch-to-buffer (second items))
                             (anything-goto-line (string-to-number (car items)))
                             (anything-match-line-color-current-line))))
    (persistent-help . "Show this line"))
  "Anything source for browsing recent tags.")

(defun anything-c-source-tags-location-ring-candidates ()
  "Build a list of anything candidates from tags-location-ring."
  (when (boundp 'tags-location-ring)
    (flet ((buf-fn (m)
                   (with-current-buffer (marker-buffer m)
                     (goto-char m)
                     (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
                       (format "%7d:%s:    %s" (line-number-at-pos) (marker-buffer m) line)))))
      (with-current-buffer anything-current-buffer
        (loop
         with recip = nil
         for i in (ring-elements tags-location-ring)
         for tag = (unless (null (marker-buffer i)) (buf-fn i))
         when (and tag (not (member tag recip)))
         collect tag into recip
         finally return recip)))))

(defun anything-my-default ()
  "Invoke anything with a default list of sources."
  (interactive)
  (anything '(anything-c-source-bookmarks
              anything-c-source-imenu
              anything-c-source-tags-location-ring
              anything-c-source-cscope-files
              anything-c-source-recentf
              anything-c-source-emacs-commands)))

(remove-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)

;------------------------------------------------------------------------------------------
; Other modes and packages
;------------------------------------------------------------------------------------------

;; Miscellaneous
(blink-cursor-mode 0)
(column-number-mode 1)
(global-font-lock-mode 1)
(menu-bar-mode 0)
(mouse-avoidance-mode 'jump)
(when (fboundp 'savehist-mode) (savehist-mode 1))
(tool-bar-mode 0)
(transient-mark-mode 1)
(which-function-mode 1)

;; Iswitchb
(iswitchb-mode 1)
(setq iswitchb-default-method 'samewindow)
(setq iswitchb-max-to-show 10)
(setq iswitchb-prompt-newbuffer nil)
(setq iswitchb-use-virtual-buffers t)

;; Show-paren mode
(show-paren-mode 1)
(setq show-paren-style 'parenthesis)

;; Strokes mode
(setq strokes-use-strokes-buffer nil)
(when window-system (strokes-mode 1))

;; Emacs-lisp mode
(define-key emacs-lisp-mode-map [f5] 'eval-buffer)
(add-hook 'emacs-lisp-mode-hook
          (lambda ()
            "Time-stamp Emacs lisp files."
            (add-hook 'before-save-hook 'time-stamp nil t)))

;; nXML mode
(add-hook 'nxml-mode-hook
          (lambda ()
            (setq nxml-sexp-element-flag t)
            (define-key nxml-mode-map "\C-c\C-f" 'find-tag)))

;; Mediawiki mode
(add-hook 'mediawiki-mode-hook (lambda () (longlines-mode 1)))
(defalias 'wiki-mode 'mediawiki-mode)

;; PC-select mode
(defun my-pc-selection-keys ()
  "Override the annoying nomark behaviour in pc-select-mode."
  (global-set-key "\C-x\C-x" 'exchange-point-and-mark))
(setq pc-select-selection-keys-only t)
(add-hook 'pc-selection-mode-hook 'my-pc-selection-keys)
(if (>= emacs-major-version 22) (pc-selection-mode 1) (pc-selection-mode))

;; Auto-revert mode
(setq auto-revert-verbose nil)
(defalias 'tail-mode 'auto-revert-tail-mode)

;; Prevent CUA mode from trampling C-return
(setq cua-rectangle-mark-key [C-M-return])

;; RE-Builder
(setq reb-re-syntax 'string)

;; Follow mode
(add-hook 'occur-mode-hook (lambda () (setq fm-working nil) (fm-start)))

;; Whitespace mode
(setq whitespace-style '(tabs))
(setq whitespace-global-modes '(c-mode makefile-mode makefile-gmake-mode))
(when (fboundp 'global-whitespace-mode) (global-whitespace-mode 1))
(when (and (>= emacs-major-version 23) (>= emacs-minor-version 2))
  ; Override the absurdly slow post-command hook in Emacs 23.2
  (defun whitespace-post-command-hook() nil))

;; Lusty explorer
(defun my-lusty-setup ()
  "Rebind some keys for lusty explorer"
  (define-key lusty-mode-map [tab] 'minibuffer-complete)
  (define-key lusty-mode-map [(control f)] 'forward-char)
  (define-key lusty-mode-map [(control b)] 'backward-char)
  (define-key lusty-mode-map [(control s)] 'lusty-highlight-next-column)
  (define-key lusty-mode-map [(control r)] 'lusty-highlight-previous-column))
(add-hook 'lusty-setup-hook 'my-lusty-setup)

;; Stop some other modes using C-c C-f
(add-hook 'makefile-mode-hook (lambda () (define-key makefile-mode-map "\C-c\C-f" 'find-tag)))
(add-hook 'sh-mode-hook (lambda () (define-key sh-mode-map "\C-c\C-f" 'find-tag)))

;------------------------------------------------------------------------------------------
; Customize
;------------------------------------------------------------------------------------------

(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.
 '(dabbrev-abbrev-char-regexp "\\\\sw\\\\|\\\\s_")
 '(dabbrev-case-distinction nil)
 '(dabbrev-case-fold-search nil)
 '(dabbrev-case-replace nil)
 '(dabbrev-upcase-means-case-search t)
 '(mode-line-position (quote ((-3 #("%p" 0 2 (help-echo "mouse-1: select (drag to resize), mouse-2 = C-x 1, mouse-3 = C-x 0"))) (size-indication-mode (8 #(" of %I" 0 6 (help-echo "mouse-1: select (drag to resize), mouse-2 = C-x 1, mouse-3 = C-x 0")))) (line-number-mode ((column-number-mode (10 #(" (%l,%c)" 0 8 (face my-line-number-face))) (6 #(" L%l" 0 4 (face my-line-number-face))))) ((column-number-mode (5 #(" C%c" 0 4 (face my-line-number-face)))))))))
 '(recentf-auto-cleanup (quote never))
 '(recentf-mode t)
 '(text-mode-hook (quote (text-mode-hook-identify)))
 '(which-func-format (quote ("{" (:propertize which-func-current local-map (keymap (mode-line keymap (mouse-3 . end-of-defun) (mouse-2 . #[nil "e\300=\203