;; ========================== ;; General ;; ========================== (setq-default indent-tabs-mode t) (setq-default transient-mark-mode t) (setq isearch-highlight t) ;; highlight matches from searches (setq search-highlight t) (setq query-replace-highlight t) (setq search-highlight t) (setq line-number-mode t) (setq scroll-preserve-screen-position 1) ;; pgup/dn return to the starting point (setq next-line-add-newlines nil) ;; don't add new lines when scrolling (setq scroll-step 1) ;; scroll 1 line when hitting bottom (setq scroll-conservatively 1) (setq frame-title-format "emacs - %b") ;; format title-barto show buffer name (setq inhibit-startup-message t) (setq delete-auto-save-files t) (setq backup-inhibited t) ;; disable backup (setq auto-save-default nil) ;; disable autosave (setq resize-minibuffer-mode t) ;; resize mini-buffer when necessary (put 'scroll-left 'disabled t) (setq auto-mode-alist (append '( ("\\.h$" . c++-mode) ("\\.dps$" . pascal-mode) ("\\.py$" . python-mode) ("\\.Xdefaults$" . xrdb-mode) ("\\.Xenvironment$" . xrdb-mode) ("\\.Xresources$" . xrdb-mode) ("\\.tei$" . xml-mode) ("\\.php$" . php-mode) ("README\\|TODO\\|BUGS\\|HACKING\\|LICENSE\\|INSTALL" . text-mode) ) auto-mode-alist)) ;; ========================== ;; Misc ;; ========================== (autoload 'comment-out-region "comment" nil t) (defalias 'yes-or-no-p 'y-or-n-p) (define-key query-replace-map [return] 'act) (define-key query-replace-map [?\C-m] 'act) ;; Use wildcards when completing file names with tab (partial-completion-mode t) ;; ========================== ;; Look ;; ========================== ;; Mostly defined in ~/.Xdefaults ;(set-cursor-color "Firebrick") ;(set-background-color "LightSkyBlue") ;(set-foreground-color "white") ;(set-face-background 'default "gray10") ;(set-face-background 'region "black") ;(set-face-foreground 'default "white") ;(set-face-foreground 'region "gray60") (set-default-font "-Misc-Fixed-Medium-R-Normal--15-140-75-75-C-90-ISO8859-1") ;; show a menu only when running within X (menu-bar-mode (if window-system 1 -1)) ;; (menu-bar-mode nil) (display-time) (column-number-mode 1) ;; ========================== ;; Compilation options ;; ========================== (setq compile-command "make") (setq compilation-ask-about-save nil) (setq compilation-window-height 10) ;; ========================== ;; ERC - IRC client ;; ========================== (add-to-list 'load-path "~/.elisp/erc") (require 'erc) (setq erc-user-full-name "Giulio") (setq erc-user-nickename "slidexd") ;; ========================== ;; C/C++ mode ;; ========================== (defun my-build-tab-stop-list (width) (let ((num-tab-stops (/ 80 width)) (counter 1) (ls nil)) (while (<= counter num-tab-stops) (setq ls (cons (* width counter) ls)) (setq counter (1+ counter))) (set (make-local-variable 'tab-stop-list) (nreverse ls)))) (defun my-c-mode-common-hook () (c-set-style "linux") ;; When hitting backspace right of a tab char, the tab is deleted and not ;; replaced with tabwidth-1 spaces (defalias 'c-electric-backspace 'delete-backward-char) (setq tab-width 8) (setq c-basic-offset tab-width) (my-build-tab-stop-list tab-width) ;; make the ENTER key indent next line properly ;;; (local-set-key "\C-m" 'newline-and-indent) (define-key c-mode-map "\C-m" 'reindent-then-newline-and-indent) (define-key c-mode-map "\C-ce" 'c-comment-edit) ;; switch/case: make each case line indent from switch (c-set-offset 'case-label '+) (c-set-offset 'substatement-open 0) (c-set-offset 'case-label '+) (c-set-offset 'arglist-cont-nonempty c-lineup-arglist) (c-set-offset 'arglist-intro '+) (c-set-offset 'topmost-intro-cont '+) (setq c-label-minimum-indentation 0) ;: make DEL remove all the whitespace (c-toggle-hungry-state 1)) ;; =========================== ;; Lisp mode ;; =========================== (defun my-lisp-mode-hook () (define-key lisp-mode-map "\C-m" 'reindent-then-newline-and-indent) (define-key lisp-mode-map "\C-i" 'lisp-indent-line) (define-key lisp-mode-map "\C-j" 'eval-print-last-sexp)) ;; =========================== ;; Python mode ;; =========================== (defun my-python-mode-hook () (define-key python-mode-map "\C-m" 'reindent-then-newline-and-indent)) ;; =========================== ;; HTML/CSS stuff ;; =========================== (setq html-mode-hook 'turn-off-auto-fill) (autoload 'css-mode "css-mode") (setq auto-mode-alist (cons '("\\.css\\'" . css-mode) auto-mode-alist)) ;; =========================== ;; Hooks ;; =========================== (add-hook 'text-mode-hook 'turn-on-auto-fill) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) (add-hook 'lisp-mode-hook 'my-lisp-mode-hook) (add-hook 'c++-mode-hook 'my-c-mode-common-hook) ;; use c mode (add-hook 'python-mode-hook 'my-python-mode-hook) ;; ========================== ;; Key bindings ;; ========================== (define-key global-map "\C-h" 'delete-backward-char) ;(define-key global-map "\C-c\C-a" 'beginning-of-buffer) ;(define-key global-map "\C-c\C-s" 'end-of-buffer) (global-set-key "\C-c\C-g" 'goto-line) (global-set-key "\C-cq" 'comment-out-region) (global-set-key "\C-x\M-s" 'insert-file-header) (global-set-key "\C-x\M-a" 'insert-function-header) (global-set-key "\C-co" 'occur) (global-set-key [C-tab] [M-tab]) (global-set-key [C-backtab] 'switch-to-next-buffer) (global-set-key [f1] 'man) (global-set-key [f2] 'rename) (global-set-key [f5] 'kill-this-buffer) (global-set-key [f8] 'grep) (global-set-key [f9] 'compile) (global-set-key [home] 'My-smart-home) (global-set-key [end] 'My-smart-end) (global-set-key "(" "\M-(") (defun unindent-region-with-tab () (interactive) (save-excursion (if (< (point) (mark)) (exchange-point-and-mark)) (let ((save-mark (mark))) (if (= (point) (line-beginning-position)) (previous-line 1)) (goto-char (line-beginning-position)) (while (>= (point) save-mark) (goto-char (line-beginning-position)) (if (= (string-to-char "\t") (char-after (point))) (delete-char 1)) (previous-line 1))))) (defun my-smart-home () "Odd home to beginning of line, even home to beginning of text/code." (interactive) (if (and (eq last-command 'my-smart-home) (/= (line-beginning-position) (point))) (beginning-of-line) (beginning-of-line-text))) (defun my-smart-end () "Odd end to end of line, even end to begin of text/code." (interactive) (if (and (eq last-command 'my-smart-end) (= (line-end-position) (point))) (end-of-line-text) (end-of-line))) (defun end-of-line-text () "Move to end of current line and skip comments and trailing space. Require `font-lock'." (interactive) (end-of-line) (let ((bol (line-beginning-position))) (unless (eq font-lock-comment-face (get-text-property bol 'face)) (while (and (/= bol (point)) (eq font-lock-comment-face (get-text-property (point) 'face))) (backward-char 1)) (unless (= (point) bol) (forward-char 1) (skip-chars-backward " \t\n"))))) (defun insert-file-header () (interactive) (insert "/*\n") (insert " * \n") (insert " * Author: Giulio Bai \n") (insert " */\n")) (defun insert-function-header () (interactive) (insert " /**\n") (insert " * \n") (insert " * @param: \n") (insert " * @return: \n") (insert " */\n")) (defalias 'switch-to-next-buffer 'bury-buffer) (defun switch-to-previous-buffer () (interactive) (switch-to-buffer (nth (- (length (buffer-list)) 1) (buffer-list)))) (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. '(cua-mode t nil (cua-base)) '(show-paren-mode t) '(transient-mark-mode t)) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. )