3 Feb 2009, Comments (0)

.emacs

Author: cjg
;; user information
(setq user-full-name "Giuseppe Coviello")
(setq user-mail-address "cjg@cruxppc.org")
 
;; setting load-path
(setq load-path (cons "~/.emacs.d/" load-path))
(setq load-path (cons "~/.emacs.d/color-theme/" load-path))
 
;; start emacs server
(server-start)
 
;; interface
;; console specific interface customization
(defun console-interface()
  (menu-bar-mode nil)
  (color-theme-pok-wob)
  (display-time-mode)
  (require 'battery)
  (display-battery-mode)
  )
 
;; X specific interface customization
(defun x-interface()
  (setq x-select-enable-clipboard t)
  (tool-bar-mode nil)
  (color-theme-blippblopp)
  (setq frame-title-format "Emacs: %b %+%+ %f")
  (setq icon-title-format "Emacs - %b")
  (pc-bindings-mode)
  (pc-selection-mode)
  (set-scroll-bar-mode 'right)
 
  ;; speedbar
  (autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
  (autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
  (define-key-after (lookup-key global-map [menu-bar tools])
    [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])
  (setq php-speedbar-config 1)
 
  ;; wheel mouse
  (defun up-slightly () (interactive) (scroll-up 5))
  (defun down-slightly () (interactive) (scroll-down 5))
  (global-set-key [mouse-4] 'down-slightly)
  (global-set-key [mouse-5] 'up-slightly)
 
  (defun up-one () (interactive) (scroll-up 1))
  (defun down-one () (interactive) (scroll-down 1))
  (global-set-key [S-mouse-4] 'down-one)
  (global-set-key [S-mouse-5] 'up-one)
 
  (defun up-a-lot () (interactive) (scroll-up))
  (defun down-a-lot () (interactive) (scroll-down))
  (global-set-key [C-mouse-4] 'down-a-lot)
  (global-set-key [C-mouse-5] 'up-a-lot)
 
  ;; avoid mouse pointer
  (require 'avoid)
  (if (display-mouse-p) (mouse-avoidance-mode 'animate))
  )
 
;; MACOSX specific interface customization
(defun mac-interface()
  (setq mac-allow-anti-aliasing t)
  (x-interface)
  (custom-set-faces
   '(hl-line ((t (:background "lightgray")))))
  )
 
;; global interface customization
(require 'font-lock)
(require 'color-theme)
(color-theme-initialize)
(setq inhibit-startup-message t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq-default transient-mark-mode t)
(blink-cursor-mode nil)
(setq track-eol t)
(line-number-mode t)
(setq column-number-mode t)
(setq scroll-step 1)
(setq query-replace-highlight t)
(setq search-highlight t)
(show-paren-mode t)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t
      font-lock-mode-maximum-decoration t
      font-lock-maximum-size nil)
(setq-default enable-multibyte-characters t)
(setq default-input-method "rfc1345")
(toggle-uniquify-buffer-names)
(setq gdb-many-windows t)
(require 'hl-line)
(global-hl-line-mode)
 
(defun shell-mode-customize()
  "Customize the shell-mode"
  (load-library 'ansi-color)
  (ansi-color-for-comint-mode-on)
  )
(add-hook 'shell-mode-hook 'shell-mode-customize)
 
(if (not window-system)
    (console-interface)
  )
(if (eq window-system 'x)
    (x-interface)
  )
(if (eq window-system 'mac)
    (mac-interface)
  )
 
;; editing
(require 'completion)
(dynamic-completion-mode)
(require 'generic-x)
(recentf-mode t)
(toggle-save-place-globally)
(set-input-mode nil nil 1)
(set-default 'truncate-lines 1)
(setq-default fill-column 80)
(setq-default auto-fill-function 'do-auto-fill)
(setq next-line-add-newlines nil)
(delete-selection-mode t)
(setq require-final-newline 't)
(require 'htmlize)
 
;; key bindings
(global-set-key "\C-a" 'mark-whole-buffer)
(global-set-key "\C-z" 'undo)
(global-set-key "\C-cg" 'goto-line)
(global-set-key "\C-b" 'buffer-menu)
(global-set-key "\M-a" 'yic-next-buffer)
(global-set-key "\M-d" 'yic-prev-buffer)
(global-set-key "\M-\S-a" 'previous-multiframe-window)
(global-set-key "\M-\S-d" 'next-multiframe-window)
(global-set-key "\M-s" 'delete-other-windows)
(global-set-key "\M-\S-s" 'kill-buffer-and-window)
(global-set-key "\M-c" 'clipboard-kill-ring-save)
(global-set-key "\M-v" 'clipboard-yank)
(global-set-key "\M-f" 'clipboard-kill-region)
(global-set-key "\M-w" 'set-mark-command)
(global-set-key "\M-q" 'comment-region)
(global-set-key "\M-e" 'uncomment-region)
(global-set-key (kbd "(") 'insert-round-brackets)
(global-set-key (kbd "[") 'insert-square-brackets)
(global-set-key (kbd "{") 'insert-brackets)
 
;; mode customization
;; latex
(defun latex-mode-fix ()
  (local-unset-key "\M-s")
  (local-unset-key (kbd "<tab>"))
  (local-set-key "\M-s" 'delete-other-windows)
  (local-set-key (kbd "<tab>") 'indent-or-complete)
  )
(add-hook 'LaTeX-mode-hook 'latex-mode-fix)
 
;; python
(defun python-mode-fix ()
  (setq py-smart-indentation nil
        py-indent-offset 4
        tab-width 4
        indent-tabs-mode nil
        current-language-environment "UTF-8"
        )
  (global-set-key [f5] 'py-execute-buffer)
  (local-set-key (kbd "<tab>") 'indent-or-complete)
  )
(add-hook 'python-mode-hook 'python-mode-fix)
 
; crux initscripts and Pkgfile
(add-to-list 'auto-mode-alist '("/etc/rc.d/*" . sh-mode))
(add-to-list 'auto-mode-alist '("Pkgfile" . sh-mode))
 
;; asm motorola 68k
(add-to-list 'auto-mode-alist '("\\.a68$" . asm-mode))
 
; C
(defun linux-c-mode ()
  "C mode with adjusted defaults for use with the Linux kernel."
  (interactive)
  (c-mode)
  (setq c-indent-level 8)
  (setq c-brace-imaginary-offset 0)
  (setq c-brace-offset -8)
  (setq c-argdecl-indent 8)
  (setq c-label-offset -8)
  (setq c-continued-statement-offset 8)
  (setq indent-tabs-mode nil)
  (setq tab-width 8))
 
(setq auto-mode-alist (cons '("*\\.[ch]$" . linux-c-mode)
                       auto-mode-alist))
;; Linux C style
(defconst linux-c-style
  '(
    (c-set-style . "k&r")
    (c-indent-level 8)
    (c-brace-imaginary-offset 0)
    (c-brace-offset -8)
    (c-argdecl-indent 8)
    (c-label-offset -8)
    (c-continued-statement-offset 8)
    (indent-tabs-mode nil)
    (c-tab-width . 8)
    (c-basic-offset . 8)
    (comment-multi-line t)
    )
  "Linux C Style"
  )
 
(defun linux-c-mode-common-hook ()
  (c-add-style "Linux" linux-c-style t)
  (cwarn-mode 1)
  (which-function-mode t)
  (setq which-func-unknown "TOP LEVEL")
  (setq compile-command "make CC=gcc")
  (local-set-key "\C-c\C-c" 'compile)
  (local-set-key "\C-c\C-d" 'gdb)
  (local-set-key "\M-m" 'man-follow)
  (local-set-key (kbd "<tab>") 'indent-or-complete)
  (local-set-key (kbd "(") 'insert-round-brackets)
  (local-set-key (kbd "[") 'insert-square-brackets)
  (local-set-key (kbd "{") 'insert-brackets)
  (require 'compile)
  (unless (file-exists-p "Makefile")
    (set (make-local-variable 'compile-command)
         (let ((file (file-name-nondirectory buffer-file-name)))
           (concat "gcc -g -W -Wall -o "
                   (file-name-sans-extension file) " " file))))
  )
(add-hook 'c-mode-common-hook 'linux-c-mode-common-hook)
 
(add-hook 'c-mode-hook
          (lambda ()
            (font-lock-add-keywords nil
                    '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
                      ("\\<\\(TODO\\):" 1 font-lock-type-face prepend)))
            )
          )
 
;; c-sharp
(autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
(setq auto-mode-alist
      (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
 
;; C# style
(defconst csharp-style
  '(
    (c-set-style . "java")
    (c-indent-level 4)
    (c-brace-imaginary-offset 0)
    (c-brace-offset -4)
    (c-argdecl-indent 4)
    (c-label-offset -4)
    (c-continued-statement-offset 4)
    (indent-tabs-mode nil)
    (c-tab-width . 4)
    (c-basic-offset . 4)
    (comment-multi-line t)
    )
  "C# Style"
  )
 
(defun csharp-mode-fix ()
  (interactive)
  (c-add-style "C#" csharp-style t)
  (setq tab-width 4
        current-language-environment "UTF-8"
        )
  (local-set-key (kbd "<tab>") 'indent-or-complete)
  (require 'compile)
  (unless (file-exists-p "Makefile")
    (set (make-local-variable 'compile-command)
         (let ((file (file-name-nondirectory buffer-file-name)))
           (concat "mcs " file))))
 )
(add-hook 'csharp-mode-hook 'csharp-mode-fix)
 
;; skeletons
(define-skeleton c-skeleton
  "Inserts a C file skeleton into current buffer.
   This only makes sense for empty buffers."\n
  "/* " (buffer-name) " */"\n
  "
/* <project_name> -- <project_description>
 *
 * Copyright (C) 2006 - 2007
 *     "(insert user-full-name)" <"(insert user-mail-address)">
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
"\n
)
 
(define-skeleton h-skeleton
  "Inserts a C include file skeleton into current buffer.
   This only makes sense for empty buffers."\n
  "/* " (buffer-name) " */"\n
  "
/* <project_name> -- <project_description>
 *
 * Copyright (C) 2006 - 2007
 *     "(insert user-full-name)" <"(insert user-mail-address)">
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
#ifndef _" (upcase (replace-regexp-in-string "\\." "_" (buffer-name))) "
#define _" (upcase (replace-regexp-in-string "\\." "_" (buffer-name))) "
 
#endif /* _" (upcase (replace-regexp-in-string "\\." "_" (buffer-name))) " */
"\n
)
 
(define-skeleton python-skeleton
  "Inserts a Python file skeleton into current buffer.
   This only makes sense for empty buffers."\n
"\"\"\"
    " (buffer-name) "
 
    <project_name> -- <project_description>
 
    Copyright (C) 2006 - 2007
        "(insert user-full-name)" <"(insert user-mail-address)">
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\"\"\"
"\n
)
 
;; defun(s)()
 
(defun yic-ignore (str)
  (or
   (string-match "\\*Buffer List\\*" str)
   (string-match "\\*scratch\\*" str)
   (string-match "^TAGS" str)
   (string-match "^\\*Messages\\*$" str)
   (string-match "^\\*Completions\\*$" str)
   (string-match "^ " str)
   (memq str
         (mapcar
          (lambda (x)
            (buffer-name
             (window-buffer
              (frame-selected-window x))))
          (visible-frame-list)))
   ))
 
(defun yic-next (ls)
  "Switch to next buffer in ls skipping unwanted ones."
  (let* ((ptr ls)
         bf bn go
         )
    (while (and ptr (null go))
      (setq bf (car ptr)  bn (buffer-name bf))
      (if (null (yic-ignore bn))
          (setq go bf)
        (setq ptr (cdr ptr))
        )
      )
    (if go
        (switch-to-buffer go))))
 
(defun yic-prev-buffer ()
  "Switch to previous buffer in current window."
  (interactive)
  (yic-next (reverse (buffer-list))))
 
(defun yic-next-buffer ()
  "Switch to the other buffer (2nd in list-buffer) in current window."
  (interactive)
  (bury-buffer (current-buffer))
  (yic-next (buffer-list)))
 
(defun indent-or-complete ()
  "Complete if point is at end of a word, otherwise indent line."
  (interactive)
  (if (looking-at "\\>")
      (complete-symbol)
    (indent-for-tab-command)))
 
(defun insert-round-brackets ()
  "Insert round brackets"
  (interactive)
  (insert "()")
  (backward-char)
  (print (current-word))
)
 
(defun insert-square-brackets ()
  "Insert square brackets"
  (interactive)
  (insert "[]")
  (backward-char)
)
 
(defun insert-brackets ()
  "Insert brackets"
  (interactive)
  (if (and (not (eq (char-before) nil)) (not (= (char-before) ?\ )))
      (insert " "))
  (insert "{")
  (reindent-then-newline-and-indent)
  (newline)
  (insert "}")
  (indent-according-to-mode)
  (backward-to-indentation)
)
 
(defun todo-list ()
  "Find TODOs"
  (interactive)
  (grep (concat "grep -nH -e 'TODO:' -e *.[ch] "
                "| awk '{ sub(/\\/\\//, \"\"); sub(/\\/\\*/, \"\"); "
                "gsub (/:[\\ \\t]*TODO/, \": TODO\"); print }' 1>&2 | true")
        )
)
 
(defun fixme-list ()
  "Find FIXMEs"
  (interactive)
  (grep (concat "grep -nH -e 'FIXME:' *.[ch] "
                "| awk '{ sub(/\\/\\//, \"\"); sub(/\\/\\*/, \"\"); "
                "gsub (/:[\\ \\t]*FIXME/, \":\ FIXME\"); print }' 1>&2 | true")
        )
)
 
(defun todo-and-fixme-list ()
  "Find TODOs and FIXMEs"
  (interactive)
  (grep (concat "grep -nH -e 'TODO:' -e 'FIXME:' *.[ch] "
                "| awk '{ sub(/\\/\\//, \"\"); sub(/\\/\\*/, \"\"); "
                "gsub (/:[\\ \\t]*TODO/, \": TODO\"); "
                "gsub (/:[\\ \\t]*FIXME/, \":\ FIXME\"); print }' 1>&2 | true")
        )
)

No comments yet.

Leave a comment

XHTML– Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">