Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
676 lines (597 sloc) 22.5 KB

Starter Kit Alexey’s customizations

This is my add-on to the Emacs Starter Kit. It provides some additional settings useful for social scientists, together with some other personal customizations I find helpful. This org-mode file documents these additions and provides the code to implement them. See the main starter-kit file for further information.

Starter Kit Alexey

YOU MUST CHANGE THE NAME OF THIS FILE to the value of the Emacs variable user-login-name OR system-name, so that it will be picked up by init.el when Emacs starts up, and be loaded properly. To find the current value of these variables on your system, do C-h-v system-name [RET] and C-h-v user-login-name [RET]. For example, on my system user-login-name is ‘Alexey’, so this file is named Alexey.org, and when Emacs starts up with the starter kit it creates the file Alexey.el.

You will also need to change the values for the location of bibtex databases, pandoc and orgmode-mobile specified below, and some other settings. Search for ‘Alexey’ in this file to find the paths that need to be updated. Change them as needed or comment them out if you don’t use these features.

Package Locations

Location of various local packages (in .emacs.d/vendor) because I don’t want to keep them in /Applications/Emacs.app/ or in /usr/share/local/.

Load path

(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
    (let* ((my-lisp-dir "~/.emacs.d/")
          (default-directory my-lisp-dir))
       (setq load-path (cons my-lisp-dir load-path))
       (normal-top-level-add-subdirs-to-load-path)))

Miscellaneous Settings and starter-kit overrides

Save session

;; (require 'desktop-menu)

(desktop-save-mode t)
(setq history-length 250)

(add-to-list 'desktop-modes-not-to-save 'dired-mode)
(add-to-list 'desktop-modes-not-to-save 'Info-mode)
(add-to-list 'desktop-modes-not-to-save 'info-lookup-mode)
(add-to-list 'desktop-modes-not-to-save 'fundamental-mode)

Window size

(setq default-frame-alist
'(
; frame width and height
(width             . 100)
(height            . 50)
)
)

Default font

Uncomment the second one if Unicode characters absent from Consolas are needed.

  (unless (null (x-list-fonts "Consolas 11"))
    (set-default-font "Consolas 11"))

;;  (unless (null (x-list-fonts "DejaVu Sans Mono"))
;;    (set-default-font "DejaVu Sans Mono"))

Recent File Menu

;; recent file menu
(require 'recentf)
(recentf-mode 1)

Color Theme and Line Highlighting

;; Color Theme from vendor directory
(require 'color-theme)

;; (load-file "~/.emacs.d/src/color-theme/themes/color-theme-twilight.el")
;; (color-theme-twilight)
(load-file "~/.emacs.d/src/color-theme/themes/color-theme-tangosoft.el")
(color-theme-tangosoft)

;; Highlight current line (twilight theme builds in support for this)
(global-hl-line-mode 1)

Full Screen Hacks

What works depends on the flavor of emacs you are using, unfortunately. Choose as appropriate.

;; require maxframe package to conveniently maxmimize the window
;; with M-x MFA. Doesn't work with Emacs 23 on Mac. 
;;(require 'maxframe)
;;(global-set-key (kbd "C-c m") 'x-maximize-frame)

;; Fullscreen toggle -- Only works with patched emacs build at git://github.com/typester/emacs.git
;; (global-set-key (kbd "C-c m") 'ns-toggle-fullscreen)

;; (global-set-key (kbd "C-c m") 'ns-toggle-fullscreen)

;; Fullscreen toggle -- using maxframe.el
;; (require 'maxframe)
;; (defvar my-fullscreen-p t "Check if fullscreen is on or off")

;; (defun my-toggle-fullscreen ()
;; (interactive)
;; (setq my-fullscreen-p (not my-fullscreen-p))
;; (if my-fullscreen-p
;; (restore-frame)
;; (maximize-frame)))

;; (global-set-key (kbd "C-c m") 'my-toggle-fullscreen)

;; For use with Yamamoto Mitsuharu's Carbon-patched Emacs 23. 
;; (set-frame-parameter nil 'fullscreen 'fullboth) 
;; (defun fullscreen (&optional f)
;;     (interactive)
;;     (set-frame-parameter f 'fullscreen
;;                          (if (frame-parameter f 'fullscreen) nil 'fullboth)))
;; (global-set-key (kbd "C-c f") 'fullscreen)
;; (add-hook 'after-make-frame-functions 'fullscreen)

Resizing inside the frame

;; resizing 'windows' (i.e., inside the frame)
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)  

Browse Kill Ring

Conveniently navigate the kill-ring (ie, the cut/copy clipboard history) in a pop-up buffer.

(when (require 'browse-kill-ring nil 'noerror)
(browse-kill-ring-default-keybindings))

ido-mode

Use ido mode for M-command completion as well as file/buffer completion. (Alreadly implemented in other starter kit files)

   (ido-mode 1)
    (setq ido-execute-command-cache nil)
(defun ido-execute-command ()
  (interactive)
  (call-interactively
   (intern
    (ido-completing-read
     "M-x "
     (progn
       (unless ido-execute-command-cache
         (mapatoms (lambda (s)
                     (when (commandp s)
                       (setq ido-execute-command-cache
                             (cons (format "%S" s) ido-execute-command-cache))))))
       ido-execute-command-cache)))))
   
(add-hook 'ido-setup-hook
          (lambda ()
            (setq ido-enable-flex-matching t)
            (global-set-key "\M-x" 'ido-execute-command)))

  ;; (setq ido-execute-command-cache nil)
  ;; (defun ido-execute-command ()
  ;; (interactive)
  ;; (call-interactively
  ;; (intern
  ;; (ido-completing-read
  ;; "M-x "
  ;; (progn
  ;; (unless ido-execute-command-cache
  ;; (mapatoms (lambda (s)
  ;; (when (commandp s)
  ;; (setq ido-execute-command-cache
  ;; (cons (format "%S" s) ido-execute-command-cache))))))
  ;; ido-execute-command-cache)))))

   (add-hook 'ido-setup-hook
   (lambda ()
   (setq ido-enable-flex-matching t)
   (global-set-key "\M-x" 'ido-execute-command)
   (define-key ido-completion-map [tab] 'ido-complete)))

   (defvar ido-enable-replace-completing-read t
     "If t, use ido-completing-read instead of completing-read if possible.
   
   Set it to nil using let in around-advice for functions where the
   original completing-read is required.  For example, if a function
   foo absolutely must use the original completing-read, define some
   advice like this:
   
   (defadvice foo (around original-completing-read-only activate)
     (let (ido-enable-replace-completing-read) ad-do-it))")
   
   ;; Replace completing-read wherever possible, unless directed otherwise
   (defadvice completing-read
     (around use-ido-when-possible activate)
     (if (or (not ido-enable-replace-completing-read) ; Manual override disable ido
             (boundp 'ido-cur-list)) ; Avoid infinite loop from ido calling this
         ad-do-it
       (let ((allcomp (all-completions "" collection predicate)))
         (if allcomp
             (setq ad-return-value
                   (ido-completing-read prompt
                                  allcomp
                                  nil require-match initial-input hist def))
           ad-do-it))))

   (setq ido-work-directory-list '("~/" "~/Desktop" "~/Documents"))

   ;; ido-mode and imenu
   (defun ido-goto-symbol (&optional symbol-list)
     "Refresh imenu and jump to a place in the buffer using Ido."
     (interactive)
     (unless (featurep 'imenu)
       (require 'imenu nil t))
     (cond
      ((not symbol-list)
       (let ((ido-mode ido-mode)
             (ido-enable-flex-matching
              (if (boundp 'ido-enable-flex-matching)
                  ido-enable-flex-matching t))
             name-and-pos symbol-names position)
         (unless ido-mode
           (ido-mode 1)
           (setq ido-enable-flex-matching t))
         (while (progn
                  (imenu--cleanup)
                  (setq imenu--index-alist nil)
                  (ido-goto-symbol (imenu--make-index-alist))
                  (setq selected-symbol
                        (ido-completing-read "Symbol? " symbol-names))
                  (string= (car imenu--rescan-item) selected-symbol)))
         (setq position (cdr (assoc selected-symbol name-and-pos)))
         (cond
          ((overlayp position)
           (goto-char (overlay-start position)))
          (t
           (goto-char position)))))
      ((listp symbol-list)
       (dolist (symbol symbol-list)
         (let (name position)
           (cond
            ((and (listp symbol) (imenu--subalist-p symbol))
             (ido-goto-symbol symbol))
            ((listp symbol)
             (setq name (car symbol))
             (setq position (cdr symbol)))
            ((stringp symbol)
             (setq name symbol)
             (setq position
                   (get-text-property 1 'org-imenu-marker symbol))))
           (unless (or (null position) (null name)
                       (string= (car imenu--rescan-item) name))
             (add-to-list 'symbol-names name)
             (add-to-list 'name-and-pos (cons name position))))))))
   (global-set-key "\C-ci" 'ido-goto-symbol) ; or any key you see fit

Word-count

Live word count in status bar, via wc. Unfortunately there seems to be a bug – it interacts badly with the smooth scrolling: when you get to the bottom of the buffer it wraps the pointer up to the middle of the screen without moving the text with it, so you end up typing inside the text that’s already there. Replaced with a simpler version instead, which gives you a straight count via M-x wc.

;; (autoload 'word-count-mode "word-count"
;; "Minor mode to count words." t nil)
;; (dolist (hook '(org-mode-hook
;; markdown-mode-hook
;; TeX-mode-hook
;; text-mode-hook))
;; (add-hook hook (lambda () (word-count-mode 1))))

(require 'wc)

Line wrapping and position

Sane line wrapping and scrolling for long documents and papers. Plus a function for removing any hard-returns in a document.

(global-visual-line-mode t)
;;; prefer auto-fill to visual line wrap in ESS mode
(add-hook 'ess-mode-hook 'turn-on-auto-fill)
(add-hook 'inferior-ess-mode-hook 'turn-on-auto-fill) 

;;; but turn off auto-fill in tex and markdown
(add-hook 'markdown-mode-hook 'turn-off-auto-fill)
(add-hook 'latex-mode-hook 'turn-off-auto-fill)

;;; unfill paragraph
(defun unfill-paragraph ()
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(global-set-key (kbd "<f6>") 'unfill-paragraph)

;; Page down/up move the point, not the screen.
;; In practice, this means that they can move the
;; point to the beginning or end of the buffer.
(global-set-key [next]
(lambda () (interactive)
(condition-case nil (scroll-up)
(end-of-buffer (goto-char (point-max))))))

(global-set-key [prior]
(lambda () (interactive)
(condition-case nil (scroll-down)
(beginning-of-buffer (goto-char (point-min))))))

;; smooth-scrolling package in src/
(require 'smooth-scrolling)

Spelling

Use cocoAspell instead of ispell. Turned off here because it loads too late. I had to put it in a separate org file of its own.

(setq ispell-program-name "aspell"
    ispell-dictionary "english"
    ispell-dictionary-alist
    (let ((default '("[A-Za-z]" "[^A-Za-z]" "[']" nil
                     ("-B" "-d" "english" "--dict-dir"
                      "/Library/Application Support/cocoAspell/aspell6-en-6.0-0")
                     nil iso-8859-1)))
      `((nil ,@default)
        ("english" ,@default))))

  ;; ispell --- make ispell skip \citep, \citet etc in .tex files.
  (setq ispell-tex-skip-alists
  '((;;("%\\[" . "%\\]") ; AMStex block comment...
  ;; All the standard LaTeX keywords from L. Lamport's guide:
  ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
  ;; \label, \nocite, \rule (in ispell - rest included here)
  ("\\\\addcontentsline"              ispell-tex-arg-end 2)
  ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
  ("\\\\\\([aA]lph\\|arabic\\)"   ispell-tex-arg-end)
  ("\\\\author"                         ispell-tex-arg-end)
  ;; New regexps here --- kjh
  ("\\\\\\(text\\|paren\\)cite" ispell-tex-arg-end)
  ("\\\\cite\\(t\\|p\\|year\\|yearpar\\)" ispell-tex-arg-end)
  ("\\\\bibliographystyle"                ispell-tex-arg-end)
  ("\\\\makebox"                  ispell-tex-arg-end 0)
  ("\\\\e?psfig"                  ispell-tex-arg-end)
  ("\\\\document\\(class\\|style\\)" .
  "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
  (;; delimited with \begin.  In ispell: displaymath, eqnarray, eqnarray*,
  ;; equation, minipage, picture, tabular, tabular* (ispell)
  ("\\(figure\\|table\\)\\*?"     ispell-tex-arg-end 0)
  ("list"                                 ispell-tex-arg-end 2)
  ("program"             . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
  ("verbatim\\*?"        . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[
  \t\n]*}"))))

;; (add-hook 'LaTeX-mode-hook 'flyspell-mode)

Skeleton mode

Enable skeleton mode in ESS for paired insertion

    (require 'skeleton)
    (setq skeleton-pair nil)
;;    (defvar my-skeleton-pair-alist
;;    '((?\) . ?\()
;;    (?\] . ?\[)
;;    (?} . ?{)
;;    (?" . ?")))
    
;;     (Defun my-skeleton-pair-end (arg)
;;     "Skip the char if it is an ending, otherwise insert it."
;;     (interactive "*p")
;;     (let ((char last-command-char))
;;     (if (and (assq char my-skeleton-pair-alist)
;;     (eq char (following-char)))
;;     (forward-char)
;;     (self-insert-command (prefix-numeric-value arg)))))
;; 
;;     (dolist (pair my-skeleton-pair-alist)
;;     (global-set-key (char-to-string (first pair))
;;     'my-skeleton-pair-end)
;;     ;; If the char for begin and end is the same,
;;     ;; use the original skeleton
;;     (global-set-key (char-to-string (rest pair))
;;     'skeleton-pair-insert-maybe))

Autopair mode

Enable autopair mode. See http://emacs-fu.blogspot.com/2010/06/automatic-pairing-of-brackets-and.html

(require 'autopair)
(autopair-global-mode 1)
(setq autopair-autowrap t)

Tabkey2 mode

(load "~/.emacs.d/src/nxhtml/util/tabkey2.el")
(require 'tabkey2)
(tabkey2-mode t)

Bookmark+

Mostly for ability to bookmark desktops

(require 'bookmark+)  

LaCarte

Library La Carte lets you auto-complete menu items and execute them as commands.

(require 'lacarte)
(global-set-key [?\C-\M-x] 'lacarte-execute-command)
;; (setq lacarte-convert-menu-item-function 'lacarte-remove-w32-keybd-accelerators)

Predictive main dict

Set predictive to use my own main dictionary

(eval-after-load "predictive"
  '(progn
     (dictree-load "dict-alexey")
     (setq predictive-main-dict 'dict-alexey)))

Magit path

Set path to the Git executable

(setq magit-git-executable "C:/Program Files (x86)/Git/bin/git.exe")

LaTeX Customizations and settings

Use MikTeX

(require 'tex-mik)

Always use math mode

(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

Automatically wrap paragraphs

(add-hook 'LaTeX-mode-hook 'auto-fill-mode)

Make emacs aware of multi-file projects

(setq-default TeX-master nil)

SyncTeX, PDF mode

;; Synctex with Skim
;;(add-hook 'TeX-mode-hook
;;(lambda ()
;;(add-to-list 'TeX-output-view-style
;;'("^pdf$" "."
;; "/Applications/Skim.app/Contents/SharedSupport/displayline %n %o %b")))
;; )

RefTeX

(autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
(autoload 'reftex-citation "reftex-cite" "Make citation" nil)
(autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
(add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode

;; Make RefTeX faster
(setq reftex-enable-partial-scans t)
(setq reftex-save-parse-info t)
(setq reftex-use-multiple-selection-buffers t)
(setq reftex-plug-into-AUCTeX t)

;; Make RefTex able to find my local bib files
(setq reftex-bibpath-environment-variables
'("F:/MyWork/bibs"))

;; Default bibliography
(setq reftex-default-bibliography
'("F:/MyWork/bibs/socbib.bib"))

;; RefTeX formats for biblatex (not natbib)
(setq reftex-cite-format
'(
(?\C-m . "\\cite[]{%l}")
(?t . "\\textcite{%l}")
(?a . "\\autocite[]{%l}")
(?p . "\\parencite{%l}")
(?f . "\\footcite[][]{%l}")
(?F . "\\fullcite[]{%l}")
(?x . "[]{%l}")
(?X . "{%l}")
))

(setq font-latex-match-reference-keywords
'(("cite" "[{")
("cites" "[{}]")
("footcite" "[{")
("footcites" "[{")
("parencite" "[{")
("textcite" "[{")
("fullcite" "[{") 
("citetitle" "[{") 
("citetitles" "[{") 
("headlessfullcite" "[{")))

(setq reftex-cite-prompt-optional-args nil)
(setq reftex-cite-cleanup-optional-args t)

;; CDLaTex minor mode: tab-trigger environments, paired paren insertion, etc
(autoload 'cdlatex-mode "cdlatex" "CDLaTeX Mode" t)
(autoload 'turn-on-cdlatex "cdlatex" "CDLaTeX Mode" nil)
(add-hook 'LaTeX-mode-hook 'turn-on-cdlatex)   ; with AUCTeX LaTeX mode

;; set which characters are autopaired // Doesn't work. Set in custom, below.
;; (add-hook 'cdlatex-mode-hook
;;   (function (lambda ()
;;               (setq cdlatex-paired-parens
;;                     '("$[{("))
;;             )))

Pandoc

Make Emacs see where pandoc is installed. (Emacs can’t access the bash $PATH directly.) #+src-name: pandoc_mode

(load "pandoc-mode")
(add-hook 'markdown-mode-hook 'turn-on-pandoc)
(add-hook 'pandoc-mode-hook 'pandoc-load-default-settings)

Markdown

(autoload 'markdown-mode "markdown-mode.el"
"Major mode for editing Markdown files" t)
(setq auto-mode-alist
(cons '("\\.Markdown" . markdown-mode) auto-mode-alist)
)
(setq auto-mode-alist
(cons '("\\.MarkDown" . markdown-mode) auto-mode-alist)
)
(setq auto-mode-alist
(cons '("\\.markdown" . markdown-mode) auto-mode-alist)
)
(setq auto-mode-alist
(cons '("\\.md" . markdown-mode) auto-mode-alist)
)

Orgmode Mobile

MobileMe iDisk. #+src-name: orgmode-mobile

(setq org-directory "~/../Documents/org")
;;(setq org-mobile-directory "/Volumes/kjhealy-1/org/")
;;(setq org-mobile-inbox-for-pull "~/Documents/org/from-mobile.org")

Org-mode Babel

Babel literate programming framework for org-mode/R. You can enable it for other languages, too.)

;; (require 'ob-R)         ;; requires R and ess-mode
(require 'ob-emacs-lisp)
(require 'ob-python)
(require 'ob-haskell)
;; (require 'ob-sh)

Haskell Mode

Haskell.

(load "haskell-site-file")
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)

iBuffer

Manage a lot of buffers easily with C-x C-b. Already set up elsewhere in the starter kit. Add local configuration here, e.g., display categories.

(setq ibuffer-saved-filter-groups
    '(("home"
	 ("emacs-config" (or (filename . ".emacs.d")
			     (filename . "emacs-config")))
	 ("Org" (or (mode . org-mode)
		    (filename . "OrgMode")))
	 ("Web Dev" (or (mode . html-mode)
			(mode . css-mode)))
	 ("Magit" (name . "\*magit"))
	 ("ESS" (mode . ess-mode))
       ("LaTeX" (mode . latex-mode))
	 ("Help" (or (name . "\*Help\*")
		     (name . "\*Apropos\*")
		     (name . "\*info\*"))))))

      (add-hook 'ibuffer-mode-hook 
	             '(lambda ()
	             (ibuffer-switch-to-saved-filter-groups "home")))
     (setq ibuffer-show-empty-filter-groups nil)                     
     (setq ibuffer-expert t)
     (add-hook 'ibuffer-mode-hook 
     '(lambda ()
     (ibuffer-auto-mode 1)
     (ibuffer-switch-to-saved-filter-groups "home")))

Final Custom elements

;; Put the menu bar back
(menu-bar-mode 1)

;; Tweak to ergo keybindings for commenting regions of text
(global-set-key (kbd "M-;") 'comment-dwim)

;; Base dir
(cd "~/")

;; ;; custom variables kludge. Why can't I get these to work via setq?
;; (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.
;; '(LaTeX-XeTeX-command "xelatex -synctex=1")
;; '(TeX-engine (quote xetex))
;; '(TeX-view-program-list (quote (("Skim"  "/Applications/Skim.app/Contents/SharedSupport/displayline %n %o %b"))))
;; '(TeX-view-program-selection (quote (((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "Skim") (output-html "xdg-open"))))
;; ;; '(cdlatex-paired-parens "$[{(")
;; )