My Emacs Configuration
- Good emacs configuration
- Good articles
- Emacs on Windows10
- Emacs on Mac OSX
- Indentation for Lisp and Elisp
- Terminal setup
- Font
- Latex
- R
- JavaScript
- Org
- C/C++ related
- Python related
- Troubleshootings
- Keybindings behave different from GUI in pure text terminal
- Copy and Paste from clipboard
- Font is not set in terminal
- Error loading autoloads: (epg-error no usable configuration OpenPGP)
- Apt install error: ument
- Cannot open load file: No such file or directories, adaptive-wrap
- DOING Network: make client process failed: Connection refused
- DOING Chinese characters could not be displayed properly
- Font missing
- DONE org-latex-preview failed with errror: Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’
Good emacs configuration
- Purcell’s emacs.d
- Chen Bin’s Emacs configuration
- seagle0128 – Vincent Zhang
- John’s Emacs Config
- Ladicle’s Emacs Configuration
- Aaron Bedra’s Emacs 26 Configuration
- Sacha Chua’s Emacs configuration
- a different way to organize configuration files
- jerryhsieh/Emacs-config
- Justin Abrahms
Good articles
- A Life Configuring Emacs
- Emacs org-mode examples and cookbook
- A Life Configuring Emacs
- GETTING STARTED WITH USE-PACKAGE
- Emacs mini manual series
Emacs on Windows10
Set terminal in Windows10 (for GitBash and msys2)
refs
- Configure Msys’s default size, color, and font
- Right click on the title bar at the top of the shell window and select “Options”
- Setup SSH Authentication for Git Bash on Windows
Edit
.bash_profile
in home directory:alias ll="ls -la" alias ls='ls --color' ############## ### Basics ### ############## # Don't wait for job termination notification set -o notify # Enables UTF-8 in Putty. # See http://www.earth.li/~huggie/blog/tech/mobile/putty-utf-8-trick.html echo -ne '\e%G\e[?47h\e%G\e[?47l' # My pretty prompt (Yay!) PS1='\[\e[32;40m\]\u\[\e[0m\]\[\e[34;40m\]\H\[\e[0m\]\[\e[40;1m\]\w\[\e[0m\] ' # Start SSH Agent #---------------------------- SSH_ENV="$HOME/.ssh/environment" function run_ssh_env { . "${SSH_ENV}" > /dev/null } function start_ssh_agent { echo "Initializing new SSH agent..." ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" echo "succeeded" chmod 600 "${SSH_ENV}" run_ssh_env; ssh-add ~/.ssh/id_rsa; } if [ -f "${SSH_ENV}" ]; then run_ssh_env; ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { start_ssh_agent; } else start_ssh_agent; fi
To generate ssh-key pairs
ssh-keygen -t rsa -C "hyperion_z@outlook.com"
After installing git for windows (it also contains ssh), configure git global info
git config --global user.name "zwpdbh" git config --global user.email "hyperion_z@outlook.com" # To set repository-specific username/email configuration: # 1. From the command line, change into the repository directory. # 2. git config user.name "FIRST_NAME LAST_NAME" # 3. git config user.email "MY_NAME@example.com" # 4. Verify it: cat .git/config
Install Emacs
- Install Emacs from Index of /gnu/emacs/pretest/windows
- Edit system environment variables for Windows10
- add “C:\Program Files\Emacs\x86_64\bin” into path variable
- Now, you should run
emacs &
from gitbash.
(optional) Emacs in WSL
enable ssh
- edit
/etc/ssh/sshd_config
- change
PassworldAuthentication
to yes - change connection port from 22 to 2222
- change
- restart sshd
service ssh status
check sshd statussudo service ssh --full-restart
- If you meet error: sshd: no hostkeys available – exiting.
Run:
/usr/bin/ssh-keygen -A
- If you meet error: sshd: no hostkeys available – exiting.
Run:
- In case meet error: “could not load host key”
- run
ssh-keygen -A
- run
- Automatically start ssh server on boot on Windows Subsystem for Linux
- edit
use MobaXterm to connect
- address: 127.0.0.1
- port: 2222
make emacsclient use our defined emacs theme, edit
~/.bashrc
# set a fancy prompt (non-color, unless we know we "want" color) # case "$TERM" in # xterm-color|*-256color) color_prompt=yes;; # esac export TERM=xterm-256color
To start emacs without GUI, run
emacs -nw
Blurry problem for Emacs GUi via MobaXterm
- right click mobaxterm executable or shortcut
- change high DPI settings
- in section High DPI scaling override
- select
application
from dropdown list
Avoid Git username and password
- ref: How do I avoid the specification of the username and password at every git push?
- copy the content of
/home/zw/.ssh/id_rsa.pub
to GitHub settings/SSH-Keys - make sure the git remote is using ssh instead of https
Use native browser in Windows10
- Delete ubuntu firefox:
sudo apt remove firefox
.
- Delete ubuntu firefox:
sometimes, you need to run docker inside WSL, see: setting up docker for windows and wsl
Install and run docker desktop for windows10 (as server)
Add the following setting
### for let linux system use remote, our pc docker server export DOCKER_HOST=tcp://localhost:2375 export DOCKER_HOST=tcp://127.0.0.1:2375
(optional) Emacs in msys2
pacman -Syu
pacman -Su base-devel
pacman -Su mingw-w64-x86_64-toolchain
pacman -Su mingw-w64-x86_64-gcc
pacman -Su mingw-w64-x86_64-cmake
pacman -Su make
# install Emacs dependencies
pacman -Su mingw-w64-x86_64-ctags mingw-w64-x86_64-zlib mingw-w64-x86_64-xpm-nox mingw-w64-x86_64-gnutls mingw-w64-x86_64-libwinpthread
# install Emacs optional dependencies
pacman -Su mingw-w64-x86_64-giflib mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-libpng mingw-w64-x86_64-librsvg mingw-w64-x86_64-libtiff mingw-w64-x86_64-imagemagick mingw-w64-x86_64-libxml2 mingw-w64-x86_64-librsvg mingw-w64-x86_64-graphviz
# install Emacs
pacman -Su mingw-w64-x86_64-emacs
Emacs on Mac OSX
steps to install latest Emacs on OSX via brew
brew tap daviderestivo/emacs-head brew install emacs-head --HEAD --with-cocoa
Indentation for Lisp and Elisp
When defmacro, we could customize how it will be indented:
(defmacro lispy-save-excursion (&rest body) "More intuitive (`save-excursion' BODY)." (declare (indent 0)) `(let ((out (save-excursion ,@body))) (when (bolp) (back-to-indentation)) out))
Terminal setup
Emacs in Microsoft Windows
Set terminal env
# for WSL, running docker
# see: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
export PATH="$PATH:$HOME/.local/bin"
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
### set my terminial configuration
alias ll="ls -la"
alias ls='ls --color'
# export TERM=xterm-color
export TERM=xterm-256color
export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
export COLOR_NC='\e[0m' # No Color
export COLOR_WHITE='\e[1;37m'
export COLOR_BLACK='\e[0;30m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_GRAY='\e[0;30m'
export COLOR_LIGHT_GRAY='\e[0;37m'
### end of terminal configuration
### for let linux system use remote, our pc docker server
export DOCKER_HOST=tcp://localhost:2375
export DOCKER_HOST=tcp://127.0.0.1:2375
### setup path for go
export PATH=$PATH:/usr/local/go/bin
- add the above content into ~/.bashrc
Setup zsh
Font
- source code pro
- git clone the repo and copy those .ttf file font files into your font directory (for ubuntu, it is ~/.fonts/)
- ref: How to use the Adobe Source Code Pro font?
- Patched fonts for Powerline users (including multiple font, easy install)
- Office code pro
- Hack
- All-the-icons
- It is used to enhance Emacs’s icons.
- To manually install it:
- On Ubuntu, copy the all the files from fonts folder from project into
/.local/share/fonts/
. - On Windows, double click those font files to install.
- After installation, restart Emacs.
- On Ubuntu, copy the all the files from fonts folder from project into
Latex
- ref: LaTeX vs. MiKTeX: The levels of TeX
- ref: Setting up Latex with Emacs
- ref: LaTeX Source Code Blocks in Org Mode
- ref: Emacs Academic Tools
- ref: Nasseralkmim’s Latex environment
- Two components
- AUCTeX
- for writing and formatting TeX files in Emacs
- provides syntax highlighting, smart indentation and formatting, previews of mathematics and other elements directly in the editing buffer
- Tex typesetting system
- TeX Live is a cross-platform, free software distribution for the TeX typesetting system that includes major TeX-related programs, macro packages, and fonts.
- Or, MiKTeX is a free distribution of the TeX/LaTeX typesetting system for Microsoft Windows.
- AUCTeX
DONE Render LaTeX fragments in Org-mode
ref: 11.8 Embedded LaTeX
ref: Preview LaTeX in org-mode
(defun krofna-hack () (when (looking-back (rx "$ ")) (save-excursion (backward-char 1) (org-toggle-latex-fragment)))) (add-hook 'org-mode-hook (lambda () (org-cdlatex-mode) (add-hook 'post-self-insert-hook #'krofna-hack 'append 'local)))
Test \[e^{\pi i }=-1\]
DOING Org-babel
R
JavaScript
Org
- ref: Use Org-Mode Links for Absolutely Anything
- a very good example how to set org-mode: Another Org-Mode Configuration
- Defining Custom Task Workflows With Emacs Org-Mode
- Beautifying Org Mode in Emacs
- Emacs org-mode examples and cookbook
Use emacs to create blog sites
Examples of website created from Emacs’s org-mode
Different staitc site generators with org
Org-mode to GitHub pages with Jekyll
Org file to blog using: Hugo, ox-hugo and Netlify
C/C++ related
- Emacs as C++ IDE
- Emacs as a C++ IDE
- https://ddavis.io/
- 使用cquery:C++ language server
- tuhdo’s C/C++ Development Environment for Emacs
- Supplement to Tudho’s C/C++ Development Enivornment for Emacs Guide
Python related
Troubleshootings
Keybindings behave different from GUI in pure text terminal
- ref: Using Emacs as a daemon (emacsclient) exhibiting weird behavior
- ref: How do I get my .emacs init files to load correctly with emacs server?
- ref: Emacs: How to Bind Super Hyper Keys
Copy and Paste from clipboard
- ref: Emacs through terminal and clipboard.
- ref: simpleclip
- use
xclip
Font is not set in terminal
- In terminal, font is controlled by the terminal app. So, go to the terminal app’s option and change it to use installed font.
Error loading autoloads: (epg-error no usable configuration OpenPGP)
- Emacs’ version: Emacs26.3 in MSYS2
- reproduce this error:
Meta-x epa-list-keys
- solution
install missing package
pacman -Su gnupg
setup windows exec-path correctly
set epg-pgp-program
(custom-set-variables '(epg-gpg-program "/usr/local/bin/gpg2"))
Apt install error: ument
- description
When try to fix it with
sudo apt install -f
, following errors show updpkg: error processing archive /var/cache/apt/archives/emacs25-common_25.3~2.gitc09215a-kk1+18.04_all.deb (--unpack): trying to overwrite '/usr/share/emacs/site-lisp/subdirs.el', which is also in package emacs26-common 26.3~1.git96dd019-kk1+18.04 dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) Errors were encountered while processing: /var/cache/apt/archives/emacs25-common_25.3~2.gitc09215a-kk1+18.04_all.deb
- Solution
ref: apt-get -f install fails with emacs25 conflict with emacs26
run the following commands to solve it
sudo dpkg -i --force-all /var/cache/apt/archives/emacs25-common_25.3~2.gitc09215a-kk1+18.04_all.deb sudo apt install -f
Cannot open load file: No such file or directories, adaptive-wrap
- Description
- can not do further operation, even open file or switch buffer
- Solution
- delete use-package and re-install use-package
DOING Network: make client process failed: Connection refused
Description
Contacting host: raw.githubusercontent.com:443 open-network-stream: make client process failed: Connection refused, :name, raw.githubusercontent.com, :buffer, #<killed buffer>, :host, raw.githubusercontent.com, :service, 443, :nowait, nil, :tls-parameters, nil
- When I run
M-x all-the-icons-install-fonts
. The above shows in message and font is not downloaded.
- When I run
Solution
DOING Chinese characters could not be displayed properly
Install Chinese language support on Ubuntu
sudo apt-get install language-pack-zh* sudo apt-get install chinese*
Font missing
- Description
There is a missfont.log
mktextfm ecrm1000
- Probably is caused by latex/tex feature.
- Solution
On Ubuntu
sudo apt-get install texlive-fonts-recommended
DONE org-latex-preview failed with errror: Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’
- Description
For preview latex in org-mode, such as: \[e^{\pi i }=-1\] (Run: C-c C-x C-l which is org-latex-preview), show error message
Creating LaTeX preview... org-compile-file: File "/tmp/orgtexHB1HLg.dvi" wasn’t produced. Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’.
- Solution
Install LaTex for Linux, TexLive
sudo apt install texlive-xetex
In Emacs configuration
(setq org-latex-compiler "xelatex")
- Test \[e^{\pi i }=-1\]