Advertisement
troglobit

My ~/.emacs

Jun 3rd, 2013
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 17.66 KB | None | 0 0
  1. ;; Dot emacs configuration file
  2. ;; Joachim Nilsson <troglobit@gmail.com>
  3. ;;
  4.  
  5. ;; Location for privately maintained packages.
  6. (add-to-list 'load-path "~/.emacs.d/site-lisp")
  7. ;;(load-file "~/.emacs.d/site-lisp/graphviz-dot-mode.el")
  8. ;;(autoload 'cflow-mode "cflow-mode")
  9. ;;(setq auto-mode-alist (append auto-mode-alist
  10. ;;                              '(("\\.cflow$" . cflow-mode))))
  11.  
  12. ;; Location for external plugins
  13. ;;(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet-0.6.1c")
  14. ;;(require 'yasnippet)
  15. ;;(yas/initialize)
  16. ;;(yas/load-directory "~/.emacs.d/plugins/yasnippet-0.6.1c/snippets")
  17.  
  18. ;;; Initialize external packages, from Debian.
  19. (let ((startup-file "/usr/share/emacs/site-lisp/debian-startup.el"))
  20.   (if (and (or (not (fboundp 'debian-startup))
  21.                (not (boundp  'debian-emacs-flavor)))
  22.            (file-readable-p startup-file))
  23.       (progn
  24.         (load-file startup-file)
  25.         (setq debian-emacs-flavor 'emacs)
  26.         (mapcar '(lambda (f)
  27.                    (and (not (string= (substring f -3) "/.."))
  28.                         (file-directory-p f)
  29.                         (add-to-list 'load-path f)))
  30.                 (directory-files "/usr/share/emacs/site-lisp" t)))))
  31.  
  32. ;; Emacs Code Browser
  33. ;;(require 'cedet)
  34. ;;(require 'ecb)
  35.  
  36. ;;; Autoload Stefan Reichoer's cool psvn
  37. ;;(require 'psvn)
  38.  
  39. ;;; Autoload magit
  40. ;;(require 'magit)
  41.  
  42. ;;; Autoload SCO UNIX Cscope
  43. ;;(require 'xcscope)
  44.  
  45. ;; Setup GNU Global code indexing
  46. ;;(autoload 'gtags-mode "gtags" "" t)
  47. ;;(setq c-mode-hook
  48. ;;  '(lambda ()
  49. ;;     (gtags-mode 1)))
  50.  
  51. ;; Cedet now part of Emacs
  52. ;;(global-ede-mode 1)                      ; Enable the Project management system
  53. ;;(semantic-load-enable-code-helpers)      ; Enable prototype help and smart completion
  54.  
  55. ;;(push '(font-backend xft x) default-frame-alist)
  56.  
  57. ;; window maximized
  58. ;;(setq default-frame-alist '((top . 1) (left . 1) (width . 132) (height . 40)))
  59.  
  60.  ;;(set-frame-parameter (selected-frame) 'alpha '(<active> [<inactive>]))
  61. (set-frame-parameter (selected-frame) 'alpha '(90 90))
  62. (add-to-list 'default-frame-alist '(alpha 90 90))
  63.  
  64. ;;; Neat gnome-terminal like F11 toggle between fullscreen and windowed.
  65. (defun fullscreen ()
  66.   (interactive)
  67.   (set-frame-parameter nil 'fullscreen
  68.                        (if (frame-parameter nil 'fullscreen) nil 'fullboth)))
  69.  
  70. ;; For Emacs 23, or older
  71. ;;(require 'color-theme)
  72. ;;(eval-after-load "color-theme"
  73. ;;  '(progn
  74. ;;     (color-theme-initialize)
  75. ;;     (color-theme-hober)))
  76.  
  77. ;; For Emacs 24, or newer
  78. (require 'package)
  79. (add-to-list 'package-archives
  80.              '("marmalade" .
  81.                "http://marmalade-repo.org/packages/"))
  82. (package-initialize)
  83. ;;(load-theme 'solarized-dark t)
  84.  
  85. ;; Emacs Multi Media System
  86. ;;(require 'emms-setup)
  87. ;;(require 'emms-browser)
  88. ;;(emms-all)
  89. ;;(emms-default-players)
  90. ;;(setq emms-source-file-default-directory "~/Music/")
  91.  
  92. ;;; Convert CamelCase() to camel_case()
  93. (defun un-camelcase-string (s &optional sep start)
  94.   "Convert CamelCase string S to lower case with word separator SEP.
  95.   Default for SEP is an underscore \"_\".
  96.  
  97.   If third argument START is non-nil, convert words after that
  98.   index in STRING."
  99.   (let ((case-fold-search nil))
  100.     (while (string-match "[A-Z]" s (or start 1))
  101.       (setq s (replace-match (concat (or sep "_")
  102.                                      (downcase (match-string 0 s)))
  103.                              t nil s)))
  104.     (downcase s)))
  105.  
  106. ;; nuke whitespaces when writing to a file
  107. ;;(add-hook 'before-save-hook 'whitespace-cleanup)
  108.  
  109. ;; http://info.borland.com/techpubs/jbuilder/jbuilder9/introjb/key_cua.html
  110. ;; These are the bindings also used in early Borland C++ versions, like 3.0
  111. ;; the last known "good" release.
  112. ; function keys
  113. ;; 1help, 2save, 3load, 4goto, 5zoom, 6next, 7split, 8exit!, 9make, 10other, 11fullscrn, 12undo
  114. ;;       C2save as,                                         C9Build
  115. ;;                                                          S9debug
  116. ;; emacs: must use command name to allow interactive input
  117.  
  118. (global-set-key [f1] 'info)
  119. (global-set-key [C-f1] 'woman)        ;; Context help
  120.  
  121. (global-set-key [f2] 'save-buffer)    ;; Save current
  122. (global-set-key [C-f2] 'write-buffer) ;; Save as
  123.  
  124. (global-set-key [f3] 'find-file)
  125. (global-set-key [f4] 'goto-line)
  126. (global-set-key [F5] 'gdb-toggle-bp-this-line)
  127. (global-set-key [C-F5] 'gud-watch)
  128. (global-set-key [S-f5] 'insert-date)
  129.  
  130. (global-set-key [f6] 'other-window)   ;;
  131. (global-set-key [C-f6] 'other-frame)
  132. (global-set-key [f7] 'previous-error)
  133. ;;(global-set-key [f7] 'gdb-next)   ;; Only set in GDB mode?
  134. (global-set-key [S-f7] 'gdb-next)   ;;
  135.  
  136. (global-set-key [f8] 'next-error)
  137. (global-set-key [S-f8] 'gdb-step)   ;; Only set in GDB mode?
  138.  
  139. (global-set-key [f9] 'compile)
  140. (global-set-key [C-f9] 'compile)
  141. (global-set-key [S-f9] 'gdb)
  142.  
  143. (global-set-key [f11] 'fullscreen)
  144.  
  145. (global-set-key (kbd "M-#") 'calculator)
  146. ;;(global-set-key (kbd "C-c c") 'calculator)
  147. ;;
  148. (global-set-key [C-prior] 'beginning-of-buffer)
  149. (global-set-key [C-next] 'end-of-buffer)
  150.  
  151. ;;; Key binding for switching to next and previous buffer
  152. ;;(global-set-key '[C-tab] 'bs-cycle-next)
  153. ;;(global-set-key '[C-S-iso-lefttab] 'bs-cycle-previous)
  154. (global-set-key '[C-tab] 'other-window)
  155. (global-set-key '[C-S-iso-lefttab] 'bs-cycle-previous)
  156.  
  157. ;; Johans hack with dabbrev
  158. (global-set-key [backtab]    'dabbrev-expand)
  159.  
  160. (defun linux-c-mode ()
  161.   "C mode with adjusted defaults for use with the Linux kernel."
  162.   (interactive)
  163.   (c-mode)
  164.   (c-set-style "K&R")
  165.   (setq tab-width 8)
  166.   (setq indent-tabs-mode t)
  167.   (setq c-basic-offset 8))
  168.  
  169. (setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode)
  170.                             auto-mode-alist))
  171.  
  172. (c-add-style "openbsd"
  173.              '("bsd"
  174.                (indent-tabs-mode . t)
  175.                (defun-block-intro . 8)
  176.                (statement-block-intro . 8)
  177.                (statement-case-intro . 8)
  178.                (substatement-open . 4)
  179.                (substatement . 8)
  180.                (arglist-cont-nonempty . 4)
  181.                (inclass . 8)
  182.                (knr-argdecl-intro . 8)))
  183.  
  184. (c-add-style "mrouted"
  185.              '("ellemtel"
  186.                (c-basic-offset . 4)))
  187.  
  188.  (c-add-style "microsoft"
  189.               '("stroustrup"
  190.                 (c-offsets-alist
  191.                  (innamespace . -)
  192.                  (inline-open . 0)
  193.                  (inher-cont . c-lineup-multi-inher)
  194.                  (arglist-cont-nonempty . +)
  195.                  (template-args-cont . +))))
  196.  
  197. ;; Add color to a shell running in emacs 'M-x shell'
  198. (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
  199. (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
  200.  
  201. ;; ============================
  202. ;; Mouse Settings
  203. ;; ============================
  204.  
  205. ;; mouse button one drags the scroll bar
  206. ;;(global-set-key [vertical-scroll-bar down-mouse-1] 'scroll-bar-drag)
  207.  
  208. ;; ============================
  209. ;; Display
  210. ;; ============================
  211.  
  212. ;; disable startup message
  213. (setq inhibit-startup-message t)
  214.  
  215. ;; ===========================
  216. ;; Behaviour
  217. ;; ===========================
  218.  
  219. ;; Make all yes-or-no questions as y-or-n
  220. (fset 'yes-or-no-p 'y-or-n-p)
  221.  
  222. ;; Pgup/dn will return exactly to the starting point.
  223. ;;(setq scroll-preserve-screen-position 1)
  224.  
  225. ;; don't automatically add new lines when scrolling down at
  226. ;; the bottom of a buffer
  227. (setq next-line-add-newlines nil)
  228.  
  229. ;; scroll just one line when hitting the bottom of the window
  230. ;;(setq scroll-step 1)
  231. ;;(setq scroll-conservatively 1)
  232.  
  233. ;; format the title-bar to always include the buffer name
  234. (setq frame-title-format "emacs - %b")
  235.  
  236. ;; show a menu only when running within X (save real estate when
  237. ;; in console)
  238. (menu-bar-mode (if window-system 1 -1))
  239.  
  240. ;; replace highlighted text with what I type rather than just
  241. ;; inserting at a point
  242. (delete-selection-mode t)
  243.  
  244. ;; resize the mini-buffer when necessary
  245. (setq resize-minibuffer-mode t)
  246.  
  247. ;; highlight during searching
  248. (setq query-replace-highlight t)
  249.  
  250. ;; highlight incremental search
  251. (setq search-highlight t)
  252.  
  253. ;; Fully redraw the display before it processes queued input events.
  254. ;; http://www.masteringemacs.org/articles/2011/10/02/improving-performance-emacs-display-engine/
  255. (setq redisplay-dont-pause t)
  256.  
  257. ;; Disable question about killing a buffer with a live process attached to it
  258. (setq kill-buffer-query-functions
  259.   (remq 'process-kill-buffer-query-function
  260.          kill-buffer-query-functions))
  261.  
  262. ;; ===========================
  263. ;; Custom Functions
  264. ;; ===========================
  265.  
  266. ;; print an ascii table
  267. (defun ascii-table ()
  268.   (interactive)
  269.   (switch-to-buffer "*ASCII*")
  270.   (erase-buffer)
  271.   (insert (format "ASCII characters up to number %d.\n" 254))
  272.   (let ((i 0))
  273.     (while (< i 254)
  274.       (setq i (+ i 1))
  275.       (insert (format "%4d %c\n" i i))))
  276.   (beginning-of-buffer))
  277.  
  278. ;; indent the entire buffer
  279. (defun c-indent-buffer ()
  280.   "Indent entire buffer of C source code."
  281.   (interactive)
  282.   (save-excursion
  283.     (goto-char (point-min))
  284.     (while (< (point) (point-max))
  285.       (c-indent-command)
  286.       (end-of-line)
  287.       (forward-char 1))))
  288.  
  289. (defun insert-function-header () (interactive)
  290.   (insert "/**\n")
  291.   (insert " * function - Short description.\n")
  292.   (insert " * @param: Description\n")
  293.   (insert " * \n")
  294.   (insert " * Returns: \n")
  295.   (insert " * \n")
  296.   (insert " */\n"))
  297.  
  298. (defun insert-file-header () (interactive)
  299.   (insert "/* \\\\/ Westermo - <FILE DESCRIPTION>\n")
  300.   (insert " *\n")
  301.   (insert " * Copyright (C) 2013  Westermo Teleindustri AB\n")
  302.   (insert " *\n")
  303.   (insert " * Author: Joachim Nilsson <joachim.nilsson@westermo.se>\n")
  304.   (insert " *\n")
  305.   (insert " * Description:\n")
  306.   (insert " *\n")
  307.   (insert " */\n"))
  308.  
  309. (defun insert-include-body () (interactive)
  310.   (insert "/* \\\\/ Westermo - <FILE DESCRIPTION>\n")
  311.   (insert " *\n")
  312.   (insert " * Copyright (C) 2013  Westermo Teleindustri AB\n")
  313.   (insert " *\n")
  314.   (insert " * Author: Joachim Nilsson <joachim.nilsson@westermo.se>\n")
  315.   (insert " *\n")
  316.   (insert " * Description:\n")
  317.   (insert " *\n")
  318.   (insert " */\n")
  319.   (insert "\n")
  320.   (insert "#ifndef FILE_H_\n")
  321.   (insert "#define FILE_H_\n")
  322.   (insert "\n")
  323.   (insert "#endif /* FILE_H_ */\n"))
  324.  
  325. (defun insert-file-footer () (interactive)
  326.   (insert "/**\n")
  327.   (insert " * Local Variables:\n")
  328.   (insert " *  version-control: t\n")
  329.   (insert " *  indent-tabs-mode: nil\n")
  330.   (insert " *  c-file-style: \"ellemtel\"\n")
  331.   (insert " * End:\n")
  332.   (insert " */\n"))
  333.  
  334. (defun insert-isc-license () (interactive)
  335.   (insert "/*\n")
  336.   (insert " *\n")
  337.   (insert " * Copyright (c) 2013  Joachim Nilsson <troglobit@gmail.com>\n")
  338.   (insert " *\n")
  339.   (insert " * Permission to use, copy, modify, and/or distribute this software for any\n")
  340.   (insert " * purpose with or without fee is hereby granted, provided that the above\n")
  341.   (insert " * copyright notice and this permission notice appear in all copies.\n")
  342.   (insert " *\n")
  343.   (insert " * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n")
  344.   (insert " * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n")
  345.   (insert " * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n")
  346.   (insert " * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n")
  347.   (insert " * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n")
  348.   (insert " * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n")
  349.   (insert " * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n")
  350.   (insert " */\n"))
  351.  
  352. (defun insert-wmo-signed-off () (interactive)
  353.   (insert "Signed-off-by: Joachim Nilsson <joachim.nilsson@westermo.se>\n"))
  354.  
  355. (defun insert-signed-off () (interactive)
  356.   (insert "Signed-off-by: Joachim Nilsson <troglobit@gmail.com>\n"))
  357.  
  358. ;; insert functions
  359. (global-unset-key "\C-t")
  360. (global-set-key "\C-t\C-l" 'insert-isc-license)     ; Alternate top
  361. (global-set-key "\C-t\C-w" 'insert-wmo-signed-off)
  362. (global-set-key "\C-t\C-s" 'insert-signed-off)
  363. (global-set-key "\C-t\C-t" 'insert-file-header)     ; Top
  364. (global-set-key "\C-t\C-b" 'insert-file-footer)     ; Bottom
  365. (global-set-key "\C-t\C-h" 'insert-function-header) ; Header
  366. (global-set-key "\C-t\C-i" 'insert-include-body)    ; Include
  367.  
  368. ;; Override buffer listing with new ibuffer
  369. (global-set-key (kbd "C-x C-b") 'ibuffer)
  370.  
  371. ;; Transparency, from http://emacs-fu.blogspot.se/2009/02/transparent-emacs.html
  372. (defun djcb-opacity-modify (&optional dec)
  373.   "modify the transparency of the emacs frame; if DEC is t,
  374.    decrease the transparency, otherwise increase it in 10%-steps"
  375.   (let* ((alpha-or-nil (frame-parameter nil 'alpha)) ; nil before setting
  376.           (oldalpha (if alpha-or-nil alpha-or-nil 100))
  377.           (newalpha (if dec (- oldalpha 10) (+ oldalpha 10))))
  378.     (when (and (>= newalpha frame-alpha-lower-limit) (<= newalpha 100))
  379.       (modify-frame-parameters nil (list (cons 'alpha newalpha))))))
  380.  
  381.  ;; C-8 will increase opacity (== decrease transparency)
  382.  ;; C-9 will decrease opacity (== increase transparency
  383.  ;; C-0 will returns the state to normal
  384. (global-set-key (kbd "C-8") '(lambda()(interactive)(djcb-opacity-modify)))
  385. (global-set-key (kbd "C-9") '(lambda()(interactive)(djcb-opacity-modify t)))
  386. (global-set-key (kbd "C-0") '(lambda()(interactive)
  387.                                (modify-frame-parameters nil `((alpha . 100)))))
  388.  
  389. ;; ===========================
  390. ;; Emacs customized settings
  391. ;; ===========================
  392. (custom-set-variables
  393.  ;; custom-set-variables was added by Custom.
  394.  ;; If you edit it by hand, you could mess it up, so be careful.
  395.  ;; Your init file should contain only one such instance.
  396.  ;; If there is more than one, they won't work right.
  397.  '(all-christian-calendar-holidays t)
  398.  '(ansi-color-names-vector [solarized-bg red green yellow blue magenta cyan solarized-fg])
  399.  '(auto-hscroll-mode t)
  400.  '(baud-rate 115200)
  401.  '(c-default-style (quote ((c-mode . "linux") (c++-mode . "ellemtel") (java-mode . "java") (awk-mode . "awk") (other . "gnu"))))
  402.  '(c-max-one-liner-length 132)
  403.  '(calendar-christian-all-holidays-flag t)
  404.  '(calendar-mark-holidays-flag t)
  405.  '(calendar-week-start-day 1)
  406.  '(case-fold-search t)
  407.  '(case-replace t)
  408.  '(column-number-mode t)
  409.  '(compilation-auto-jump-to-first-error nil)
  410.  '(compilation-scroll-output t)
  411.  '(compilation-window-height 15)
  412.  '(confirm-kill-emacs (quote y-or-n-p))
  413.  '(cua-enable-cua-keys (quote shift))
  414.  '(cua-highlight-region-shift-only t)
  415.  '(cua-mode t nil (cua-base))
  416.  '(custom-enabled-themes (quote (wheatgrass)))
  417.  '(custom-safe-themes (quote ("72cc9ae08503b8e977801c6d6ec17043b55313cda34bcf0e6921f2f04cf2da56" "d2622a2a2966905a5237b54f35996ca6fda2f79a9253d44793cfe31079e3c92b" "501caa208affa1145ccbb4b74b6cd66c3091e41c5bb66c677feda9def5eab19c" default)))
  418.  '(desktop-save-mode t)
  419.  '(diff-default-read-only nil)
  420.  '(diff-mode-hook (quote (diff-make-unified)))
  421.  '(diff-switches "-u")
  422.  '(diff-update-on-the-fly nil)
  423.  '(dired-ls-F-marks-symlinks t)
  424.  '(display-time-24hr-format t)
  425.  '(display-time-day-and-date nil)
  426.  '(display-time-default-load-average nil)
  427.  '(display-time-mail-file (quote none))
  428.  '(ecb-directories-menu-user-extension-function (quote ignore))
  429.  '(ecb-history-menu-user-extension-function (quote ignore))
  430.  '(ecb-layout-name "leftright2")
  431.  '(ecb-methods-menu-user-extension-function (quote ignore))
  432.  '(ecb-options-version "2.32")
  433.  '(ecb-primary-secondary-mouse-buttons (quote mouse-1--mouse-2))
  434.  '(ecb-sources-menu-user-extension-function (quote ignore))
  435.  '(ecb-tip-of-the-day nil)
  436.  '(ecb-vc-supported-backends (quote ((ecb-vc-dir-managed-by-CVS . ecb-vc-state) (ecb-vc-dir-managed-by-RCS . ecb-vc-state) (ecb-vc-dir-managed-by-SVN . ecb-vc-state))))
  437.  '(ecb-windows-width 0.13)
  438.  '(ediff-merge-split-window-function (quote split-window-vertically))
  439.  '(erc-nick "troglobit")
  440.  '(erc-server "irc.labs.westermo.se")
  441.  '(erc-user-full-name "Joachim Nilsson")
  442.  '(european-calendar-style t)
  443.  '(fci-rule-color "#eee8d5")
  444.  '(fill-column 72)
  445.  '(gdb-same-frame t)
  446.  '(gdb-show-main t)
  447.  '(global-auto-revert-mode t)
  448.  '(global-hl-line-mode nil)
  449.  '(hide-ifdef-lines t)
  450.  '(hide-ifdef-shadow t)
  451.  '(ido-enabled (quote both) nil (ido))
  452.  '(ido-everywhere t)
  453.  '(ido-mode (quote both) nil (ido))
  454.  '(indent-tabs-mode nil)
  455.  '(indicate-buffer-boundaries (quote ((top . left) (bottom . right))))
  456.  '(indicate-empty-lines t)
  457.  '(inhibit-startup-screen t)
  458.  '(make-backup-files nil)
  459.  '(mark-holidays-in-calendar t)
  460.  '(org-support-shift-select t)
  461.  '(pc-select-selection-keys-only t)
  462.  '(pc-selection-mode t)
  463.  '(safe-local-variable-values (quote ((c-style . pluto) (c-indent-style . "ellemtel"))))
  464.  '(save-place t nil (saveplace))
  465.  '(scroll-bar-mode (quote right))
  466.  '(server-done-hook (quote (delete-frame)))
  467.  '(server-mode t)
  468.  '(server-window (quote switch-to-buffer-other-frame))
  469.  '(sh-basic-offset 8)
  470.  '(sh-indentation 8)
  471.  '(sh-learn-basic-offset (quote usually))
  472.  '(show-paren-mode t)
  473.  '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
  474.  '(todoo-collapse-items t)
  475.  '(todoo-indent-column 0)
  476.  '(tool-bar-mode nil)
  477.  '(tooltip-mode nil)
  478.  '(truncate-lines t)
  479.  '(uniquify-buffer-name-style (quote forward) nil (uniquify))
  480.  '(vc-annotate-background "white")
  481.  '(vc-consult-headers nil)
  482.  '(vc-dired-recurse nil)
  483.  '(vc-dired-terse-display nil)
  484.  '(vc-display-status nil)
  485.  '(version-control (quote never))
  486.  '(wdired-enable nil)
  487.  '(which-function-mode t)
  488.  '(x-select-enable-clipboard t))
  489. (custom-set-faces
  490.  ;; custom-set-faces was added by Custom.
  491.  ;; If you edit it by hand, you could mess it up, so be careful.
  492.  ;; Your init file should contain only one such instance.
  493.  ;; If there is more than one, they won't work right.
  494.  '(default ((t (:family "Inconsolata" :foundry "unknown" :slant normal :weight normal :height 113 :width normal)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement