My .emacs configuration
In case you like peeking into other people's configuration file or learn how to configure Emacs in Windows, here is my last set of settings.
Note: this relies on a personal fork of shackle to have LaTeX pop-up windows be automatically closed https://github.com/juanjosegarciaripoll/shackle when they are no longer used (AucTeX kills the buffer with errors but shackle does not close the window which showed the errors)
;;; -*- mode: emacs-lisp; -*- ;;; Different computers have different customizations due to ;;; monitor screen sizes, resolutions, etc. ;;; (defun tic (&optional n) (print (list n (get-internal-run-time)))) ;;; ;;; All our files will be located under a Dropbox common folder ;;; whose location may shift between computers. Also, fonts ;;; screen resolutions, etc, may vary. ;;; (setq dropbox "~/Dropbox/Library/") (setq dropbox-elpa "~/Dropbox/Library/Emacs/elpa-25") (cond ((string= system-name "DEUTSCH") (setq juanjo:text-font-family "Noto Serif" juanjo:text-font-height 110 juanjo:text-line-spacing 0.3 juanjo:margin 2)) ((string= system-name "DESKTOP-HDKKLFG") (setq juanjo:text-font-height 140 juanjo:text-font-family "Vollkorn" juanjo:text-line-spacing 0.0 juanjo:margin 1) (setq juanjo:text-font-family "Noto Serif" juanjo:text-font-height 120 juanjo:text-line-spacing 0.3 juanjo:margin 2)) (t (setq juanjo:text-font-family "DejaVu Serif" juanjo:text-line-spacing 0.3 juanjo:text-font-height 110 juanjo:margin 1))) (let ((custom-file (expand-file-name "dot.custom.el" dropbox))) (when (file-exists-p custom-file) (load custom-file))) ;;; ;;; Change to home directory. When using emacs.exe from Chocolatey, ;;; Emacs tends to start from the location of the shim executable. ;;; (cd "~/") (require 'package) (setq package-user-dir dropbox-elpa) (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/")) (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/")) (package-initialize) ;;(package-refresh-contents t) ;;; ;;; Lazy package management with postponed initialization, automatic ;;; installation of those packages. ;;; (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (require 'use-package) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Persistence ;;; ;; Remember from session to session all the commands introduced ;; in the minibuffer, files opened, etc. (setq savehist-file (expand-file-name "Emacs/dot.history" dropbox)) (savehist-mode 1) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Emacs quirks ;;; ;;; Do not use tabs when editing files (setq-default indent-tabs-mode nil) (setq tab-width 4) ;;; Make tabs indent first, then complete (setq-default tab-always-indent 'complete) ;;; Remove yes-or-no questions, defaulting to single-keystroke (fset 'yes-or-no-p 'y-or-n-p) ;;; Remove text from *scratch* buffer (setq initial-scratch-message nil) ;;; Do not disable commands (setq disabled-command-function nil) ;;(put 'downcase-region 'disabled nil) ;;(put 'scroll-left 'disabled nil) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Visual appearance: ;; ;; My preferred fonts for text and coding. I store them ;; as variables because they are used in buffer-local ;; customizations. (setq code-face '(:family "Source Code Pro" :foundry "outline" :slant normal :weight normal :height 98 :width normal) text-face `(:family ,juanjo:text-font-family :foundry "outline" :slant normal :weight normal :height ,juanjo:text-font-height :width normal) bold-text-face (plist-put (copy-sequence text-face) :weight 'bold)) (apply 'set-face-attribute 'default nil code-face) ;; ;; Darker background, softer coloring (load "~/Dropbox/Library/Emacs/mycarthy-theme.el") (load-theme 'mycarthy) ;; No blinking cursor (blink-cursor-mode -1) ;; No fringe bars on both sides (fringe-mode 0) ;; No continuation character on truncate-line mode (set-display-table-slot standard-display-table 0 ?\ ) ;;; ;;; Text editing with proportional fonts, good interline spacing ;;; and window margins. ;;; (defun juanjo:text-mode-hooks () ;; Some more spacing between lines (setq-local line-spacing juanjo:text-line-spacing) ;; Wrap around words (visual-line-mode +1) ;; Text modes should have proportional fonts (buffer-face-set text-face) (setq left-margin-width juanjo:margin right-margin-width juanjo:margin) ) (add-hook 'text-mode-hook 'juanjo:text-mode-hooks) ;; ;; Placement of windows ;; (use-package shackle :load-path "~/Dropbox/Library/Emacs/local/shackle/" :commands shackle-mode :config (setq shackle-rules '(("\\*TeX.*\\*" :regexp t :autoclose t :align below :size 10) ("\\*.*Help\\*" :regexp t :autoclose t :align below :size 10))) (setq shackle-default-rule '(:select t))) (shackle-mode) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; My convenience bindings ;;; ;;; Delete whole buffer (defun mps-clear-all () (interactive) (delete-region (point-min) (line-end-position 0))) (global-set-key [?\C-x ?\C-u] 'mps-clear-all) ;; (add-to-list 'load-path (concat dropbox "Emacs/fakecygpty/")) ;; (require 'fakecygpty) ;; (fakecygpty-activate) ;; (setq fakecygpty-ignored-program-regexps '("[cC][mM][dD]" "[cC][mM][dD][pP][rR][oO][xX][yY]")) ;; ;; We need to force using fakecygpty with tramp ;; (eval-after-load "tramp" ;; '(progn ;; (add-to-list 'tramp-methods ;; (mapcar ;; (lambda (x) ;; (cond ;; ((equal x "sshx") "cygssh") ;; ((eq (car x) 'tramp-login-program) ;; (list 'tramp-login-program "fakecygpty ssh")) ;; (t x))) ;; (assoc "sshx" tramp-methods))) ;; (setq tramp-default-method "cygssh"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; LaTeX with AucTeX ;;; ;; ;; TeXcount setup for TeXcount version 2.3 and later ;; (defun juanjo:texcount () (interactive) (let* ((this-file (buffer-file-name)) (enc-str (symbol-name buffer-file-coding-system)) (enc-opt (cond ((string-match "utf-8" enc-str) "-utf8") ((string-match "latin" enc-str) "-latin1") ("-encoding=guess") )) (process-environment ;; Windows screwes this for me (append '("LANG=") process-environment)) (word-count (with-output-to-string (with-current-buffer standard-output (call-process "texcount" nil t nil "-0" enc-opt this-file)))) ) (message word-count) )) (use-package latex :defer t :mode ("\\.tex\\'" . latex-mode) :bind (:map LaTeX-mode-map ("C-c l" . TeX-error-overview) ("C-c w" . juanjo:textcount)) :config ;; Minor changes to the LaTeX mode (add-hook 'LaTeX-mode-hook 'juanjo:latex-hooks) (add-hook 'LaTeX-mode-hook 'turn-on-reftex) (add-hook 'LaTeX-mode-hook 'juanjo:latex-hooks) (add-hook 'LaTeX-mode-hook 'flyspell-mode) (setq TeX-PDF-mode t TeX-save-query nil TeX-source-correlate-mode t TeX-source-correlate-method 'synctex ;; Tell SumatraPDF to open the current PDF file, indicating ;; which is the source file and line number (used by synctex) ;; and provide a valid command line to edit at the desired ;; location of a source file that is linked in the PDF. TeX-view-program-list '(("Sumatra PDF" ("\"SumatraPDF.exe\" -reuse-instance " "-inverse-search \"emacsclientw.exe +%%l \\\"%%f\\\"\" " (mode-io-correlate " -forward-search %a %n ") " %o"))) TeX-view-program-selection '(((output-dvi style-pstricks) "dvips and start") (output-dvi "Yap") (output-pdf "Sumatra PDF") (output-html "start")) ;; Open TeX error list after compilation ;; and show all warnings TeX-error-overview-open-after-TeX-run t TeX-debug-warnings t) ;; Replace viewer with SumatraPDF (assq-delete-all 'output-pdf TeX-view-program-selection) (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF")) ) ; use-package latex ;; ;; Hook into font-latex to reduce the size of some section, ;; chapter, subscript and superscript fonts ;; (use-package font-latex :defer t :config (set-face-attribute 'font-latex-subscript-face nil :height 0.6) (set-face-attribute 'font-latex-superscript-face nil :height 0.6) ;; I do not like large fonts for the sections, chapters, etc (let ((height (round (* 1.1 juanjo:text-font-height)))) (dolist (face '(font-latex-sectioning-0-face font-latex-sectioning-1-face font-latex-sectioning-2-face font-latex-sectioning-3-face font-latex-sectioning-4-face font-latex-sectioning-5-face)) (apply 'set-face-attribute face nil (plist-put (copy-sequence bold-text-face) :height height)))) ) (use-package reftex :defer t :commands turn-on-reftex :init (setq reftex-plug-into-AUCTeX t ;; RefTeX list of sections, labels and figures shows as ;; vertical bar to the left of the window. reftex-toc-split-windows-horizontally t ;; RefTeX table of contents does not indicate which ;; sections are in which files. reftex-toc-include-file-boundaries nil)) (use-package latex-extra :defer t :ensure t :commands latex-extra-mode :bind (:map LaTeX-mode-map ("M-" . latex/next-section-same-level) ("M-" . latex/previous-section-same-level)) :init (add-hook 'LaTeX-mode-hook (lambda () (latex-extra-mode) (auto-fill-mode -1))) ;; Do not override AucTex's font commands (setq latex/override-font-map nil)) (defun delatexify () (save-excursion (goto-char 0) (replace-string "{\'\i}" "í") (replace-string "\\'o" "ó") (replace-string "\\'a" "á") (replace-string "\\'e" "é") (replace-string "\\'u" "ú") (replace-string "\\\"a" "ä") (replace-string "\\\"o" "ö"))) (defun juanjo:html-mode-hooks() ;; Wrap around words (visual-line-mode +1) ;; Text modes should have proportional fonts (buffer-face-set code-face)) (add-hook 'html-mode-hook 'juanjo:html-mode-hooks) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Dictionaries, languages and encodings ;; ;; ;; Use hunspell.exe for automatic spell checking. Available ;; from Chocolately as choco install hunspell ;; (use-package flyspell :defer t :bind (("" . ispell-word) ("C-S-" . flyspell-mode) ("C-M-" . flyspell-buffer) ("C-" . flyspell-check-previous-highlighted-word) ("M-" . flyspell-check-next-highlighted-word)) :init (setenv "DICTPATH" "c:\\ProgramData\\chocolatey\\lib\\hunspell.portable\\tools\\share\\hunspell\\") (setenv "DICTIONARY" "c:\\ProgramData\\chocolatey\\lib\\hunspell.portable\\tools\\bin\\..\\share\\hunspell\\en_US") (setq ispell-program-name "c:\\ProgramData\\chocolatey\\bin\\hunspell.exe" ;; Save dictionary in common location ispell-extra-args `("-p" ,(expand-file-name "hunspell" dropbox)) ;; Save dictionary without asking ispell-silently-savep t ;; Do not issue warnings for all wrong words flyspell-issue-message-flag nil) (defun flyspell-check-next-highlighted-word () "Custom function to spell check next highlighted word" (interactive) (flyspell-goto-next-error) (ispell-word) ) :config (ispell-change-dictionary "en_US" t) ) ; use-package flyspell ;;; Encoding for everything (prefer-coding-system 'utf-8-unix) ;;; ;;; Convenience keybindings for Greek letters ;;; (progn (global-set-key (kbd "C-x C-g a") "α") (global-set-key (kbd "C-x C-g b") "β") (global-set-key (kbd "C-x C-g g") "γ") (global-set-key (kbd "C-x C-g d") "δ") (global-set-key (kbd "C-x C-g ep") "ε") (global-set-key (kbd "C-x C-g z") "ζ") (global-set-key (kbd "C-x C-g et") "η") (global-set-key (kbd "C-x C-g Th") "θ") (global-set-key (kbd "C-x C-g i") "ι") (global-set-key (kbd "C-x C-g í") "ί") (global-set-key (kbd "C-x C-g k") "κ") (global-set-key (kbd "C-x C-g l") "λ") (global-set-key (kbd "C-x C-g m") "μ") (global-set-key (kbd "C-x C-g n") "ν") (global-set-key (kbd "C-x C-g xi") "ξ") (global-set-key (kbd "C-x C-g o") "ο") (global-set-key (kbd "C-x C-g ó") "ό") (global-set-key (kbd "C-x C-g pi") "π") (global-set-key (kbd "C-x C-g r") "ρ") (global-set-key (kbd "C-x C-g fs") "ς") (global-set-key (kbd "C-x C-g s") "σ") (global-set-key (kbd "C-x C-g t") "τ") (global-set-key (kbd "C-x C-g y") "υ") (global-set-key (kbd "C-x C-g ý") "ύ") (global-set-key (kbd "C-x C-g ph") "φ") (global-set-key (kbd "C-x C-g chi") "φ") (global-set-key (kbd "C-x C-g ps") "ψ") (global-set-key (kbd "C-x C-g w") "ω")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Windows and unix-like shells ;; (defun cygwin-shell () "Run cygwin bash in shell mode." (interactive) (let ((explicit-shell-file-name "bash") (explicit-bash-args '("-i"))) (call-interactively 'shell))) (defun wunix-shell () "Run Windows' bash in shell mode." (interactive) (let ((explicit-shell-file-name "cmd.exe") (explicit-cmd.exe-args '("/C" "c:\\Windows\\WinSxS\\amd64_microsoft-windows-lxss-bash_31bf3856ad364e35_10.0.16299.15_none_62878a822db68b25\\bash.exe" "-i"))) (call-interactively 'shell))) (defun visual-studio-2017-x84-shell () "Run Windows shell with Visual Studio environment." (interactive) (let ((explicit-shell-file-name "cmd.exe") (explicit-cmd.exe-args '("/k" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat"))) (shell))) (setq tramp-default-method "ssh") (defun browser-sync () "Starts a browser-sync script if it exists in this directory" (interactive) (start-process "browser-sync" "*browser-sync*" (expand-file-name "debug.cmd"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Email, web and other services ;; (use-package wunderlist :defer t :init (setq wl-folders-file "~/Dropbox/Library/dot.folders" ;; SMTP server for mail posting. Default: nil wl-smtp-posting-server "smtpin.xxxxxx.es" wl-smtp-posting-port 465 wl-smtp-posting-user "xxxxx" wl-smtp-authenticate-type "plain" wl-smtp-connection-type 'ssl wl-from "xxxx@xxx.es" smtp-fqdn "xxx.xxxx.es" elmo-imap4-default-user "xxxxx" elmo-imap4-default-server "xxxx.xxx.es" elmo-imap4-default-port 993 elmo-imap4-default-authenticate-type 'clear elmo-imap4-default-stream-type 'ssl ;; Location of archives elmo-archive-folder-path "~/Dropbox/Mail/" ;; Location of MH and Maildir folders elmo-localdir-folder-path "~/Dropbox/Mail/" elmo-maildir-folder-path "~/Dropbox/Mail/" wl-message-id-domain "xxxx@xxxx.es" wl-from "Juan Jose Garcia-Ripoll " wl-stay-folder-window t wl-folder-window-width 25 wl-folder-use-frame nil wl-message-ignored-field-list '("^.*") wl-message-visible-field-list '("^From:" "^To:" "^Cc:" "^Date:" "^Subject:") wl-message-sort-field-list wl-message-visible-field-list wl-summary-default-sort-spec 'date wl-message-window-size '(1 . 3) ) :config (if (boundp 'mail-user-agent) (setq mail-user-agent 'wl-user-agent)) (if (fboundp 'define-mail-user-agent) (define-mail-user-agent 'wl-user-agent 'wl-user-agent-compose 'wl-draft-send 'wl-draft-kill 'mail-send-hook)) ) ; use-package wunderlist ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Auto completion with IDO ;;; (use-package ido :ensure t :init (setq ido-enable-flex-matching t ido-ignore-extensions t ido-use-virtual-buffers t ido-everywhere t) :config (ido-mode 1) (ido-everywhere 1) (add-to-list 'completion-ignored-extensions ".pyc")) (use-package flx-ido :ensure t :init (setq ido-enable-flex-matching t ido-use-faces nil) :config (flx-ido-mode 1)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Version control ;;; (use-package magit :defer t :ensure t )