(defvar *emacs-load-start* (current-time))
(require 'cl)
(defun byte-compile-user-init-file ()
(let ((byte-compile-warnings '(unresolved)))
(when (file-exists-p (concat user-init-file ".elc"))
(delete-file (concat user-init-file ".elc")))
(byte-compile-file user-init-file)
(message "%s compiled" user-init-file)
))
(defun my-emacs-lisp-mode-hook ()
(when (equal buffer-file-name user-init-file)
(add-hook 'after-save-hook 'byte-compile-user-init-file t t)))
(add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook)
(defvar missing-packages-list nil
"List of packages that `try-require' can't find.")
(defun try-require (feature)
"Attempt to load a library or module. Return true if the
library given as argument is successfully loaded. If not, instead
of an error, just add the package to a list of missing packages."
(condition-case err
(progn
(message "Checking for library `%s'..." feature)
(if (stringp feature)
(load-library feature)
(require feature))
(message "Checking for library `%s'... Found" feature))
(file-error (progn
(message "Checking for library `%s'... Missing" feature)
(add-to-list 'missing-packages-list feature))
nil)))
(custom-set-variables
'(LaTeX-command "latex -shell-escape")
'(LaTeX-command-style (quote (("" "%(PDF)%(latex) -file-line-error %S%(PDFout) "))))
'(LaTeX-indent-environment-list (quote (("verbatim" current-indentation) ("verbatim*" current-indentation) ("array") ("displaymath") ("eqnarray") ("eqnarray*") ("equation") ("equation*") ("picture") ("tabbing") ("table") ("table*") ("spreadtab" ignore) ("tabular" ignore) ("tabular*"))))
'(TeX-PDF-mode t)
'(TeX-auto-local ".auctex-auto")
'(TeX-command-list (quote (("TeX" "%(PDF)%(tex) %`%S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (plain-tex-mode texinfo-mode ams-tex-mode) :help "Run plain TeX") ("LaTeX" "%`%l%(mode)%' %t" TeX-run-TeX nil (latex-mode doctex-mode) :help "Run LaTeX") ("Makeinfo" "makeinfo %t" TeX-run-compile nil (texinfo-mode) :help "Run Makeinfo with Info output") ("Makeinfo HTML" "makeinfo --html %t" TeX-run-compile nil (texinfo-mode) :help "Run Makeinfo with HTML output") ("AmSTeX" "%(PDF)amstex %`%S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX") ("ConTeXt" "texexec --once --texutil %(execopts)%t" TeX-run-TeX nil (context-mode) :help "Run ConTeXt once") ("ConTeXt Full" "texexec %(execopts)%t" TeX-run-TeX nil (context-mode) :help "Run ConTeXt until completion") ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX") ("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer") ("Print" "%p" TeX-run-command t t :help "Print the file") ("Queue" "%q" TeX-run-background nil t :help "View the printer queue" :visible TeX-queue-command) ("File" "%(o?)dvips %d -o %f " TeX-run-command t t :help "Generate PostScript file") ("Index" "makeindex %s" TeX-run-command nil t :help "Create index file") ("Check" "lacheck %s" TeX-run-compile nil (latex-mode) :help "Check LaTeX file for correctness") ("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t :help "Spell-check the document") ("Clean" "TeX-clean" TeX-run-function nil t :help "Delete generated intermediate files") ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help "Delete generated intermediate and output files") ("Other" "" TeX-run-command t t :help "Run an arbitrary command"))))
'(TeX-output-view-style (quote (("^dvi$" ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$") "%(o?)dvips -t landscape %d -o && gv %f") ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "%(o?)dvips %d -o && gv %f") ("^dvi$" ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$") "%(o?)xdvi %dS -paper a4r -s 0 %d") ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "%(o?)xdvi %dS -paper a4 %d") ("^dvi$" ("^a5\\(?:comb\\|paper\\)$" "^landscape$") "%(o?)xdvi %dS -paper a5r -s 0 %d") ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d") ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d") ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d") ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d") ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d") ("^dvi$" "." "%(o?)xdvi %dS %d") ("^pdf$" "." "okular %o") ("^html?$" "." "netscape %o"))))
'(TeX-view-program-list (quote (("okular" "okular %o"))))
'(TeX-view-program-selection (quote (((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "okular") (output-html "xdg-open"))))
'(blink-cursor-mode nil)
'(browse-url-browser-function (quote browse-url-default-browser))
'(c-default-style (quote ((c-mode . "K&R") (java-mode . "java") (other . "gnu"))))
'(case-fold-search t)
'(case-replace t)
'(column-number-mode t)
'(compilation-scroll-output (quote first-error))
'(diff-default-read-only t)
'(ediff-window-setup-function (quote ediff-setup-windows-plain))
'(ess-default-style (quote DEFAULT))
'(ess-execute-in-process-buffer t)
'(ess-language "R" t)
'(ffap-url-fetcher (quote browse-url-emacs))
'(fill-column 79)
'(font-latex-fontify-script nil)
'(font-latex-fontify-sectioning (quote color))
'(font-latex-title-fontify (quote color) t)
'(font-lock-maximum-decoration t)
'(frame-title-format "Emacs: %b %+%+ %f" t)
'(gc-cons-threshold 1600000)
'(grep-files-aliases (quote (("all" . "* .*") ("el" . "*.el") ("ch" . "*.cc *.[ch]xx *.[ch]pp *.[cCHh] *.CC *.HH *.[ch]++") ("c" . "*.[ch]") ("cc" . "*.cc *.cxx *.cpp *.C *.CC *.c++") ("cchh" . "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++") ("hh" . "*.hxx *.hpp *.[Hh] *.HH *.h++") ("h" . "*.h") ("l" . "[Cc]hange[Ll]og*") ("m" . "[Mm]akefile*") ("tex" . "*.tex") ("texi" . "*.texi") ("asm" . "*.[sS]"))))
'(highlight-nonselected-windows t)
'(icon-title-format "Emacs - %b" t)
'(inhibit-startup-screen t)
'(initial-frame-alist (quote ((top . 1) (height . 90))))
'(isearch-regexp-lax-whitespace t t)
'(ispell-program-name "aspell")
'(line-number-display-limit-width 1000)
'(line-number-mode 1)
'(markdown-enable-math t)
'(mouse-wheel-mode t nil (mwheel))
'(reftex-extra-bindings t)
'(ring-bell-function (quote ignore) t)
'(safe-local-variable-values (quote ((TeX-master . ACO-MetaHandbook) (LocalWords . Vanzyl) (LocalWords . Tchebycheff) (LocalWords . "Tchebycheff") (ispell-dictionary . "english") (c-file-offsets (c . 0)) (c++-member-init-indent . 8) (TeX-master quote paper) (ispell-dictionary . "british") (auto-fill-mode) (TeX-master . race-test) (ess-indent-level . 2) (ess-continued-statement-offset . 2) (ess-brace-offset . 0) (ess-expression-offset . 4) (ess-else-offset . 0) (ess-brace-imaginary-offset . 0) (ess-continued-brace-offset . 0) (ess-arg-function-offset . 2) (ess-close-brace-offset . 0) (ispell-current-dictionary . british) (LocalWords . parallelized) (TeX-master . automoaco\.tex) (TeX-master . beamaco-csa) (ess-style . DEFAULT) (ess-fancy-comments) (ispell-local-dictionary . british) (Local . british) (bibtex-sort-ignore-string-entries))))
'(scroll-bar-mode (quote right))
'(scroll-step 1)
'(search-whitespace-regexp "[
]+")
'(show-paren-mode t)
'(smerge-command-prefix "")
'(speedbar-frame-parameters (quote ((minibuffer) (width . 20) (border-width . 0) (menu-bar-lines . 0) (tool-bar-lines . 0) (unsplittable . t) (set-background-color "black"))))
'(suggest-key-bindings 10)
'(switch-to-buffer-preserve-window-point t)
'(tool-bar-mode nil)
'(track-eol t)
'(transient-mark-mode t)
'(undo-limit 200000)
'(undo-strong-limit 300000)
'(vc-follow-symlinks nil)
'(vc-make-backup-files t)
'(wc-modeline-format "[%tw words|%tc chars]")
'(which-func-non-auto-modes (quote (bibtex-mode)))
'(whitespace-modes (quote (ada-mode asm-mode autoconf-mode awk-mode c-mode c++-mode cc-mode change-log-mode cperl-mode electric-nroff-mode emacs-lisp-mode f90-mode fortran-mode html-mode html3-mode java-mode jde-mode ksh-mode latex-mode LaTeX-mode lisp-mode m4-mode makefile-mode modula-2-mode nroff-mode objc-mode pascal-mode perl-mode prolog-mode python-mode scheme-mode sgml-mode sh-mode shell-script-mode simula-mode tcl-mode tex-mode texinfo-mode vrml-mode xml-mode bibtex-mode))))
(if (not (fboundp 'Xlaunch))
(defmacro Xlaunch (&rest x)
(list 'if (eq window-system 'x)(cons 'progn x)))
(message ".emacs: Xlaunch already defined!"))
(Xlaunch
(setq default-frame-alist
'(
(icon-type . t)
(cursor-color . "Orchid")
(mouse-color . "Orchid")
))
(set-face-attribute 'default nil
:family "Terminus"
:height 120
:weight 'normal
:width 'normal
:foreground "Wheat"
:background "DarkSlateGray")
(setq mode-line-end-spaces (make-string 1024 ?─))
(setq-default mode-line-position
`((-3 ,(propertize
"%p"
'mouse-face 'mode-line-highlight
'help-echo "Relative position"))
(size-indication-mode
(8 ,(propertize
" of %I"
'mouse-face 'mode-line-highlight
'help-echo "Relative position")))
(line-number-mode
((column-number-mode
(10 ,(propertize
" %l:%c"
'mouse-face 'mode-line-highlight
'help-echo "Line number and Column number"))
(6 ,(propertize
" L%l"
''mouse-face 'mode-line-highlight
'help-echo "Line Number"))))
((column-number-mode
(5 ,(propertize
" C%c"
'mouse-face 'mode-line-highlight
'help-echo "Column number")))))))
(make-face 'mode-line-read-only-face)
(set-face-attribute 'mode-line-read-only-face nil
:inherit 'mode-line-face
:foreground "#4271ae"
)
(make-face 'mode-line-modified-face)
(set-face-attribute 'mode-line-modified-face nil
:inherit 'mode-line-face
:foreground "#c82829"
)
(setq-default mode-line-modified
(list `(:eval (if (buffer-modified-p)
(propertize "MM" 'face 'mode-line-modified-face
'help-echo "Buffer is modified")
(propertize
(if buffer-read-only "RO" " ")
'face 'mode-line-read-only-face
'help-echo (purecopy (lambda (window object point)
(format "Buffer is %s\nmouse-1 toggles"
(save-selected-window
(select-window window)
(if buffer-read-only
"read-only" "writable")))))
'local-map (purecopy (make-mode-line-mouse-map
'mouse-1 #'mode-line-toggle-read-only))
'mouse-face 'mode-line-highlight
)))
":"))
)
(custom-set-faces
'(diff-added ((t (:foreground "#44DD11"))))
'(diff-context ((t nil)))
'(diff-file-header ((((class color) (min-colors 88) (background dark)) (:foreground "gray"))))
'(diff-function ((t (:foreground "gray"))))
'(diff-header ((((class color) (min-colors 88) (background dark)) (:foreground "gray"))))
'(diff-hunk-header ((t (:foreground "gray"))))
'(diff-nonexistent ((t (:inherit diff-file-header :strike-through nil))))
'(diff-refine-change ((((class color) (min-colors 88) (background dark)) (:background "#182042"))))
'(diff-removed ((t (:foreground "#FF3300"))))
'(mode-line ((((class color) (min-colors 88)) (:background "grey75" :foreground "black" :box (:line-width -1 :style released-button))))))
(if (not window-system)
(progn (menu-bar-mode nil)
(when (try-require 'color-theme)
(color-theme-initialize)
(color-theme-dark-laptop))))
(require 'font-lock)
(if (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))
(which-function-mode t) (setq which-func-maxout 0) (fset 'yes-or-no-p 'y-or-n-p) (setq use-dialog-box nil)(setq use-file-dialog nil)
(when (fboundp 'windmove-default-keybindings)
(progn
(global-set-key (kbd "C-x C-<left>") 'windmove-left)
(global-set-key (kbd "C-x C-<right>") 'windmove-right)
(global-set-key (kbd "C-x C-<up>") 'windmove-up)
(global-set-key (kbd "C-x C-<down>") 'windmove-down)))
(defvar last-different-window nil "")
(defvar last-selected-window nil "")
(setq last-different-window nil)
(setq last-selected-window (selected-window))
(defadvice select-window (before update-last-window (window &optional norecord) activate)
"Record the last-selected-window that was different"
(let ((curr (selected-window)))
(if (and (not (equal window last-selected-window))
(not (equal window curr))
(window-live-p curr))
(setq last-different-window curr))
(setq last-selected-window curr))
)
(defun select-next-window ()
"Switch to the next window"
(interactive)
(select-window (next-window)))
(defun select-previous-window ()
"Switch to the previous window"
(interactive)
(select-window (previous-window)))
(defun switch-windows ()
"Switch to the previously selected window"
(interactive)
(if (or (equal last-different-window (selected-window))
(not (window-live-p last-different-window))
(and (window-minibuffer-p last-different-window)
(not (minibuffer-window-active-p last-different-window))))
(progn
(message "next-window (%s)" (next-window))
(select-window (next-window)))
(progn
(message "last-different-window (%s)" last-different-window)
(select-window last-different-window))
))
(defun other-window-reverse ()
"Switch to other window in reverse order"
(interactive)
(other-window -1))
(global-set-key "\C-o" 'select-previous-window)
(global-set-key "\C-x\C-o" 'select-next-window)
(global-set-key "\C-xo" 'switch-windows)
(defun close-and-kill-next-pane ()
"Close the other pane and kill the buffer in it also."
(interactive)
(other-window 1)
(kill-buffer)
(delete-window)
)
(defun close-and-kill-this-pane ()
"Close this pane and kill the buffer in it also."
(interactive)
(kill-buffer)
(delete-window)
)
(prefer-coding-system 'utf-8)
(Xlaunch (define-key global-map [(delete)] "\C-d"))
(when (member (getenv "TERM") '("linux" "xterm"))
(dolist (prefix '("\eO" "\eO1;" "\e[1;"))
(dolist (m '(("2" . "S-") ("3" . "M-") ("4" . "S-M-") ("5" . "C-")
("6" . "S-C-") ("7" . "C-M-") ("8" . "S-C-M-")))
(dolist (k '(("A" . "<up>") ("B" . "<down>") ("C" . "<right>")
("D" . "<left>") ("H" . "<home>") ("F" . "<end>")))
(define-key function-key-map
(concat prefix (car m) (car k))
(read-kbd-macro (concat (cdr m) (cdr k))))))))
(if (not (fboundp 'x-own-selection))
(defun x-own-selection (s) (x-set-selection `PRIMARY s))
(message ".emacs: x-own-selection already defined!"))
(global-set-key [(shift insert)] '(lambda () (interactive)
(insert (x-get-selection))))
(global-set-key [(control insert)] '(lambda () (interactive)
(x-own-selection (buffer-substring (point) (mark)))))
(global-set-key [(control tab)] `other-window)
(global-set-key [(meta g)] `goto-line)
(defun switch-to-other-buffer ()
(interactive) (switch-to-buffer (other-buffer) 1))
(global-set-key [(meta control ?l)] `switch-to-other-buffer)
(global-set-key [(meta O) ?H] 'beginning-of-line)
(global-set-key [(meta O) ?F] 'end-of-line)
(global-set-key (kbd "<backtab>") 'tab-to-tab-stop)
(defun recompile-quietly ()
"Re-compile without changing the window configuration."
(interactive)
(save-window-excursion
(recompile)))
(defun compile-again (pfx)
"Run the same compile as the last time. If there was no last time, or there is a prefix argument, this acts like M-x compile."
(interactive "p")
(save-window-excursion
(if (and (eq pfx 1)
compilation-last-buffer)
(progn
(set-buffer compilation-last-buffer)
(revert-buffer t t))
(call-interactively 'compile))))
(setq compilation-last-buffer nil)
(define-key global-map [f5] 'compile-again)
(define-key global-map [f6] 'isearch-repeat-forward)
(define-key global-map [f10] 'wrap-up)
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key [(control home)] 'beginning-of-buffer)
(global-set-key [(control end)] 'end-of-buffer)
(global-set-key [(control next)] 'scroll-other-window)
(global-set-key [(control prior)] 'scroll-other-window-down)
(global-set-key [(control shift z)] 'redo)
(global-unset-key "\C-x\C-z")
(global-set-key "\C-x\C-b" 'electric-buffer-list)
(defun swap-compile-comment-keys ()
"Swap compile and commen-region keybindings"
(local-unset-key "\C-c\C-c")
(local-unset-key "\C-cc")
(local-set-key "\C-c\C-c" 'compile)
(local-set-key "\C-cc" 'comment-region)
)
(defun compilation-mode-keys ()
""
(local-set-key "\C-c`" 'next-error-no-select)
)
(add-hook 'makefile-mode-hook 'swap-compile-comment-keys)
(add-hook 'compilation-mode-hook 'compilation-mode-keys)
(add-hook 'c++-mode-hook 'compilation-mode-keys)
(add-hook 'c-mode-hook 'compilation-mode-keys)
(add-hook 'makefile-mode-hook 'compilation-mode-keys)
(defun my-smerge-keys ()
""
(local-set-key "\C-csn" 'smerge-next)
(local-set-key "\C-csp" 'smerge-prev)
(local-set-key "\C-cs+" 'smerge-refine)
)
(add-hook 'smerge-mode-hook 'my-smerge-keys)
(defun nxml-mode-keys()
""
(local-unset-key "\C-c\C-f")
(local-set-key "\C-c]" 'nxml-finish-element)
)
(add-hook 'nxml-mode-hook 'nxml-mode-keys)
(add-to-list 'auto-mode-alist '("TODO\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(global-set-key "\C-cg" 'goto-line)
(global-set-key "\C-x\C-r" 'revert-buffer)
(global-set-key [(control ?()] 'forward-sexp)
(global-set-key [(control ?))] 'backward-sexp)
(global-unset-key (read-kbd-macro "C-M-SPC"))
(defun shuffle-lines (beg end)
"Scramble all the lines in region defined by BEG END
If region contains less than 2 lines, lines are left untouched."
(interactive "*r")
(catch 'cancel
(save-restriction
(narrow-to-region beg end)
(if (< (- (point-max) (point-min)) 3)
(throw 'cancel t))
(goto-char (point-min))
(while (not (eobp))
(insert (int-to-string (random 32000)) " ")
(forward-line 1))
(sort-numeric-fields 1 (point-min) (point-max))
(goto-char (point-min)) (while (not (eobp))
(delete-region (point) (progn (forward-word 1) (+ (point) 1)))
(forward-line 1))
)))
(global-set-key [(control s)] 'isearch-forward-regexp)
(global-set-key [(control r)] 'isearch-backward-regexp)
(global-set-key [(control c)(meta %)] 'query-replace-regexp)
(defalias 'cr 'comment-region)
(defalias 'ucr 'uncomment-region)
(defalias 'rr 'replace-rectangle)
(defun move-line (&optional n)
"Move current line N (1) lines up/down leaving point in place."
(interactive "p")
(when (null n)
(setq n 1))
(let ((col (current-column)))
(beginning-of-line)
(forward-line)
(transpose-lines n)
(forward-line -1)
(forward-char col))
(indent-according-to-mode))
(defun move-line-up (n)
"Moves current line N (1) lines up leaving point in place."
(interactive "p")
(move-line (if (null n) -1 (- n))))
(defun move-line-down (n)
"Moves current line N (1) lines down leaving point in place."
(interactive "p")
(move-line (if (null n) 1 n)))
(defun move-region (start end n)
"Move the current region up or down by N lines."
(interactive "r\np")
(let ((line-text (delete-and-extract-region start end)))
(forward-line n)
(let ((start (point)))
(insert line-text)
(setq deactivate-mark nil)
(set-mark start))))
(defun move-region-up (start end n)
"Move the current region up by N lines."
(interactive "r\np")
(move-region start end (if (null n) -1 (- n))))
(defun move-region-down (start end n)
"Move the current region down by N lines."
(interactive "r\np")
(move-region start end (if (null n) 1 n)))
(defun move-line-region-up (start end n)
(interactive "r\np")
(if (region-active-p) (move-region-up start end n) (move-line-up n)))
(defun move-line-region-down (start end n)
(interactive "r\np")
(if (region-active-p) (move-region-down start end n) (move-line-down n)))
(global-set-key [(meta up)] 'move-line-region-up)
(global-set-key [(meta down)] 'move-line-region-down)
(when (try-require 'rect)
(defun copy-rectangle-as-kill (start end)
"Copy rectangle with corners at point and mark; save as last
killed one. Calling from program, supply two args START and END,
buffer positions. But in programs you might prefer to use
`extract-rectangle'."
(interactive "r")
(setq killed-rectangle (extract-rectangle start end))
(message "Rectangle saved."))
(global-set-key "\C-xrw" 'copy-rectangle-as-kill)
)
(defun insert-date-string ()
"Insert a nicely formatted date string."
(interactive)
(insert (format-time-string "%Y-%m-%d")))
(defun delete-horizontal-space-forward ()
"*Delete all spaces and tabs after point."
(interactive "*")
(delete-region (point) (progn (skip-chars-forward " \t") (point))))
(global-set-key "\M- " 'delete-horizontal-space-forward)
(setq diff-switches "-u")
(defun rename-file-and-buffer ()
"Rename the current buffer and file it is visiting."
(interactive)
(let ((filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(message "Buffer is not visiting a file!")
(let ((new-name (read-file-name "New name: " filename)))
(cond
((vc-backend filename) (vc-rename-file filename new-name))
(t
(rename-file filename new-name t)
(set-visited-file-name new-name t t)))))))
(setq-default major-mode (lambda () (text-mode) (font-lock-mode t)))
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'sgml-mode-hook 'turn-off-auto-fill)
(add-hook 'nxml-mode-hook 'turn-off-auto-fill)
(add-hook 'text-mode-hook 'turn-on-flyspell)(add-hook 'autoconf-mode-hook 'flyspell-prog-mode)
(add-hook 'autotest-mode-hook 'flyspell-prog-mode)
(add-hook 'c++-mode-hook 'flyspell-prog-mode)
(add-hook 'c-mode-hook 'flyspell-prog-mode)
(add-hook 'cperl-mode-hook 'flyspell-prog-mode)
(add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode)
(add-hook 'makefile-mode-hook 'flyspell-prog-mode)
(add-hook 'nxml-mode-hook 'flyspell-prog-mode)
(add-hook 'python-mode-hook 'flyspell-prog-mode)
(add-hook 'sh-mode-hook 'flyspell-prog-mode)
(add-hook 'ess-mode-hook 'flyspell-prog-mode)
(setq next-line-add-newlines nil)
(setq-default indent-tabs-mode nil)
(auto-compression-mode t)
(put 'downcase-region 'disabled nil)
(setq load-path
(cons (concat (getenv "HOME") "/.emacs.d/")
(cons "/usr/local/share/emacs/site-lisp/" load-path)))
(if (< emacs-major-version 24)
(when (try-require 'per-window-point)
(pwp-mode 1)))
(when (try-require 'fill-column-indicator)
(setq-default fci-rule-column 80)
(add-hook 'prog-mode-hook 'fci-mode)
(add-hook 'ess-mode-hook 'fci-mode)
(add-hook 'text-mode-hook 'fci-mode)
(add-hook 'diff-mode-hook 'fci-mode)
)
(add-hook 'gdb-mode-hook 'compilation-shell-minor-mode)
(when (try-require 'autopair)
(autopair-global-mode) (setq autopair-autowrap t) )
(when (try-require 'ess-site)
(setq ess-fancy-comments nil)
(setq ess-use-tracebug t)
(setq ess-tracebug-prefix "\M-c")
(setq ess-eval-visibly-p nil)
(setq ess-ask-for-ess-directory nil)
(setq ess-local-process-name "R")
(setq ansi-color-for-comint-mode 'filter)
(setq comint-scroll-to-bottom-on-input t)
(setq comint-scroll-to-bottom-on-output t)
(setq comint-move-point-for-output t)
(defun my-ess-start-R ()
(interactive)
(if (not (member "*R*" (mapcar (function buffer-name) (buffer-list))))
(progn
(delete-other-windows)
(setq w1 (selected-window))
(setq w1name (buffer-name))
(setq w2 (split-window w1 nil t))
(R)
(set-window-buffer w2 "*R*")
(set-window-buffer w1 w1name))))
(defun my-ess-eval ()
(interactive)
(my-ess-start-R)
(if (and transient-mark-mode mark-active)
(call-interactively 'ess-eval-region)
(call-interactively 'ess-eval-line-and-step)))
(defun my-ess-mode-keys ()
(local-set-key [(shift return)] 'my-ess-eval)
)
(defun my-inferior-ess-mode-keys ()
(local-set-key [C-up] 'comint-previous-input)
(local-set-key [C-down] 'comint-next-input)
)
(add-hook 'ess-mode-hook 'my-inferior-ess-mode-keys)
(add-hook 'inferior-ess-mode-hook 'my-inferior-ess-mode-keys)
(add-hook 'Rnw-mode-hook 'my-inferior-ess-mode-keys)
)
(defadvice find-tag (around refresh-etags activate)
"Rerun etags and reload tags if tag not found and redo find-tag.
If buffer is modified, ask about save before running etags."
(let ((extension (file-name-extension (buffer-file-name))))
(condition-case err
ad-do-it
(error (and (buffer-modified-p)
(not (ding))
(y-or-n-p "Buffer is modified, save it? ")
(save-buffer))
(refresh-etags extension)
ad-do-it))))
(defun refresh-etags (&optional extension)
"Run etags on all peer files in current dir and reload them silently."
(interactive)
(shell-command (format "etags *.%s" (or extension "el")))
(let ((tags-revert-without-query t)) (visit-tags-table default-directory nil)))
(setq revert-without-query (cons "TAGS" revert-without-query))
(when (try-require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)
(setq uniquify-after-kill-buffer-p t)
)
(defun uniquify-all-lines-region (start end)
"Find duplicate lines in region START to END keeping first occurrence."
(interactive "*r")
(save-excursion
(let ((end (copy-marker end)))
(while
(progn
(goto-char start)
(re-search-forward "^\\(.*\\)\n\\(\\(.*\n\\)*\\)\\1\n" end t))
(replace-match "\\1\n\\2")))))
(defun uniquify-all-lines-buffer ()
"Delete duplicate lines in buffer and keep first occurrence."
(interactive "*")
(uniquify-all-lines-region (point-min) (point-max)))
(when (try-require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t) (setq ido-everywhere t) (setq ido-use-filename-at-point 'guess) (add-hook 'ido-setup-hook 'ido-my-keys)
(defun ido-my-keys ()
"Add my keybindings for ido."
(define-key ido-file-dir-completion-map [C-return] 'ido-enter-dired)
(define-key ido-file-dir-completion-map [down] 'ido-next-work-directory)
(define-key ido-file-dir-completion-map [up] 'ido-prev-work-directory)
)
)
(when (try-require 'wc-mode)
(global-set-key "\C-cw" 'wc-mode)
)
(when (try-require 'ffap) (global-set-key [S-mouse-3] 'ffap-at-mouse)
(global-set-key [C-S-mouse-3] 'ffap-menu)
(global-set-key "\C-xf" 'find-file-at-point)
)
(eval-after-load "flyspell"
'(progn
(define-key flyspell-mouse-map [mouse-2] #'undefined)
(define-key flyspell-mouse-map [down-mouse-2] #'mouse-yank-primary)
(define-key flyspell-mouse-map [down-mouse-3] #'flyspell-correct-word)
(define-key flyspell-mouse-map [mouse-3] #'undefined)))
(when (try-require 'savehist)
(savehist-mode t))
(autoload 'tidy-buffer "tidy" "Run Tidy HTML parser on current buffer" t)
(autoload 'tidy-parse-config-file "tidy" "Parse the `tidy-config-file'" t)
(autoload 'tidy-save-settings "tidy" "Save settings to `tidy-config-file'" t)
(autoload 'tidy-build-menu "tidy" "Install an options menu for HTML Tidy." t)
(defun my-html-helper-mode-hook () "Customize my html-helper-mode."
(tidy-build-menu html-helper-mode-map)
(local-set-key [(control c) (control c)] 'tidy-buffer)
(setq sgml-validate-command "tidy")
(tidy-build-menu))
(defun my-html-mode-hook () "Customize my html-mode."
(tidy-build-menu html-mode-map)
(local-set-key [(control c) (control c)] 'tidy-buffer)
(setq sgml-validate-command "tidy")
(tidy-build-menu)
(set (make-local-variable 'time-stamp-active) t)
(set (make-local-variable 'time-stamp-pattern)
"-20/Last modified:[\t ]+%:d %:b %Y[\n\t ]*<!-- hhmts end -->")
)
(add-hook 'html-helper-mode-hook 'my-html-helper-mode-hook)
(add-to-list 'magic-mode-alist
'("\\(?:<\\?xml\\s +[^>]*>\\)?\\s *<\\(?:!--\\(?:[^-]\\|-[^-]\\)*-->\\s *<\\)*\\(?:!DOCTYPE\\s +[^>]*>\\s *<\\s *\\(?:!--\\(?:[^-]\\|-[^-]\\)*-->\\s *\<\\)*\\)?[Hh][Tt][Mm][Ll]"
. html-mode))
(defun html-helper-custom-insert-timestamp ()
"Custom timestamp insertion function."
(insert "Last modified: ")
(insert (format-time-string "%e %B %Y")))
(setq html-helper-timestamp-hook 'html-helper-custom-insert-timestamp)
(eval-after-load 'sgml-mode
'(add-hook 'html-mode-hook 'my-html-mode-hook))
(add-hook 'write-file-hooks 'time-stamp)
(setq cssm-indent-level 4)
(setq cssm-newline-before-closing-bracket t)
(setq cssm-indent-function 'cssm-c-style-indenter)
(setq cssm-mirror-mode nil)
(setq
auto-save-interval 60 auto-save-timeout nil
)
(add-hook 'gud-mode-hook 'turn-off-auto-fill)
(defun clear-comint-buffer()
(interactive)
(delete-region (point-min)
(save-excursion
(goto-char (point-max))
(forward-line 0)
(point))))
(when (try-require 'tex-site)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil) (setq LaTeX-default-options "a4paper")
(setq font-latex-title-fontify 'color)
(defun LaTeX-insert-footnote ()
"Insert a \\footnote{} macro in a LaTeX-document."
(interactive)
(TeX-insert-macro "footnote"))
(defun LaTeX-insert-note ()
"Insert a \\note{} macro in a LaTeX-document."
(interactive)
(TeX-insert-macro "note"))
(defun LaTeX-insert-index ()
"Insert a \\index{} macro in a LaTeX-document."
(interactive)
(TeX-insert-macro "index"))
(defun my-auctex-settings ()
"Some local modifications to AucTeX variables."
(setq TeX-master nil) )
(defvar LaTeX-mode-setup-hook nil
"Hook for things to do before LaTeX-mode is defined.")
(defadvice latex-mode (before latex-mode-setup-advice)
(run-hooks 'LaTeX-mode-setup-hook))
(add-hook 'LaTeX-mode-setup-hook 'my-auctex-settings t)
(defun my-auctex-keys ()
"Some local modifications to AucTeX keybindings."
(local-set-key "\C-cf" 'LaTeX-insert-footnote)
(local-set-key "\C-cn" 'LaTeX-insert-note)
(local-set-key [(control s)] 'isearch-forward-regexp)
(local-set-key [(control meta s)] 'isearch-forward)
(local-set-key [(control r)] 'isearch-backward-regexp)
(local-set-key [(control meta r)] 'isearch-backward)
(define-key LaTeX-mode-map "\C-ci" 'latex-help)
)
(defun my-latex-add-ons ()
"Anything you ever wanted in LaTeX-mode."
(try-require 'bib-cite)
(try-require 'font-latex)
(my-auctex-keys)
(local-set-key [mouse-3] 'reftex-mode-menu)
(setq
reftex-enable-partial-scans t reftex-save-parse-info t reftex-use-multiple-selection-buffers t reftex-plug-into-AUCTeX t reftex-extra-bindings t )
(turn-on-reftex)
(turn-off-auto-fill)
(defvar LaTeX-align-current-environments
(mapcar 'car '(("tabbing")
("spreadtab")
("tabular")
("tabular*")))
"List of LaTeX environments to do align.")
(defun LaTeX-align-or-fill-function (&optional justify)
"Variant of 'fill-paragraph-function' based on current
environment. In tabular-like environments, align
columns. Otherwise, fill as normal."
(interactive "P")
(if (member (LaTeX-current-environment)
LaTeX-align-current-environments)
(save-excursion
(LaTeX-mark-environment)
(align-current) t)
(LaTeX-fill-paragraph)))
(setq fill-paragraph-function 'LaTeX-align-or-fill-function)
(message "Making private modifications ..."))
(add-hook 'LaTeX-mode-hook 'my-latex-add-ons)
(add-hook 'TeX-mode-hook 'turn-off-auto-fill)
)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(autoload 'javascript-mode "javascript" nil t)
(setq javascript-indent-level 8)
(c-add-style
"my-c-common-style"
'("k&r"
(c-basic-offset . 4)
(c-set-offset 'case-label 2)
))
(defun my-c-mode-common-hook ()
"C/C++ mode with adjusted defaults."
(c-set-style "my-c-common-style")
(setq c++-tab-always-indent t)
(setq c-backslash-column 79)
(setq c-backslash-max-column 79)
(c-set-offset 'case-label 2)
(c-set-offset 'inextern-lang 0) (c-set-offset 'inline-open 0) (c-set-offset 'innamespace 0) (message "Loading my-c-common-mode-hook...")
(swap-compile-comment-keys)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel."
(interactive)
(c-mode)
(c-set-style "k&r")
(setq c-basic-offset 3)
(swap-compile-comment-keys)
(message "Loading linux-c-mode...")
)
(defun gcc-c-mode-hook ()
"C mode for GCC development."
(which-function-mode t) (setq which-func-maxout 0) (c-set-style "gnu")
(setq c-basic-offset 2)
(c-set-offset 'inline-open 0)
(setq-default indent-tabs-mode t)
(swap-compile-comment-keys)
(message "Loading gcc-c-mode...")
)
(defun gcc-c-mode ()
"C mode for GCC development."
(interactive)
(remove-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(add-hook 'c-mode-common-hook 'gcc-c-mode-hook)
(text-mode)
(c-mode)
)
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(defun my-gnuplot-mode-keys ()
(define-key gnuplot-mode-map "\C-c\C-c" 'gnuplot-send-buffer-to-gnuplot))
(eval-after-load "gnuplot"
(add-hook 'gnuplot-mode-hook 'my-gnuplot-mode-keys))
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
(defun n-cperl-mode-hook ()
"cPerl mode with adjusted defaults."
(setq cperl-indent-level 4)
(setq cperl-continued-statement-offset 0)
(setq cperl-extra-newline-before-brace t)
(set-face-background 'cperl-array-face "dark slate gray")
(set-face-background 'cperl-hash-face "dark slate gray")
)
(add-hook 'cperl-mode-hook 'n-cperl-mode-hook t)
(setq cperl-invalid-face (quote off))
(defun find-non-ascii ()
"Find any non-ascii characters in the current buffer."
(interactive)
(occur "[^[:ascii:]]"))
(defun count-words-region (beginning end)
"Print number of words in the region."
(interactive "r")
(message "Counting words in region ... ")
(save-excursion
(let ((count 0))
(goto-char beginning)
(while (and (< (point) end)
(re-search-forward "\\w+\\W*" end t))
(setq count (1+ count)))
(cond ((zerop count)
(message
"The region does NOT have any words."))
((= 1 count)
(message
"The region has 1 word."))
(t
(message
"The region has %d words." count)))))
)
(when (try-require 'printing) (pr-update-menus t))
(fset 'pump_replace
[?\C- C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right C-right ?\C-w down C-right ? ?\C-y ?\C-k ?\C- home ?\C-w delete up return up ?\C-y home down])
(if missing-packages-list
(progn (message "Packages not found: %S"
(nreverse missing-packages-list))))