Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
324 lines (290 sloc) 15.5 KB
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
;;; ---- the above was auto generated AFTER installing Melpa (see below) ----
;;; +------------------------------------------+
;;; | ECE 486 Lab (Day 0: Intro Emacs + LaTeX) |
;;; | |
;;; | by Yün Han |
;;; | 2017-08-09 |
;;; +------------------------------------------+
;;; First of all, reference card for emacs itself. See
;;; https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf
;;;
;;; The most important parts for us are (in that order):
;;;
;;; - Motion
;;; - Killing and Deleting
;;; - Files
;;; - Spelling Check
;;; - Getting Help
;;; - Incremental Search
;;;
;;; For mode specific refcard, see
;;; https://www.emacswiki.org/emacs/ReferenceCards
;;; Our aim is to have a (lightweight) *portable* setup for writing in LaTeX
;;; on Windows(R) platform:
;;;
;;; 1. Download 'emacs-25.2-x86_64.zip' for 64 bit Windows machines from
;;; https://ftp.gnu.org/gnu/emacs/windows/
;;; 2. Unpack 'emacs' anywhere you like as long as you have write privilege.
;;; 3. Create a *.bat file like below. As for '%~dp0' expansion, see
;;; https://stackoverflow.com/a/10290765/1489881
;;;
;;; +-------------------------------------------------------------------------+
;;; | rem This is Windows *.bat file for launching portable emacs |
;;; | rem Set emacs HOME as current directory |
;;; | set HOME=%~dp0 |
;;; | rem Launch emacs. Note '%*' for situations where input args are present |
;;; | "%~dp0bin\runemacs.exe" %* |
;;; +-------------------------------------------------------------------------+
;;;
;;; Line 'set HOME=%~dp0' forces emacs to save config files under the same
;;; directory as emacs root installation. '%~dp0' expands to a path (p) where
;;; current batch file resides including drive letter (d). Number '0' refers
;;; to batch file itself. (Update: See the latest 'emacs_launch.bat'.)
;;;
;;; ----> CURRENT FOLDER ./
;;; ./EMACS25_ROOT/BIN ----> SUB FOLDERS
;;; ./EMACS25_ROOT/LIB ----> SUB FOLDERS
;;; ./EMACS25_ROOT/...
;;; ./EMACS25_ROOT/_EMACS (THIS FILE)
;;; ./EMACS25_ROOT/EMACS_LAUNCH.BAT
;;; ./...
;;;
;;; 4. Download 'hunspell-1.3.2-3-w32-bin.zip' from 'ezwinport' project,
;;; https://sourceforge.net/projects/ezwinports/files/
;;; 5. Unpack 'hunspell' but keep hunspell root under the same folder as
;;; emacs root, i.e.,
;;;
;;; ----> CURRENT FOLDER ./
;;; ./EMACS25_ROOT/BIN ----> SUB FOLDERS
;;; ./EMACS25_ROOT/LIB ----> SUB FOLDERS
;;; ./EMACS25_ROOT/...
;;; ./HUNSPELL1323_ROOT/BIN ----> SUB FOLDERS
;;; ./HUNSPELL1323_ROOT/LIB ----> SUB FOLDERS
;;; ./HUNSPELL1323_ROOT/...
;;; ./...
;;;
;;; 6. Download 'SumatraPDF-3.1.2-64.zip' (portable) from
;;; https://www.sumatrapdfreader.org/download-free-pdf-viewer.html
;;; 7. Unpack 'SumatraPDF' but keep sumatrapdf root under the same folder as
;;; emacs root, i.e.,
;;;
;;; ----> CURRENT FOLDER ./
;;; ./EMACS25_ROOT/BIN ----> SUB FOLDERS
;;; ./EMACS25_ROOT/LIB ----> SUB FOLDERS
;;; ./EMACS25_ROOT/...
;;; ./SUMATRAPDF312_ROOT/SUMATRAPDF.EXE (STANDALONE)
;;; ./...
;;;
;;; 8. Download 'miktex-portable-2.9.6361.exe' (portable, 7z self-extract) from
;;; https://miktex.org/portable
;;; 9. Unpack 'miktex' but keep miktex root under the same folder as emacs
;;; root, i.e.,
;;;
;;; ----> CURRENT FOLDER ./
;;; ./EMACS25_ROOT/BIN ----> SUB FOLDERS
;;; ./EMACS25_ROOT/LIB ----> SUB FOLDERS
;;; ./EMACS25_ROOT/...
;;; ./MIKTEX29_ROOT/MIKTEX-PORTABLE.CMD (BAT FILE)
;;; ./MIKTEX29_ROOT/TEXMFS ----> SUB FOLDERS
;;; ./...
;;;
;;; 10. Keep reading this file.
;;; Do you know the differences among ';',';;' and ';;;'?
;;; For the answer, see
;;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Comment-Tips.html
;;; Minimum Configuration
;;; ---------------------
(set-language-environment "UTF-8") ; UTF-8 as default encoding
(column-number-mode 1) ; Show column number
(scroll-bar-mode -1) ; Don't show scroll bar
(tool-bar-mode -1) ; Don't show tool bar
(blink-cursor-mode -1) ; Don't blink the cursor
;;; Highlight matching parentheses
(require 'paren)
(show-paren-mode 1) ; Highlight matching parentheses
(electric-pair-mode 1) ; Auto pair parentheses
(setq visible-bell 1) ; Mute emacs beep sound
(setq-default fill-column 80) ; Paragraph filling/wrapping at col 80
;;; Need to install 'fill-column-indicator'. It draws a thin rule at col 80
;; (require 'fill-column-indicator) ; Show wrapping rule at col 80
(auto-fill-mode 1) ; Auto wrap at line width set at col 80
;;; See http://geosoft.no/development/emacs.html
(setq default-frame-alist (append (list
'(width . 81) ; Width set to 81 characters
'(height . 36)) ; Height set to ~55 lines
default-frame-alist))
(setq inhibit-startup-message t) ; Don't want any startup message
(setq make-backup-files nil) ; Don't want any backup files
(setq auto-save-list-file-name nil) ; Don't want any .saves files
(setq auto-save-default nil) ; Don't want any auto saving
(setq search-highlight t) ; Highlight search object
(setq query-replace-highlight t) ; Highlight query object
(setq mouse-sel-retain-highlight t) ; Keep mouse highlighting
(set-face-background 'region "yellow") ; Set region background color
(set-background-color "khaki") ; Set emacs background color
;;; Spell Check
;;; -----------
;;; See https://www.emacswiki.org/emacs/InteractiveSpell
;;; and https://lists.gnu.org/archive/html/help-gnu-emacs/2014-04/msg00030.html
(setenv "LANG" "en_US") ; Needed for Windows. Tested on Win 7/10.
;;; 'en_US' is the key for 'hunspell' to search in dictionary path. Dictionaries
;;; are saved in 'HUNSPELL1323_ROOT/share/hunspell'.
(setq ispell-local-dictionary "en_US")
(setq ispell-local-dictionary-alist '("american"
"[[:alpha:]]"
"[^[:alpha:]]"
"[']"
t
("-d" "en_US")
nil
utf-8))
(setq ispell-program-name "~/../hunspell1323/bin/hunspell.exe")
(setq ispell-dictionary "american")
;;; ____
;;; Note: Multi-dicts (multi-lang) is possible but that is not our top priority.
;;; ¯¯¯¯
;;; +--------------------------------------------------------------------------+
;;; | Mini How-to (ispell/hunspell) |
;;; | ============================= |
;;; | |
;;; | 1. If unsure of a word, move cursor to the word and 'M-$'. |
;;; | 2. Highlight a block of text then 'M-x ispell-region' is always useful. |
;;; | 3. See 'Tools -> Spell Checking -> ... ' in the menu bar for other |
;;; | options. |
;;; | 4. 'flyspell' mode can be enabled by 'M-x flyspell-mode'. It can be slow |
;;; | for large documents. Therefore, on demand usage like methods 1 & 2 |
;;; | is recommended. |
;;; | |
;;; +--------------------------------------------------------------------------+
;;; Melpa Package Manager
;;; ---------------------
;;; See https://stable.melpa.org/#/getting-started
(require 'package) ;; You might already have this line
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
(add-to-list 'package-archives (cons "melpa" url) t))
(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
;;; ---- the below was auto generated AFTER installing Melpa ----
(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.
'(package-selected-packages (quote (auctex auto-complete))))
(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.
)
;;; ---- the above was auto generated AFTER installing Melpa ----
;;; +--------------------------------------------------------------------------+
;;; | Mini How-to (Melpa) |
;;; | =================== |
;;; | |
;;; | 1. After successful install, type 'package-list-packages' to refresh |
;;; | repository list. |
;;; | 2. Browse the list of packages (1000+, standard emacs navigation |
;;; | available), type 'i' to mark new installation, type 'U' to mark |
;;; | upgrade, and type'x' to execute. Deletion seems to be manual (go to |
;;; | '~/.emacs.d/elpa/' directory). |
;;; | ____ |
;;; | Note: In our case, emacs HOME '~' is just the same as EMACS_ROOT. |
;;; | ¯¯¯¯ |
;;; +--------------------------------------------------------------------------+
;;; Auto-Complete
;;; -------------
;;; See https://github.com/auto-complete/auto-complete
(ac-config-default)
;;; LaTeX + SumatraPDF
;;; ------------------
;;; MikTeX binary path
;;; "~/../miktex29/texmfs/install/miktex/bin"
;;; SumatraPDF path
;;; "~/../SumatraPDF312"
;;; Not working, have to set PATH in 'emacs_launch.bat'
;;; Add SumatraPDF and MikTeX folders to PATH and prioritize them.
(setenv "PATH" (concat
"~/../miktex29/texmfs/install/miktex/bin" ";"
"~/../SumatraPDF312" ";"
(getenv "PATH") ";"
))
;;; Not working, have to set PATH in 'emacs_launch.bat'
;;; Add SumatraPDF and MikTeX folders to the front of 'exec-path' as well.
(setq exec-path (append '(
"~/../miktex29/texmfs/install/miktex/bin" ";"
"~/../SumatraPDF312" ";"
exec-path)))
;;; Install AUCTeX from Melpa then enable 'auctex' mode.
(if (eq system-type 'windows-nt)
(load "auctex.el" nil t t)
;; (load "preview-latex.el" nil t t)
(require 'tex-mik) ;; Link between AUCTeX and SumatraPDF
)
;;; Turn on flyspell for LaTeX writing
;; (add-hook 'LaTeX-mode-hook 'flyspell-mode)
;;; Turn on visual-line mode
;; (add-hook 'LaTeX-mode-hook 'visual-line-mode)
;;; auto-complete and flyspell are bound the same key, so use the workaround
;; (ac-flyspell-workaround)
;;; Turn on 'ac-math' (see refcard for auctex how to enter symbols or greek
;;; letters quickly). Need to install 'ac-math' package.
;; (require 'ac-math)
;;; Make auto-complete aware of `latex-mode`
(add-to-list 'ac-modes 'latex-mode)
;;; +--------------------------------------------------------------------------+
;;; | Mini How-to (Inverse Search in SumatraPDF) |
;;; | ========================================== |
;;; | |
;;; | 1. Go to SUMATRAPDF_ROOT and start SumatraPDF.exe. |
;;; | 2. Click the menu icon on the top left corner and go to |
;;; | 'Settings -> Options'. |
;;; | 3. In 'Set inverse search command-line', enter (with quotes) |
;;; | +-----------------------------------------------+ |
;;; | | "emacsclientw.exe" -n +%l "%f" | |
;;; | +-----------------------------------------------+ |
;;; | TODO (fixed): At the moment I don't know how to pass current directory|
;;; | to SumatraPDF setting, so EMACS_ROOT has to be hard coded, e.g., |
;;; | 'C:\path\to\emacs' (local drive) or 'U:\path\to\emacs' (EWS network |
;;; | drive). |
;;; | 4. Also go to 'Settings -> Advanced Options' and set |
;;; | 'EnableTeXEnhancements = true'. |
;;; | |
;;; +--------------------------------------------------------------------------+
;;; Always start the server for inverse search
(setq-default TeX-source-correlate-start-server t)
;;; ____
;;; Note: If error pops up when 'C-c C-c' view the pdf file,
;;; ¯¯¯¯
;;; +---------------------------------------------------------------------+
;;; | server-ensure-safe-dir: The directory '~/.emacs.d/server' is unsafe |
;;; +---------------------------------------------------------------------+
;;;
;;; go to '~/.emacs.d/' and change the owner of folder 'server' to your
;;; own account from 'Administrator'. This is most likely the case when
;;; you unpack emacs in 'C:\' drive on lab computers. 'U:\' drive does
;;; not suffer from this problem but things run slower.
;;; Turn on pdf mode
;;; See more about 'hooks' with 'lambda' function,
;;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html
(add-hook 'LaTeX-mode-hook
(lambda () (tex-pdf-mode t) (TeX-source-correlate-mode t)))
;;; Set SumatraPDF as PDF viewer. See known problems in 'Reeeeaaaaddddme.txt'
(setq TeX-view-program-list
;; '(("Sumatra PDF" ("\"~/../SumatraPDF312/SumatraPDF.exe\" -reuse-instance"
'(("Sumatra PDF" ("SumatraPDF -reuse-instance"
(mode-io-correlate " -forward-search %b %n ") " %o"))))
;;; (Fixed) 'SumatraPDF' is in the path, no need to provide path for *.exe
(setq TeX-view-program-selection
'(
(output-pdf "Sumatra PDF")
))