unix-conf/.emacs.el

251 lines
7.8 KiB
EmacsLisp
Raw Normal View History

2016-02-18 13:53:30 +00:00
(require 'iso-transl)
;; Packages
(require 'package) ;; You might already have this line
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/"))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line
2016-02-22 11:25:50 +00:00
(add-to-list 'load-path "~/.emacs.d/one-file-mode/")
2016-02-18 13:53:30 +00:00
;; Encoding
(set-language-environment "UTF-8")
(delete-selection-mode 1)
;; Indentation mode
(setq-default indent-tabs-mode nil)
(setq inhibit-startup-screen t)
(setq tab-width 4)
;; Auto complete
2016-03-03 06:56:09 +00:00
(require 'yasnippet)
2016-02-18 13:53:30 +00:00
(yas-global-mode 1)
2016-03-03 06:56:09 +00:00
(define-key yas-minor-mode-map (kbd "<C-tab>") 'yas-next-field)
2016-02-18 13:53:30 +00:00
2016-03-19 12:38:55 +00:00
(require 'auto-complete)
2016-03-03 06:56:09 +00:00
(require 'auto-complete-config)
2016-02-18 13:53:30 +00:00
(ac-config-default)
2016-03-19 12:38:55 +00:00
;; (require 'auto-complete-clang-async)
2016-02-22 11:25:50 +00:00
(require 'ac-c-headers)
2016-02-18 13:53:30 +00:00
(add-to-list 'ac-modes 'latex-mode) ; make auto-complete aware of `latex-mode`
2016-02-22 11:25:50 +00:00
(add-to-list 'ac-modes 'org-mode)
2016-02-18 13:53:30 +00:00
(require 'ac-math)
(defun ac-cc-mode-setup ()
(add-to-list 'ac-sources 'ac-source-c-headers)
(hs-minor-mode))
2016-02-22 11:25:50 +00:00
(add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
(add-hook 'c++-mode-common-hook 'ac-cc-mode-setup)
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
2016-02-18 13:53:30 +00:00
(defun ac-latex-mode-setup () ; add ac-sources to default ac-sources
(setq ac-sources
(append '(ac-source-math-unicode
ac-source-math-latex
ac-source-latex-commands)
2016-02-22 11:25:50 +00:00
ac-sources)))
2016-02-18 13:53:30 +00:00
2016-02-22 11:25:50 +00:00
(add-hook 'LaTeX-mode-hook 'ac-latex-mode-setup)
2016-02-18 13:53:30 +00:00
2016-02-22 11:25:50 +00:00
(global-auto-complete-mode t)
2016-02-18 13:53:30 +00:00
(setq ac-math-unicode-in-math-p t)
(ac-flyspell-workaround)
;; Latex
(require 'tex-mik)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(defun my-latex-mode-setup ()
"Redefines and updates variables for various customizations."
(setq LaTeX-paragraph-commands
'("If" "State" "Loop" "For" "ForAll"))
(setq LaTeX-begin-regexp
(concat LaTeX-begin-regexp "\\|If\\b" "\\|Loop\\b" "\\|For\\b" "\\|ForAll\\b"))
(setq LaTeX-end-regexp
(concat LaTeX-end-regexp "\\|EndIf\\b" "\\|EndLoop\\b"
"\\|EndFor\\b" "\\|Else\\b" "\\|ElsIf\\b"))
(setq LaTeX-paragraph-commands-regexp (LaTeX-paragraph-commands-regexp-make))
(defun LaTeX-indent-level-count ()
"Count indentation change caused by all \\left, \\right, \\begin, and
\\end commands in the current line."
(save-excursion
(save-restriction
(let ((count 0))
(narrow-to-region (point)
(save-excursion
(re-search-forward
(concat "[^" TeX-esc "]"
"\\(" LaTeX-indent-comment-start-regexp
"\\)\\|\n\\|\\'"))
(backward-char)
(point)))
(while (search-forward TeX-esc nil t)
(cond
((looking-at "left\\b")
(setq count (+ count LaTeX-left-right-indent-level)))
((looking-at "right\\b")
(setq count (- count LaTeX-left-right-indent-level)))
((looking-at LaTeX-begin-regexp)
(setq count (+ count LaTeX-indent-level)))
((looking-at "Else\\b"))
((looking-at "ElsIf\\b"))
((looking-at LaTeX-end-regexp)
(setq count (- count LaTeX-indent-level)))
((looking-at (regexp-quote TeX-esc))
(forward-char 1))))
count)))))
(add-hook 'LaTeX-mode-hook 'my-latex-mode-setup)
2016-02-18 13:53:30 +00:00
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(require 'tex)
(TeX-global-PDF-mode t)
2016-03-03 06:56:09 +00:00
;; C mode
2016-02-18 13:53:30 +00:00
(setq c-default-style "k&r")
(setq c-basic-offset 4)
2016-03-03 06:56:09 +00:00
(setq c-doc-comment-style
'((java-mode . javadoc)
(pike-mode . autodoc)
(c-mode . javadoc)
(c++-mode . javadoc)))
(defun my-cc-init-hook ()
"Initialization hook for CC-mode runs before any other hooks."
(hide-ifdef-mode)
(setq hide-ifdef-shadow t))
(add-hook 'c-mode-hook 'my-cc-init-hook)
(add-hook 'c++-mode-hook 'my-cc-init-hook)
(add-to-list 'auto-mode-alist '("\\.hpp\\'" . c++-mode))
2016-02-18 13:53:30 +00:00
;; CSS style
(setq css-indent-offset 2)
;; No menu, scrollbar, display line and column
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(column-number-mode t)
(line-number-mode t)
;; Markdown mode
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
;; White space mode
(setq whitespace-line-column 100)
(add-hook 'before-save-hook 'whitespace-cleanup)
2016-02-18 13:53:30 +00:00
(add-hook 'python-mode-hook (lambda () (setq whitespace-line-column 140)))
2016-03-03 06:56:09 +00:00
(add-hook 'LaTeX-mode-hook (lambda () (setq whitespace-line-column -1)))
2016-02-18 13:53:30 +00:00
(global-whitespace-mode 1)
;; Electric pair mode
(electric-pair-mode 1)
(show-paren-mode 1)
(setq show-paren-delay 0)
;; Run C programs directly from within emacs
(setq execute-command nil)
(setq compile-command nil)
(setq execute-buffer-name "*output*")
(setq execute-process-name "execute")
(defun set-execute-command ()
(interactive)
(setq sp (split-string (read-from-minibuffer "Execute command: ")))
(setq execute-command (combine-and-quote-strings (cons (file-truename (car sp)) (cdr sp)))))
(defun kill-execute-c-program ()
(interactive)
(if (get-process execute-process-name)
(delete-process (get-process execute-process-name))))
(defun execute-c-program ()
(interactive)
(if (not execute-command) (set-execute-command))
(kill-execute-c-program)
(setq old-buffer (current-buffer))
(setq output-buffer (get-buffer-create execute-buffer-name))
(switch-to-buffer-other-window output-buffer)
(end-of-buffer)
(insert (concat (propertize execute-command 'face 'bold) "\n"))
(switch-to-buffer-other-window old-buffer)
(start-process-shell-command execute-process-name execute-buffer-name execute-command)
)
(defun set-compile-command ()
(interactive)
(setq compile-command (read-from-minibuffer "Compile command: ")))
(defun compile-c-program ()
(interactive)
(if (not compile-command) (set-compile-command))
(compile compile-command))
(defun key-c-mode-setup ()
(local-set-key [f1] 'compile-c-program)
(local-set-key [f2] 'execute-c-program)
(local-set-key [f3] 'kill-execute-c-program)
(local-set-key [f4] 'set-execute-command)
(local-set-key [f5] 'set-compile-command))
(add-hook 'c++-mode-common-hook 'key-c-mode-setup)
(add-hook 'c-mode-common-hook 'key-c-mode-setup)
;; Flyspell dictionarie
(defun fd-switch-dictionary ()
(interactive)
(let* ((dic ispell-current-dictionary)
(change (if (string= dic "francais") "english" "francais")))
(ispell-change-dictionary change)
(message "Dictionary switched from %s to %s" dic change)
))
(defun key-latex-mode-setup ()
(local-set-key [f8] 'fd-switch-dictionary))
(add-hook 'LaTeX-mode-hook 'key-latex-mode-setup)
(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.
'(custom-safe-themes
(quote
("737d9d0e0f6c4279e80f7479ec5138af6e4908a2d052126f254e1e6d1a0d0188" default))))
2016-02-18 13:53:30 +00:00
(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.
)
(load-theme 'hydandata-light)