;;---------------------------------------------------------------------------- ;; Melpa repository ;;---------------------------------------------------------------------------- (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) (package-initialize) ;;-------------------------------------------------------------------------- ;; UTF-8 ;;-------------------------------------------------------------------------- (prefer-coding-system 'utf-8) (set-default-coding-systems 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) ; backwards compatibility as default-buffer-file-coding-system ; is deprecated in 23.2. (if (boundp 'buffer-file-coding-system) (setq-default buffer-file-coding-system 'utf-8) (setq default-buffer-file-coding-system 'utf-8)) ; Treat clipboard input as UTF-8 string first; compound text next, etc. (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)) ;;---------------------------------------------------------------------------- ;; Set auto-mode-alist ;; (taken from http://www.dotemacs.de/dotfiles/ElijahDaniel.emacs.html) ;;---------------------------------------------------------------------------- (setq auto-mode-alist '(("\\.[Cc][Oo][Mm]\\'" . text-mode) ("\\.bat\\'" . bat-generic-mode) ("\\.inf\\'" . inf-generic-mode) ("\\.rc\\'" . rc-generic-mode) ("\\.reg\\'" . reg-generic-mode) ("\\.cob\\'" . cobol-mode) ("\\.cbl\\'" . cobol-mode) ("\\.te?xt\\'" . text-mode) ("\\.c\\'" . c-mode) ("\\.h\\'" . c++-mode) ("\\.tex$" . LaTeX-mode) ("\\.sty$" . LaTeX-mode) ("\\.bbl$" . LaTeX-mode) ("\\.bib$" . BibTeX-mode) ("\\.el\\'" . emacs-lisp-mode) ("\\.scm\\'" . scheme-mode) ("\\.l\\'" . lisp-mode) ("\\.lisp\\'" . lisp-mode) ("\\.f\\'" . fortran-mode) ("\\.F\\'" . fortran-mode) ("\\.for\\'" . fortran-mode) ("\\.p\\'" . pascal-mode) ("\\.pas\\'" . pascal-mode) ("\\.ad[abs]\\'" . ada-mode) ("\\.\\([pP][Llm]\\|al\\)\\'" . perl-mode) ("\\.s?html?\\'" . html-helper-mode) ("\\.idl\\'" . c++-mode) ("\\.cc\\'" . c++-mode) ("\\.hh\\'" . c++-mode) ("\\.hpp\\'" . c++-mode) ("\\.C\\'" . c++-mode) ("\\.H\\'" . c++-mode) ("\\.cpp\\'" . c++-mode) ("\\.[cC][xX][xX]\\'" . c++-mode) ("\\.hxx\\'" . c++-mode) ("\\.c\\+\\+\\'" . c++-mode) ("\\.h\\+\\+\\'" . c++-mode) ("\\.m\\'" . objc-mode) ("\\.java\\'" . java-mode) ("\\.ma?k\\'" . makefile-mode) ("\\(M\\|m\\|GNUm\\)akefile\\(\\.in\\)?" . makefile-mode) ("\\.am\\'" . makefile-mode) ("\\.mms\\'" . makefile-mode) ("\\.texinfo\\'" . texinfo-mode) ("\\.te?xi\\'" . texinfo-mode) ("\\.s\\'" . asm-mode) ("\\.S\\'" . asm-mode) ("\\.asm\\'" . asm-mode) ("ChangeLog\\'" . change-log-mode) ("change\\.log\\'" . change-log-mode) ("changelo\\'" . change-log-mode) ("ChangeLog\\.[0-9]+\\'" . change-log-mode) ("changelog\\'" . change-log-mode) ("changelog\\.[0-9]+\\'" . change-log-mode) ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) ("\\.scm\\.[0-9]*\\'" . scheme-mode) ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode) ("\\(/\\|\\`\\)\\.\\(bash_profile\\|z?login\\|bash_login\\|z?logout\\)\\'" . sh-mode) ("\\(/\\|\\`\\)\\.\\(bash_logout\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode) ("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode) ("\\.mm\\'" . nroff-mode) ("\\.me\\'" . nroff-mode) ("\\.ms\\'" . nroff-mode) ("\\.man\\'" . nroff-mode) ("\\.[12345678]\\'" . nroff-mode) ("\\.TeX\\'" . TeX-mode) ("\\.sty\\'" . LaTeX-mode) ("\\.cls\\'" . LaTeX-mode) ("\\.clo\\'" . LaTeX-mode) ("\\.bbl\\'" . LaTeX-mode) ("\\.bib\\'" . BibTeX-mode) ("\\.m4\\'" . m4-mode) ("\\.mc\\'" . m4-mode) ("\\.mf\\'" . metafont-mode) ("\\.mp\\'" . metapost-mode) ("\\.vhdl?\\'" . vhdl-mode) ("\\.article\\'" . text-mode) ("\\.letter\\'" . text-mode) ("\\.tcl\\'" . tcl-mode) ("\\.exp\\'" . tcl-mode) ("\\.itcl\\'" . tcl-mode) ("\\.itk\\'" . tcl-mode) ("\\.icn\\'" . icon-mode) ("\\.sim\\'" . simula-mode) ("\\.mss\\'" . scribe-mode) ("\\.f90\\'" . f90-mode) ("\\.lsp\\'" . lisp-mode) ("\\.awk\\'" . awk-mode) ("\\.prolog\\'" . prolog-mode) ("\\.tar\\'" . tar-mode) ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|jar\\)\\'" . archive-mode) ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\|JAR\\)\\'" . archive-mode) ("\\`/tmp/Re" . text-mode) ("/Message[0-9]*\\'" . text-mode) ("/drafts/[0-9]+\\'" . mh-letter-mode) ("\\.zone\\'" . zone-mode) ("\\`/tmp/fol/" . text-mode) ("\\.y\\'" . c-mode) ("\\.lex\\'" . c-mode) ("\\.oak\\'" . scheme-mode) ("\\.sgml?\\'" . sgml-mode) ("\\.xml\\'" . sgml-mode) ("\\.dtd\\'" . sgml-mode) ("\\.ds\\(ss\\)?l\\'" . dsssl-mode) ("\\.idl\\'" . c++-mode) ("[]>:/\\]\\..*emacs\\'" . emacs-lisp-mode) ("\\`\\..*emacs\\'" . emacs-lisp-mode) ("[:/]_emacs\\'" . emacs-lisp-mode) ("\\.py\\'" . python-mode) ("\\.ml\\'" . lisp-mode))) ;;---------------------------------------------------------------------------- ;; Implementing favourite directories in Emacs. ;;---------------------------------------------------------------------------- (defvar drkm-fav:favourite-directories-alist ; '(("saxon-src" . "y:/Saxon/saxon-resources9-0-0-1/source/net/sf/saxon") ; ("kernow-src" . "~/xslt/kernow/svn-2007-09-29/kernow/trunk/src/net/sf/kernow")) '(("latex-code" . "~/Documents/latex") ("river-valley" . "~/Documents/latex/typotexnica/rv/git/classes-rv/")) "See `drkm-fav:handler'.") (defvar drkm-fav::fav-dirs-re ;; TODO: Is tehre really no other way (than mapcar) to get the list ;; of the keys of an alist?!? (concat "^@" (regexp-opt (mapcar 'car drkm-fav:favourite-directories-alist) t)) "Internal variable that stores a regex computed from `drkm-fav:favourite-directories-alist'. WARNING: This is not updated automatically if the later variable is changed.") (defun drkm-fav:handler (primitive &rest args) "Magic handler for favourite directories. With this handler installed into `file-name-handler-alist', it is possible to use shortcuts for often used directories. It uses the mapping in the alist `drkm-fav:favourite-directories-alist'. Once installed, say you have the following alist in the mapping variable: ((\"dir-1\" . \"~/some/real/dir\") (\"dir-2\" . \"c:/other/dir/for/windows/users\")) You can now use \"@dir-1\" while opening a file with C-x C-f for instance, with completion for the abbreviation names themselves as well as for files under the target directory." (cond ;; expand-file-name ((and (eq primitive 'expand-file-name) (string-match drkm-fav::fav-dirs-re (car args))) (replace-match (cdr (assoc (match-string 1 (car args)) drkm-fav:favourite-directories-alist)) t t (car args))) ;; file-name-completion ((and (eq primitive 'file-name-completion) (string-match "^@\\([^/]*\\)$" (car args))) (let ((compl (try-completion (match-string 1 (car args)) drkm-fav:favourite-directories-alist))) (cond ((eq t compl) (concat "@" (match-string 1 (car args)) "/")) ((not compl) nil) (t (concat "@" compl))))) ;; file-name-all-completions ((and (eq primitive 'file-name-all-completions) (string-match "^@\\([^/]*\\)$" (car args))) (all-completions (match-string 1 (car args)) drkm-fav:favourite-directories-alist)) ;; Handle any primitive we don't know about (from the info node ;; (info "(elisp)Magic File Names")). (t (let ((inhibit-file-name-handlers (cons 'drkm-fav:handler (and (eq inhibit-file-name-operation primitive) inhibit-file-name-handlers))) (inhibit-file-name-operation primitive)) (apply primitive args))))) ;; Actually plug the feature into Emacs. (push '("\\`@" . drkm-fav:handler) file-name-handler-alist)