terdon

.emacs

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