This file documents the configuration used by "Emacs for the rest of us".
See the quick start guide for instructions on installing and using Emacs with this configuration.
It is difficult to support multiple versions of emacs, so we will pick an arbitrary cutoff and throw an error if the version of emacs is "too old".
when (< emacs-major-version 26)
(error "Your version of emacs is old and must be upgraded before you can use these packages! Version >= 26 is required."))
(
;; start maximized
setq frame-resize-pixelwise t
(t)
x-frame-normalize-before-maximize
(add-to-list 'initial-frame-alist '(fullscreen . fullheight))
;; set coding system so emacs doesn't choke on melpa file listings
-8)
(set-language-environment 'utfsetq locale-coding-system 'utf-8)
(-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utfunless (eq system-type 'windows-nt)
(-8))
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utfsetq buffer-file-coding-system 'utf-8)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
(
;; set things that need to be set before packages load
setq outline-minor-mode-prefix "\C-c\C-o")
(
(add-hook 'outline-minor-mode-hooklambda () (local-set-key "\C-c\C-o"
(
outline-mode-prefix-map)))setq save-abbrevs 'silently)
(setq max-specpdl-size 10000
(5000) max-lisp-eval-depth
The main purpose of these emacs configuration files is to install and configure useful emacs packages. Here we carry out the installation.
Note that we use a heuristic to decide whether to install language support (e.g., for R
or Scala
etc.). If the corresponding program is in your PATH
Emacs support will be installed. For example, if R
is in your PATH
the ESS package will be installed.
If a program is not in your PATH
but you wish to install an Emacs package anyway you can add it to the list of required packages following the instructions in the custom.el
file. For example, putting (add-to-list 'package-slected-packages 'ess)
in your custom.el
file will ensure that the ESS package is installed even if the R
program is not in your PATH
.
;; load the package manager
require 'package)
(when (< emacs-major-version 27)
(
(package-initialize))
require 'cl-lib)
(
;; Add additional package sources
"melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '(
;; Fix gnu package archive verification in Emacs 26.2 by disabling broken TLS 1.3 support
;; per https://www.reddit.com/r/emacs/comments/cdei4p/failed_to_download_gnu_archive_bad_request/
if (and (= emacs-major-version 26) (= emacs-minor-version 2))
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
(
;; Assume yes to the package installation prompts if EMACS_AUTOINSTALL_PACKAGES=yes
if (string-equal (getenv "EMACS_AUTOINSTALL_PACKAGES") "yes")
(compile activate)
(defadvice package-install-selected-packages (around auto-confirm symbol-function 'yes-or-no-p) (lambda (&rest args) t))
(letf (((symbol-function 'y-or-n-p) (lambda (&rest args) t)))
((
ad-do-it)))
;; A list of the packages we always want
setq package-selected-packages
(;; gnu packages
'(
windresize
diff-hl
adaptive-wrap
pdf-tools
yasnippet
yasnippet-snippets
multiple-cursors
visual-regexp
command-log-mode
undo-tree
better-defaults
minions
ace-window
rotate
howdoi
multi-term
with-editor
anzu
counsel
flx-ido
smex
hydra
ivy-hydra
wgrep
which-key
outline-magic
smooth-scroll
unfill
company
company-math
web-mode
markdown-mode
polymode
poly-markdown
poly-org
poly-noweb
eval-in-repl
exec-path-from-shell
dumb-jump
flycheck
htmlize
dictionary
untitled-new-buffer))
;; hide compilation buffer when complete
;; from http://emacs.stackexchange.com/questions/62/hide-compilation-window
(add-hook 'compilation-finish-functionslambda (buf str)
(if (null (string-match ".*exited abnormally.*" str))
(;;no errors, make the compilation window go away in a few seconds
progn
(
(run-at-time"2 sec" nil 'delete-windows-on
"*compilation*"))
(get-buffer-create
(run-at-time"2 sec" nil 'delete-windows-on
"*Compile-Log*"))
(get-buffer-create "No Compilation Errors!")))))
(message
;; install packages if needed
unless (cl-every 'package-installed-p package-selected-packages)
("Missing packages detected, please wait...")
(message
(package-refresh-contents)
(package-install-selected-packages))
(package-initialize)
We try to install most things using the package manager, but a few things need to be included in a custom lisp directory. Add it to the path so we can load from it easily.
;; add custom lisp directory to path
unless
("lisp"))
(file-exists-p (concat user-emacs-directory "lisp")))
(make-directory (concat user-emacs-directory
;; add custom lisp directory to path
let ((default-directory (concat user-emacs-directory "lisp/")))
(setq load-path
(append
(let ((load-path (copy-sequence load-path))) ;; Shadow
(append
(".")))
(copy-sequence (normal-top-level-add-to-load-path '(
(normal-top-level-add-subdirs-to-load-path)))
load-path)))
;; on OSX Emacs needs help setting up the system paths
when (memq window-system '(mac ns))
(require 'exec-path-from-shell)
(;; From https://github.com/aculich/.emacs.d/blob/master/init.el
;; Import additional environment variables beyond just $PATH
dolist (var '("PYTHONPATH" ; Python modules
("INFOPATH" ; Info directories
"JAVA_OPTS" ; Options for java processes
"SBT_OPTS" ; Options for SBT
"RUST_SRC_PATH" ; Rust sources, for racer
"CARGO_HOME" ; Cargo home, for racer
"EMAIL" ; My personal email
"GPG_TTY"
"GPG_AGENT_INFO"
"SSH_AUTH_SOCK"
"SSH_AGENT_PID"
))
(add-to-list 'exec-path-from-shell-variables var))
(exec-path-from-shell-initialize))
;; Add to the list of the packages we want
when (executable-find "R")
(
(add-to-list 'package-selected-packages 'ess)
(add-to-list 'package-selected-packages 'poly-R))when (executable-find "python")
(
(add-to-list 'package-selected-packages 'poetry)
(add-to-list 'package-selected-packages 'conda))when (executable-find "pdflatex")
(
(add-to-list 'package-selected-packages 'auctex)
(add-to-list 'package-selected-packages 'ivy-bibtex))when (executable-find "git")
(
(add-to-list 'package-selected-packages 'git-commit)
(add-to-list 'package-selected-packages 'magit))when (executable-find "julia")
(
(add-to-list 'package-selected-packages 'julia-mode)
(add-to-list 'package-selected-packages 'julia-repl))when (or (executable-find "ghc")
("stack"))
(executable-find
(add-to-list 'package-selected-packages 'haskell-mode)
(add-to-list 'package-selected-packages 'company-ghci))when (executable-find "jupyter")
(
(add-to-list 'package-selected-packages 'ein))when (executable-find "pandoc")
(
(add-to-list 'package-selected-packages 'pandoc-mode)
(add-to-list 'package-selected-packages 'ox-pandoc))when (executable-find "scala")
(
(add-to-list 'package-selected-packages 'scala-mode)
(add-to-list 'package-selected-packages 'sbt-mode))
;; install packages if needed
unless (cl-every 'package-installed-p package-selected-packages)
("Missing packages detected, please wait...")
(message
(package-refresh-contents) (package-install-selected-packages))
This section sets up various utilities and conveniences. Many of these are low priority, so we set them first in order to allow any conflicting settings to be overridden later.
;; ;; clean up the mode line
setq minions-mode-line-lighter "☰")
(1)
(minions-mode
;; No, we do not need the splash screen
setq inhibit-startup-screen t)
(
require 'better-defaults)
(;; better defaults are well, better... but we don't always agree
"menu-bar"
(with-eval-after-load 1))
(menu-bar-mode "scroll-bar"
(with-eval-after-load 1))
(scroll-bar-mode
setq select-active-regions 'only)
(
;; from https://github.com/bbatsov/prelude/
;; store all backup and autosave files in the tmp dir
setq backup-directory-alist
(".*" . ,temporary-file-directory)))
`((setq auto-save-file-name-transforms
(".*" ,temporary-file-directory t)))
`((;; autosave the undo-tree history
setq undo-tree-history-directory-alist
(".*" . ,temporary-file-directory)))
`((
;; scrolling behavior
setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ; one line at a time
(setq mouse-wheel-progressive-speed nil) ; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ; scroll window under mouse
(setq scroll-preserve-screen-position t)
(setq scroll-conservatively 100000)
(setq scroll-error-top-bottom t)
(setq scroll-preserve-screen-position t)
(;; scroll without moving point
require 'smooth-scroll)
(-1)
(global-set-key [(control down)] 'scroll-up-1)
(global-set-key [(control up)] 'scroll-down-1)
(global-set-key [(control left)] 'scroll-right-1)
(global-set-key [(control right)] 'scroll-left
;; Use y/n instead of yes/no
(fset 'yes-or-no-p 'y-or-n-p)
1) ; makes the region visible
(transient-mark-mode 1) ; makes the line number show up
(line-number-mode 1) ; makes the column number show up
(column-number-mode
;; make home and end behave
"<home>") 'move-beginning-of-line)
(global-set-key (kbd "<end>") 'move-end-of-line)
(global-set-key (kbd
;; enable toggling paragraph un-fill
"\M-Q" 'unfill-paragraph)
(define-key global-map
;;; line wrapping
;; neck beards be damned, we don't need to hard wrap. The editor can soft wrap for us.
(remove-hook 'text-mode-hook 'turn-on-auto-fill);; (add-hook 'visual-line-mode-hook 'adaptive-wrap-prefix-mode)
;;
t)
(setq-default truncate-lines 1)
(global-visual-line-mode
(add-hook 'prog-mode-hooklambda()
(setq truncate-lines t)
(t)))
(outline-minor-mode
;; indicate visual-line-mode wrap
setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))
(setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))
(;; but be gentle
when (fboundp 'set-fringe-bitmap-face)
(
(defface visual-line-wrap-facet (:foreground "gray")))
'(("Face for visual line indicators.")
(set-fringe-bitmap-face 'left-curly-arrow 'visual-line-wrap-face)
(set-fringe-bitmap-face 'right-curly-arrow 'visual-line-wrap-face))
;; don't require two spaces for sentence end.
setq sentence-end-double-space nil)
(
;; The beeping can be annoying--turn it off
setq visible-bell t
(
ring-bell-function #'ignore)
;; save place -- move to the place I was last time I visited this file
t)
(save-place-mode
;; regular cursor
;(setq-default cursor-type '(bar . 5))
0)
(setq-default blink-cursor-blinks
(add-hook 'after-init-hooklambda()
(setq blink-cursor-blinks 0)))
(
;; easy navigation in read-only buffers
setq view-read-only t)
("view-mode"
(with-eval-after-load "s") 'isearch-forward-regexp))
(define-key view-mode-map (kbd
;; set up read-only buffers
(add-hook 'read-only-mode-hook lambda()
(cond
(and (not buffer-read-only)
((not (eq (get major-mode 'mode-class) 'special)))
(-1)
(hl-line-mode 0)
(setq-local blink-cursor-blinks 3))
(setq-local cursor-type '(bar . t))
(company-mode and buffer-read-only
((not (eq (get major-mode 'mode-class) 'special)))
(t)
(hl-line-mode 1)
(setq-local blink-cursor-blinks
(setq-local cursor-type 'hollow)-1)))))
(company-mode
;; show parentheses
1)
(show-paren-mode setq show-paren-delay 0) (
Emacs will never to as simple as Notepad, but perhaps it can be made more consistent with the way most other programs behave. In addition to more consistent copy/paste, undo/redo, we also implement multiple cursors. Use C-c C-m
to add or remove cursors.
;; Use CUA mode to make life easier. We do _not__ use standard copy/paste etc. (see below).
t)
(cua-mode
t) ;; cua goodness without copy/paste etc.
(cua-selection-mode
;; load windows-style keys using windows key instead of control.
require 'win-win)
(
;; ;; Make control-z undo
let ((map (make-sparse-keymap)))
(;; remap `undo' and `undo-only' to `undo-tree-undo'
;; (define-key map [remap undo] 'undo-tree-undo)
;; (define-key map [remap undo-only] 'undo-tree-undo)
;; bind standard undo bindings (since these match redo counterparts)
;; (define-key map (kbd "C-/") 'undo-tree-undo)
;; (define-key map "\C-_" 'undo-tree-undo)
;; redo doesn't exist normally, so define our own keybindings
map (kbd "C-?") 'undo-tree-redo)
(define-key map (kbd "M-_") 'undo-tree-redo)
(define-key map (kbd "C-S-z") 'undo-tree-redo)
(define-key ;; just in case something has defined `redo'...
map [remap redo] 'undo-tree-redo)
(define-key ;; we use "C-x U" for the undo-tree visualizer
map (kbd "\C-x U") 'undo-tree-visualize)
(define-key ;; bind register commands
map (kbd "C-x r u") 'undo-tree-save-state-to-register)
(define-key map (kbd "C-x r U") 'undo-tree-restore-state-from-register)
(define-key ;; set keymap
setq undo-tree-map map))
(
t)
(global-undo-tree-mode
;; Make C-g quit undo tree
"C-g") 'undo-tree-visualizer-quit)
(define-key undo-tree-visualizer-mode-map (kbd "<escape> <escape> <escape>") 'undo-tree-visualizer-quit)
(define-key undo-tree-visualizer-mode-map (kbd
;;
;; Make right-click do something close to what people expect
require 'mouse3)
("<mouse-3>") 'mouse3-popup-menu)
(global-set-key (kbd ;; (global-set-key (kbd "C-f") 'isearch-forward)
;; (global-set-key (kbd "C-s") 'save-buffer)
;; (global-set-key (kbd "C-o") 'counsel-find-file)
"<C-S-SPC>") nil)
(define-key cua-global-keymap (kbd "<C-return>") nil)
(define-key cua-global-keymap (kbd setq cua-rectangle-mark-key (kbd "<C-S-SPC>"))
("<C-S-SPC>") 'cua-rectangle-mark-mode)
(define-key cua-global-keymap (kbd
;; zoom in/out like we do everywhere else.
"C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
(global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease)
(global-set-key (kbd "<C-mouse-4>") 'text-scale-increase)
(global-set-key (kbd ;; page up/down
"<C-prior>") 'beginning-of-buffer)
(global-set-key (kbd "<C-next>") 'end-of-buffer)
(global-set-key (kbd
;; allow multiple cursors, as in Sublime and VScode
require 'multiple-cursors)
(nil)
(defhydra multiple-cursors-hydra (:hint "
^Up^ ^Down^ ^Other^
----------------------------------------------
[_p_] Next [_n_] Next [_l_] Edit lines
[_P_] Skip [_N_] Skip [_a_] Mark all
[_M-p_] Unmark [_M-n_] Unmark [_r_] Mark by regexp
^ ^ ^ ^ [_q_] Quit
"
"l" mc/edit-lines :exit t)
("a" mc/mark-all-like-this :exit t)
("n" mc/mark-next-like-this)
("N" mc/skip-to-next-like-this)
("M-n" mc/unmark-next-like-this)
("p" mc/mark-previous-like-this)
("P" mc/skip-to-previous-like-this)
("M-p" mc/unmark-previous-like-this)
("r" mc/mark-all-in-region-regexp :exit t)
("q" nil))
(
"C-c m") #'multiple-cursors-hydra/body) (global-set-key (kbd
windmove
allows you to move point to adjacent windows; these functions are bound to C-x S-<arrow>
. For example, to move to the window below, press "Control-x shift-down", and to move to the window to the right press "Control-x shift-right". If you have more than one split you can use C-x O
to quickly navigate to an window arbitrary window (e.g., diagonal from the current window; see https://github.com/abo-abo/ace-window/ for details).
winner-mode
allows you to undo/redo window configuration changes. Use C-c <left>
to undo and C-c <right>
to redo.
Emacs has window layout management, built-in but it's not convenient to use. We use ivy to make it easier. Store the current view with C-c v
, switch with C-c V
.
Finally, emacs-rotate makes arranging your windows much easier. Use C-c b
to rotate buffers and C-c a
to rotate the window arrangement.
;; Undo/redo window changes
1)
(winner-mode
;; windmove
"C-x <S-left>") 'windmove-left)
(global-set-key (kbd "C-x <S-right>") 'windmove-right)
(global-set-key (kbd "C-x <S-up>") 'windmove-up)
(global-set-key (kbd "C-x <S-down>") 'windmove-down)
(global-set-key (kbd
;; Store and recall window layouts (views!)
"C-c v") 'ivy-push-view)
(global-set-key (kbd "C-c V") 'ivy-switch-view)
(global-set-key (kbd
;; use ace-window for navigating windows
"C-x O") 'ace-window)
(global-set-key (kbd "ace-window"
(with-eval-after-load setq aw-dispatch-always t)
(nil :height 2.5))
(set-face-attribute 'aw-leading-char-face
;; rotate buffers and window arrangements
"C-c b") 'rotate-window)
(global-set-key (kbd "C-c a") 'rotate-layout)
(global-set-key (kbd
;; modified from https://github.com/aculich/.emacs.d/blob/master/init.el
setq frame-title-format
(if (buffer-file-name)
'(:eval ("%b"))
(abbreviate-file-name (buffer-file-name)) ;; Size new windows proportionally wrt other windows
;;window-combination-resize t
)
Emacs comes with spell checking built-in, it just needs to be turned on. By default automatic spell checking is enabled in text-mode
and prog-mode
buffers. You can also spell-check on demand with ispell-word
, bound to M-$
. Finally, dictionaries look-up is available and bound to C-c d
.
More information is available at https://www.gnu.org/software/emacs/manual/html_node/emacs/Spelling.html and https://github.com/abo-abo/define-word.
;; enable on-the-fly spell checking
setq flyspell-use-meta-tab nil)
(
(add-hook 'text-mode-hooklambda ()
(1)))
(flyspell-mode ;; prevent flyspell from finding misspellings in code
(add-hook 'prog-mode-hooklambda ()
(;; `ispell-comments-and-strings'
(flyspell-prog-mode)))
;; ispell should not check code blocks in org mode
":\\(PROPERTIES\\|LOGBOOK\\):" . ":END:"))
(add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
(add-to-list 'ispell-skip-region-alist '("#\\+begin_src" . "#\\+end_src"))
(add-to-list 'ispell-skip-region-alist '("^#\\+begin_example " . "#\\+end_example$"))
(add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_EXAMPLE " . "#\\+END_EXAMPLE$"))
(add-to-list 'ispell-skip-region-alist '(
;; Dictionaries
"C-c d") 'dictionary-search)
(global-set-key (kbd "C-c D") 'dictionary-match-words) (global-set-key (kbd
If you're using Vincent Goulet's emacs on Windows printing should work out of the box. If you're on Linux or Mac the experience of printing from emacs may leave something to be desired. Here we try to make it work a little better by making it easier to preview buffers in a web browser (you can print from there as usual) and by using gtklp on Linux if it is available.
when (eq system-type 'gnu/linux)
(setq mygtklp (executable-find "gtklp"))
(when mygtklp
(setq lpr-command "gtklp")
(setq ps-lpr-command "gtklp"))) (
There are several different systems for providing completion hints in emacs. The default pcomplete system shows completions on demand (usually bound to tab key) in an emacs buffer. Here we set up ivy, which instead shows these completions on-the-fly in the minibuffer. These completions are primarily used to show available files (e.g., with find-file
) and emacs functions (e.g., with execute-extended-command
).
When selecting candidates using the minibuffer you can execute the default action (e.g., open a file) by pressing return
. You can get a list of other actions by pressing M-o
.
Note that selecting long candidates can be a bit awkward. Candidates longer than the current Emacs frame are wrapped by default. You can turn wrapping off (so that each candidate occupies a single line) by pressing C-l
in the minibuffer selection window.
More information is available at http://oremacs.com/swiper/.
;; use ivy instead of ido
nil)
(ido-mode 1)
(ivy-mode 1)
(counsel-mode require 'ivy-hydra)
(
;; make sure we wrap in the minibuffer
setq ivy-truncate-lines nil)
(
;; more obvious separator for yank-pop
setq counsel-yank-pop-separator "
(
-%<-%<-%<-%<-%<-%<-%<-%<-%<-%<-%<-%<
")
setq counsel-find-file-ignore-regexp "\\`\\.")
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
(setq ivy-use-selectable-prompt t)
(;; (setq ivy-display-style nil)
;; Ivy-based interface to describe keybindings
"C-h b") 'counsel-descbinds)
(global-set-key (kbd
;; isearch
setq enable-recursive-minibuffers t
(t)
isearch-allow-scroll require 'hl-line)
(require 'anzu)
(1)
(global-anzu-mode +"C-s") 'isearch-forward)
(global-set-key (kbd "C-S-s") 'isearch-forward-regexp)
(global-set-key (kbd defun my-turn-on-hl-line ()
(setq old-hl-line-mode-value hl-line-mode)
(1))
(hl-line-mode defun my-toggle-hl-line ()
(unless old-hl-line-mode-value (hl-line-mode -1)))
(
(add-hook 'isearch-mode-hook 'my-turn-on-hl-line)
(add-hook 'isearch-mode-end-hook 'my-toggle-hl-line);; from https://emacs.stackexchange.com/questions/10307/how-to-center-the-current-line-vertically-during-isearch
(defadvice isearch-update (before my-isearch-reposite activate)0)
(sit-for
(recenter))"C-'") 'avy-isearch)
(define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
(define-key isearch-mode-map (kbd "C-p") 'isearch-repeat-backward)
(define-key isearch-mode-map (kbd "C-p") 'isearch-repeat-backward)
(define-key isearch-mode-map (kbd "C-o") 'isearch-occur)
(define-key isearch-mode-map (kbd
;; visual query replace
"C-r") 'vr/query-replace)
(global-set-key (kbd "C-S-r") 'vr/replace)
(global-set-key (kbd ;; default file searcher if we don't find something better
"C-c f") 'find-grep-dired)
(global-set-key (kbd "C-c f") 'find-grep-dired)
(global-set-key (kbd ;; use better searching tool if available
cond
("rg") ; search with ripgrep if we have it
((executable-find "C-c f") 'counsel-rg)
(global-set-key (kbd "C-c s") 'counsel-rg))
(global-set-key (kbd "ag") ; otherwise search with ag if we have it
((executable-find "C-c f") 'counsel-ag)
(global-set-key (kbd "C-c s") 'counsel-ag))
(global-set-key (kbd "pt") ; otherwise search with pt if we have it
((executable-find "C-c f") 'counsel-pt)
(global-set-key (kbd "C-c f") 'counsel-pt)))
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "M-y") 'counsel-yank-pop)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "C-o") 'counsel-find-file)
(global-set-key (kbd ;; search for files to open with "C-O=
when (memq window-system '(mac ns)) ; use mdfind on Mac. TODO: what about windows?
(setq locate-command "mdfind")
(setq counsel-locate-cmd 'counsel-locate-cmd-mdfind))
(;; default file-finding in case we don't have something better
"C-x C-S-F") 'find-name-dired)
(global-set-key (kbd "C-c l") 'find-name-dired)
(global-set-key (kbd ;; use locate if we have it.
when (executable-find "locate")
("C-c l") 'counsel-locate)
(global-set-key (kbd ;;(global-set-key (kbd "C-x C-S-F") 'counsel-locate) ;; FIXME -- need better key
)"C-x C-r") 'counsel-recentf)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> l") 'counsel-load-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd ;; Ivy-based interface to shell and system tools
"C-c g") 'counsel-git)
(global-set-key (kbd "C-c j") 'counsel-git-grep)
(global-set-key (kbd "C-c k") 'counsel-ag)
(global-set-key (kbd
;; Ivy-resume and other commands
"C-c i") 'ivy-resume)
(global-set-key (kbd
;; Make Ivy more like ido
"RET") 'ivy-alt-done)
(define-key ivy-minibuffer-map (kbd "C-d") 'ivy-done)
(define-key ivy-minibuffer-map (kbd "C-b") 'ivy-immediate-done)
(define-key ivy-minibuffer-map (kbd "C-f") 'ivy-immediate-done)
(define-key ivy-minibuffer-map (kbd
defun my-toggle-truncate-lines ()
("Toggle truncate lines in quietly."
(interactive)let ((inhibit-message t))
(
(toggle-truncate-lines)))"C-l") 'my-toggle-truncate-lines)
(define-key ivy-minibuffer-map (kbd "C-l") 'my-toggle-truncate-lines)
(define-key swiper-map (kbd
;; show recently opened files
"recentf"
(with-eval-after-load setq recentf-max-menu-items 50)
("/\\.git/.*\\'")
(add-to-list 'recentf-exclude "/elpa/.*\\'")
(add-to-list 'recentf-exclude "/tramp.*\\'")
(add-to-list 'recentf-exclude "/sudo.*\\'"))
(add-to-list 'recentf-exclude 1)
(recentf-mode
;; better occur mode
(add-hook 'occur-mode-hooklambda()
(t)
(toggle-truncate-lines
(setq-local cursor-type 'box)1)
(setq-local blink-cursor-blinks -1)
(company-mode t)
(hl-line-mode t)))
(next-error-follow-minor-mode
;; Jump easy to definition
setq dumb-jump-selector 'ivy
(nil
dumb-jump-aggressive "./") dumb-jump-default-project
Here we configure in-buffer text completion using the company-mode package. These completions are available on-demand using TAB
for in-buffer popup or C-M-S-i
for search-able minibuffer list. More information is available at https://company-mode.github.io/.
require 'company)
(;; cancel if input doesn't match, be patient, and don't complete automatically.
setq company-require-match nil
(2
company-async-timeout 1
company-idle-delay 2
company-minimum-prefix-length not term-mode))
company-global-modes '(;; use C-n and C-p to cycle through completions
"C-n") 'company-select-next)
(define-key company-active-map (kbd "<tab>") 'company-complete-common)
(define-key company-active-map (kbd "C-p") 'company-select-previous)
(define-key company-active-map (kbd "<backtab>") 'company-select-previous)
(define-key company-active-map (kbd
require 'company-capf)
(require 'company-files)
(require 'company-math)
(push 'company-math-symbols-unicode company-backends))
(delete-dups (push 'company-capf company-backends))
(delete-dups (push 'company-files company-backends))
(delete-dups (
;; completion key bindings
setq tab-always-indent 'complete)
(
(define-key company-mode-map [remap indent-for-tab-command] #'company-indent-or-complete-common)"C-M-i") 'company-complete)
(define-key company-mode-map (kbd "C-M-S-i") 'counsel-company)
(define-key company-mode-map (kbd
(add-hook 'after-init-hook 'global-company-mode)
This mode shows a keymap when an incomplete command is entered. It is especially useful for families of commands with a prefix, e.g., C-c C-o
for outline-mode
commands, or C-c C-v
for org-babel
commands. Just start typing your command and pause if you want a hint.
;; which-key settings taken mostly from https://github.com/aculich/.emacs.d/blob/master/init.el
"which-key"
(with-eval-after-load setq which-key-sort-order 'which-key-prefix-then-key-order
(;; Let's go unicode :)
which-key-key-replacement-alist"<\\([[:alnum:]-]+\\)>" . "\\1")
'(("up" . "↑")
("right" . "→")
("down" . "↓")
("left" . "←")
("DEL" . "⌫")
("deletechar" . "⌦")
("RET" . "⏎"))
(
which-key-description-replacement-alist"Prefix Command" . "prefix")
'((;; Lambdas
"\\`\\?\\?\\'" . "λ")
(;; Prettify hydra entry points
"/body\\'" . "|=")
(;; Drop/shorten package prefixes
"magit-" . "ma-")))
(
(which-key-declare-prefixes;; Prefixes for global prefixes and minor modes
"C-c C-o" "outline"
"C-c C-l" "window/layouts")
;; Prefixes for major modes
(which-key-declare-prefixes-for-mode 'markdown-mode"C-c TAB" "markdown/images"
"C-c C-a" "markdown/links"
"C-c C-c" "markdown/process"
"C-c C-s" "markdown/style"
"C-c C-t" "markdown/header"
"C-c C-x" "markdown/structure"
"C-c m" "markdown/personal")
(which-key-declare-prefixes-for-mode 'emacs-lisp-mode"C-c m" "elisp"
"C-c m e" "eval")
(which-key-declare-prefixes-for-mode 'haskell-mode"C-c m" "haskell/personal"
"C-c m i" "haskell/imports")
(which-key-declare-prefixes-for-mode 'web-mode"C-c C-a" "web/attributes"
"C-c C-b" "web/blocks"
"C-c C-d" "web/dom"
"C-c C-e" "web/element"
"C-c C-t" "web/tags"))
t) (which-key-mode
I encourage you to use org-mode for note taking and outlining, but it can be convenient to treat arbitrary buffers as outlines. The outline-magic mode can help with that.
;;; Configure outline minor modes
;; Less crazy key bindings for outline-minor-mode
setq outline-minor-mode-prefix "\C-c\C-o")
(;; load outline-magic along with outline-minor-mode
(add-hook 'outline-minor-mode-hook lambda ()
(require 'outline-magic)
("\C-c\C-o\t" 'outline-cycle)
(define-key outline-minor-mode-map "<backtab>") 'outline-cycle))) (define-key outline-minor-mode-map (kbd
command-log-mode
is useful for giving emacs demonstrations/tutorials. It shows the keys you've pressed and the commands they called. More information is available at https://github.com/lewang/command-log-mode.
setq command-log-mode-auto-show t)
("C-x cl") 'global-command-log-mode) (global-set-key (kbd
Many programs using REPLs are derived from comint-mode
, so we can affect all of them by changing comint-mode
settings. Here we disable line wrapping and ask programs to echo the input.
Load eval-in-repl for bash, elisp, and python interaction.
;; require the main file containing common functions
require 'eval-in-repl)
(setq comint-process-echoes t
(
eir-repl-placement 'below)
;; truncate lines in comint buffers
(add-hook 'comint-mode-hooklambda()
(setq truncate-lines 1)))
(
;; Scroll down for input and output
setq comint-scroll-to-bottom-on-input t)
(setq comint-scroll-to-bottom-on-output t)
(setq comint-move-point-for-output t) (
Support for R in Emacs is good, thanks to http://ess.r-project.org/. As with other programming languages this configuration enables completion via the <tab>
key and code evaluation with C-ret
. Many more features are provided by ESS, refer to http://ess.r-project.org/ for details.
;;; ESS (Emacs Speaks Statistics)
"ess"
(with-eval-after-load require 'ess-site)
(require 'ess-mode)
(;; standard control-enter evaluation
"<C-return>") 'ess-eval-region-or-function-or-paragraph-and-step)
(define-key ess-mode-map (kbd "<C-S-return>") 'ess-eval-buffer)
(define-key ess-mode-map (kbd
(define-key ess-mode-map [remap ess-indent-or-complete] #'company-indent-or-complete-common);; Set ESS options
setq
(
ess-auto-width 'windownil
ess-use-auto-complete nil
ess-use-flymake
ess-use-company 't;; ess-r-package-auto-set-evaluation-env nil
nil
inferior-ess-same-window nil ; don't indent comments
ess-indent-with-fancy-comments t ; enable echoing input
ess-eval-visibly t ; don't skip non-code lines.
ess-eval-empty nil ; start R in the working directory by default
ess-ask-for-ess-directory nil ; start R in the working directory by default
ess-ask-for-ess-directory ; font-lock, but not too much
ess-R-font-lock-keywords quote
(
((ess-R-fl-keyword:modifiers)t)
(ess-R-fl-keyword:fun-defs . t)
(ess-R-fl-keyword:keywords . t)
(ess-R-fl-keyword:assign-ops . 1)
(ess-R-fl-keyword:constants . t)
(ess-fl-keyword:fun-calls .
(ess-fl-keyword:numbers)t)
(ess-fl-keyword:operators .
(ess-fl-keyword:delimiters)
(ess-fl-keyword:=) (ess-R-fl-keyword:F&T)))))
Emacs has decent python support out of the box. As with other programming languages you can get completion suggestions with the <tab>
key, and evaluate code with C-ret
. Many more features are provided and are accessible via the menu.
(defalias 'python 'run-python)
"python"
(with-eval-after-load ;; conda (https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) environment support
require 'conda)
(;; poetry (https://poetry.eustace.io/) environment support
require 'poetry)
(;; try to get indent/completion working nicely
;; readline support is wonky at the moment
setq python-shell-completion-native-enable nil)
(;; simple evaluation with C-ret
require 'eval-in-repl-python)
(;;(setq eir-use-python-shell-send-string nil)
"C-c C-c") 'eir-eval-in-python)
(define-key python-mode-map (kbd "<C-return>") 'eir-eval-in-python)
(define-key python-mode-map (kbd "C-c C-b") 'python-shell-send-buffer)
(define-key python-mode-map (kbd "<C-S-return>") 'python-shell-send-buffer)
(define-key python-mode-map (kbd ;; use ipython if we can
when (executable-find "ipython")
(setq python-shell-interpreter "ipython"
("--simple-prompt -i"))
python-shell-interpreter-args ;; make outline work
(add-hook 'python-mode-hooklambda()
(;;(setq-local outline-regexp "[#]+")
t)))) (outline-minor-mode
when (executable-find "julia")
(;(require 'julia-mode)
;(require 'julia-repl)
(add-hook 'julia-mode-hook 'julia-repl-mode))
If you want to get the most out of Emacs, you'll eventually need to learn a little Emacs-lisp. This configuration helps by providing a standard C-ret
evaluation key binding, and by providing completion with the <tab>
key.
"elisp-mode"
(with-eval-after-load require 'company-elisp)
(;; ielm
require 'eval-in-repl-ielm)
(;; For .el files
"C-c C-c") 'eir-eval-in-ielm)
(define-key emacs-lisp-mode-map (kbd "<C-return>") 'eir-eval-in-ielm)
(define-key emacs-lisp-mode-map (kbd "C-c C-b") 'eval-buffer)
(define-key emacs-lisp-mode-map (kbd "<C-S-return>") 'eval-buffer)
(define-key emacs-lisp-mode-map (kbd ;; For *scratch*
"\C-c\C-c" 'eir-eval-in-ielm)
(define-key lisp-interaction-mode-map "<C-return>") 'eir-eval-in-ielm)
(define-key lisp-interaction-mode-map (kbd "C-c C-b") 'eval-buffer)
(define-key lisp-interaction-mode-map (kbd "<C-S-return>") 'eval-buffer)
(define-key lisp-interaction-mode-map (kbd ;; For M-x info
"C-c C-c") 'eir-eval-in-ielm)
(define-key Info-mode-map (kbd ;; Set up completions
(add-hook 'emacs-lisp-mode-hooklambda()
(require 'company-elisp)))) (
I just recently started learning Haskell. There's not much to the configuration at this point, but you should get completion with <tab>
. To cycle indentation press Shift+tab
.
"haskell-mode"
(with-eval-after-load (defalias 'haskell 'haskell-interactive-bring))
Markdown is a light-weight markup language that makes easy things easy and stays out of your way. You can export Markdown documents to a wide range of formats including .pdf (via latex), .html, .doc, and more using pandoc
. For more information about authoring markdown in Emacs refer to http://jblevins.org/projects/markdown-mode/. For information about Markdown syntax or exporting to other formats refer to http://pandoc.org.
;; Use markdown-mode for files with .markdown or .md extensions
setq
(t
markdown-enable-math t)
markdown-fontify-code-blocks-natively "\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '(
(add-hook 'markdown-mode-hook 'turn-on-orgtbl)when (executable-find "pandoc")
( (add-hook 'markdown-mode-hook 'pandoc-mode))
Editing HTML in Emacs is OK out of the box, but it doesn't support template systems well. We can fix that with web-mode.
"\\.html?\\'" . web-mode)) (add-to-list 'auto-mode-alist `(
I don't write nearly as much in LaTeX as I used to, as Markdown and/or Org mode are simpler and good enough for my needs. But LaTeX is still the tool of choice for much academic writing, so we use AUCTEX and turn on lots of features. Completion of math and latex commands is available with <tab>
, and auto-compile is available with C-ret
.
See https://www.gnu.org/software/auctex/ for more details about AUCTEX.
;;; AucTeX config
;; Modified from https://emacs.stackexchange.com/questions/33198/how-to-get-auctex-to-automatically-generate-atex-engineluatex-file-variable-d/33204
"tex-site"
(with-eval-after-load defun iqss-prompt-tex-engine ()
(when (eq major-mode 'latex-mode)
(;; Check if we are looking at a new or shared file that doesn't specify a TeX engine.
when (and (not buffer-read-only)
(not (member 'TeX-engine (mapcar 'car file-local-variables-alist))))
(
(save-excursion
(add-file-local-variable
'TeX-engineintern (completing-read "TeX engine not set, how should this document be typeset?: "
(mapcar 'car (TeX-engine-alist)) nil nil nil nil "default"))))
(t)
(TeX-normal-mode
(blink-cursor-start))))
(add-hook
'find-file-hooklambda() (run-at-time "0.5 sec" nil 'iqss-prompt-tex-engine)))
(
"Latex"
(with-eval-after-load ;; Highlight beamer alert
setq font-latex-user-keyword-classes
("beamer-alert" (("alert" "{")
'(("alerta" "{")
("alertb" "{")
("alertc" "{")
("alertd" "{")
("alerte" "{"))
(
font-latex-bold-face command)));; Easy compile key
"<C-return>") 'TeX-command-run-all)
(define-key LaTeX-mode-map (kbd defun my-tex-quit ()
(
(interactive)"Kill any running tex jobs, and cancel other operations."
ignore-errors
(let ((inhibit-message t))
(
(TeX-kill-job)))
(keyboard-quit))
"C-g")
(define-key LaTeX-mode-map (kbd
'my-tex-quit);; Allow paragraph filling in tables
setq LaTeX-indent-environment-list
(assoc "table" LaTeX-indent-environment-list)
(delq (
LaTeX-indent-environment-list))setq LaTeX-indent-environment-list
(assoc "table*" LaTeX-indent-environment-list)
(delq (
LaTeX-indent-environment-list));; Misc. latex settings
setq TeX-parse-self t
(t)
TeX-auto-save ;; (setq TeX-master 'dwim)
setq TeX-save-query nil)
(
(setq-default TeX-master 'dwim);; Add beamer frames to outline list
setq TeX-outline-extra
(".*\\\\begin{frame}\n\\|.*\\\\begin{frame}\\[.*\\]\\|.*\\\\begin{frame}.*{.*}\\|.*[ ]*\\\\frametitle\\b" 3)))
'((;; reftex settings
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)
(
(add-hook 'TeX-mode-hooklambda ()
(
(turn-on-reftex)t)
(TeX-PDF-mode
(LaTeX-math-mode)t)
(TeX-source-correlate-mode "Index")
(imenu-add-to-menubar
(outline-minor-mode)require 'company-math)))
(;; Use pdf-tools to open PDF files
when (eq system-type 'gnu/linux)
(if (string-equal (getenv "EMACS_AUTOINSTALL_PACKAGES") "yes")
(t)
(pdf-tools-install
(pdf-tools-install))setq TeX-view-program-selection '((output-pdf "PDF Tools")))
(t
TeX-source-correlate-start-server ;; Update PDF buffers after successful LaTeX runs
(add-hook 'TeX-after-compilation-finished-functions
#'TeX-revert-document-buffer))
;; Count words in latex
;; see http://app.uio.no/ifi/texcount/faq.html#emacs
;; TeXcount setup for TeXcount version 2.3 and later
;;
when (executable-find "texcount")
(defun texcount ()
(
(interactive)let*
(
((this-file (buffer-file-name))symbol-name buffer-file-coding-system))
(enc-str (
(enc-optcond
("utf-8" enc-str) "-utf8")
((string-match "latin" enc-str) "-latin1")
((string-match "-encoding=guess")))
(
(word-countwith-output-to-string
(
(with-current-buffer standard-output"texcount" nil t nil "-0" enc-opt this-file)))))
(call-process
(message word-count)))"Count the number of words in the buffer."))
(defalias 'tex-count-words 'texcount "\C-cw" 'tex-count-words)
(define-key LaTeX-mode-map
(add-to-list 'TeX-command-listlist "TeX-count-words" "tex-count-words" 'TeX-run-function nil t)))
(
"reftex"
(with-eval-after-load "frametitle" . 2))
(add-to-list 'reftex-section-levels '(setq reftex-toc-split-windows-horizontally t)
(lambda() (company-mode -1))))
(add-hook 'reftex-toc-mode-hook (
"bibtex"
(with-eval-after-load
(add-hook 'bibtex-mode-hooklambda ()
("\M-q" 'bibtex-fill-entry)))))
(define-key bibtex-mode-map
This allows you to search your BibTeX files for references to insert into the current document. For it to work you will need to set `bibtex-completion-bibliography` to the location of your BibTeX files.
Initiate a citation search with ivy-bibtex
, bound to C-c r
.
See https://github.com/tmalsburg/helm-bibtex for information about reading attached .pdf files, searching online bibliography sources and more.
setq ivy-bibtex-default-action 'ivy-bibtex-insert-citation)
("C-c r") 'ivy-bibtex) (global-set-key (kbd
Org mode is a powerful markup-language native to Emacs. It can be compared to markdown, but it has many more features. I use it for note taking a preparing lecture materials, but people use it for all kinds of things, from TODO lists to project planning to authoring academic papers. The settings below try to make Org mode play nicely with other packages, and enable many of the literate programming features. More information about Org mode can be found at http://orgmode.org.
"org"
(with-eval-after-load setq org-replace-disputed-keys t
(t)
org-support-shift-select setf (alist-get ':eval org-babel-default-header-args) "never-export"
("both")
(alist-get ':exports org-babel-default-header-args) ;; (setq org-startup-indented t)
;; increase imenu depth to include third level headings
setq org-imenu-depth 3)
(;; Set sensible mode for editing dot files
"dot" . graphviz-dot))
(add-to-list 'org-src-lang-modes '(;; Update images from babel code blocks automatically
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images);; configure org-mode when opening first org-mode file
;; Load additional export formats
require 'ox-ascii)
(require 'ox-md)
(require 'ox-html)
(require 'ox-latex)
(require 'ox-odt)
(when (executable-find "pandoc")
(require 'ox-pandoc))
(
require 'org-capture)
(require 'org-protocol)
(
;; Enable common programming language support in org-mode
require 'ob-shell)
(require 'ob-emacs-lisp)
(require 'ob-org)
(require 'ob-R)
(when (executable-find "python") (require 'ob-python))
(when (executable-find "matlab") (require 'ob-matlab))
(when (executable-find "octave") (require 'ob-octave))
(when (executable-find "perl") (require 'ob-perl))
(when (executable-find "dot") (require 'ob-dot))
(when (executable-find "ghci") (require 'ob-haskell))
(when (executable-find "ditaa") (require 'ob-ditaa))
(
;; Fontify code blocks in org-mode
setq org-src-fontify-natively t)
(setq org-src-tab-acts-natively t)
(setq org-confirm-babel-evaluate nil))
(
Emacs uses different modes for different kinds of files and buffers. This is what makes is possible to have one set of behaviors when editing LaTeX, and a different set of behaviors when writing R code. But what if we want to do both, in the same file? Then we need to have multiple modes, in the same buffer, and we can thanks to polymode.
;;; polymode
;; (require 'polymode)
;; (require 'poly-R)
;; (with-eval-after-load "markdown"
;; (require 'poly-markdown))
;; (with-eval-after-load "org"
;; (require 'poly-org))
Not everyone wants to read email in Emacs, but you can if you want. The settings below configure some basic things, but you will need additional configuration to set up your email accounts. See the mue4 manual and example configurations for details.
when (executable-find "mu")
("mu4e" "Read your mail." t)
(autoload 'mu4e "mu4e"
(with-eval-after-load require 'mu4e)
(require 'mu4e-headers)
(setq mu4e-headers-include-related t
(nil
mu4e-headers-show-threads t
mu4e-headers-skip-duplicates ;; don't keep message buffers around
t
message-kill-buffer-on-exit ;; enable notifications
t
mu4e-enable-mode-line
mu4e-headers-fields '(12)
(:human-date . 6)
(:flags . ;; (:mailing-list . 10)
22)
(:from-or-to .
(:subject)));; ;; use org for composing rich text emails
;; (require 'org-mu4e)
;; (setq org-mu4e-convert-to-html t)
;; (define-key mu4e-headers-mode-map (kbd "C-c c") 'org-mu4e-store-and-capture)
;; (define-key mu4e-view-mode-map (kbd "C-c c") 'org-mu4e-store-and-capture)
;;
;; rerender html
require 'mu4e-contrib)
(setq mu4e-html2text-command 'mu4e-shr2text)
( (add-hook 'mu4e-view-mode-hook 'visual-line-mode)))
Emacs makes a decent file browser, we just need to tweak a few things to make it nicer. In particular you can open files in an external program using the E
key.
;;; Dired configuration
(add-hook 'dired-mode-hook lambda()
(
(diff-hl-dired-mode)
(diff-hl-margin-mode)))
;; show details by default
setq diredp-hide-details-initially-flag nil)
(
;; set dired listing options
if (eq system-type 'gnu/linux)
(setq dired-listing-switches "-alDhp"))
(
;; make sure dired buffers end in a slash so we can identify them easily
defun ensure-buffer-name-ends-in-slash ()
("change buffer name to end with slash"
let ((name (buffer-name)))
(if (not (string-match "/$" name))
("/") t))))
(rename-buffer (concat name
(add-hook 'dired-mode-hook 'ensure-buffer-name-ends-in-slash)
(add-hook 'dired-mode-hooklambda()
(setq truncate-lines 1)))
(
;; open files in external programs
;; (from http://ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html
;; consider replacing with https://github.com/thamer/runner
defun xah-open-in-external-app (&optional file)
("Open the current file or dired marked files in external app.
The app is chosen from your OS's preference."
(interactive)let (doIt
(
(myFileListcond
(string-equal major-mode "dired-mode")
((
(dired-get-marked-files))not file) (list (buffer-file-name)))
((list file)))))
(file (setq doIt (if (<= (length myFileList) 5)
(t
y-or-n-p "Open more than 5 files? ")))
(when doIt
(cond
(string-equal system-type "windows-nt")
((mapc
(lambda (fPath)
("open" (replace-regexp-in-string "/" "\\" fPath t t)))
(w32-shell-execute
myFileList))string-equal system-type "darwin")
((mapc
(lambda (fPath)
(format "open \"%s\"" fPath)))
(shell-command (
myFileList))string-equal system-type "gnu/linux")
((mapc
(lambda (fPath)
(let ((process-connection-type nil))
("" nil "xdg-open" fPath))) myFileList))))))
(start-process ;; use zip/unzip to compress/uncompress zip archives
"dired-aux"
(with-eval-after-load
(add-to-list 'dired-compress-file-suffixes "\\.zip\\'" "" "unzip"))
'(;; open files from dired with "E"
"E") 'xah-open-in-external-app)) (define-key dired-mode-map (kbd
"git-commit"
(with-eval-after-load require 'magit)) (
There are several different shells available in Emacs by default. In addition multi-term
is available to give you a nicer way of running your default shell in Emacs. Convenience functions are enabled to set your EDITOR variable so that Emacs will be used as your editor when running shell commands inside Emacs.
;; term
"term"
(with-eval-after-load "C-j") 'term-char-mode)
(define-key term-mode-map (kbd "C-j") 'term-line-mode)
(define-key term-raw-map (kbd require 'with-editor)
(when (executable-find "git") (require 'git-commit))
(t)
(shell-command-with-editor-mode
(add-hook 'term-mode-hooklambda ()
(1))))
(toggle-truncate-lines
;; multi-term
defun terminal ()
("Create new term buffer.
Will prompt you shell name when you type `C-u' before this command."
(interactive)require 'multi-term)
(let (term-buffer)
(;; Set buffer.
setq term-buffer (multi-term-get-buffer current-prefix-arg))
(setq multi-term-buffer-list (nconc multi-term-buffer-list (list term-buffer)))
(
(set-buffer term-buffer);; Internal handle for `multi-term' buffer.
(multi-term-internal);;(with-editor-export-editor)
;;(with-editor-export-git-editor)
(call-interactively 'comint-clear-buffer);; Switch buffer
;;(display-buffer term-buffer t)
(pop-to-buffer term-buffer)
))
"multi-term"
(with-eval-after-load "C-j") 'term-char-mode)
(define-key term-mode-map (kbd "C-j") 'term-line-mode)
(define-key term-raw-map (kbd require 'with-editor)
(when (executable-find "git") (require 'git-commit))
(setq multi-term-switch-after-close nil)
(t))
(shell-command-with-editor-mode
;; shell
"sh-script"
(with-eval-after-load require 'essh) ; if not done elsewhere; essh is in the local lisp folder
(require 'eval-in-repl-shell)
("\C-c\C-c" 'eir-eval-in-shell)
(define-key sh-mode-map "<C-return>") 'eir-eval-in-shell)
(define-key sh-mode-map (kbd "<C-S-return>") 'executable-interpret))
(define-key sh-mode-map (kbd "shell"
(with-eval-after-load require 'with-editor)
(when (executable-find "git") (require 'git-commit))
(t))
(shell-command-with-editor-mode
"eshell"
(with-eval-after-load require 'with-editor)
(when (executable-find "git") (require 'git-commit))
(t))
(shell-command-with-editor-mode
;; Automatically adjust output width in commint buffers
;; from http://stackoverflow.com/questions/7987494/emacs-shell-mode-display-is-too-wide-after-splitting-window
defun comint-fix-window-size ()
("Change process window size."
when (derived-mode-p 'comint-mode)
(let ((process (get-buffer-process (current-buffer))))
(unless (eq nil process)
(
(set-process-window-size process (window-height) (window-width))))))
defun my-shell-mode-hook ()
(;; add this hook as buffer local, so it runs once per window.
nil t))
(add-hook 'window-configuration-change-hook 'comint-fix-window-size
(add-hook 'shell-mode-hooklambda()
(;; add this hook as buffer local, so it runs once per window.
nil t)))
(add-hook 'window-configuration-change-hook 'comint-fix-window-size
;; Use emacs as editor when running external processes or using shells in emacs
when (and (string-match-p "remacs" (prin1-to-string (frame-list)))
("remacsclient"))
(executable-find setq with-editor-emacsclient-executable (executable-find "remacsclient")))
(
;; (add-hook 'shell-mode-hook
;; (lambda()
;; (with-editor-export-editor)
;; (with-editor-export-git-editor)
;; ;;(sleep-for 0.5) ; this is bad, but thinking hurts and it works.
;; (call-interactively 'comint-clear-buffer)))
;; (add-hook 'term-exec-hook
;; (lambda()
;; (with-editor-export-editor)
;; (with-editor-export-git-editor)
;; (call-interactively 'comint-clear-buffer)
;; ;; (term-send-return)
;; ;; (term-send-return)
;; ;; (term-send-return)
;; ;; (call-interactively 'comint-clear-buffer)
;; ))
(add-hook 'eshell-mode-hooklambda()
(;; programs that don't work well in eshell and should be run in visual mode
"ssh")
(add-to-list 'eshell-visual-commands "tail")
(add-to-list 'eshell-visual-commands "htop")
(add-to-list 'eshell-visual-commands ;; git editor support
;; (with-editor-export-editor)
;;(with-editor-export-git-editor)
))
Emacs built-in sql mode is good, just needs a little tweak to work with MariaDB
;; from https://unix.stackexchange.com/questions/233518/mariadb-client-has-no-prompt-in-emacs-sql-mode
"sql"
(with-eval-after-load "^\\(MariaDB\\|MySQL\\) \\[[_a-zA-Z()]*\\]> ")) (sql-set-product-feature 'mysql :prompt-regexp
This Emacs configuration sets up lots of packages and configures a number of keybindings. To add our own customizations, place them in ~/.emacs.d/custom.el
. This file will be sourced last, so you always have the ability to override any settings provided here.
;; save settings made using the customize interface to a sparate file
setq custom-file (concat user-emacs-directory "custom.el"))
(unless (file-exists-p custom-file)
(";; Put your personal user configuration in this file.
(write-region
;; To require addional packages add them to 'package-selected-packages, e.g.
;; (add-to-list 'package-selected-packages 'ess)
;; will ensure that the ess package is installed the next time Emacs starts.
;; Don't remove this:
(unless (cl-every 'package-installed-p package-selected-packages)
(package-refresh-contents)
(package-install-selected-packages))
" nil custom-file))
load custom-file 'noerror)
(
;; start with untitled new buffer
(add-hook 'after-init-hooklambda()
(setq inhibit-startup-screen t) ;; yes, we really want to do this!
(
(delete-other-windows)
(untitled-new-buffer-with-select-major-mode 'text-mode)))
setq untitled-new-buffer-major-modes '(text-mode python-mode r-mode markdown-mode LaTeX-mode emacs-lisp-mode))
(;; Change default buffer name.
setq untitled-new-buffer-default-name "*Untitled*")
(
;; make sure emacs doesn't mess with our package list.
defun
( package--save-selected-packages (&rest opt) nil)
unless (cl-every 'package-installed-p package-selected-packages)
(
(package-refresh-contents)
(package-install-selected-packages))
(package-autoremove)
;; Start the server if it is not already running
require 'server)
(unless (server-running-p) (server-start)) (
That's all folks, report any bugs or feature requests at https://github.com/IQSS/IQSS.emacs.