Advertisement
Guest User

.emacs file

a guest
May 13th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 28.24 KB | None | 0 0
  1. ;; Are we running XEmacs or Emacs?
  2. (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
  3.  
  4. ;; disable menu bar when running in terminal
  5. (when (not (display-graphic-p))
  6.   (menu-bar-mode -1))
  7.  
  8. ;;My libraries, ebib, wordcount etc
  9. (add-to-list 'load-path "~/.emacs-lisp/")
  10.  
  11.  
  12. ;;;;;;;;;;;;;;;
  13. ;; emacs IDE ;;
  14. ;;;;;;;;;;;;;;;
  15. ;;  (package-initialize)
  16. ;;  (eide-start)
  17.  
  18. (add-to-list 'load-path "/home/terdon/.emacs-lisp/Emacs-PDE-0.2.16/lisp")
  19. ;;(load "pde-load")
  20. (load "imenu-tree")
  21. ;; (setq pde-extra-setting t)
  22.  
  23.  
  24. ;; ;; Load imenu automatically in CPerl mode
  25. ;; (add-hook 'cperl-mode-hook 'imenu-tree)
  26.  
  27.  
  28. ;; (add-to-list 'load-path "~/.emacs.d/elpa/archives")
  29. ;; (add-to-list 'load-path "~/.emacs.d/elpa/auto-complete-20160310.2248")
  30. ;; (add-to-list 'load-path "~/.emacs.d/elpa/eide-2.1.1")
  31. ;; (add-to-list 'load-path "~/.emacs.d/elpa/gnupg")
  32. ;; (add-to-list 'load-path "~/.emacs.d/elpa/log4e-20150105.505")
  33. ;; (add-to-list 'load-path "~/.emacs.d/elpa/plsense-20151104.645")
  34. ;; (add-to-list 'load-path "~/.emacs.d/elpa/popup-20151222.1339")
  35. ;; (add-to-list 'load-path "~/.emacs.d/elpa/yaxception-20150105.652")
  36.  
  37. ;; (require 'plsense)
  38. ;; (require 'auto-complete-config)
  39. ;; (ac-config-default)
  40.  
  41.  
  42. ;; ;; Key binding
  43. ;; (setq plsense-popup-help-key "C-:")
  44. ;; (setq plsense-display-help-buffer-key "M-:")
  45. ;; (setq plsense-jump-to-definition-key "C->")
  46.  
  47. ;; ;; Make config suit for you. About the config item, eval the following sexp.
  48. ;; ;; (customize-group "plsense")
  49.  
  50. ;; ;; Do setting recommemded configuration
  51. ;; (plsense-config-default)
  52.  
  53.  
  54. ;;;;;;;;;;;;;;;;;;;;;
  55. ;; Disable toolbar ;;
  56. ;;;;;;;;;;;;;;;;;;;;;
  57. (tool-bar-mode -1)
  58.  
  59. ;;;;;;;;;;;;;;;;;;;;;;
  60. ;; Disable the bell ;;
  61. ;;;;;;;;;;;;;;;;;;;;;;
  62. (setq ring-bell-function 'ignore)
  63.  
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  65. ;; Set the autosave interval to 30 minutes ;;
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. (setq auto-save-timeout 1800)
  68.  
  69. ;;;;;;;;;;;;;;;;;;;;
  70. ;; Start a server ;;
  71. ;;;;;;;;;;;;;;;;;;;;
  72. ;;(server-start)
  73.  
  74.  
  75. ;; use Shift+arrow_keys to move cursor around split panes
  76. (windmove-default-keybindings)
  77.  
  78. ;; when cursor is on edge, move to the other side, as in a torus space
  79. (setq windmove-wrap-around t )
  80.  
  81.  
  82. ;;;;;;;;;;;;;;;;;;;;;
  83. ;; Tabs or spaces? ;;
  84. ;;;;;;;;;;;;;;;;;;;;;
  85. (setq-default tab-width 2)
  86. (setq-default indent-tabs-mode t)
  87. (defvaralias 'c-basic-offset 'tab-width)
  88. (defvaralias 'cperl-indent-level 'tab-width)
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ;; Enable installing packages from melpa.org ;;
  91. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  92. (require 'package) ;; You might already have this line
  93. (add-to-list 'package-archives
  94.              '("melpa" . "http://melpa.org/packages/") t)
  95. (when (< emacs-major-version 24)
  96.   ;; For important compatibility libraries like cl-lib
  97.   (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
  98. (package-initialize) ;; You might already have this line
  99.  
  100.  
  101. ;; ===== Make Text mode the default mode for new buffers =====
  102. ;;(setq major-mode 'text-mode)
  103. ;; ===== Make markdown mode the default mode for new buffers =====
  104. (setq major-mode 'markdown-mode)
  105.  
  106. ;;;;;;;;;;;;;;;;;;;;
  107. ;; org mode stuff ;;
  108. ;;;;;;;;;;;;;;;;;;;;
  109. (require 'org-install)
  110. (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
  111.  
  112. (define-key global-map "\C-cl" 'org-store-link)
  113. (define-key global-map "\C-ca" 'org-agenda)
  114. (setq org-log-done t)
  115.  
  116.  
  117.  
  118. ;; disable blinking cursor
  119. (blink-cursor-mode 0)
  120.  
  121. ;; Interpret ANSI color escape codes
  122. (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
  123.  
  124. ;; Set up the keyboard so the delete key on both the regular keyboard
  125. ;; and the keypad delete the character under the cursor and to the right
  126. ;; under X, instead of the default, backspace behavior.
  127. (global-set-key [delete] 'delete-char)
  128. (global-set-key [kp-delete] 'delete-char)
  129. (global-set-key "\C-cc" 'comment-region)
  130. (global-set-key "\C-cb" 'comment-box)
  131. (global-set-key "\C-cu" 'uncomment-region)
  132. (global-set-key "\C-cr" 'query-replace)
  133. (global-set-key "\M-gg" 'goto-line)
  134. (global-set-key "\C-ci" 'ebib-insert-bibtex-key)
  135. ;; (global-set-key "\C-ce" 'ecb-activate)
  136.  
  137. ;;; Compare windows
  138. (global-set-key "\C-cw" 'compare-windows)
  139. ;;; Rebind `C-x C-b' for `buffer-menu'
  140. (global-set-key "\C-x\C-b" 'buffer-menu)
  141. ;; Turn on font-lock mode for Emacs
  142. (cond ((not running-xemacs)
  143.        (global-font-lock-mode t)
  144. ))
  145. ;; use all spaces, no tabs for indentation
  146. ;;(setq-default indent-tabs-mode nil)
  147.  
  148. ;; delete with backspace and delete
  149. (delete-selection-mode t)
  150. (add-hook 'LaTeX-mode-hook 'flyspell-mode)
  151.  
  152. ;; make flyspell mode ignore latex commands
  153. (setq ispell-extra-args '("--dont-tex-check-comments"))
  154.  
  155. ;;(set-default-font "-apple-Monaco-normal-normal-normal-*-14-*-*-*-*-0-iso10646-1")
  156. (set-default-font "Monaco")
  157. ;; set font size
  158. (set-face-attribute 'default nil :height 110)
  159. ;;(set-default-font "monaco")
  160.  
  161. ;;-*-Monaco-normal-r-*-*-16-*-*-*-*-*-*-*")
  162. ;;;;                   -*-Monaco-medium-r-*-*-10-*-*-*-*-*-*-*
  163. ;; Visual feedback on selections
  164. (setq-default transient-mark-mode t)
  165.  
  166. ;; Always end a file with a newline
  167. (setq require-final-newline t)
  168.  
  169. ;; Stop at the end of the file, not just add lines
  170. (setq next-line-add-newlines nil)
  171.  
  172.  
  173. ;; highlight paired parentheses
  174. (show-paren-mode t )
  175.  
  176.  
  177.  
  178. ;; Pretty parentheses
  179. (when (require 'rainbow-delimiters nil 'noerror)
  180.   (add-hook 'cperl-mode-hook 'rainbow-delimiters-mode))
  181.  
  182. ;;;;;;;;;;;;;;;;;;;;;
  183. ;; auto-install.el ;;
  184. ;;;;;;;;;;;;;;;;;;;;;
  185. ;; (require 'auto-install)
  186. ;; (auto-install-update-emacswiki-package-name t)
  187.  
  188.  
  189. ;;;;;;;;;;;;;;;;;;;;;
  190. ;; perl completion ;;
  191. ;;;;;;;;;;;;;;;;;;;;;
  192. (add-hook 'cperl-mode-hook
  193.           (lambda()
  194.             (require 'perl-completion)
  195.             (perl-completion-mode t)))
  196.  
  197.  
  198.  
  199. ;;;;;;;;;;;;;;;;;;;;
  200. ;; ----- ECB ---- ;;
  201. ;;;;;;;;;;;;;;;;;;;;
  202. ;; (add-to-list 'load-path
  203. ;;              "~/.emacs-lisp/ecb/");;"/usr/share/emacs23/site-lisp/ecb/")
  204. ;; (require 'ecb)
  205. ;;;; activate ecb for the following modes
  206. ;; (dolist (hook '(
  207. ;;      c-mode-hook        
  208. ;;      cperl-mode-hook
  209. ;;      perl-mode-hook
  210. ;;      php-mode-hook      
  211. ;;      js-mode-hook        
  212. ;;      python-mode        
  213. ;;      sh-mode-hook        
  214. ;;      ))
  215. ;;   (add-hook hook 'ecb-activate))
  216.  
  217. ;;; Modify the variable ecb-layout-name to use change the layout
  218. ;;; then C-c . l to refresh the ecb screen
  219. ;;; or just use the function ecb-change-layout
  220. ;;(setq ecb-layout-name "terdon1")
  221. ;;(setq ecb-layout-name "terdon2")
  222. ;(setq initial-buffer-choice user-init-file)
  223.  
  224. ;;; use the icons in the tree displays (t)
  225. ;;(setq ecb-tree-use-image-icons t)
  226.  
  227.  
  228. ;; Enable wheelmouse support by default
  229. (cond (window-system
  230.        (mwheel-install)
  231. ))
  232. (custom-set-variables
  233.  ;; custom-set-variables was added by Custom.
  234.  ;; If you edit it by hand, you could mess it up, so be careful.
  235.  ;; Your init file should contain only one such instance.
  236.  ;; If there is more than one, they won't work right.
  237.  '(case-fold-search t)
  238.  '(current-language-environment "English")
  239.  '(custom-enabled-themes (quote (tango-dark)))
  240.  '(custom-safe-themes
  241.      (quote
  242.         ("38908037082b9fc2e6762961026299d026963e57c726c3bc0b9e66cd0def0926" default)))
  243.  '(default-input-method "latin-9-prefix")
  244.  '(ebib-preload-bib-files (quote ("~/doc/Papers/moonlighting.bib")))
  245.  '(global-font-lock-mode t nil (font-lock))
  246.  '(inhibit-startup-screen t)
  247.  '(safe-local-variable-values (quote ((Local . "american"))))
  248.  '(save-place t nil (saveplace))
  249.  '(show-paren-mode t nil (paren))
  250.  '(tex-dvi-view-command
  251.      (quote
  252.         (cond
  253.          ((eq window-system
  254.                     (quote x))
  255.             "evince")
  256.          ((eq window-system
  257.                     (quote w32))
  258.             "yap")
  259.          (t "dvi2tty * | cat -s"))))
  260.  '(transient-mark-mode t))
  261. (custom-set-faces
  262.  ;; custom-set-faces was added by Custom.
  263.  ;; If you edit it by hand, you could mess it up, so be careful.
  264.  ;; Your init file should contain only one such instance.
  265.  ;; If there is more than one, they won't work right.
  266.  '(cperl-array-face ((((class color) (background light)) (:foreground "OrangeRed"))))
  267.  '(cperl-hash-face ((((class color) (background light)) (:foreground "coral4"))))
  268.  '(cperl-nonoverridable-face ((t (:foreground "RoyalBlue"))))
  269.  '(font-lock-comment-face ((t (:foreground "SlateGray"))))
  270.  '(markdown-header-face-1 ((t (:inherit markdown-header-face :height 1.1))))
  271.  '(markdown-header-face-2 ((t (:inherit markdown-header-face :height 1.05))))
  272.  '(markdown-header-face-3 ((t (:inherit markdown-header-face :height 1.03))))
  273.  '(markdown-header-face-4 ((t (:inherit markdown-header-face :height 1.01)))))
  274.  
  275.  
  276.  
  277.  
  278. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  279. ;; enable highlighting regions from the keyboard ;;
  280. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  281. (setq transient-mark-mode t)
  282.  
  283.  
  284. ;; Load Ebib mode
  285. (autoload 'ebib "ebib" "Ebib, a BibTeX database manager." t)
  286.  
  287. ;; Load wc mode
  288. (autoload 'wc "wc" "Word Count" t)
  289.  
  290.  
  291. ;; enable wordcount for LaTex
  292. ;; http://superuser.com/questions/125027/word-count-for-latex-within-emacs
  293. (defun latex-word-count ()
  294.   (interactive)
  295.   (shell-command (concat "~/scripts/texcount.pl "
  296.                          ; "uncomment then options go here "
  297.                          (buffer-file-name))))
  298.  
  299. ;; save history across sessions
  300. (require 'recentf)
  301. (recentf-mode 1)
  302. (setq recentf-max-menu-items 50)
  303.  
  304. ;; ralee mode is good for RNA alignment editing
  305. ;; (add-to-list 'load-path "~/.ralee/")
  306. ;; (autoload 'ralee-mode "ralee-mode" "Yay! RNA things" t)
  307. ;; (setq auto-mode-alist (cons '("\\.stk$" . ralee-mode) auto-mode-alist))
  308.  
  309. ;; Show current line and column number
  310. (setq-default column-number-mode t)
  311. (line-number-mode t)
  312.  
  313. ;; Set encoding
  314. (prefer-coding-system 'utf-8)
  315. (setq coding-system-for-read 'utf-8)
  316. (setq coding-system-for-write 'utf-8)
  317.  
  318. ;; tramp for remote file editing
  319. (setq tramp-default-method "sshx")
  320. (setq tramp-verbose 10)
  321.  
  322.  
  323.  
  324. ;;/lacoloc@badabing:/home/lacoloc/foo1
  325. ;;; Buffer tricks for C-x C-b
  326. (require 'ibuffer)
  327. (setq ibuffer-saved-filter-groups
  328.   (quote (("default"      
  329.            
  330.             ("Coding" ;; prog stuff not already in MyProjectX
  331.               (or
  332.                 (mode . c-mode)
  333.                 (mode . perl-mode)
  334.         (mode . cperl-mode)
  335.                 (mode . python-mode)
  336.                 (mode . emacs-lisp-mode)
  337.         (mode . php-mode)
  338.         (mode . js-mode)
  339.         (mode . shell-script\[sh\]-mode)
  340.         (mode . shell-script\[bash\]-mode)
  341.         (mode . shell-script-mode)
  342.         (mode . shell-script-mode)
  343.         (mode . shell-script-mode)
  344.         (mode . shell-script-mode)
  345.         (name . "\\.sh$")
  346.          
  347.  
  348.                 )
  349.           )
  350.         ("HTML/CSS"
  351.        
  352.           (or
  353.            (mode . myhtml-mode)
  354.            (mode . html-mode)
  355.            (mode . htm-mode)
  356.            (mode . css-mode)
  357.            
  358.           )
  359.  
  360.          )
  361.         ("PlainText"  (mode . text-mode))
  362.         ))))
  363.  
  364.      (add-hook 'ibuffer-mode-hook
  365.            (lambda ()
  366.              (ibuffer-switch-to-saved-filter-groups "default")))
  367. (global-set-key (kbd "C-x C-b") 'ibuffer)
  368.  
  369.  
  370.  
  371. ;;;;;; HTML stuff  ;;;;;;;;;;;
  372. ;;;;;;; Color colors in css and html files
  373. (autoload 'myhtml-mode "myhtml-mode" "My HTML mode." t)
  374. (autoload 'rainbow-mode "rainbow-mode" "Color stuff" t)
  375.  
  376. ;;; set myHTML as default mode
  377. (setq auto-mode-alist (cons '("\\.html$" . myhtml-mode) auto-mode-alist))
  378.  
  379. ;;;  web-mode single mode for web docs
  380. (require 'web-mode)
  381. (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
  382. (add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))
  383. (add-to-list 'auto-mode-alist '("\\.css\\'" . web-mode))
  384. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  385. (add-to-list 'auto-mode-alist '("\\.htm\\'" . web-mode))
  386.  
  387. (add-hook 'css-mode-hook 'rainbow-mode)
  388.  
  389. ;;;;;;;;;; HTML keybindings ;;;;;;;;
  390.  
  391. ;;; Ctrl+c Ctrl+d :Delete matching tags. WARNING: if your HTML tags
  392. ;;; are not always matched, it might delete the wrong starting/ending tag
  393.  
  394.  
  395. (add-hook 'myhtml-mode-hook
  396.       (lambda ()
  397.  ;;; sgml-delete-tag function
  398.        
  399.         (local-set-key (kbd "C-c b") 'bold-word)
  400.         (local-set-key (kbd "C-c p") 'insert-p)
  401.         (local-set-key (kbd "M-4") 'tag-image)
  402.         (local-set-key (kbd "M-5") 'wrap-url)
  403.         (local-set-key (kbd "C-c C-d") 'sgml-delete-tag)
  404.        
  405.         )
  406.       )
  407.  
  408.  
  409.  
  410. ;;; Idle highlight stuff
  411. ;; (defun my-coding-hook () (make-local-variable 'column-number-mode) (column-number-mode t)  (idle-highlight t))
  412.  
  413. ;; (add-hook 'emacs-lisp-mode-hook 'my-coding-hook) (add-hook 'ruby-mode-hook 'my-coding-hook) (add-hook 'js2-mode-hook 'my-coding-hook) (add-hook 'perl-mode-hook 'my-coding-hook) (add-hook 'python-mode-hook 'my-coding-hook) (add-hook 'php-mode-hook 'my-coding-hook) (add-hook 'js-mode-hook 'my-coding-hook)  
  414.  
  415. ;;; This was installed by package-install.el.
  416. ;;; This provides support for the package system and
  417. ;;; interfacing with ELPA, the package archive.
  418. ;;; Move this code earlier if you want to reference
  419. ;;; packages in your .emacs.
  420. ;; (when
  421. ;;     (load
  422. ;;      (expand-file-name "~/.emacs.d/elpa/package.el"))
  423. ;;   (package-initialize))
  424.  
  425.  
  426. ;;
  427. (define-key isearch-mode-map (kbd "C-o")
  428.   (lambda ()
  429.     (interactive)
  430.     (let ((case-fold-search isearch-case-fold-search))
  431.       (occur (if isearch-regexp isearch-string
  432.                (regexp-quote isearch-string))))))
  433.  
  434.  
  435. ;;; yasnippet for tab autocomplete
  436. ;;; https://github.com/capitaomorte/yasnippet
  437.  
  438. (add-to-list 'load-path
  439.               "~/.emacs.d/plugins/yasnippet")
  440. (require 'yasnippet)
  441. (yas/global-mode 1)
  442.  
  443.  
  444. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  445. ;; Customize cperl-mode ;;
  446. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  447.  
  448. ;; make cperl-mode always highlight scalar variables
  449.  (setq cperl-highlight-variables-indiscriminately t)
  450.  
  451. ;; Disable whitespace underline
  452. (setq cperl-invalid-face (quote off))
  453.  
  454. ;; Set as default for perl files
  455. (require 'cperl-mode)
  456. ;; Perl file extension associations
  457. (add-to-list 'auto-mode-alist '("\\.pl$" . cperl-mode))
  458. (add-to-list 'auto-mode-alist '("\\.ph$" . cperl-mode))
  459. (add-to-list 'auto-mode-alist '("\\.cgi$" . cperl-mode))
  460. (add-to-list 'auto-mode-alist '("\\.pm$" . cperl-mode))
  461. (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
  462. (add-to-list 'auto-mode-alist '("\\.pl$" . cperl-mode))
  463. (add-to-list 'auto-mode-alist '("\\.cgi$" . cperl-mode))
  464. (add-to-list 'auto-mode-alist '("\\.pm$" . cperl-mode))
  465. (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
  466. (add-to-list 'auto-mode-alist '("\\.pm$" . cperl-mode))
  467. ;; BSD/Allman indentation style using cperl-mode
  468. (cperl-set-style "BSD")
  469. (setq cperl-electric-keywords t) ;; expands for keywords such as
  470.                                      ;; foreach, while, etc...
  471. ;; Load README files with markdown-mode
  472. (add-to-list 'auto-mode-alist '(".*README.*" . markdown-mode))
  473.  
  474. ; Outline-minor-mode key map
  475.  (define-prefix-command 'cm-map nil "Outline-")
  476.  ; HIDE
  477.  (define-key cm-map "q" 'hide-sublevels)    ; Hide everything but the top-level headings
  478.  (define-key cm-map "t" 'hide-body)         ; Hide everything but headings (all body lines)
  479.  (define-key cm-map "o" 'hide-other)        ; Hide other branches
  480.  (define-key cm-map "c" 'hide-entry)        ; Hide this entry's body
  481.  (define-key cm-map "l" 'hide-leaves)       ; Hide body lines in this entry and sub-entries
  482.  (define-key cm-map "d" 'hide-subtree)      ; Hide everything in this entry and sub-entries
  483.  ; SHOW
  484.  (define-key cm-map "a" 'show-all)          ; Show (expand) everything
  485.  (define-key cm-map "e" 'show-entry)        ; Show this heading's body
  486.  (define-key cm-map "i" 'show-children)     ; Show this heading's immediate child sub-headings
  487.  (define-key cm-map "k" 'show-branches)     ; Show all sub-headings under this heading
  488.  (define-key cm-map "s" 'show-subtree)      ; Show (expand) everything in this heading & below
  489.  ; MOVE
  490.  (define-key cm-map "u" 'outline-up-heading)                ; Up
  491.  (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
  492.  (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
  493.  (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
  494.  (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
  495.  (global-set-key "\M-o" cm-map)
  496.  
  497.  
  498.  
  499. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  500. ;; Make TAB expand words. Source:                 ;;
  501. ;; http://emacsblog.org/2007/03/12/tab-completion-everywhere/ ;;
  502. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  503. (defun my-tab-fix ()
  504.   (local-set-key [tab] 'indent-or-expand))
  505.  
  506. (add-hook 'c-mode-hook          'my-tab-fix)
  507. (add-hook 'cperl-mode-hook          'my-tab-fix)
  508. (add-hook 'php-mode-hook          'my-tab-fix)
  509. (add-hook 'js-mode-hook          'my-tab-fix)
  510. (add-hook 'python-mode          'my-tab-fix)
  511. (add-hook 'sh-mode-hook         'my-tab-fix)
  512. (add-hook 'emacs-lisp-mode-hook 'my-tab-fix)
  513. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  514. ;; Define the indent-or-expand function we ;;
  515. ;; just mapped to TAB              ;;
  516. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  517. (defun indent-or-expand (arg)
  518.   "Either indent according to mode, or expand the word preceding
  519. point."
  520.   (interactive "*P")
  521.   (if (and
  522.        (or (bobp) (= ?w (char-syntax (char-before))))
  523.        (or (eobp) (not (= ?w (char-syntax (char-after))))))
  524.       (dabbrev-expand arg)
  525.     (indent-according-to-mode)))
  526.  
  527. ;;; Stop emacs from showing buffer menu when >=3 files opened
  528. (setq inhibit-startup-buffer-menu t)
  529.  
  530.  
  531. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  532. ;; Bury unwanted buffers ;;
  533. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  534.  
  535. ; necessary support function for buffer burial
  536. (defun crs-delete-these (delete-these from-this-list)
  537.   "Delete DELETE-THESE FROM-THIS-LIST."
  538.   (cond
  539.    ((car delete-these)
  540.     (if (member (car delete-these) from-this-list)
  541.         (crs-delete-these (cdr delete-these) (delete (car delete-these)
  542.                              from-this-list))
  543.       (crs-delete-these (cdr delete-these) from-this-list)))
  544.    (t from-this-list)))
  545.                     ; this is the list of buffers I never want to see
  546. (defvar crs-hated-buffers
  547.   '("KILL" "*Compile-Log*" "*Messages*" "*scratch*" "*auto-install"))
  548.                     ; might as well use this for both
  549. (setq iswitchb-buffer-ignore (append '("^ " "*Buffer") crs-hated-buffers))
  550. (defun crs-hated-buffers ()
  551.   "List of buffers I never want to see, converted from names to buffers."
  552.   (delete nil
  553.           (append
  554.            (mapcar 'get-buffer crs-hated-buffers)
  555.            (mapcar (lambda (this-buffer)
  556.                      (if (string-match "^ " (buffer-name this-buffer))
  557.                          this-buffer))
  558.                    (buffer-list)))))
  559. ; I'm sick of switching buffers only to find KILL right in front of me
  560. (defun crs-bury-buffer (&optional n)
  561.   (interactive)
  562.   (unless n
  563.     (setq n 1))
  564.   (let ((my-buffer-list (crs-delete-these (crs-hated-buffers)
  565.                                           (buffer-list (selected-frame)))))
  566.     (switch-to-buffer
  567.      (if (< n 0)
  568.          (nth (+ (length my-buffer-list) n)
  569.               my-buffer-list)
  570.        (bury-buffer)
  571.        (nth n my-buffer-list)))))
  572. (global-set-key [(control tab)] 'crs-bury-buffer)
  573. (global-set-key [(control meta tab)] (lambda ()
  574.                                        (interactive)
  575.                                        (crs-bury-buffer -1)))
  576.  
  577.  
  578.  
  579. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  580. ;;                  ETAGS                 ;;
  581. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  582.   (defun create-tags (dir-name)
  583.      "Create tags file."
  584.      (interactive "DDirectory: ")
  585.      (eshell-command
  586.       (format "find %s -type f -name \"*.[ch]\" | etags -L -" dir-name)))
  587.  
  588.  
  589.   ;;;  Jonas.Jarnestrom<at>ki.ericsson.se A smarter              
  590.   ;;;  find-tag that automagically reruns etags when it cant find a              
  591.   ;;;  requested item and then makes a new try to locate it.                      
  592.   ;;;  Fri Mar 15 09:52:14 2002    
  593.  
  594.   (defadvice find-tag (around refresh-etags activate)
  595.    "Rerun etags and reload tags if tag not found and redo find-tag.              
  596.   If buffer is modified, ask about save before running etags."
  597.   (let ((extension (file-name-extension (buffer-file-name))))
  598.     (condition-case err
  599.     ad-do-it
  600.       (error (and (buffer-modified-p)
  601.           (not (ding))
  602.           (y-or-n-p "Buffer is modified, save it? ")
  603.           (save-buffer))
  604.          (er-refresh-etags extension)
  605.          ad-do-it))))
  606.  
  607.   (defun er-refresh-etags (&optional extension)
  608.   "Run etags on all peer files in current dir and reload them silently."
  609.   (interactive)
  610.   (shell-command (format "etags *.%s" (or extension "el")))
  611.   (let ((tags-revert-without-query t))  ; don't query, revert silently          
  612.     (visit-tags-table default-directory nil)))
  613.  
  614.  
  615. (global-set-key "\M-s" 'tags-search)
  616.  
  617.  
  618. ;;; Delete  buffer
  619. ;;(kill-buffer "*Completions*")
  620.  
  621.  
  622.  
  623. ;;;;;;;; Color theme ;;;;;;;;;;;;;;
  624.  
  625. (defun color-theme-djcb-dark ()
  626.   "dark color theme created by djcb, Jan. 2009."
  627.   (interactive)
  628.   (color-theme-install
  629.     '(color-theme-djcb-dark
  630.        ((foreground-color . "#a9eadf")
  631.          (background-color . "black")
  632.          (background-mode . dark))
  633.        (bold ((t (:bold t))))
  634.        (bold-italic ((t (:italic t :bold t))))
  635.        (default ((t (nil))))
  636.        
  637.        (font-lock-builtin-face ((t (:italic t :foreground "#a96da0"))))
  638.        (font-lock-comment-face ((t (:italic t :foreground "#bbbbbb"))))
  639.        (font-lock-comment-delimiter-face ((t (:foreground "#666666"))))
  640.        (font-lock-constant-face ((t (:bold t :foreground "#197b6e"))))
  641.        (font-lock-doc-string-face ((t (:foreground "#3041c4"))))
  642.        (font-lock-doc-face ((t (:foreground "gray"))))
  643.        (font-lock-reference-face ((t (:foreground "white"))))
  644.        (font-lock-function-name-face ((t (:foreground "#356da0"))))
  645.        (font-lock-keyword-face ((t (:bold t :foreground "#bcf0f1"))))
  646.        (font-lock-preprocessor-face ((t (:foreground "#e3ea94"))))
  647.        (font-lock-string-face ((t (:foreground "#ffffff"))))
  648.        (font-lock-type-face ((t (:bold t :foreground "#364498"))))
  649.        (font-lock-variable-name-face ((t (:foreground "#7685de"))))
  650.        (font-lock-warning-face ((t (:bold t :italic nil :underline nil
  651.                                      :foreground "yellow"))))
  652.        (hl-line ((t (:background "#112233"))))
  653.        (mode-line ((t (:foreground "#ffffff" :background "#333333"))))
  654.        (region ((t (:foreground nil :background "#555555"))))
  655.        (show-paren-match-face ((t (:bold t :foreground "#ffffff"
  656.                                     :background "#050505")))))))
  657.  
  658.  
  659.  
  660. (add-to-list 'process-coding-system-alist '("zsh" . utf-8))
  661.  
  662. (put 'upcase-region 'disabled nil)
  663.  
  664.  
  665. ;; Informative comments,
  666. ;; comments that I want to keep or whatever
  667. (add-hook 'tex-mode-hook
  668.   (lambda ()
  669.     (font-lock-add-keywords nil
  670.       ;;'(("\\<\\(FIXME\\|TODO\\|HACK\\|fixme\\|todo\\|hack\\)" 1
  671.                 '(("\\(%#.*\\)" 1
  672.         font-lock-warning-face t)))))
  673. (add-hook 'cperl-mode-hook
  674.   (lambda ()
  675.     (font-lock-add-keywords nil
  676.                 '(("\\(#%.*\\)" 1
  677.         font-lock-warning-face t)))))
  678.  
  679. ;;;;;;;;;;;;;;;;;;;;
  680. ;; Enable tabbar  ;;
  681. ;;;;;;;;;;;;;;;;;;;;
  682. ;(tabbar-mode t)
  683.  
  684.  
  685. ;;; Markdown mode
  686. (autoload 'markdown-mode "markdown-mode.el" "Major mode for editing Markdown files" t)
  687. (setq auto-mode-alist (cons '("\\.text$" . markdown-mode) auto-mode-alist))
  688. (setq auto-mode-alist (cons '("\\.md$" . markdown-mode) auto-mode-alist))
  689. (setq auto-mode-alist (cons '("\\.mdown$" . markdown-mode) auto-mode-alist))
  690. (setq auto-mode-alist (cons '("\\.mdt$" . markdown-mode) auto-mode-alist))
  691. (setq auto-mode-alist (cons '("\\.markdown$" . markdown-mode) auto-mode-alist))
  692.  
  693.  
  694. ;;;;;;;;;;;;;;;;;;
  695. ;; Color themes ;;
  696. ;;;;;;;;;;;;;;;;;;
  697.  
  698. (add-to-list 'load-path "~/.emacs-lisp/emacs-color-theme-solarized")
  699.  (load-theme 'tango-dark)
  700.  
  701. ;;;;;;;;;;;;;;;;;
  702. ;; LaTeX stuff ;;
  703. ;;;;;;;;;;;;;;;;;
  704. (setq TeX-PDF-mode t)
  705.  
  706. (setq TeX-auto-save t)
  707. (setq TeX-parse-self t)
  708. (setq-default TeX-master nil)
  709.  
  710. (add-hook 'LaTeX-mode-hook 'visual-line-mode)
  711. (add-hook 'LaTeX-mode-hook 'flyspell-mode)
  712. (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
  713.  
  714. (add-hook 'LaTeX-mode-hook 'turn-on-reftex)
  715. (setq reftex-plug-into-AUCTeX t)
  716.  
  717. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  718. ;; Chrome edit with emacs extension ;;
  719. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  720. (add-to-list 'load-path "~/.emacs.d/plugins")
  721. (require 'edit-server)
  722. (edit-server-start)
  723.  
  724. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  725. ;; Enable markdown mode for editing SE posts ;;
  726. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  727. ;; Integrate Emacs with Stack Exchange http://stackoverflow.com/a/10386560/789593
  728. (add-to-list 'auto-mode-alist '("stack\\(exchange\\|overflow\\)\\.com\\.[a-z0-9]+\\.txt" . markdown-mode))
  729. (add-to-list 'auto-mode-alist '("superuser\\.com\\.[a-z0-9]+\\.txt" . markdown-mode))
  730.  
  731.  
  732.  
  733. ;; Insert text around a region. In this case, it's
  734. ;; the LaTeX code environment from the listings package
  735. (defun wrap-code (start end)
  736.   "Insert a \begin{code} and \end{code} around a region."
  737.   (interactive "r")
  738.  
  739.   (save-excursion
  740.     (goto-char end) (insert "\\end{code}")
  741.     (goto-char start)(insert "\\begin{code}") (newline-and-indent)
  742.     ))
  743. ;; Assign its shortcut
  744. (global-set-key (kbd "C-c p") 'wrap-code)
  745.  
  746.  
  747.  
  748. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  749. ;; SE Markdown: http://emacs.stackexchange.com/questions/723/how-can-i-use-the-se-flavor-of-markdown-in-emacs ;;
  750. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  751. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  752. ;; This variable controls how you want lists to look. It adds some space  ;;
  753. ;; to indent the list, and uses a pretty bullet-point.                    ;;
  754. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  755. (defvar endless/bullet-appearance
  756.   (propertize (if (char-displayable-p ?•) "  •" "  *")
  757.               'face 'markdown-list-face)
  758.   "String to be displayed as the bullet of markdown list items.")
  759.  
  760.  
  761. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  762. ;; This is the command that actually adds the rules. There is one for lists and one for links. ;;
  763. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  764. (font-lock-add-keywords
  765.  'markdown-mode
  766.  '(("^ *\\(\\*\\|\\+\\|-\\|\\) "
  767.     1 `(face nil display ,endless/bullet-appearance) prepend)
  768.    ("\\[[^]]*\\]\\(([^)]*)\\|\\[[^]]*\\]\\)"
  769.     1 '(face nil display "") prepend))
  770.  'append)
  771. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  772. ;; Because we’re using the display property to hide part of the link,     ;;
  773. ;; we need to tell font-lock that it should erase that property whenever  ;;
  774. ;; you delete part of the link (that way we can still edit it).           ;;
  775. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  776. (add-hook 'markdown-mode-hook #'endless/markdown-font-lock)
  777.  
  778. (defun endless/markdown-font-lock ()
  779.   "Configure aggressive font-locking of `markdown-mode'."
  780.   (add-to-list (make-local-variable 'font-lock-extra-managed-props) 'display))
  781.  
  782. ;; Faces
  783.  
  784.  
  785.  
  786. ;; Insert links and make them editable
  787.  
  788. (add-hook 'markdown-mode-hook #'endless/markdown-font-lock)
  789.  
  790. (defun endless/markdown-font-lock ()
  791.   "Configure aggressive font-locking of `markdown-mode'."
  792.   (define-key markdown-mode-map "\C-c\C-l" #'endless/markdown-insert-link)
  793.   (add-to-list (make-local-variable 'font-lock-extra-managed-props) 'display))
  794. (defun endless/markdown-insert-link ()
  795.   "Insert or edit link at point."
  796.   (interactive)
  797.   (if (or (looking-at endless/markdown-link-regexp)
  798.           (and (ignore-errors (backward-up-list) t)
  799.                (or (looking-at endless/markdown-link-regexp)
  800.                    (and (forward-sexp -1)
  801.                         (looking-at endless/markdown-link-regexp)))))
  802.       (let ((data (endless/ask-for-link
  803.                    (match-string-no-properties 1)
  804.                    (or (match-string-no-properties 2)
  805.                        (match-string-no-properties 3)))))
  806.         (if (match-string-no-properties 2)
  807.             (replace-match (cdr data) :fixedcase :literal nil 2)
  808.           (replace-match (cdr data) :fixedcase :literal nil 3))
  809.         (replace-match (car data) :fixedcase :literal nil 1))
  810.     (let ((data (endless/ask-for-link)))
  811.       (insert "[" (car data) "](" (cdr data) ")"))))
  812.  
  813. (defun endless/ask-for-link (&optional name link)
  814.   (cons (read-string "Text of the link: " name)
  815.         (read-string "URL of the link: " link)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement