Skip to content

Instantly share code, notes, and snippets.

@tnaia
Forked from btskinner/.emacs
Created May 9, 2022 20:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tnaia/9e32aee3bbd2b82ea1ea36a38e8e6b29 to your computer and use it in GitHub Desktop.
My .emacs file
;; -----------------------------------------------------------------------------
;;
;; [ FILE ] Emacs customization file
;; [ NAME ] .emacs
;; [ PATH ] ~/.emacs
;; [ AUTH ] Benjamin Skinner @btskinner
;; [ INIT ] 2 August 2017
;; [ REVN ] 22 May 2021
;;
;; -----------------------------------------------------------------------------
;; -- ENVIRONMENT ------------------------------------------
(unless (getenv "LANG") (setenv "LANG" "en_US.UTF-8"))
(setq default-directory "~/" )
;; -- PACKAGES (MELPA) -------------------------------------
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
;; -- THEME AND VISUAL SETTINGS ----------------------------
;; high-contrast zenburn theme (melpa)
(load-theme 'hc-zenburn t)
;; no tool bar
(tool-bar-mode 0)
;; no scroll bars
(scroll-bar-mode -1)
;; no start up message
(setq inhibit-startup-message t)
(setq initial-scratch-message "")
;; removes *messages* from the buffer
(setq-default message-log-max nil)
(kill-buffer "*Messages*")
;; Removes *Completions* from buffer
(add-hook 'minibuffer-exit-hook
'(lambda ()
(let ((buffer "*Completions*"))
(and (get-buffer buffer)
(kill-buffer buffer)))))
;; no audible or visual bell when emacs is mad
(setq ring-bell-function 'ignore)
;; font size
(set-face-attribute 'default nil :height 160)
;; turn on line and column numbers
(setq line-number-mode t)
(setq column-number-mode t)
;; default frame size
(add-to-list 'default-frame-alist '(width . 90)
'(height . 100))
;; quick toggle fullscreen to match MacOS (Command + Control + f)
(global-set-key (kbd "M-C-f") 'toggle-frame-fullscreen)
;; unique buffer names (with directory)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
;; correct shell path
(setq explicit-shell-file-name "/usr/local/bin/bash")
(define-key global-map (kbd "C-M-t")
(lambda () (interactive) (term explicit-shell-file-name)))
;; -- GENERAL SETTINGS -------------------------------------
;; SPELLING (brew install hunspell)
;; (setq-default ispell-program-name "/usr/local/bin/hunspell")
;; (setq ispell-really-hunspell t)
;; use the tab key to make 4 spaces
(setq tab-width 4)
(setq indent-tabs-mode nil)
;; no backup~ files
(setq make-backup-files nil)
;; no #autosave# files
(setq auto-save-default nil)
;; allow upcase (C-x C-u) and downcase (C-x C-l) region
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
;; -- OTHER KEY BINDINGS/MODIFICATIONS ---------------------
;; jump to other window (split screen)
(global-set-key [C-tab] 'other-window)
;; jump to other frame (split window)
(global-set-key (kbd "C-\`") 'other-frame)
;; Mac option and command keys to meta (helps with non-Mac external keyboard)
(setq mac-option-key-is-meta t
mac-command-key-is-meta t
mac-command-modifier 'meta
mac-option-modifier 'meta)
;; -- MODES ------------------------------------------------
;; -- STATA --------
;; Stata name
(setq inferior-STA-program-name
"/Applications/Stata/StataMP.app/Contents/MacOS/stata-mp")
;; better Stata ado-mode (https://github.com/louabill/ado-mode)
(add-to-list 'load-path "~/.emacs.d/ado-mode/lisp")
(require 'ado-mode)
;; my comment style for Stata
(defun my-Stata-comment-style ()
"Change comment style for ESS Stata"
(if (string= mode-name "Ado")
(progn
(setq comment-start "// "
comment-end ""))))
;; add my Stata comment style to hook
(add-hook 'ado-mode-hook 'my-Stata-comment-style)
;; don't indent closing brace
(setq ado-close-under-line-flag nil)
;; intent 4 spaces with continued line (not 2)
(setq ado-continued-statement-indent-spaces 4)
;; -- R ------------
(require 'ess-site)
;; functions for R pipes
;; (h/t https://emacs.stackexchange.com/a/8055)
(defun then_R_operator ()
"R - %>% operator or 'then' pipe operator"
(interactive)
(just-one-space 1)
(insert "%>%")
(just-one-space 1)
)
(defun base_R_pipe ()
"R - |> operator or 'base' pipe operator"
(interactive)
(just-one-space 1)
(insert "|>")
(just-one-space 1)
)
;; remap ";" key:
;; ; --> "<-"
;; Control + ; --> "|>"
;; Control + Meta + ; --> "%>%"
;; NB: quick tap ; to get semicolon
(dolist (map (list ess-mode-map inferior-ess-mode-map))
(define-key map (kbd ";") 'ess-insert-assign))
(dolist (map (list ess-mode-map inferior-ess-mode-map))
(define-key map (kbd "C-M-;") 'then_R_operator))
(dolist (map (list ess-mode-map inferior-ess-mode-map))
(define-key map (kbd "C-;") 'base_R_pipe))
;; Rmd modes
(require 'poly-R)
(require 'poly-markdown)
(add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))
(add-to-list 'auto-mode-alist '("\\.rmd" . poly-markdown+r-mode))
;; -- Markdown -----
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist
'("\\.md" . markdown-mode))
(autoload 'gfm-mode "markdown-mode"
"Major mode for editing GitHub Flavored Markdown files" t)
(add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
;; open current file in Marked 2
(defun markdown-preview-file ()
"use Marked 2 to preview the current file"
(interactive)
(shell-command
(format "open -a 'Marked 2.app' %s"
(shell-quote-argument (buffer-file-name))))
)
(global-set-key "\C-cm" 'markdown-preview-file)
(add-hook 'markdown-mode-hook 'pandoc-mode)
(add-hook 'pandoc-mode-hook 'pandoc-load-default-settings)
;; -- LaTeX --------
;; set LaTeX engine
(setq TeX-engine (quote xetex))
;; save when compiling
(setq TeX-save-query nil)
;; add synctex
(setq LaTeX-command "pdflatex -synctex=1")
;; auctex parse on load and save
(setq tex-parse-self t)
(setq tex-auto-save t)
(setq TeX-command-list
(quote
(("LaTeX" "%`%l%(mode)%' %t" TeX-run-TeX nil
(latex-mode doctex-mode) :help "Run LaTeX")
("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX")
("Biber" "biber %s" TeX-run-Biber t t :help "Run Biber")
("View" "%V" TeX-run-discard-or-function nil t :help "Run Viewer"))))
;; set default TeX command
(setq TeX-command-default "xelatex")
;; SWV settings
(setq ess-swv-processor (quote knitr))
(setq ess-swv-pdflatex-commands '("pdflatex"))
;; only change sectioning colour
(setq font-latex-fontify-sectioning 'color)
;; super-/sub-script on baseline
(setq font-latex-script-display (quote (nil)))
;; -- Other --------
;; no Flymake
(setq ess-use-flymake nil)
;; Macros indent in C/C++ code
(c-set-offset (quote cpp-macro) 0 nil)
;; Stan mode
(require 'stan-mode)
;; -- FUNCTIONS --------------------------------------------
;; replace smart quotes (h/t https://superuser.com/a/604264)
(defun replace-smart-quotes (beg end)
"Replace 'smart quotes' in buffer or region with ascii quotes."
(interactive "r")
(format-replace-strings '(("\x201C" . "\"")
("\x201D" . "\"")
("\x2018" . "'")
("\x2019" . "'"))
nil beg end))
;; do not change super-/sub-script font
(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.
'(font-latex-subscript-face ((t nil)))
'(font-latex-superscript-face ((t nil))))
;; exclude bold/italic from keywords
(setq font-latex-deactivated-keyword-classes
'("italic-command"
"bold-command"
"italic-declaration"
"bold-declaration"))
(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
(pandoc-mode dash ess use-package xterm-color zmq jupyter exec-path-from-shell poly-R markdown-mode stan-mode xkcd julia-mode auctex writeroom-mode hc-zenburn-theme))))
;; -----------------------------------------------------------------------------
;; END FILE
;; -----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment